* config/tc-ppc.c (ppc_csect): An unnamed csect is storage class
[deliverable/binutils-gdb.git] / gas / config / tc-ppc.c
1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include <stdio.h>
22 #include <ctype.h>
23 #include "as.h"
24 #include "subsegs.h"
25
26 #include "opcode/ppc.h"
27
28 #ifdef OBJ_ELF
29 #include "elf/ppc.h"
30 #endif
31
32 #ifdef TE_PE
33 #include "coff/pe.h"
34 #endif
35
36 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
37
38 /* Tell the main code what the endianness is. */
39 extern int target_big_endian;
40
41 /* Whether or not, we've set target_big_endian. */
42 static int set_target_endian = 0;
43
44 static void ppc_set_cpu PARAMS ((void));
45 static unsigned long ppc_insert_operand
46 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
47 offsetT val, char *file, unsigned int line));
48 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
49 static void ppc_byte PARAMS ((int));
50 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
51 static void ppc_tc PARAMS ((int));
52
53 #ifdef OBJ_XCOFF
54 static void ppc_comm PARAMS ((int));
55 static void ppc_bb PARAMS ((int));
56 static void ppc_bc PARAMS ((int));
57 static void ppc_bf PARAMS ((int));
58 static void ppc_biei PARAMS ((int));
59 static void ppc_bs PARAMS ((int));
60 static void ppc_eb PARAMS ((int));
61 static void ppc_ec PARAMS ((int));
62 static void ppc_ef PARAMS ((int));
63 static void ppc_es PARAMS ((int));
64 static void ppc_csect PARAMS ((int));
65 static void ppc_change_csect PARAMS ((symbolS *));
66 static void ppc_function PARAMS ((int));
67 static void ppc_extern PARAMS ((int));
68 static void ppc_lglobl PARAMS ((int));
69 static void ppc_section PARAMS ((int));
70 static void ppc_stabx PARAMS ((int));
71 static void ppc_rename PARAMS ((int));
72 static void ppc_toc PARAMS ((int));
73 #endif
74
75 #ifdef OBJ_ELF
76 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **));
77 static void ppc_elf_cons PARAMS ((int));
78 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
79 #endif
80
81 #ifdef TE_PE
82 static void ppc_set_current_section PARAMS ((segT));
83 static void ppc_previous PARAMS ((int));
84 static void ppc_pdata PARAMS ((int));
85 static void ppc_ydata PARAMS ((int));
86 static void ppc_reldata PARAMS ((int));
87 static void ppc_rdata PARAMS ((int));
88 static void ppc_ualong PARAMS ((int));
89 static void ppc_znop PARAMS ((int));
90 static void ppc_pe_comm PARAMS ((int));
91 static void ppc_pe_section PARAMS ((int));
92 static void ppc_pe_function PARAMS ((int));
93 static void ppc_pe_tocd PARAMS ((int));
94 #endif
95 \f
96 /* Generic assembler global variables which must be defined by all
97 targets. */
98
99 /* Characters which always start a comment. */
100 const char comment_chars[] = "#";
101
102 /* Characters which start a comment at the beginning of a line. */
103 const char line_comment_chars[] = "#";
104
105 /* Characters which may be used to separate multiple commands on a
106 single line. */
107 const char line_separator_chars[] = ";";
108
109 /* Characters which are used to indicate an exponent in a floating
110 point number. */
111 const char EXP_CHARS[] = "eE";
112
113 /* Characters which mean that a number is a floating point constant,
114 as in 0d1.0. */
115 const char FLT_CHARS[] = "dD";
116 \f
117 /* The target specific pseudo-ops which we support. */
118
119 const pseudo_typeS md_pseudo_table[] =
120 {
121 /* Pseudo-ops which must be overridden. */
122 { "byte", ppc_byte, 0 },
123
124 #ifdef OBJ_XCOFF
125 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
126 legitimately belong in the obj-*.c file. However, XCOFF is based
127 on COFF, and is only implemented for the RS/6000. We just use
128 obj-coff.c, and add what we need here. */
129 { "comm", ppc_comm, 0 },
130 { "lcomm", ppc_comm, 1 },
131 { "bb", ppc_bb, 0 },
132 { "bc", ppc_bc, 0 },
133 { "bf", ppc_bf, 0 },
134 { "bi", ppc_biei, 0 },
135 { "bs", ppc_bs, 0 },
136 { "csect", ppc_csect, 0 },
137 { "data", ppc_section, 'd' },
138 { "eb", ppc_eb, 0 },
139 { "ec", ppc_ec, 0 },
140 { "ef", ppc_ef, 0 },
141 { "ei", ppc_biei, 1 },
142 { "es", ppc_es, 0 },
143 { "extern", ppc_extern, 0 },
144 { "function", ppc_function, 0 },
145 { "lglobl", ppc_lglobl, 0 },
146 { "rename", ppc_rename, 0 },
147 { "stabx", ppc_stabx, 0 },
148 { "text", ppc_section, 't' },
149 { "toc", ppc_toc, 0 },
150 #endif
151
152 #ifdef OBJ_ELF
153 { "long", ppc_elf_cons, 4 },
154 { "word", ppc_elf_cons, 2 },
155 { "short", ppc_elf_cons, 2 },
156 #endif
157
158 #ifdef TE_PE
159 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
160 { "previous", ppc_previous, 0 },
161 { "pdata", ppc_pdata, 0 },
162 { "ydata", ppc_ydata, 0 },
163 { "reldata", ppc_reldata, 0 },
164 { "rdata", ppc_rdata, 0 },
165 { "ualong", ppc_ualong, 0 },
166 { "znop", ppc_znop, 0 },
167 { "comm", ppc_pe_comm, 0 },
168 { "lcomm", ppc_pe_comm, 1 },
169 { "section", ppc_pe_section, 0 },
170 { "function", ppc_pe_function,0 },
171 { "tocd", ppc_pe_tocd, 0 },
172 #endif
173
174 /* This pseudo-op is used even when not generating XCOFF output. */
175 { "tc", ppc_tc, 0 },
176
177 { NULL, NULL, 0 }
178 };
179
180 \f
181 #ifdef TE_PE
182 /* The Windows NT PowerPC assembler uses predefined names. */
183
184 /* In general, there are lots of them, in an attempt to be compatible */
185 /* with a number of other Windows NT assemblers. */
186
187 /* Structure to hold information about predefined registers. */
188 struct pd_reg
189 {
190 char *name;
191 int value;
192 };
193
194 /* List of registers that are pre-defined:
195
196 Each general register has predefined names of the form:
197 1. r<reg_num> which has the value <reg_num>.
198 2. r.<reg_num> which has the value <reg_num>.
199
200
201 Each floating point register has predefined names of the form:
202 1. f<reg_num> which has the value <reg_num>.
203 2. f.<reg_num> which has the value <reg_num>.
204
205 Each condition register has predefined names of the form:
206 1. cr<reg_num> which has the value <reg_num>.
207 2. cr.<reg_num> which has the value <reg_num>.
208
209 There are individual registers as well:
210 sp or r.sp has the value 1
211 rtoc or r.toc has the value 2
212 fpscr has the value 0
213 xer has the value 1
214 lr has the value 8
215 ctr has the value 9
216 pmr has the value 0
217 dar has the value 19
218 dsisr has the value 18
219 dec has the value 22
220 sdr1 has the value 25
221 srr0 has the value 26
222 srr1 has the value 27
223
224 The table is sorted. Suitable for searching by a binary search. */
225
226 static const struct pd_reg pre_defined_registers[] =
227 {
228 { "cr.0", 0 }, /* Condition Registers */
229 { "cr.1", 1 },
230 { "cr.2", 2 },
231 { "cr.3", 3 },
232 { "cr.4", 4 },
233 { "cr.5", 5 },
234 { "cr.6", 6 },
235 { "cr.7", 7 },
236
237 { "cr0", 0 },
238 { "cr1", 1 },
239 { "cr2", 2 },
240 { "cr3", 3 },
241 { "cr4", 4 },
242 { "cr5", 5 },
243 { "cr6", 6 },
244 { "cr7", 7 },
245
246 { "ctr", 9 },
247
248 { "dar", 19 }, /* Data Access Register */
249 { "dec", 22 }, /* Decrementer */
250 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
251
252 { "f.0", 0 }, /* Floating point registers */
253 { "f.1", 1 },
254 { "f.10", 10 },
255 { "f.11", 11 },
256 { "f.12", 12 },
257 { "f.13", 13 },
258 { "f.14", 14 },
259 { "f.15", 15 },
260 { "f.16", 16 },
261 { "f.17", 17 },
262 { "f.18", 18 },
263 { "f.19", 19 },
264 { "f.2", 2 },
265 { "f.20", 20 },
266 { "f.21", 21 },
267 { "f.22", 22 },
268 { "f.23", 23 },
269 { "f.24", 24 },
270 { "f.25", 25 },
271 { "f.26", 26 },
272 { "f.27", 27 },
273 { "f.28", 28 },
274 { "f.29", 29 },
275 { "f.3", 3 },
276 { "f.30", 30 },
277 { "f.31", 31 },
278 { "f.4", 4 },
279 { "f.5", 5 },
280 { "f.6", 6 },
281 { "f.7", 7 },
282 { "f.8", 8 },
283 { "f.9", 9 },
284
285 { "f0", 0 },
286 { "f1", 1 },
287 { "f10", 10 },
288 { "f11", 11 },
289 { "f12", 12 },
290 { "f13", 13 },
291 { "f14", 14 },
292 { "f15", 15 },
293 { "f16", 16 },
294 { "f17", 17 },
295 { "f18", 18 },
296 { "f19", 19 },
297 { "f2", 2 },
298 { "f20", 20 },
299 { "f21", 21 },
300 { "f22", 22 },
301 { "f23", 23 },
302 { "f24", 24 },
303 { "f25", 25 },
304 { "f26", 26 },
305 { "f27", 27 },
306 { "f28", 28 },
307 { "f29", 29 },
308 { "f3", 3 },
309 { "f30", 30 },
310 { "f31", 31 },
311 { "f4", 4 },
312 { "f5", 5 },
313 { "f6", 6 },
314 { "f7", 7 },
315 { "f8", 8 },
316 { "f9", 9 },
317
318 { "fpscr", 0 },
319
320 { "lr", 8 }, /* Link Register */
321
322 { "pmr", 0 },
323
324 { "r.0", 0 }, /* General Purpose Registers */
325 { "r.1", 1 },
326 { "r.10", 10 },
327 { "r.11", 11 },
328 { "r.12", 12 },
329 { "r.13", 13 },
330 { "r.14", 14 },
331 { "r.15", 15 },
332 { "r.16", 16 },
333 { "r.17", 17 },
334 { "r.18", 18 },
335 { "r.19", 19 },
336 { "r.2", 2 },
337 { "r.20", 20 },
338 { "r.21", 21 },
339 { "r.22", 22 },
340 { "r.23", 23 },
341 { "r.24", 24 },
342 { "r.25", 25 },
343 { "r.26", 26 },
344 { "r.27", 27 },
345 { "r.28", 28 },
346 { "r.29", 29 },
347 { "r.3", 3 },
348 { "r.30", 30 },
349 { "r.31", 31 },
350 { "r.4", 4 },
351 { "r.5", 5 },
352 { "r.6", 6 },
353 { "r.7", 7 },
354 { "r.8", 8 },
355 { "r.9", 9 },
356
357 { "r.sp", 1 }, /* Stack Pointer */
358
359 { "r.toc", 2 }, /* Pointer to the table of contents */
360
361 { "r0", 0 }, /* More general purpose registers */
362 { "r1", 1 },
363 { "r10", 10 },
364 { "r11", 11 },
365 { "r12", 12 },
366 { "r13", 13 },
367 { "r14", 14 },
368 { "r15", 15 },
369 { "r16", 16 },
370 { "r17", 17 },
371 { "r18", 18 },
372 { "r19", 19 },
373 { "r2", 2 },
374 { "r20", 20 },
375 { "r21", 21 },
376 { "r22", 22 },
377 { "r23", 23 },
378 { "r24", 24 },
379 { "r25", 25 },
380 { "r26", 26 },
381 { "r27", 27 },
382 { "r28", 28 },
383 { "r29", 29 },
384 { "r3", 3 },
385 { "r30", 30 },
386 { "r31", 31 },
387 { "r4", 4 },
388 { "r5", 5 },
389 { "r6", 6 },
390 { "r7", 7 },
391 { "r8", 8 },
392 { "r9", 9 },
393
394 { "rtoc", 2 }, /* Table of contents */
395
396 { "sdr1", 25 }, /* Storage Description Register 1 */
397
398 { "sp", 1 },
399
400 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
401 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
402
403 { "xer", 1 },
404
405 };
406
407 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
408
409 /* Given NAME, find the register number associated with that name, return
410 the integer value associated with the given name or -1 on failure. */
411
412 static int reg_name_search PARAMS ( (char * name) );
413
414 static int
415 reg_name_search (name)
416 char *name;
417 {
418 int middle, low, high;
419 int cmp;
420
421 low = 0;
422 high = REG_NAME_CNT - 1;
423
424 do
425 {
426 middle = (low + high) / 2;
427 cmp = strcasecmp (name, pre_defined_registers[middle].name);
428 if (cmp < 0)
429 high = middle - 1;
430 else if (cmp > 0)
431 low = middle + 1;
432 else
433 return pre_defined_registers[middle].value;
434 }
435 while (low <= high);
436
437 return -1;
438 }
439
440 #endif
441
442 \f
443 /* Local variables. */
444
445 /* The type of processor we are assembling for. This is one or more
446 of the PPC_OPCODE flags defined in opcode/ppc.h. */
447 static int ppc_cpu = 0;
448
449 /* The size of the processor we are assembling for. This is either
450 PPC_OPCODE_32 or PPC_OPCODE_64. */
451 static int ppc_size = PPC_OPCODE_32;
452
453 /* Opcode hash table. */
454 static struct hash_control *ppc_hash;
455
456 /* Macro hash table. */
457 static struct hash_control *ppc_macro_hash;
458
459 #ifdef OBJ_ELF
460 /* Whether to warn about non PC relative relocations that aren't
461 in the .got2 section. */
462 static boolean mrelocatable = false;
463
464 /* Flags to set in the elf header */
465 static flagword ppc_flags = 0;
466 #endif
467
468 #ifdef OBJ_XCOFF
469
470 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
471 using a bunch of different sections. These assembler sections,
472 however, are all encompassed within the .text or .data sections of
473 the final output file. We handle this by using different
474 subsegments within these main segments. */
475
476 /* Next subsegment to allocate within the .text segment. */
477 static subsegT ppc_text_subsegment = 2;
478
479 /* Linked list of csects in the text section. */
480 static symbolS *ppc_text_csects;
481
482 /* Next subsegment to allocate within the .data segment. */
483 static subsegT ppc_data_subsegment = 2;
484
485 /* Linked list of csects in the data section. */
486 static symbolS *ppc_data_csects;
487
488 /* The current csect. */
489 static symbolS *ppc_current_csect;
490
491 /* The RS/6000 assembler uses a TOC which holds addresses of functions
492 and variables. Symbols are put in the TOC with the .tc pseudo-op.
493 A special relocation is used when accessing TOC entries. We handle
494 the TOC as a subsegment within the .data segment. We set it up if
495 we see a .toc pseudo-op, and save the csect symbol here. */
496 static symbolS *ppc_toc_csect;
497
498 /* The first frag in the TOC subsegment. */
499 static fragS *ppc_toc_frag;
500
501 /* The first frag in the first subsegment after the TOC in the .data
502 segment. NULL if there are no subsegments after the TOC. */
503 static fragS *ppc_after_toc_frag;
504
505 /* The current static block. */
506 static symbolS *ppc_current_block;
507
508 /* The COFF debugging section; set by md_begin. This is not the
509 .debug section, but is instead the secret BFD section which will
510 cause BFD to set the section number of a symbol to N_DEBUG. */
511 static asection *ppc_coff_debug_section;
512
513 #endif /* OBJ_XCOFF */
514
515 #ifdef TE_PE
516
517 /* Various sections that we need for PE coff support. */
518 static segT ydata_section;
519 static segT pdata_section;
520 static segT reldata_section;
521 static segT rdata_section;
522 static segT tocdata_section;
523
524 /* The current section and the previous section. See ppc_previous. */
525 static segT ppc_previous_section;
526 static segT ppc_current_section;
527
528 #endif /* TE_PE */
529
530 #ifdef OBJ_ELF
531 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
532 #endif /* OBJ_ELF */
533
534 #ifndef WORKING_DOT_WORD
535 const int md_short_jump_size = 4;
536 const int md_long_jump_size = 4;
537 #endif
538 \f
539 #ifdef OBJ_ELF
540 CONST char *md_shortopts = "um:VQ:";
541 #else
542 CONST char *md_shortopts = "um:";
543 #endif
544 struct option md_longopts[] = {
545 {NULL, no_argument, NULL, 0}
546 };
547 size_t md_longopts_size = sizeof(md_longopts);
548
549 int
550 md_parse_option (c, arg)
551 int c;
552 char *arg;
553 {
554 switch (c)
555 {
556 case 'u':
557 /* -u means that any undefined symbols should be treated as
558 external, which is the default for gas anyhow. */
559 break;
560
561 case 'm':
562 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
563 (RIOS2). */
564 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
565 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
566 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
567 else if (strcmp (arg, "pwr") == 0)
568 ppc_cpu = PPC_OPCODE_POWER;
569 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
570 instructions that are holdovers from the Power. */
571 else if (strcmp (arg, "601") == 0)
572 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
573 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
574 Motorola PowerPC 603/604. */
575 else if (strcmp (arg, "ppc") == 0
576 || strcmp (arg, "ppc32") == 0
577 || strcmp (arg, "403") == 0
578 || strcmp (arg, "603") == 0
579 || strcmp (arg, "604") == 0)
580 ppc_cpu = PPC_OPCODE_PPC;
581 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
582 620. */
583 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
584 {
585 ppc_cpu = PPC_OPCODE_PPC;
586 ppc_size = PPC_OPCODE_64;
587 }
588 /* -mcom means assemble for the common intersection between Power
589 and PowerPC. At present, we just allow the union, rather
590 than the intersection. */
591 else if (strcmp (arg, "com") == 0)
592 ppc_cpu = PPC_OPCODE_COMMON;
593 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
594 else if (strcmp (arg, "any") == 0)
595 ppc_cpu = PPC_OPCODE_ANY;
596
597 #ifdef OBJ_ELF
598 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
599 else if (strcmp (arg, "relocatable") == 0)
600 {
601 mrelocatable = true;
602 ppc_flags |= EF_PPC_RELOCATABLE;
603 }
604
605 else if (strcmp (arg, "relocatable-lib") == 0)
606 {
607 mrelocatable = true;
608 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
609 }
610
611 /* -memb, set embedded bit */
612 else if (strcmp (arg, "emb") == 0)
613 ppc_flags |= EF_PPC_EMB;
614
615 /* -mlittle/-mbig set the endianess */
616 else if (strcmp (arg, "little") == 0 || strcmp (arg, "little-endian") == 0)
617 {
618 target_big_endian = 0;
619 set_target_endian = 1;
620 }
621
622 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
623 {
624 target_big_endian = 1;
625 set_target_endian = 1;
626 }
627 #endif
628 else
629 {
630 as_bad ("invalid switch -m%s", arg);
631 return 0;
632 }
633 break;
634
635 #ifdef OBJ_ELF
636 /* -V: SVR4 argument to print version ID. */
637 case 'V':
638 print_version_id ();
639 break;
640
641 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
642 should be emitted or not. FIXME: Not implemented. */
643 case 'Q':
644 break;
645 #endif
646
647 default:
648 return 0;
649 }
650
651 return 1;
652 }
653
654 void
655 md_show_usage (stream)
656 FILE *stream;
657 {
658 fprintf(stream, "\
659 PowerPC options:\n\
660 -u ignored\n\
661 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
662 -mpwr generate code for IBM POWER (RIOS1)\n\
663 -m601 generate code for Motorola PowerPC 601\n\
664 -mppc, -mppc32, -m403, -m603, -m604\n\
665 generate code for Motorola PowerPC 603/604\n\
666 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
667 -mcom generate code Power/PowerPC common instructions\n\
668 -many generate code for any architecture (PWR/PWRX/PPC)\n");
669 #ifdef OBJ_ELF
670 fprintf(stream, "\
671 -mrelocatable support for GCC's -mrelocatble option\n\
672 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
673 -memb set PPC_EMB bit in ELF flags\n\
674 -mlittle, -mlittle-endian\n\
675 generate code for a little endian machine\n\
676 -mbig, -mbig-endian generate code for a big endian machine\n\
677 -V print assembler version number\n\
678 -Qy, -Qn ignored\n");
679 #endif
680 }
681 \f
682 /* Set ppc_cpu if it is not already set. */
683
684 static void
685 ppc_set_cpu ()
686 {
687 const char *default_cpu = TARGET_CPU;
688
689 if (ppc_cpu == 0)
690 {
691 if (strcmp (default_cpu, "rs6000") == 0)
692 ppc_cpu = PPC_OPCODE_POWER;
693 else if (strcmp (default_cpu, "powerpc") == 0
694 || strcmp (default_cpu, "powerpcle") == 0)
695 ppc_cpu = PPC_OPCODE_PPC;
696 else
697 as_fatal ("Unknown default cpu = %s", default_cpu);
698 }
699 }
700
701 /* Figure out the BFD architecture to use. */
702
703 enum bfd_architecture
704 ppc_arch ()
705 {
706 const char *default_cpu = TARGET_CPU;
707 ppc_set_cpu ();
708
709 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
710 return bfd_arch_powerpc;
711 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
712 return bfd_arch_rs6000;
713 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
714 {
715 if (strcmp (default_cpu, "rs6000") == 0)
716 return bfd_arch_rs6000;
717 else if (strcmp (default_cpu, "powerpc") == 0
718 || strcmp (default_cpu, "powerpcle") == 0)
719 return bfd_arch_powerpc;
720 }
721
722 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
723 return bfd_arch_unknown;
724 }
725
726 /* This function is called when the assembler starts up. It is called
727 after the options have been parsed and the output file has been
728 opened. */
729
730 void
731 md_begin ()
732 {
733 register const struct powerpc_opcode *op;
734 const struct powerpc_opcode *op_end;
735 const struct powerpc_macro *macro;
736 const struct powerpc_macro *macro_end;
737 boolean dup_insn = false;
738
739 ppc_set_cpu ();
740
741 #ifdef OBJ_ELF
742 /* Set the ELF flags if desired. */
743 if (ppc_flags)
744 bfd_set_private_flags (stdoutput, ppc_flags);
745 #endif
746
747 /* Insert the opcodes into a hash table. */
748 ppc_hash = hash_new ();
749
750 op_end = powerpc_opcodes + powerpc_num_opcodes;
751 for (op = powerpc_opcodes; op < op_end; op++)
752 {
753 know ((op->opcode & op->mask) == op->opcode);
754
755 if ((op->flags & ppc_cpu) != 0
756 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
757 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size))
758 {
759 const char *retval;
760
761 retval = hash_insert (ppc_hash, op->name, (PTR) op);
762 if (retval != (const char *) NULL)
763 {
764 /* Ignore Power duplicates for -m601 */
765 if ((ppc_cpu & PPC_OPCODE_601) != 0
766 && (op->flags & PPC_OPCODE_POWER) != 0)
767 continue;
768
769 as_bad ("Internal assembler error for instruction %s", op->name);
770 dup_insn = true;
771 }
772 }
773 }
774
775 /* Insert the macros into a hash table. */
776 ppc_macro_hash = hash_new ();
777
778 macro_end = powerpc_macros + powerpc_num_macros;
779 for (macro = powerpc_macros; macro < macro_end; macro++)
780 {
781 if ((macro->flags & ppc_cpu) != 0)
782 {
783 const char *retval;
784
785 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
786 if (retval != (const char *) NULL)
787 {
788 as_bad ("Internal assembler error for macro %s", macro->name);
789 dup_insn = true;
790 }
791 }
792 }
793
794 if (dup_insn)
795 abort ();
796
797 /* Tell the main code what the endianness is if it is not overidden by the user. */
798 if (!set_target_endian)
799 {
800 set_target_endian = 1;
801 target_big_endian = PPC_BIG_ENDIAN;
802 }
803
804 #ifdef OBJ_XCOFF
805 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
806
807 /* Create dummy symbols to serve as initial csects. This forces the
808 text csects to precede the data csects. These symbols will not
809 be output. */
810 ppc_text_csects = symbol_make ("dummy\001");
811 ppc_text_csects->sy_tc.within = ppc_text_csects;
812 ppc_data_csects = symbol_make ("dummy\001");
813 ppc_data_csects->sy_tc.within = ppc_data_csects;
814 #endif
815
816 #ifdef TE_PE
817
818 ppc_current_section = text_section;
819 ppc_previous_section = 0;
820
821 #endif
822 }
823
824 /* Insert an operand value into an instruction. */
825
826 static unsigned long
827 ppc_insert_operand (insn, operand, val, file, line)
828 unsigned long insn;
829 const struct powerpc_operand *operand;
830 offsetT val;
831 char *file;
832 unsigned int line;
833 {
834 if (operand->bits != 32)
835 {
836 long min, max;
837 offsetT test;
838
839 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
840 {
841 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0
842 && ppc_size == PPC_OPCODE_32)
843 max = (1 << operand->bits) - 1;
844 else
845 max = (1 << (operand->bits - 1)) - 1;
846 min = - (1 << (operand->bits - 1));
847 }
848 else
849 {
850 max = (1 << operand->bits) - 1;
851 min = 0;
852 }
853
854 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
855 test = - val;
856 else
857 test = val;
858
859 if (test < (offsetT) min || test > (offsetT) max)
860 {
861 const char *err =
862 "operand out of range (%s not between %ld and %ld)";
863 char buf[100];
864
865 sprint_value (buf, test);
866 if (file == (char *) NULL)
867 as_warn (err, buf, min, max);
868 else
869 as_warn_where (file, line, err, buf, min, max);
870 }
871 }
872
873 if (operand->insert)
874 {
875 const char *errmsg;
876
877 errmsg = NULL;
878 insn = (*operand->insert) (insn, (long) val, &errmsg);
879 if (errmsg != (const char *) NULL)
880 as_warn (errmsg);
881 }
882 else
883 insn |= (((long) val & ((1 << operand->bits) - 1))
884 << operand->shift);
885
886 return insn;
887 }
888
889 #ifdef OBJ_ELF
890 /* Parse @got, etc. and return the desired relocation. */
891 static bfd_reloc_code_real_type
892 ppc_elf_suffix (str_p)
893 char **str_p;
894 {
895 struct map_bfd {
896 char *string;
897 int length;
898 bfd_reloc_code_real_type reloc;
899 };
900
901 char ident[20];
902 char *str = *str_p;
903 char *str2;
904 int ch;
905 int len;
906 struct map_bfd *ptr;
907
908 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
909
910 static struct map_bfd mapping[] = {
911 MAP ("l", BFD_RELOC_LO16),
912 MAP ("h", BFD_RELOC_HI16),
913 MAP ("ha", BFD_RELOC_HI16_S),
914 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
915 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
916 MAP ("got", BFD_RELOC_16_GOTOFF),
917 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
918 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
919 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
920 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
921 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
922 MAP ("copy", BFD_RELOC_PPC_COPY),
923 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
924 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
925 MAP ("plt", BFD_RELOC_32_PLTOFF),
926 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
927 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
928 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
929 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
930 MAP ("sdarel", BFD_RELOC_GPREL16),
931 MAP ("sectoff", BFD_RELOC_32_BASEREL),
932 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
933 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
934 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
935 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
936 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
937 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
938 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
939 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
940 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
941 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
942 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
943 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21),
944 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
945 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
946 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
947 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
948 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
949 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
950 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
951 MAP ("xgot", BFD_RELOC_PPC_TOC16),
952
953 { (char *)0, 0, BFD_RELOC_UNUSED }
954 };
955
956 if (*str++ != '@')
957 return BFD_RELOC_UNUSED;
958
959 for (ch = *str, str2 = ident;
960 str2 < ident + sizeof(ident) - 1 && isalnum (ch) || ch == '@';
961 ch = *++str)
962 {
963 *str2++ = (islower (ch)) ? ch : tolower (ch);
964 }
965
966 *str2 = '\0';
967 len = str2 - ident;
968
969 ch = ident[0];
970 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
971 if (ch == ptr->string[0] && len == ptr->length && memcmp (ident, ptr->string, ptr->length) == 0)
972 {
973 *str_p = str;
974 return ptr->reloc;
975 }
976
977 return BFD_RELOC_UNUSED;
978 }
979
980 /* Like normal .long/.short/.word, except support @got, etc. */
981 /* clobbers input_line_pointer, checks */
982 /* end-of-line. */
983 static void
984 ppc_elf_cons (nbytes)
985 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
986 {
987 expressionS exp;
988 bfd_reloc_code_real_type reloc;
989
990 if (is_it_end_of_statement ())
991 {
992 demand_empty_rest_of_line ();
993 return;
994 }
995
996 do
997 {
998 expression (&exp);
999 if (exp.X_op == O_symbol
1000 && *input_line_pointer == '@'
1001 && (reloc = ppc_elf_suffix (&input_line_pointer)) != BFD_RELOC_UNUSED)
1002 {
1003 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1004 int size = bfd_get_reloc_size (reloc_howto);
1005
1006 if (size > nbytes)
1007 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto->name, nbytes);
1008
1009 else
1010 {
1011 register char *p = frag_more ((int) nbytes);
1012 int offset = nbytes - size;
1013
1014 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
1015 }
1016 }
1017 else
1018 emit_expr (&exp, (unsigned int) nbytes);
1019 }
1020 while (*input_line_pointer++ == ',');
1021
1022 input_line_pointer--; /* Put terminator back into stream. */
1023 demand_empty_rest_of_line ();
1024 }
1025
1026 /* Validate any relocations emitted for -mrelocatable, possibly adding
1027 fixups for word relocations in writable segments, so we can adjust
1028 them at runtime. */
1029 static void
1030 ppc_elf_validate_fix (fixp, seg)
1031 fixS *fixp;
1032 segT seg;
1033 {
1034 if (mrelocatable
1035 && !fixp->fx_done
1036 && !fixp->fx_pcrel
1037 && fixp->fx_r_type <= BFD_RELOC_UNUSED
1038 && strcmp (segment_name (seg), ".got2") != 0
1039 && strcmp (segment_name (seg), ".dtors") != 0
1040 && strcmp (segment_name (seg), ".ctors") != 0
1041 && strcmp (segment_name (seg), ".fixup") != 0
1042 && strcmp (segment_name (seg), ".stab") != 0
1043 && strcmp (segment_name (seg), ".gcc_except_table") != 0)
1044 {
1045 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1046 || fixp->fx_r_type != BFD_RELOC_CTOR)
1047 {
1048 as_warn_where (fixp->fx_file, fixp->fx_line,
1049 "Relocation cannot be done when using -mrelocatable");
1050 }
1051 }
1052 }
1053
1054 #endif /* OBJ_ELF */
1055
1056 #ifdef TE_PE
1057 /*
1058 * Summary of register_name().
1059 *
1060 * in: Input_line_pointer points to 1st char of operand.
1061 *
1062 * out: A expressionS.
1063 * The operand may have been a register: in this case, X_op == O_register,
1064 * X_add_number is set to the register number, and truth is returned.
1065 * Input_line_pointer->(next non-blank) char after operand, or is in its
1066 * original state.
1067 */
1068
1069 static int
1070 register_name (expressionP)
1071 expressionS *expressionP;
1072 {
1073 int reg_number;
1074 char *name;
1075 char c;
1076
1077 /* Find the spelling of the operand */
1078 name = input_line_pointer;
1079 c = get_symbol_end ();
1080 reg_number = reg_name_search (name);
1081
1082 /* look to see if it's in the register table */
1083 if (reg_number >= 0)
1084 {
1085 expressionP->X_op = O_register;
1086 expressionP->X_add_number = reg_number;
1087
1088 /* make the rest nice */
1089 expressionP->X_add_symbol = NULL;
1090 expressionP->X_op_symbol = NULL;
1091 *input_line_pointer = c; /* put back the delimiting char */
1092 return 1;
1093 }
1094 else
1095 {
1096 /* reset the line as if we had not done anything */
1097 *input_line_pointer = c; /* put back the delimiting char */
1098 input_line_pointer = name; /* reset input_line pointer */
1099 return 0;
1100 }
1101 }
1102
1103 /*
1104 * Summary of parse_toc_entry().
1105 *
1106 * in: Input_line_pointer points to the '[' in one of:
1107 *
1108 * [toc] [tocv] [toc32] [toc64]
1109 *
1110 * Anything else is an error of one kind or another.
1111 *
1112 * out:
1113 * return value: success or failure
1114 * toc_kind: kind of toc reference
1115 * input_line_pointer:
1116 * success: first char after the ']'
1117 * failure: unchanged
1118 *
1119 * settings:
1120 *
1121 * [toc] - rv == success, toc_kind = default_toc
1122 * [tocv] - rv == success, toc_kind = data_in_toc
1123 * [toc32] - rv == success, toc_kind = must_be_32
1124 * [toc64] - rv == success, toc_kind = must_be_64
1125 *
1126 */
1127
1128 enum toc_size_qualifier
1129 {
1130 default_toc, /* The toc cell constructed should be the system default size */
1131 data_in_toc, /* This is a direct reference to a toc cell */
1132 must_be_32, /* The toc cell constructed must be 32 bits wide */
1133 must_be_64 /* The toc cell constructed must be 64 bits wide */
1134 };
1135
1136 static int
1137 parse_toc_entry(toc_kind)
1138 enum toc_size_qualifier *toc_kind;
1139 {
1140 char *start;
1141 char *toc_spec;
1142 char c;
1143 enum toc_size_qualifier t;
1144
1145 /* save the input_line_pointer */
1146 start = input_line_pointer;
1147
1148 /* skip over the '[' , and whitespace */
1149 ++input_line_pointer;
1150 SKIP_WHITESPACE ();
1151
1152 /* find the spelling of the operand */
1153 toc_spec = input_line_pointer;
1154 c = get_symbol_end ();
1155
1156 if (strcmp(toc_spec, "toc") == 0)
1157 {
1158 t = default_toc;
1159 }
1160 else if (strcmp(toc_spec, "tocv") == 0)
1161 {
1162 t = data_in_toc;
1163 }
1164 else if (strcmp(toc_spec, "toc32") == 0)
1165 {
1166 t = must_be_32;
1167 }
1168 else if (strcmp(toc_spec, "toc64") == 0)
1169 {
1170 t = must_be_64;
1171 }
1172 else
1173 {
1174 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec);
1175 *input_line_pointer = c; /* put back the delimiting char */
1176 input_line_pointer = start; /* reset input_line pointer */
1177 return 0;
1178 }
1179
1180 /* now find the ']' */
1181 *input_line_pointer = c; /* put back the delimiting char */
1182
1183 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1184 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1185
1186 if (c != ']')
1187 {
1188 as_bad ("syntax error: expected `]', found `%c'", c);
1189 input_line_pointer = start; /* reset input_line pointer */
1190 return 0;
1191 }
1192
1193 *toc_kind = t; /* set return value */
1194 return 1;
1195 }
1196
1197 #endif
1198
1199
1200 /* We need to keep a list of fixups. We can't simply generate them as
1201 we go, because that would require us to first create the frag, and
1202 that would screw up references to ``.''. */
1203
1204 struct ppc_fixup
1205 {
1206 expressionS exp;
1207 int opindex;
1208 bfd_reloc_code_real_type reloc;
1209 };
1210
1211 #define MAX_INSN_FIXUPS (5)
1212
1213 /* This routine is called for each instruction to be assembled. */
1214
1215 void
1216 md_assemble (str)
1217 char *str;
1218 {
1219 char *s;
1220 const struct powerpc_opcode *opcode;
1221 unsigned long insn;
1222 const unsigned char *opindex_ptr;
1223 int skip_optional;
1224 int need_paren;
1225 int next_opindex;
1226 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1227 int fc;
1228 char *f;
1229 int i;
1230 #ifdef OBJ_ELF
1231 bfd_reloc_code_real_type reloc;
1232 #endif
1233
1234 /* Get the opcode. */
1235 for (s = str; *s != '\0' && ! isspace (*s); s++)
1236 ;
1237 if (*s != '\0')
1238 *s++ = '\0';
1239
1240 /* Look up the opcode in the hash table. */
1241 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1242 if (opcode == (const struct powerpc_opcode *) NULL)
1243 {
1244 const struct powerpc_macro *macro;
1245
1246 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1247 if (macro == (const struct powerpc_macro *) NULL)
1248 as_bad ("Unrecognized opcode: `%s'", str);
1249 else
1250 ppc_macro (s, macro);
1251
1252 return;
1253 }
1254
1255 insn = opcode->opcode;
1256
1257 str = s;
1258 while (isspace (*str))
1259 ++str;
1260
1261 /* PowerPC operands are just expressions. The only real issue is
1262 that a few operand types are optional. All cases which might use
1263 an optional operand separate the operands only with commas (in
1264 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1265 cases never have optional operands). There is never more than
1266 one optional operand for an instruction. So, before we start
1267 seriously parsing the operands, we check to see if we have an
1268 optional operand, and, if we do, we count the number of commas to
1269 see whether the operand should be omitted. */
1270 skip_optional = 0;
1271 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1272 {
1273 const struct powerpc_operand *operand;
1274
1275 operand = &powerpc_operands[*opindex_ptr];
1276 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1277 {
1278 unsigned int opcount;
1279
1280 /* There is an optional operand. Count the number of
1281 commas in the input line. */
1282 if (*str == '\0')
1283 opcount = 0;
1284 else
1285 {
1286 opcount = 1;
1287 s = str;
1288 while ((s = strchr (s, ',')) != (char *) NULL)
1289 {
1290 ++opcount;
1291 ++s;
1292 }
1293 }
1294
1295 /* If there are fewer operands in the line then are called
1296 for by the instruction, we want to skip the optional
1297 operand. */
1298 if (opcount < strlen (opcode->operands))
1299 skip_optional = 1;
1300
1301 break;
1302 }
1303 }
1304
1305 /* Gather the operands. */
1306 need_paren = 0;
1307 next_opindex = 0;
1308 fc = 0;
1309 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1310 {
1311 const struct powerpc_operand *operand;
1312 const char *errmsg;
1313 char *hold;
1314 expressionS ex;
1315 char endc;
1316
1317 if (next_opindex == 0)
1318 operand = &powerpc_operands[*opindex_ptr];
1319 else
1320 {
1321 operand = &powerpc_operands[next_opindex];
1322 next_opindex = 0;
1323 }
1324
1325 errmsg = NULL;
1326
1327 /* If this is a fake operand, then we do not expect anything
1328 from the input. */
1329 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1330 {
1331 insn = (*operand->insert) (insn, 0L, &errmsg);
1332 if (errmsg != (const char *) NULL)
1333 as_warn (errmsg);
1334 continue;
1335 }
1336
1337 /* If this is an optional operand, and we are skipping it, just
1338 insert a zero. */
1339 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1340 && skip_optional)
1341 {
1342 if (operand->insert)
1343 {
1344 insn = (*operand->insert) (insn, 0L, &errmsg);
1345 if (errmsg != (const char *) NULL)
1346 as_warn (errmsg);
1347 }
1348 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1349 next_opindex = *opindex_ptr + 1;
1350 continue;
1351 }
1352
1353 /* Gather the operand. */
1354 hold = input_line_pointer;
1355 input_line_pointer = str;
1356
1357 #ifdef TE_PE
1358 if (*input_line_pointer == '[')
1359 {
1360 /* We are expecting something like the second argument here:
1361
1362 lwz r4,[toc].GS.0.static_int(rtoc)
1363 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1364 The argument following the `]' must be a symbol name, and the
1365 register must be the toc register: 'rtoc' or '2'
1366
1367 The effect is to 0 as the displacement field
1368 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1369 the appropriate variation) reloc against it based on the symbol.
1370 The linker will build the toc, and insert the resolved toc offset.
1371
1372 Note:
1373 o The size of the toc entry is currently assumed to be
1374 32 bits. This should not be assumed to be a hard coded
1375 number.
1376 o In an effort to cope with a change from 32 to 64 bits,
1377 there are also toc entries that are specified to be
1378 either 32 or 64 bits:
1379 lwz r4,[toc32].GS.0.static_int(rtoc)
1380 lwz r4,[toc64].GS.0.static_int(rtoc)
1381 These demand toc entries of the specified size, and the
1382 instruction probably requires it.
1383 */
1384
1385 int valid_toc;
1386 enum toc_size_qualifier toc_kind;
1387 bfd_reloc_code_real_type toc_reloc;
1388
1389 /* go parse off the [tocXX] part */
1390 valid_toc = parse_toc_entry(&toc_kind);
1391
1392 if (!valid_toc)
1393 {
1394 /* Note: message has already been issued. */
1395 /* FIXME: what sort of recovery should we do? */
1396 /* demand_rest_of_line(); return; ? */
1397 }
1398
1399 /* Now get the symbol following the ']' */
1400 expression(&ex);
1401
1402 switch (toc_kind)
1403 {
1404 case default_toc:
1405 /* In this case, we may not have seen the symbol yet, since */
1406 /* it is allowed to appear on a .extern or .globl or just be */
1407 /* a label in the .data section. */
1408 toc_reloc = BFD_RELOC_PPC_TOC16;
1409 break;
1410 case data_in_toc:
1411 /* 1. The symbol must be defined and either in the toc */
1412 /* section, or a global. */
1413 /* 2. The reloc generated must have the TOCDEFN flag set in */
1414 /* upper bit mess of the reloc type. */
1415 /* FIXME: It's a little confusing what the tocv qualifier can */
1416 /* be used for. At the very least, I've seen three */
1417 /* uses, only one of which I'm sure I can explain. */
1418 if (ex.X_op == O_symbol)
1419 {
1420 assert (ex.X_add_symbol != NULL);
1421 if (ex.X_add_symbol->bsym->section != tocdata_section)
1422 {
1423 as_warn("[tocv] symbol is not a toc symbol");
1424 }
1425 }
1426
1427 toc_reloc = BFD_RELOC_PPC_TOC16;
1428 break;
1429 case must_be_32:
1430 /* FIXME: these next two specifically specify 32/64 bit toc */
1431 /* entries. We don't support them today. Is this the */
1432 /* right way to say that? */
1433 toc_reloc = BFD_RELOC_UNUSED;
1434 as_bad ("Unimplemented toc32 expression modifier");
1435 break;
1436 case must_be_64:
1437 /* FIXME: see above */
1438 toc_reloc = BFD_RELOC_UNUSED;
1439 as_bad ("Unimplemented toc64 expression modifier");
1440 break;
1441 default:
1442 fprintf(stderr,
1443 "Unexpected return value [%d] from parse_toc_entry!\n",
1444 toc_kind);
1445 abort();
1446 break;
1447 }
1448
1449 /* We need to generate a fixup for this expression. */
1450 if (fc >= MAX_INSN_FIXUPS)
1451 as_fatal ("too many fixups");
1452
1453 fixups[fc].reloc = toc_reloc;
1454 fixups[fc].exp = ex;
1455 fixups[fc].opindex = *opindex_ptr;
1456 ++fc;
1457
1458 /* Ok. We've set up the fixup for the instruction. Now make it
1459 look like the constant 0 was found here */
1460 ex.X_unsigned = 1;
1461 ex.X_op = O_constant;
1462 ex.X_add_number = 0;
1463 ex.X_add_symbol = NULL;
1464 ex.X_op_symbol = NULL;
1465 }
1466 else
1467 {
1468 if (!register_name(&ex))
1469 {
1470 expression (&ex);
1471 }
1472 }
1473
1474 str = input_line_pointer;
1475 input_line_pointer = hold;
1476 #else
1477 expression (&ex);
1478 str = input_line_pointer;
1479 input_line_pointer = hold;
1480 #endif
1481
1482 if (ex.X_op == O_illegal)
1483 as_bad ("illegal operand");
1484 else if (ex.X_op == O_absent)
1485 as_bad ("missing operand");
1486 else if (ex.X_op == O_constant)
1487 {
1488 #ifdef OBJ_ELF
1489 /* Allow @HA, @L, @H on constants. */
1490 char *orig_str = str;
1491
1492 if ((reloc = ppc_elf_suffix (&str)) != BFD_RELOC_UNUSED)
1493 switch (reloc)
1494 {
1495 default:
1496 str = orig_str;
1497 break;
1498
1499 case BFD_RELOC_LO16:
1500 ex.X_add_number = ((ex.X_add_number & 0xffff) ^ 0x8000) - 0x8000;
1501 break;
1502
1503 case BFD_RELOC_HI16:
1504 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
1505 break;
1506
1507 case BFD_RELOC_HI16_S:
1508 ex.X_add_number = ((ex.X_add_number >> 16) & 0xffff)
1509 + ((ex.X_add_number >> 15) & 1);
1510 break;
1511 }
1512 #endif
1513 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1514 (char *) NULL, 0);
1515 }
1516 #ifdef TE_PE
1517 else if (ex.X_op == O_register)
1518 {
1519 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1520 (char *) NULL, 0);
1521 }
1522 #endif
1523 #ifdef OBJ_ELF
1524 else if ((reloc = ppc_elf_suffix (&str)) != BFD_RELOC_UNUSED)
1525 {
1526 /* For the absoulte forms of branchs, convert the PC relative form back into
1527 the absolute. */
1528 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
1529 switch (reloc)
1530 {
1531 case BFD_RELOC_PPC_B26: reloc = BFD_RELOC_PPC_BA26; break;
1532 case BFD_RELOC_PPC_B16: reloc = BFD_RELOC_PPC_BA16; break;
1533 case BFD_RELOC_PPC_B16_BRTAKEN: reloc = BFD_RELOC_PPC_BA16_BRTAKEN; break;
1534 case BFD_RELOC_PPC_B16_BRNTAKEN: reloc = BFD_RELOC_PPC_BA16_BRNTAKEN; break;
1535 }
1536
1537 /* We need to generate a fixup for this expression. */
1538 if (fc >= MAX_INSN_FIXUPS)
1539 as_fatal ("too many fixups");
1540 fixups[fc].exp = ex;
1541 fixups[fc].opindex = 0;
1542 fixups[fc].reloc = reloc;
1543 ++fc;
1544 }
1545 #endif /* OBJ_ELF */
1546
1547 else
1548 {
1549 /* We need to generate a fixup for this expression. */
1550 if (fc >= MAX_INSN_FIXUPS)
1551 as_fatal ("too many fixups");
1552 fixups[fc].exp = ex;
1553 fixups[fc].opindex = *opindex_ptr;
1554 fixups[fc].reloc = BFD_RELOC_UNUSED;
1555 ++fc;
1556 }
1557
1558 if (need_paren)
1559 {
1560 endc = ')';
1561 need_paren = 0;
1562 }
1563 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
1564 {
1565 endc = '(';
1566 need_paren = 1;
1567 }
1568 else
1569 endc = ',';
1570
1571 /* The call to expression should have advanced str past any
1572 whitespace. */
1573 if (*str != endc
1574 && (endc != ',' || *str != '\0'))
1575 {
1576 as_bad ("syntax error; found `%c' but expected `%c'", *str, endc);
1577 break;
1578 }
1579
1580 if (*str != '\0')
1581 ++str;
1582 }
1583
1584 while (isspace (*str))
1585 ++str;
1586
1587 if (*str != '\0')
1588 as_bad ("junk at end of line: `%s'", str);
1589
1590 /* Write out the instruction. */
1591 f = frag_more (4);
1592 md_number_to_chars (f, insn, 4);
1593
1594 /* Create any fixups. At this point we do not use a
1595 bfd_reloc_code_real_type, but instead just use the
1596 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1597 handle fixups for any operand type, although that is admittedly
1598 not a very exciting feature. We pick a BFD reloc type in
1599 md_apply_fix. */
1600 for (i = 0; i < fc; i++)
1601 {
1602 const struct powerpc_operand *operand;
1603
1604 operand = &powerpc_operands[fixups[i].opindex];
1605 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1606 {
1607 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1608 int size;
1609 int offset;
1610 fixS *fixP;
1611
1612 if (!reloc_howto)
1613 abort ();
1614
1615 size = bfd_get_reloc_size (reloc_howto);
1616 offset = target_big_endian ? (4 - size) : 0;
1617
1618 if (size < 1 || size > 4)
1619 abort();
1620
1621 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, size,
1622 &fixups[i].exp, reloc_howto->pc_relative,
1623 fixups[i].reloc);
1624
1625 /* Turn off complaints that the addend is too large for things like
1626 foo+100000@ha. */
1627 switch (fixups[i].reloc)
1628 {
1629 case BFD_RELOC_LO16:
1630 case BFD_RELOC_HI16:
1631 case BFD_RELOC_HI16_S:
1632 fixP->fx_no_overflow = 1;
1633 break;
1634 default:
1635 break;
1636 }
1637 }
1638 else
1639 fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1640 &fixups[i].exp,
1641 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
1642 ((bfd_reloc_code_real_type)
1643 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1644 }
1645 }
1646
1647 #ifndef WORKING_DOT_WORD
1648 /* Handle long and short jumps */
1649 void
1650 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1651 char *ptr;
1652 addressT from_addr, to_addr;
1653 fragS *frag;
1654 symbolS *to_symbol;
1655 {
1656 abort ();
1657 }
1658
1659 void
1660 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1661 char *ptr;
1662 addressT from_addr, to_addr;
1663 fragS *frag;
1664 symbolS *to_symbol;
1665 {
1666 abort ();
1667 }
1668 #endif
1669
1670 /* Handle a macro. Gather all the operands, transform them as
1671 described by the macro, and call md_assemble recursively. All the
1672 operands are separated by commas; we don't accept parentheses
1673 around operands here. */
1674
1675 static void
1676 ppc_macro (str, macro)
1677 char *str;
1678 const struct powerpc_macro *macro;
1679 {
1680 char *operands[10];
1681 unsigned int count;
1682 char *s;
1683 unsigned int len;
1684 const char *format;
1685 int arg;
1686 char *send;
1687 char *complete;
1688
1689 /* Gather the users operands into the operands array. */
1690 count = 0;
1691 s = str;
1692 while (1)
1693 {
1694 if (count >= sizeof operands / sizeof operands[0])
1695 break;
1696 operands[count++] = s;
1697 s = strchr (s, ',');
1698 if (s == (char *) NULL)
1699 break;
1700 *s++ = '\0';
1701 }
1702
1703 if (count != macro->operands)
1704 {
1705 as_bad ("wrong number of operands");
1706 return;
1707 }
1708
1709 /* Work out how large the string must be (the size is unbounded
1710 because it includes user input). */
1711 len = 0;
1712 format = macro->format;
1713 while (*format != '\0')
1714 {
1715 if (*format != '%')
1716 {
1717 ++len;
1718 ++format;
1719 }
1720 else
1721 {
1722 arg = strtol (format + 1, &send, 10);
1723 know (send != format && arg >= 0 && arg < count);
1724 len += strlen (operands[arg]);
1725 format = send;
1726 }
1727 }
1728
1729 /* Put the string together. */
1730 complete = s = (char *) alloca (len + 1);
1731 format = macro->format;
1732 while (*format != '\0')
1733 {
1734 if (*format != '%')
1735 *s++ = *format++;
1736 else
1737 {
1738 arg = strtol (format + 1, &send, 10);
1739 strcpy (s, operands[arg]);
1740 s += strlen (s);
1741 format = send;
1742 }
1743 }
1744 *s = '\0';
1745
1746 /* Assemble the constructed instruction. */
1747 md_assemble (complete);
1748 }
1749 \f
1750 #ifdef OBJ_ELF
1751 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
1752
1753 int
1754 ppc_section_letter (letter, ptr_msg)
1755 int letter;
1756 char **ptr_msg;
1757 {
1758 if (letter == 'e')
1759 return SHF_EXCLUDE;
1760
1761 *ptr_msg = "Bad .section directive: want a,w,x,e in string";
1762 return 0;
1763 }
1764
1765 int
1766 ppc_section_word (ptr_str)
1767 char **ptr_str;
1768 {
1769 if (strncmp (*ptr_str, "exclude", sizeof ("exclude")-1) == 0)
1770 {
1771 *ptr_str += sizeof ("exclude")-1;
1772 return SHF_EXCLUDE;
1773 }
1774
1775 return 0;
1776 }
1777
1778 int
1779 ppc_section_type (ptr_str)
1780 char **ptr_str;
1781 {
1782 if (strncmp (*ptr_str, "ordered", sizeof ("ordered")-1) == 0)
1783 {
1784 *ptr_str += sizeof ("ordered")-1;
1785 return SHT_ORDERED;
1786 }
1787
1788 return 0;
1789 }
1790
1791 int
1792 ppc_section_flags (flags, attr, type)
1793 int flags;
1794 int attr;
1795 int type;
1796 {
1797 if (type == SHT_ORDERED)
1798 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
1799
1800 if (attr & SHF_EXCLUDE)
1801 flags |= SEC_EXCLUDE;
1802
1803 return flags;
1804 }
1805 #endif /* OBJ_ELF */
1806
1807 \f
1808 /* Pseudo-op handling. */
1809
1810 /* The .byte pseudo-op. This is similar to the normal .byte
1811 pseudo-op, but it can also take a single ASCII string. */
1812
1813 static void
1814 ppc_byte (ignore)
1815 int ignore;
1816 {
1817 if (*input_line_pointer != '\"')
1818 {
1819 cons (1);
1820 return;
1821 }
1822
1823 /* Gather characters. A real double quote is doubled. Unusual
1824 characters are not permitted. */
1825 ++input_line_pointer;
1826 while (1)
1827 {
1828 char c;
1829
1830 c = *input_line_pointer++;
1831
1832 if (c == '\"')
1833 {
1834 if (*input_line_pointer != '\"')
1835 break;
1836 ++input_line_pointer;
1837 }
1838
1839 FRAG_APPEND_1_CHAR (c);
1840 }
1841
1842 demand_empty_rest_of_line ();
1843 }
1844 \f
1845 #ifdef OBJ_XCOFF
1846
1847 /* XCOFF specific pseudo-op handling. */
1848
1849 /* This is set if we are creating a .stabx symbol, since we don't want
1850 to handle symbol suffixes for such symbols. */
1851 static boolean ppc_stab_symbol;
1852
1853 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1854 symbols in the .bss segment as though they were local common
1855 symbols, and uses a different smclas. */
1856
1857 static void
1858 ppc_comm (lcomm)
1859 int lcomm;
1860 {
1861 asection *current_seg = now_seg;
1862 subsegT current_subseg = now_subseg;
1863 char *name;
1864 char endc;
1865 char *end_name;
1866 offsetT size;
1867 offsetT align;
1868 symbolS *lcomm_sym = NULL;
1869 symbolS *sym;
1870 char *pfrag;
1871
1872 name = input_line_pointer;
1873 endc = get_symbol_end ();
1874 end_name = input_line_pointer;
1875 *end_name = endc;
1876
1877 if (*input_line_pointer != ',')
1878 {
1879 as_bad ("missing size");
1880 ignore_rest_of_line ();
1881 return;
1882 }
1883 ++input_line_pointer;
1884
1885 size = get_absolute_expression ();
1886 if (size < 0)
1887 {
1888 as_bad ("negative size");
1889 ignore_rest_of_line ();
1890 return;
1891 }
1892
1893 if (! lcomm)
1894 {
1895 /* The third argument to .comm is the alignment. */
1896 if (*input_line_pointer != ',')
1897 align = 3;
1898 else
1899 {
1900 ++input_line_pointer;
1901 align = get_absolute_expression ();
1902 if (align <= 0)
1903 {
1904 as_warn ("ignoring bad alignment");
1905 align = 3;
1906 }
1907 }
1908 }
1909 else
1910 {
1911 char *lcomm_name;
1912 char lcomm_endc;
1913
1914 if (size <= 1)
1915 align = 0;
1916 else if (size <= 2)
1917 align = 1;
1918 else if (size <= 4)
1919 align = 2;
1920 else
1921 align = 3;
1922
1923 /* The third argument to .lcomm appears to be the real local
1924 common symbol to create. References to the symbol named in
1925 the first argument are turned into references to the third
1926 argument. */
1927 if (*input_line_pointer != ',')
1928 {
1929 as_bad ("missing real symbol name");
1930 ignore_rest_of_line ();
1931 return;
1932 }
1933 ++input_line_pointer;
1934
1935 lcomm_name = input_line_pointer;
1936 lcomm_endc = get_symbol_end ();
1937
1938 lcomm_sym = symbol_find_or_make (lcomm_name);
1939
1940 *input_line_pointer = lcomm_endc;
1941 }
1942
1943 *end_name = '\0';
1944 sym = symbol_find_or_make (name);
1945 *end_name = endc;
1946
1947 if (S_IS_DEFINED (sym)
1948 || S_GET_VALUE (sym) != 0)
1949 {
1950 as_bad ("attempt to redefine symbol");
1951 ignore_rest_of_line ();
1952 return;
1953 }
1954
1955 record_alignment (bss_section, align);
1956
1957 if (! lcomm
1958 || ! S_IS_DEFINED (lcomm_sym))
1959 {
1960 symbolS *def_sym;
1961 offsetT def_size;
1962
1963 if (! lcomm)
1964 {
1965 def_sym = sym;
1966 def_size = size;
1967 S_SET_EXTERNAL (sym);
1968 }
1969 else
1970 {
1971 lcomm_sym->sy_tc.output = 1;
1972 def_sym = lcomm_sym;
1973 def_size = 0;
1974 }
1975
1976 subseg_set (bss_section, 1);
1977 frag_align (align, 0);
1978
1979 def_sym->sy_frag = frag_now;
1980 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
1981 def_size, (char *) NULL);
1982 *pfrag = 0;
1983 S_SET_SEGMENT (def_sym, bss_section);
1984 def_sym->sy_tc.align = align;
1985 }
1986 else if (lcomm)
1987 {
1988 /* Align the size of lcomm_sym. */
1989 lcomm_sym->sy_frag->fr_offset =
1990 ((lcomm_sym->sy_frag->fr_offset + (1 << align) - 1)
1991 &~ ((1 << align) - 1));
1992 if (align > lcomm_sym->sy_tc.align)
1993 lcomm_sym->sy_tc.align = align;
1994 }
1995
1996 if (lcomm)
1997 {
1998 /* Make sym an offset from lcomm_sym. */
1999 S_SET_SEGMENT (sym, bss_section);
2000 sym->sy_frag = lcomm_sym->sy_frag;
2001 S_SET_VALUE (sym, lcomm_sym->sy_frag->fr_offset);
2002 lcomm_sym->sy_frag->fr_offset += size;
2003 }
2004
2005 subseg_set (current_seg, current_subseg);
2006
2007 demand_empty_rest_of_line ();
2008 }
2009
2010 /* The .csect pseudo-op. This switches us into a different
2011 subsegment. The first argument is a symbol whose value is the
2012 start of the .csect. In COFF, csect symbols get special aux
2013 entries defined by the x_csect field of union internal_auxent. The
2014 optional second argument is the alignment (the default is 2). */
2015
2016 static void
2017 ppc_csect (ignore)
2018 int ignore;
2019 {
2020 char *name;
2021 char endc;
2022 symbolS *sym;
2023
2024 name = input_line_pointer;
2025 endc = get_symbol_end ();
2026
2027 sym = symbol_find_or_make (name);
2028
2029 *input_line_pointer = endc;
2030
2031 if (S_GET_NAME (sym)[0] == '\0')
2032 {
2033 /* An unnamed csect is assumed to be [PR]. */
2034 sym->sy_tc.class = XMC_PR;
2035 }
2036
2037 ppc_change_csect (sym);
2038
2039 if (*input_line_pointer == ',')
2040 {
2041 ++input_line_pointer;
2042 sym->sy_tc.align = get_absolute_expression ();
2043 }
2044
2045 demand_empty_rest_of_line ();
2046 }
2047
2048 /* Change to a different csect. */
2049
2050 static void
2051 ppc_change_csect (sym)
2052 symbolS *sym;
2053 {
2054 if (S_IS_DEFINED (sym))
2055 subseg_set (S_GET_SEGMENT (sym), sym->sy_tc.subseg);
2056 else
2057 {
2058 symbolS **list_ptr;
2059 int after_toc;
2060 symbolS *list;
2061
2062 /* This is a new csect. We need to look at the symbol class to
2063 figure out whether it should go in the text section or the
2064 data section. */
2065 after_toc = 0;
2066 switch (sym->sy_tc.class)
2067 {
2068 case XMC_PR:
2069 case XMC_RO:
2070 case XMC_DB:
2071 case XMC_GL:
2072 case XMC_XO:
2073 case XMC_SV:
2074 case XMC_TI:
2075 case XMC_TB:
2076 S_SET_SEGMENT (sym, text_section);
2077 sym->sy_tc.subseg = ppc_text_subsegment;
2078 ++ppc_text_subsegment;
2079 list_ptr = &ppc_text_csects;
2080 break;
2081 case XMC_RW:
2082 case XMC_TC0:
2083 case XMC_TC:
2084 case XMC_DS:
2085 case XMC_UA:
2086 case XMC_BS:
2087 case XMC_UC:
2088 if (ppc_toc_csect != NULL
2089 && ppc_toc_csect->sy_tc.subseg + 1 == ppc_data_subsegment)
2090 after_toc = 1;
2091 S_SET_SEGMENT (sym, data_section);
2092 sym->sy_tc.subseg = ppc_data_subsegment;
2093 ++ppc_data_subsegment;
2094 list_ptr = &ppc_data_csects;
2095 break;
2096 default:
2097 abort ();
2098 }
2099
2100 subseg_new (segment_name (S_GET_SEGMENT (sym)), sym->sy_tc.subseg);
2101 if (after_toc)
2102 ppc_after_toc_frag = frag_now;
2103
2104 sym->sy_frag = frag_now;
2105 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2106
2107 sym->sy_tc.align = 2;
2108 sym->sy_tc.output = 1;
2109 sym->sy_tc.within = sym;
2110
2111 for (list = *list_ptr;
2112 list->sy_tc.next != (symbolS *) NULL;
2113 list = list->sy_tc.next)
2114 ;
2115 list->sy_tc.next = sym;
2116
2117 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2118 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2119 }
2120
2121 ppc_current_csect = sym;
2122 }
2123
2124 /* This function handles the .text and .data pseudo-ops. These
2125 pseudo-ops aren't really used by XCOFF; we implement them for the
2126 convenience of people who aren't used to XCOFF. */
2127
2128 static void
2129 ppc_section (type)
2130 int type;
2131 {
2132 const char *name;
2133 symbolS *sym;
2134
2135 if (type == 't')
2136 name = ".text[PR]";
2137 else if (type == 'd')
2138 name = ".data[RW]";
2139 else
2140 abort ();
2141
2142 sym = symbol_find_or_make (name);
2143
2144 ppc_change_csect (sym);
2145
2146 demand_empty_rest_of_line ();
2147 }
2148
2149 /* The .extern pseudo-op. We create an undefined symbol. */
2150
2151 static void
2152 ppc_extern (ignore)
2153 int ignore;
2154 {
2155 char *name;
2156 char endc;
2157
2158 name = input_line_pointer;
2159 endc = get_symbol_end ();
2160
2161 (void) symbol_find_or_make (name);
2162
2163 *input_line_pointer = endc;
2164
2165 demand_empty_rest_of_line ();
2166 }
2167
2168 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2169
2170 static void
2171 ppc_lglobl (ignore)
2172 int ignore;
2173 {
2174 char *name;
2175 char endc;
2176 symbolS *sym;
2177
2178 name = input_line_pointer;
2179 endc = get_symbol_end ();
2180
2181 sym = symbol_find_or_make (name);
2182
2183 *input_line_pointer = endc;
2184
2185 sym->sy_tc.output = 1;
2186
2187 demand_empty_rest_of_line ();
2188 }
2189
2190 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2191 although I don't know why it bothers. */
2192
2193 static void
2194 ppc_rename (ignore)
2195 int ignore;
2196 {
2197 char *name;
2198 char endc;
2199 symbolS *sym;
2200 int len;
2201
2202 name = input_line_pointer;
2203 endc = get_symbol_end ();
2204
2205 sym = symbol_find_or_make (name);
2206
2207 *input_line_pointer = endc;
2208
2209 if (*input_line_pointer != ',')
2210 {
2211 as_bad ("missing rename string");
2212 ignore_rest_of_line ();
2213 return;
2214 }
2215 ++input_line_pointer;
2216
2217 sym->sy_tc.real_name = demand_copy_C_string (&len);
2218
2219 demand_empty_rest_of_line ();
2220 }
2221
2222 /* The .stabx pseudo-op. This is similar to a normal .stabs
2223 pseudo-op, but slightly different. A sample is
2224 .stabx "main:F-1",.main,142,0
2225 The first argument is the symbol name to create. The second is the
2226 value, and the third is the storage class. The fourth seems to be
2227 always zero, and I am assuming it is the type. */
2228
2229 static void
2230 ppc_stabx (ignore)
2231 int ignore;
2232 {
2233 char *name;
2234 int len;
2235 symbolS *sym;
2236 expressionS exp;
2237
2238 name = demand_copy_C_string (&len);
2239
2240 if (*input_line_pointer != ',')
2241 {
2242 as_bad ("missing value");
2243 return;
2244 }
2245 ++input_line_pointer;
2246
2247 ppc_stab_symbol = true;
2248 sym = symbol_make (name);
2249 ppc_stab_symbol = false;
2250
2251 sym->sy_tc.real_name = name;
2252
2253 (void) expression (&exp);
2254
2255 switch (exp.X_op)
2256 {
2257 case O_illegal:
2258 case O_absent:
2259 case O_big:
2260 as_bad ("illegal .stabx expression; zero assumed");
2261 exp.X_add_number = 0;
2262 /* Fall through. */
2263 case O_constant:
2264 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2265 sym->sy_frag = &zero_address_frag;
2266 break;
2267
2268 case O_symbol:
2269 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2270 sym->sy_value = exp;
2271 else
2272 {
2273 S_SET_VALUE (sym,
2274 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2275 sym->sy_frag = exp.X_add_symbol->sy_frag;
2276 }
2277 break;
2278
2279 default:
2280 /* The value is some complex expression. This will probably
2281 fail at some later point, but this is probably the right
2282 thing to do here. */
2283 sym->sy_value = exp;
2284 break;
2285 }
2286
2287 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2288 sym->bsym->flags |= BSF_DEBUGGING;
2289
2290 if (*input_line_pointer != ',')
2291 {
2292 as_bad ("missing class");
2293 return;
2294 }
2295 ++input_line_pointer;
2296
2297 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2298
2299 if (*input_line_pointer != ',')
2300 {
2301 as_bad ("missing type");
2302 return;
2303 }
2304 ++input_line_pointer;
2305
2306 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2307
2308 sym->sy_tc.output = 1;
2309
2310 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
2311 sym->sy_tc.within = ppc_current_block;
2312
2313 if (exp.X_op != O_symbol
2314 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2315 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2316 ppc_frob_label (sym);
2317 else
2318 {
2319 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2320 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2321 if (ppc_current_csect->sy_tc.within == exp.X_add_symbol)
2322 ppc_current_csect->sy_tc.within = sym;
2323 }
2324
2325 demand_empty_rest_of_line ();
2326 }
2327
2328 /* The .function pseudo-op. This takes several arguments. The first
2329 argument seems to be the external name of the symbol. The second
2330 argment seems to be the label for the start of the function. gcc
2331 uses the same name for both. I have no idea what the third and
2332 fourth arguments are meant to be. The optional fifth argument is
2333 an expression for the size of the function. In COFF this symbol
2334 gets an aux entry like that used for a csect. */
2335
2336 static void
2337 ppc_function (ignore)
2338 int ignore;
2339 {
2340 char *name;
2341 char endc;
2342 char *s;
2343 symbolS *ext_sym;
2344 symbolS *lab_sym;
2345
2346 name = input_line_pointer;
2347 endc = get_symbol_end ();
2348
2349 /* Ignore any [PR] suffix. */
2350 name = ppc_canonicalize_symbol_name (name);
2351 s = strchr (name, '[');
2352 if (s != (char *) NULL
2353 && strcmp (s + 1, "PR]") == 0)
2354 *s = '\0';
2355
2356 ext_sym = symbol_find_or_make (name);
2357
2358 *input_line_pointer = endc;
2359
2360 if (*input_line_pointer != ',')
2361 {
2362 as_bad ("missing symbol name");
2363 ignore_rest_of_line ();
2364 return;
2365 }
2366 ++input_line_pointer;
2367
2368 name = input_line_pointer;
2369 endc = get_symbol_end ();
2370
2371 lab_sym = symbol_find_or_make (name);
2372
2373 *input_line_pointer = endc;
2374
2375 if (ext_sym != lab_sym)
2376 {
2377 ext_sym->sy_value.X_op = O_symbol;
2378 ext_sym->sy_value.X_add_symbol = lab_sym;
2379 ext_sym->sy_value.X_op_symbol = NULL;
2380 ext_sym->sy_value.X_add_number = 0;
2381 }
2382
2383 if (ext_sym->sy_tc.class == -1)
2384 ext_sym->sy_tc.class = XMC_PR;
2385 ext_sym->sy_tc.output = 1;
2386
2387 if (*input_line_pointer == ',')
2388 {
2389 expressionS ignore;
2390
2391 /* Ignore the third argument. */
2392 ++input_line_pointer;
2393 expression (&ignore);
2394 if (*input_line_pointer == ',')
2395 {
2396 /* Ignore the fourth argument. */
2397 ++input_line_pointer;
2398 expression (&ignore);
2399 if (*input_line_pointer == ',')
2400 {
2401 /* The fifth argument is the function size. */
2402 ++input_line_pointer;
2403 ext_sym->sy_tc.size = symbol_new ("L0\001",
2404 absolute_section,
2405 (valueT) 0,
2406 &zero_address_frag);
2407 pseudo_set (ext_sym->sy_tc.size);
2408 }
2409 }
2410 }
2411
2412 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2413 SF_SET_FUNCTION (ext_sym);
2414 SF_SET_PROCESS (ext_sym);
2415 coff_add_linesym (ext_sym);
2416
2417 demand_empty_rest_of_line ();
2418 }
2419
2420 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2421 ".bf". */
2422
2423 static void
2424 ppc_bf (ignore)
2425 int ignore;
2426 {
2427 symbolS *sym;
2428
2429 sym = symbol_make (".bf");
2430 S_SET_SEGMENT (sym, text_section);
2431 sym->sy_frag = frag_now;
2432 S_SET_VALUE (sym, frag_now_fix ());
2433 S_SET_STORAGE_CLASS (sym, C_FCN);
2434
2435 coff_line_base = get_absolute_expression ();
2436
2437 S_SET_NUMBER_AUXILIARY (sym, 1);
2438 SA_SET_SYM_LNNO (sym, coff_line_base);
2439
2440 sym->sy_tc.output = 1;
2441
2442 ppc_frob_label (sym);
2443
2444 demand_empty_rest_of_line ();
2445 }
2446
2447 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2448 ".ef", except that the line number is absolute, not relative to the
2449 most recent ".bf" symbol. */
2450
2451 static void
2452 ppc_ef (ignore)
2453 int ignore;
2454 {
2455 symbolS *sym;
2456
2457 sym = symbol_make (".ef");
2458 S_SET_SEGMENT (sym, text_section);
2459 sym->sy_frag = frag_now;
2460 S_SET_VALUE (sym, frag_now_fix ());
2461 S_SET_STORAGE_CLASS (sym, C_FCN);
2462 S_SET_NUMBER_AUXILIARY (sym, 1);
2463 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2464 sym->sy_tc.output = 1;
2465
2466 ppc_frob_label (sym);
2467
2468 demand_empty_rest_of_line ();
2469 }
2470
2471 /* The .bi and .ei pseudo-ops. These take a string argument and
2472 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2473 the symbol list. */
2474
2475 static void
2476 ppc_biei (ei)
2477 int ei;
2478 {
2479 char *name;
2480 int len;
2481 symbolS *sym;
2482 symbolS *look;
2483
2484 name = demand_copy_C_string (&len);
2485
2486 /* The value of these symbols is actually file offset. Here we set
2487 the value to the index into the line number entries. In
2488 ppc_frob_symbols we set the fix_line field, which will cause BFD
2489 to do the right thing. */
2490
2491 sym = symbol_make (name);
2492 /* obj-coff.c currently only handles line numbers correctly in the
2493 .text section. */
2494 S_SET_SEGMENT (sym, text_section);
2495 S_SET_VALUE (sym, coff_n_line_nos);
2496 sym->bsym->flags |= BSF_DEBUGGING;
2497
2498 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
2499 sym->sy_tc.output = 1;
2500
2501 for (look = symbol_rootP;
2502 (look != (symbolS *) NULL
2503 && (S_GET_STORAGE_CLASS (look) == C_FILE
2504 || S_GET_STORAGE_CLASS (look) == C_BINCL
2505 || S_GET_STORAGE_CLASS (look) == C_EINCL));
2506 look = symbol_next (look))
2507 ;
2508 if (look != (symbolS *) NULL)
2509 {
2510 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2511 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
2512 }
2513
2514 demand_empty_rest_of_line ();
2515 }
2516
2517 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2518 There is one argument, which is a csect symbol. The value of the
2519 .bs symbol is the index of this csect symbol. */
2520
2521 static void
2522 ppc_bs (ignore)
2523 int ignore;
2524 {
2525 char *name;
2526 char endc;
2527 symbolS *csect;
2528 symbolS *sym;
2529
2530 if (ppc_current_block != NULL)
2531 as_bad ("nested .bs blocks");
2532
2533 name = input_line_pointer;
2534 endc = get_symbol_end ();
2535
2536 csect = symbol_find_or_make (name);
2537
2538 *input_line_pointer = endc;
2539
2540 sym = symbol_make (".bs");
2541 S_SET_SEGMENT (sym, now_seg);
2542 S_SET_STORAGE_CLASS (sym, C_BSTAT);
2543 sym->bsym->flags |= BSF_DEBUGGING;
2544 sym->sy_tc.output = 1;
2545
2546 sym->sy_tc.within = csect;
2547
2548 ppc_frob_label (sym);
2549
2550 ppc_current_block = sym;
2551
2552 demand_empty_rest_of_line ();
2553 }
2554
2555 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2556
2557 static void
2558 ppc_es (ignore)
2559 int ignore;
2560 {
2561 symbolS *sym;
2562
2563 if (ppc_current_block == NULL)
2564 as_bad (".es without preceding .bs");
2565
2566 sym = symbol_make (".es");
2567 S_SET_SEGMENT (sym, now_seg);
2568 S_SET_STORAGE_CLASS (sym, C_ESTAT);
2569 sym->bsym->flags |= BSF_DEBUGGING;
2570 sym->sy_tc.output = 1;
2571
2572 ppc_frob_label (sym);
2573
2574 ppc_current_block = NULL;
2575
2576 demand_empty_rest_of_line ();
2577 }
2578
2579 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2580 line number. */
2581
2582 static void
2583 ppc_bb (ignore)
2584 int ignore;
2585 {
2586 symbolS *sym;
2587
2588 sym = symbol_make (".bb");
2589 S_SET_SEGMENT (sym, text_section);
2590 sym->sy_frag = frag_now;
2591 S_SET_VALUE (sym, frag_now_fix ());
2592 S_SET_STORAGE_CLASS (sym, C_BLOCK);
2593
2594 S_SET_NUMBER_AUXILIARY (sym, 1);
2595 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2596
2597 sym->sy_tc.output = 1;
2598
2599 SF_SET_PROCESS (sym);
2600
2601 ppc_frob_label (sym);
2602
2603 demand_empty_rest_of_line ();
2604 }
2605
2606 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2607 line number. */
2608
2609 static void
2610 ppc_eb (ignore)
2611 int ignore;
2612 {
2613 symbolS *sym;
2614
2615 sym = symbol_make (".eb");
2616 S_SET_SEGMENT (sym, text_section);
2617 sym->sy_frag = frag_now;
2618 S_SET_VALUE (sym, frag_now_fix ());
2619 S_SET_STORAGE_CLASS (sym, C_BLOCK);
2620 S_SET_NUMBER_AUXILIARY (sym, 1);
2621 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2622 sym->sy_tc.output = 1;
2623
2624 SF_SET_PROCESS (sym);
2625
2626 ppc_frob_label (sym);
2627
2628 demand_empty_rest_of_line ();
2629 }
2630
2631 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
2632 specified name. */
2633
2634 static void
2635 ppc_bc (ignore)
2636 int ignore;
2637 {
2638 char *name;
2639 int len;
2640 symbolS *sym;
2641
2642 name = demand_copy_C_string (&len);
2643 sym = symbol_make (name);
2644 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2645 sym->bsym->flags |= BSF_DEBUGGING;
2646 S_SET_STORAGE_CLASS (sym, C_BCOMM);
2647 S_SET_VALUE (sym, 0);
2648 sym->sy_tc.output = 1;
2649
2650 ppc_frob_label (sym);
2651
2652 demand_empty_rest_of_line ();
2653 }
2654
2655 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
2656
2657 static void
2658 ppc_ec (ignore)
2659 int ignore;
2660 {
2661 symbolS *sym;
2662
2663 sym = symbol_make (".ec");
2664 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2665 sym->bsym->flags |= BSF_DEBUGGING;
2666 S_SET_STORAGE_CLASS (sym, C_ECOMM);
2667 S_SET_VALUE (sym, 0);
2668 sym->sy_tc.output = 1;
2669
2670 ppc_frob_label (sym);
2671
2672 demand_empty_rest_of_line ();
2673 }
2674
2675 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2676
2677 static void
2678 ppc_toc (ignore)
2679 int ignore;
2680 {
2681 if (ppc_toc_csect != (symbolS *) NULL)
2682 subseg_set (data_section, ppc_toc_csect->sy_tc.subseg);
2683 else
2684 {
2685 subsegT subseg;
2686 symbolS *sym;
2687 symbolS *list;
2688
2689 subseg = ppc_data_subsegment;
2690 ++ppc_data_subsegment;
2691
2692 subseg_new (segment_name (data_section), subseg);
2693 ppc_toc_frag = frag_now;
2694
2695 sym = symbol_find_or_make ("TOC[TC0]");
2696 sym->sy_frag = frag_now;
2697 S_SET_SEGMENT (sym, data_section);
2698 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2699 sym->sy_tc.subseg = subseg;
2700 sym->sy_tc.output = 1;
2701 sym->sy_tc.within = sym;
2702
2703 ppc_toc_csect = sym;
2704
2705 for (list = ppc_data_csects;
2706 list->sy_tc.next != (symbolS *) NULL;
2707 list = list->sy_tc.next)
2708 ;
2709 list->sy_tc.next = sym;
2710
2711 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2712 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2713 }
2714
2715 ppc_current_csect = ppc_toc_csect;
2716
2717 demand_empty_rest_of_line ();
2718 }
2719
2720 #endif /* OBJ_XCOFF */
2721 \f
2722 /* The .tc pseudo-op. This is used when generating either XCOFF or
2723 ELF. This takes two or more arguments.
2724
2725 When generating XCOFF output, the first argument is the name to
2726 give to this location in the toc; this will be a symbol with class
2727 TC. The rest of the arguments are 4 byte values to actually put at
2728 this location in the TOC; often there is just one more argument, a
2729 relocateable symbol reference.
2730
2731 When not generating XCOFF output, the arguments are the same, but
2732 the first argument is simply ignored. */
2733
2734 static void
2735 ppc_tc (ignore)
2736 int ignore;
2737 {
2738 #ifdef OBJ_XCOFF
2739
2740 /* Define the TOC symbol name. */
2741 {
2742 char *name;
2743 char endc;
2744 symbolS *sym;
2745
2746 if (ppc_toc_csect == (symbolS *) NULL
2747 || ppc_toc_csect != ppc_current_csect)
2748 {
2749 as_bad (".tc not in .toc section");
2750 ignore_rest_of_line ();
2751 return;
2752 }
2753
2754 name = input_line_pointer;
2755 endc = get_symbol_end ();
2756
2757 sym = symbol_find_or_make (name);
2758
2759 *input_line_pointer = endc;
2760
2761 if (S_IS_DEFINED (sym))
2762 {
2763 symbolS *label;
2764
2765 label = ppc_current_csect->sy_tc.within;
2766 if (label->sy_tc.class != XMC_TC0)
2767 {
2768 as_warn (".tc with no label");
2769 ignore_rest_of_line ();
2770 return;
2771 }
2772
2773 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
2774 label->sy_frag = sym->sy_frag;
2775 S_SET_VALUE (label, S_GET_VALUE (sym));
2776
2777 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2778 ++input_line_pointer;
2779
2780 return;
2781 }
2782
2783 S_SET_SEGMENT (sym, now_seg);
2784 sym->sy_frag = frag_now;
2785 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2786 sym->sy_tc.class = XMC_TC;
2787 sym->sy_tc.output = 1;
2788
2789 ppc_frob_label (sym);
2790 }
2791
2792 #else /* ! defined (OBJ_XCOFF) */
2793
2794 /* Skip the TOC symbol name. */
2795 while (is_part_of_name (*input_line_pointer)
2796 || *input_line_pointer == '['
2797 || *input_line_pointer == ']'
2798 || *input_line_pointer == '{'
2799 || *input_line_pointer == '}')
2800 ++input_line_pointer;
2801
2802 /* Align to a four byte boundary. */
2803 frag_align (2, 0);
2804 record_alignment (now_seg, 2);
2805
2806 #endif /* ! defined (OBJ_XCOFF) */
2807
2808 if (*input_line_pointer != ',')
2809 demand_empty_rest_of_line ();
2810 else
2811 {
2812 ++input_line_pointer;
2813 cons (4);
2814 }
2815 }
2816 \f
2817 #ifdef TE_PE
2818
2819 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2820
2821 /* Set the current section. */
2822 static void
2823 ppc_set_current_section (new)
2824 segT new;
2825 {
2826 ppc_previous_section = ppc_current_section;
2827 ppc_current_section = new;
2828 }
2829
2830 /* pseudo-op: .previous
2831 behaviour: toggles the current section with the previous section.
2832 errors: None
2833 warnings: "No previous section"
2834 */
2835 static void
2836 ppc_previous(ignore)
2837 int ignore;
2838 {
2839 symbolS *tmp;
2840
2841 if (ppc_previous_section == NULL)
2842 {
2843 as_warn("No previous section to return to. Directive ignored.");
2844 return;
2845 }
2846
2847 subseg_set(ppc_previous_section, 0);
2848
2849 ppc_set_current_section(ppc_previous_section);
2850 }
2851
2852 /* pseudo-op: .pdata
2853 behaviour: predefined read only data section
2854 double word aligned
2855 errors: None
2856 warnings: None
2857 initial: .section .pdata "adr3"
2858 a - don't know -- maybe a misprint
2859 d - initialized data
2860 r - readable
2861 3 - double word aligned (that would be 4 byte boundary)
2862
2863 commentary:
2864 Tag index tables (also known as the function table) for exception
2865 handling, debugging, etc.
2866
2867 */
2868 static void
2869 ppc_pdata(ignore)
2870 int ignore;
2871 {
2872 if (pdata_section == 0)
2873 {
2874 pdata_section = subseg_new (".pdata", 0);
2875
2876 bfd_set_section_flags (stdoutput, pdata_section,
2877 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2878 | SEC_READONLY | SEC_DATA ));
2879
2880 bfd_set_section_alignment (stdoutput, pdata_section, 2);
2881 }
2882 else
2883 {
2884 pdata_section = subseg_new(".pdata", 0);
2885 }
2886 ppc_set_current_section(pdata_section);
2887 }
2888
2889 /* pseudo-op: .ydata
2890 behaviour: predefined read only data section
2891 double word aligned
2892 errors: None
2893 warnings: None
2894 initial: .section .ydata "drw3"
2895 a - don't know -- maybe a misprint
2896 d - initialized data
2897 r - readable
2898 3 - double word aligned (that would be 4 byte boundary)
2899 commentary:
2900 Tag tables (also known as the scope table) for exception handling,
2901 debugging, etc.
2902 */
2903 static void
2904 ppc_ydata(ignore)
2905 int ignore;
2906 {
2907 if (ydata_section == 0)
2908 {
2909 ydata_section = subseg_new (".ydata", 0);
2910 bfd_set_section_flags (stdoutput, ydata_section,
2911 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2912 | SEC_READONLY | SEC_DATA ));
2913
2914 bfd_set_section_alignment (stdoutput, ydata_section, 3);
2915 }
2916 else
2917 {
2918 ydata_section = subseg_new (".ydata", 0);
2919 }
2920 ppc_set_current_section(ydata_section);
2921 }
2922
2923 /* pseudo-op: .reldata
2924 behaviour: predefined read write data section
2925 double word aligned (4-byte)
2926 FIXME: relocation is applied to it
2927 FIXME: what's the difference between this and .data?
2928 errors: None
2929 warnings: None
2930 initial: .section .reldata "drw3"
2931 d - initialized data
2932 r - readable
2933 w - writeable
2934 3 - double word aligned (that would be 8 byte boundary)
2935
2936 commentary:
2937 Like .data, but intended to hold data subject to relocation, such as
2938 function descriptors, etc.
2939 */
2940 static void
2941 ppc_reldata(ignore)
2942 int ignore;
2943 {
2944 if (reldata_section == 0)
2945 {
2946 reldata_section = subseg_new (".reldata", 0);
2947
2948 bfd_set_section_flags (stdoutput, reldata_section,
2949 ( SEC_ALLOC | SEC_LOAD | SEC_RELOC
2950 | SEC_DATA ));
2951
2952 bfd_set_section_alignment (stdoutput, reldata_section, 2);
2953 }
2954 else
2955 {
2956 reldata_section = subseg_new (".reldata", 0);
2957 }
2958 ppc_set_current_section(reldata_section);
2959 }
2960
2961 /* pseudo-op: .rdata
2962 behaviour: predefined read only data section
2963 double word aligned
2964 errors: None
2965 warnings: None
2966 initial: .section .rdata "dr3"
2967 d - initialized data
2968 r - readable
2969 3 - double word aligned (that would be 4 byte boundary)
2970 */
2971 static void
2972 ppc_rdata(ignore)
2973 int ignore;
2974 {
2975 if (rdata_section == 0)
2976 {
2977 rdata_section = subseg_new (".rdata", 0);
2978 bfd_set_section_flags (stdoutput, rdata_section,
2979 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2980 | SEC_READONLY | SEC_DATA ));
2981
2982 bfd_set_section_alignment (stdoutput, rdata_section, 2);
2983 }
2984 else
2985 {
2986 rdata_section = subseg_new (".rdata", 0);
2987 }
2988 ppc_set_current_section(rdata_section);
2989 }
2990
2991 /* pseudo-op: .ualong
2992 behaviour: much like .int, with the exception that no alignment is
2993 performed.
2994 FIXME: test the alignment statement
2995 errors: None
2996 warnings: None
2997 */
2998 static void
2999 ppc_ualong(ignore)
3000 int ignore;
3001 {
3002 /* try for long */
3003 cons ( 4 );
3004 }
3005
3006 /* pseudo-op: .znop <symbol name>
3007 behaviour: Issue a nop instruction
3008 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3009 the supplied symbol name.
3010 errors: None
3011 warnings: Missing symbol name
3012 */
3013 static void
3014 ppc_znop(ignore)
3015 int ignore;
3016 {
3017 unsigned long insn;
3018 const struct powerpc_opcode *opcode;
3019 expressionS ex;
3020 char *f;
3021
3022 symbolS *sym;
3023
3024 /* Strip out the symbol name */
3025 char *symbol_name;
3026 char c;
3027 char *name;
3028 unsigned int exp;
3029 flagword flags;
3030 asection *sec;
3031
3032 symbol_name = input_line_pointer;
3033 c = get_symbol_end ();
3034
3035 name = xmalloc (input_line_pointer - symbol_name + 1);
3036 strcpy (name, symbol_name);
3037
3038 sym = symbol_find_or_make (name);
3039
3040 *input_line_pointer = c;
3041
3042 SKIP_WHITESPACE ();
3043
3044 /* Look up the opcode in the hash table. */
3045 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3046
3047 /* stick in the nop */
3048 insn = opcode->opcode;
3049
3050 /* Write out the instruction. */
3051 f = frag_more (4);
3052 md_number_to_chars (f, insn, 4);
3053 fix_new (frag_now,
3054 f - frag_now->fr_literal,
3055 4,
3056 sym,
3057 0,
3058 0,
3059 BFD_RELOC_16_GOT_PCREL);
3060
3061 }
3062
3063 /* pseudo-op:
3064 behaviour:
3065 errors:
3066 warnings:
3067 */
3068 static void
3069 ppc_pe_comm(lcomm)
3070 int lcomm;
3071 {
3072 register char *name;
3073 register char c;
3074 register char *p;
3075 offsetT temp;
3076 register symbolS *symbolP;
3077 offsetT align;
3078
3079 name = input_line_pointer;
3080 c = get_symbol_end ();
3081
3082 /* just after name is now '\0' */
3083 p = input_line_pointer;
3084 *p = c;
3085 SKIP_WHITESPACE ();
3086 if (*input_line_pointer != ',')
3087 {
3088 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3089 ignore_rest_of_line ();
3090 return;
3091 }
3092
3093 input_line_pointer++; /* skip ',' */
3094 if ((temp = get_absolute_expression ()) < 0)
3095 {
3096 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
3097 ignore_rest_of_line ();
3098 return;
3099 }
3100
3101 if (! lcomm)
3102 {
3103 /* The third argument to .comm is the alignment. */
3104 if (*input_line_pointer != ',')
3105 align = 3;
3106 else
3107 {
3108 ++input_line_pointer;
3109 align = get_absolute_expression ();
3110 if (align <= 0)
3111 {
3112 as_warn ("ignoring bad alignment");
3113 align = 3;
3114 }
3115 }
3116 }
3117
3118 *p = 0;
3119 symbolP = symbol_find_or_make (name);
3120
3121 *p = c;
3122 if (S_IS_DEFINED (symbolP))
3123 {
3124 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3125 S_GET_NAME (symbolP));
3126 ignore_rest_of_line ();
3127 return;
3128 }
3129
3130 if (S_GET_VALUE (symbolP))
3131 {
3132 if (S_GET_VALUE (symbolP) != (valueT) temp)
3133 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3134 S_GET_NAME (symbolP),
3135 (long) S_GET_VALUE (symbolP),
3136 (long) temp);
3137 }
3138 else
3139 {
3140 S_SET_VALUE (symbolP, (valueT) temp);
3141 S_SET_EXTERNAL (symbolP);
3142 }
3143
3144 demand_empty_rest_of_line ();
3145 }
3146
3147 /*
3148 * implement the .section pseudo op:
3149 * .section name {, "flags"}
3150 * ^ ^
3151 * | +--- optional flags: 'b' for bss
3152 * | 'i' for info
3153 * +-- section name 'l' for lib
3154 * 'n' for noload
3155 * 'o' for over
3156 * 'w' for data
3157 * 'd' (apparently m88k for data)
3158 * 'x' for text
3159 * But if the argument is not a quoted string, treat it as a
3160 * subsegment number.
3161 *
3162 * FIXME: this is a copy of the section processing from obj-coff.c, with
3163 * additions/changes for the moto-pas assembler support. There are three
3164 * categories:
3165 *
3166 * FIXME: I just noticed this. This doesn't work at all really. It it
3167 * setting bits that bfd probably neither understands or uses. The
3168 * correct approach (?) will have to incorporate extra fields attached
3169 * to the section to hold the system specific stuff. (krk)
3170 *
3171 * Section Contents:
3172 * 'a' - unknown - referred to in documentation, but no definition supplied
3173 * 'c' - section has code
3174 * 'd' - section has initialized data
3175 * 'u' - section has uninitialized data
3176 * 'i' - section contains directives (info)
3177 * 'n' - section can be discarded
3178 * 'R' - remove section at link time
3179 *
3180 * Section Protection:
3181 * 'r' - section is readable
3182 * 'w' - section is writeable
3183 * 'x' - section is executable
3184 * 's' - section is sharable
3185 *
3186 * Section Alignment:
3187 * '0' - align to byte boundary
3188 * '1' - align to halfword undary
3189 * '2' - align to word boundary
3190 * '3' - align to doubleword boundary
3191 * '4' - align to quadword boundary
3192 * '5' - align to 32 byte boundary
3193 * '6' - align to 64 byte boundary
3194 *
3195 */
3196
3197 void
3198 ppc_pe_section (ignore)
3199 int ignore;
3200 {
3201 /* Strip out the section name */
3202 char *section_name;
3203 char c;
3204 char *name;
3205 unsigned int exp;
3206 flagword flags;
3207 segT sec;
3208 int align;
3209
3210 section_name = input_line_pointer;
3211 c = get_symbol_end ();
3212
3213 name = xmalloc (input_line_pointer - section_name + 1);
3214 strcpy (name, section_name);
3215
3216 *input_line_pointer = c;
3217
3218 SKIP_WHITESPACE ();
3219
3220 exp = 0;
3221 flags = SEC_NO_FLAGS;
3222
3223 if (strcmp (name, ".idata$2") == 0)
3224 {
3225 align = 0;
3226 }
3227 else if (strcmp (name, ".idata$3") == 0)
3228 {
3229 align = 0;
3230 }
3231 else if (strcmp (name, ".idata$4") == 0)
3232 {
3233 align = 2;
3234 }
3235 else if (strcmp (name, ".idata$5") == 0)
3236 {
3237 align = 2;
3238 }
3239 else if (strcmp (name, ".idata$6") == 0)
3240 {
3241 align = 1;
3242 }
3243 else
3244 align = 4; /* default alignment to 16 byte boundary */
3245
3246 if (*input_line_pointer == ',')
3247 {
3248 ++input_line_pointer;
3249 SKIP_WHITESPACE ();
3250 if (*input_line_pointer != '"')
3251 exp = get_absolute_expression ();
3252 else
3253 {
3254 ++input_line_pointer;
3255 while (*input_line_pointer != '"'
3256 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3257 {
3258 switch (*input_line_pointer)
3259 {
3260 /* Section Contents */
3261 case 'a': /* unknown */
3262 as_warn ("Unsupported section attribute -- 'a'");
3263 break;
3264 case 'c': /* code section */
3265 flags |= SEC_CODE;
3266 break;
3267 case 'd': /* section has initialized data */
3268 flags |= SEC_DATA;
3269 break;
3270 case 'u': /* section has uninitialized data */
3271 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3272 in winnt.h */
3273 flags |= SEC_ROM;
3274 break;
3275 case 'i': /* section contains directives (info) */
3276 /* FIXME: This is IMAGE_SCN_LNK_INFO
3277 in winnt.h */
3278 flags |= SEC_HAS_CONTENTS;
3279 break;
3280 case 'n': /* section can be discarded */
3281 flags &=~ SEC_LOAD;
3282 break;
3283 case 'R': /* Remove section at link time */
3284 flags |= SEC_NEVER_LOAD;
3285 break;
3286
3287 /* Section Protection */
3288 case 'r': /* section is readable */
3289 flags |= IMAGE_SCN_MEM_READ;
3290 break;
3291 case 'w': /* section is writeable */
3292 flags |= IMAGE_SCN_MEM_WRITE;
3293 break;
3294 case 'x': /* section is executable */
3295 flags |= IMAGE_SCN_MEM_EXECUTE;
3296 break;
3297 case 's': /* section is sharable */
3298 flags |= IMAGE_SCN_MEM_SHARED;
3299 break;
3300
3301 /* Section Alignment */
3302 case '0': /* align to byte boundary */
3303 flags |= IMAGE_SCN_ALIGN_1BYTES;
3304 align = 0;
3305 break;
3306 case '1': /* align to halfword boundary */
3307 flags |= IMAGE_SCN_ALIGN_2BYTES;
3308 align = 1;
3309 break;
3310 case '2': /* align to word boundary */
3311 flags |= IMAGE_SCN_ALIGN_4BYTES;
3312 align = 2;
3313 break;
3314 case '3': /* align to doubleword boundary */
3315 flags |= IMAGE_SCN_ALIGN_8BYTES;
3316 align = 3;
3317 break;
3318 case '4': /* align to quadword boundary */
3319 flags |= IMAGE_SCN_ALIGN_16BYTES;
3320 align = 4;
3321 break;
3322 case '5': /* align to 32 byte boundary */
3323 flags |= IMAGE_SCN_ALIGN_32BYTES;
3324 align = 5;
3325 break;
3326 case '6': /* align to 64 byte boundary */
3327 flags |= IMAGE_SCN_ALIGN_64BYTES;
3328 align = 6;
3329 break;
3330
3331 default:
3332 as_warn("unknown section attribute '%c'",
3333 *input_line_pointer);
3334 break;
3335 }
3336 ++input_line_pointer;
3337 }
3338 if (*input_line_pointer == '"')
3339 ++input_line_pointer;
3340 }
3341 }
3342
3343 sec = subseg_new (name, (subsegT) exp);
3344
3345 ppc_set_current_section(sec);
3346
3347 if (flags != SEC_NO_FLAGS)
3348 {
3349 if (! bfd_set_section_flags (stdoutput, sec, flags))
3350 as_warn ("error setting flags for \"%s\": %s",
3351 bfd_section_name (stdoutput, sec),
3352 bfd_errmsg (bfd_get_error ()));
3353 }
3354
3355 bfd_set_section_alignment(stdoutput, sec, align);
3356
3357 }
3358
3359 static void
3360 ppc_pe_function (ignore)
3361 int ignore;
3362 {
3363 char *name;
3364 char endc;
3365 symbolS *ext_sym;
3366
3367 name = input_line_pointer;
3368 endc = get_symbol_end ();
3369
3370 ext_sym = symbol_find_or_make (name);
3371
3372 *input_line_pointer = endc;
3373
3374 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3375 SF_SET_FUNCTION (ext_sym);
3376 SF_SET_PROCESS (ext_sym);
3377 coff_add_linesym (ext_sym);
3378
3379 demand_empty_rest_of_line ();
3380 }
3381
3382 static void
3383 ppc_pe_tocd (ignore)
3384 int ignore;
3385 {
3386 if (tocdata_section == 0)
3387 {
3388 tocdata_section = subseg_new (".tocd", 0);
3389 /* FIXME: section flags won't work */
3390 bfd_set_section_flags (stdoutput, tocdata_section,
3391 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3392 | SEC_READONLY | SEC_DATA ));
3393
3394 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
3395 }
3396 else
3397 {
3398 rdata_section = subseg_new (".tocd", 0);
3399 }
3400
3401 ppc_set_current_section(tocdata_section);
3402
3403 demand_empty_rest_of_line ();
3404 }
3405
3406 /* Don't adjust TOC relocs to use the section symbol. */
3407
3408 int
3409 ppc_pe_fix_adjustable (fix)
3410 fixS *fix;
3411 {
3412 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
3413 }
3414
3415 #endif
3416 \f
3417 #ifdef OBJ_XCOFF
3418
3419 /* XCOFF specific symbol and file handling. */
3420
3421 /* Canonicalize the symbol name. We use the to force the suffix, if
3422 any, to use square brackets, and to be in upper case. */
3423
3424 char *
3425 ppc_canonicalize_symbol_name (name)
3426 char *name;
3427 {
3428 char *s;
3429
3430 if (ppc_stab_symbol)
3431 return name;
3432
3433 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
3434 ;
3435 if (*s != '\0')
3436 {
3437 char brac;
3438
3439 if (*s == '[')
3440 brac = ']';
3441 else
3442 {
3443 *s = '[';
3444 brac = '}';
3445 }
3446
3447 for (s++; *s != '\0' && *s != brac; s++)
3448 if (islower (*s))
3449 *s = toupper (*s);
3450
3451 if (*s == '\0' || s[1] != '\0')
3452 as_bad ("bad symbol suffix");
3453
3454 *s = ']';
3455 }
3456
3457 return name;
3458 }
3459
3460 /* Set the class of a symbol based on the suffix, if any. This is
3461 called whenever a new symbol is created. */
3462
3463 void
3464 ppc_symbol_new_hook (sym)
3465 symbolS *sym;
3466 {
3467 const char *s;
3468
3469 sym->sy_tc.next = NULL;
3470 sym->sy_tc.output = 0;
3471 sym->sy_tc.class = -1;
3472 sym->sy_tc.real_name = NULL;
3473 sym->sy_tc.subseg = 0;
3474 sym->sy_tc.align = 0;
3475 sym->sy_tc.size = NULL;
3476 sym->sy_tc.within = NULL;
3477
3478 if (ppc_stab_symbol)
3479 return;
3480
3481 s = strchr (S_GET_NAME (sym), '[');
3482 if (s == (const char *) NULL)
3483 {
3484 /* There is no suffix. */
3485 return;
3486 }
3487
3488 ++s;
3489
3490 switch (s[0])
3491 {
3492 case 'B':
3493 if (strcmp (s, "BS]") == 0)
3494 sym->sy_tc.class = XMC_BS;
3495 break;
3496 case 'D':
3497 if (strcmp (s, "DB]") == 0)
3498 sym->sy_tc.class = XMC_DB;
3499 else if (strcmp (s, "DS]") == 0)
3500 sym->sy_tc.class = XMC_DS;
3501 break;
3502 case 'G':
3503 if (strcmp (s, "GL]") == 0)
3504 sym->sy_tc.class = XMC_GL;
3505 break;
3506 case 'P':
3507 if (strcmp (s, "PR]") == 0)
3508 sym->sy_tc.class = XMC_PR;
3509 break;
3510 case 'R':
3511 if (strcmp (s, "RO]") == 0)
3512 sym->sy_tc.class = XMC_RO;
3513 else if (strcmp (s, "RW]") == 0)
3514 sym->sy_tc.class = XMC_RW;
3515 break;
3516 case 'S':
3517 if (strcmp (s, "SV]") == 0)
3518 sym->sy_tc.class = XMC_SV;
3519 break;
3520 case 'T':
3521 if (strcmp (s, "TC]") == 0)
3522 sym->sy_tc.class = XMC_TC;
3523 else if (strcmp (s, "TI]") == 0)
3524 sym->sy_tc.class = XMC_TI;
3525 else if (strcmp (s, "TB]") == 0)
3526 sym->sy_tc.class = XMC_TB;
3527 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
3528 sym->sy_tc.class = XMC_TC0;
3529 break;
3530 case 'U':
3531 if (strcmp (s, "UA]") == 0)
3532 sym->sy_tc.class = XMC_UA;
3533 else if (strcmp (s, "UC]") == 0)
3534 sym->sy_tc.class = XMC_UC;
3535 break;
3536 case 'X':
3537 if (strcmp (s, "XO]") == 0)
3538 sym->sy_tc.class = XMC_XO;
3539 break;
3540 }
3541
3542 if (sym->sy_tc.class == -1)
3543 as_bad ("Unrecognized symbol suffix");
3544 }
3545
3546 /* Set the class of a label based on where it is defined. This
3547 handles symbols without suffixes. Also, move the symbol so that it
3548 follows the csect symbol. */
3549
3550 void
3551 ppc_frob_label (sym)
3552 symbolS *sym;
3553 {
3554 if (ppc_current_csect != (symbolS *) NULL)
3555 {
3556 if (sym->sy_tc.class == -1)
3557 sym->sy_tc.class = ppc_current_csect->sy_tc.class;
3558
3559 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3560 symbol_append (sym, ppc_current_csect->sy_tc.within, &symbol_rootP,
3561 &symbol_lastP);
3562 ppc_current_csect->sy_tc.within = sym;
3563 }
3564 }
3565
3566 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3567 seen. It tells ppc_adjust_symtab whether it needs to look through
3568 the symbols. */
3569
3570 static boolean ppc_saw_abs;
3571
3572 /* Change the name of a symbol just before writing it out. Set the
3573 real name if the .rename pseudo-op was used. Otherwise, remove any
3574 class suffix. Return 1 if the symbol should not be included in the
3575 symbol table. */
3576
3577 int
3578 ppc_frob_symbol (sym)
3579 symbolS *sym;
3580 {
3581 static symbolS *ppc_last_function;
3582 static symbolS *set_end;
3583
3584 /* Discard symbols that should not be included in the output symbol
3585 table. */
3586 if (! sym->sy_used_in_reloc
3587 && ((sym->bsym->flags & BSF_SECTION_SYM) != 0
3588 || (! S_IS_EXTERNAL (sym)
3589 && ! sym->sy_tc.output
3590 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
3591 return 1;
3592
3593 if (sym->sy_tc.real_name != (char *) NULL)
3594 S_SET_NAME (sym, sym->sy_tc.real_name);
3595 else
3596 {
3597 const char *name;
3598 const char *s;
3599
3600 name = S_GET_NAME (sym);
3601 s = strchr (name, '[');
3602 if (s != (char *) NULL)
3603 {
3604 unsigned int len;
3605 char *snew;
3606
3607 len = s - name;
3608 snew = xmalloc (len + 1);
3609 memcpy (snew, name, len);
3610 snew[len] = '\0';
3611
3612 S_SET_NAME (sym, snew);
3613 }
3614 }
3615
3616 if (set_end != (symbolS *) NULL)
3617 {
3618 SA_SET_SYM_ENDNDX (set_end, sym);
3619 set_end = NULL;
3620 }
3621
3622 if (SF_GET_FUNCTION (sym))
3623 {
3624 if (ppc_last_function != (symbolS *) NULL)
3625 as_warn ("two .function pseudo-ops with no intervening .ef");
3626 ppc_last_function = sym;
3627 if (sym->sy_tc.size != (symbolS *) NULL)
3628 {
3629 resolve_symbol_value (sym->sy_tc.size);
3630 SA_SET_SYM_FSIZE (sym, (long) S_GET_VALUE (sym->sy_tc.size));
3631 }
3632 }
3633 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
3634 && strcmp (S_GET_NAME (sym), ".ef") == 0)
3635 {
3636 if (ppc_last_function == (symbolS *) NULL)
3637 as_warn (".ef with no preceding .function");
3638 else
3639 {
3640 set_end = ppc_last_function;
3641 ppc_last_function = NULL;
3642
3643 /* We don't have a C_EFCN symbol, but we need to force the
3644 COFF backend to believe that it has seen one. */
3645 coff_last_function = NULL;
3646 }
3647 }
3648
3649 if (! S_IS_EXTERNAL (sym)
3650 && (sym->bsym->flags & BSF_SECTION_SYM) == 0
3651 && S_GET_STORAGE_CLASS (sym) != C_FILE
3652 && S_GET_STORAGE_CLASS (sym) != C_FCN
3653 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
3654 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
3655 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
3656 && S_GET_STORAGE_CLASS (sym) != C_BINCL
3657 && S_GET_STORAGE_CLASS (sym) != C_EINCL
3658 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
3659 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
3660
3661 if (S_GET_STORAGE_CLASS (sym) == C_EXT
3662 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
3663 {
3664 int i;
3665 union internal_auxent *a;
3666
3667 /* Create a csect aux. */
3668 i = S_GET_NUMBER_AUXILIARY (sym);
3669 S_SET_NUMBER_AUXILIARY (sym, i + 1);
3670 a = &coffsymbol (sym->bsym)->native[i + 1].u.auxent;
3671 if (sym->sy_tc.class == XMC_TC0)
3672 {
3673 /* This is the TOC table. */
3674 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
3675 a->x_csect.x_scnlen.l = 0;
3676 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
3677 }
3678 else if (sym->sy_tc.subseg != 0)
3679 {
3680 /* This is a csect symbol. x_scnlen is the size of the
3681 csect. */
3682 if (sym->sy_tc.next == (symbolS *) NULL)
3683 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
3684 S_GET_SEGMENT (sym))
3685 - S_GET_VALUE (sym));
3686 else
3687 {
3688 resolve_symbol_value (sym->sy_tc.next);
3689 a->x_csect.x_scnlen.l = (S_GET_VALUE (sym->sy_tc.next)
3690 - S_GET_VALUE (sym));
3691 }
3692 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_SD;
3693 }
3694 else if (S_GET_SEGMENT (sym) == bss_section)
3695 {
3696 /* This is a common symbol. */
3697 a->x_csect.x_scnlen.l = sym->sy_frag->fr_offset;
3698 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_CM;
3699 if (S_IS_EXTERNAL (sym))
3700 sym->sy_tc.class = XMC_RW;
3701 else
3702 sym->sy_tc.class = XMC_BS;
3703 }
3704 else if (S_GET_SEGMENT (sym) == absolute_section)
3705 {
3706 /* This is an absolute symbol. The csect will be created by
3707 ppc_adjust_symtab. */
3708 ppc_saw_abs = true;
3709 a->x_csect.x_smtyp = XTY_LD;
3710 if (sym->sy_tc.class == -1)
3711 sym->sy_tc.class = XMC_XO;
3712 }
3713 else if (! S_IS_DEFINED (sym))
3714 {
3715 /* This is an external symbol. */
3716 a->x_csect.x_scnlen.l = 0;
3717 a->x_csect.x_smtyp = XTY_ER;
3718 }
3719 else if (sym->sy_tc.class == XMC_TC)
3720 {
3721 symbolS *next;
3722
3723 /* This is a TOC definition. x_scnlen is the size of the
3724 TOC entry. */
3725 next = symbol_next (sym);
3726 while (next->sy_tc.class == XMC_TC0)
3727 next = symbol_next (next);
3728 if (next == (symbolS *) NULL
3729 || next->sy_tc.class != XMC_TC)
3730 {
3731 if (ppc_after_toc_frag == (fragS *) NULL)
3732 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
3733 data_section)
3734 - S_GET_VALUE (sym));
3735 else
3736 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
3737 - S_GET_VALUE (sym));
3738 }
3739 else
3740 {
3741 resolve_symbol_value (next);
3742 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
3743 - S_GET_VALUE (sym));
3744 }
3745 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
3746 }
3747 else
3748 {
3749 symbolS *csect;
3750
3751 /* This is a normal symbol definition. x_scnlen is the
3752 symbol index of the containing csect. */
3753 if (S_GET_SEGMENT (sym) == text_section)
3754 csect = ppc_text_csects;
3755 else if (S_GET_SEGMENT (sym) == data_section)
3756 csect = ppc_data_csects;
3757 else
3758 abort ();
3759
3760 /* Skip the initial dummy symbol. */
3761 csect = csect->sy_tc.next;
3762
3763 if (csect == (symbolS *) NULL)
3764 {
3765 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym));
3766 a->x_csect.x_scnlen.l = 0;
3767 }
3768 else
3769 {
3770 while (csect->sy_tc.next != (symbolS *) NULL)
3771 {
3772 resolve_symbol_value (csect->sy_tc.next);
3773 if (S_GET_VALUE (csect->sy_tc.next) > S_GET_VALUE (sym))
3774 break;
3775 csect = csect->sy_tc.next;
3776 }
3777
3778 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
3779 coffsymbol (sym->bsym)->native[i + 1].fix_scnlen = 1;
3780 }
3781 a->x_csect.x_smtyp = XTY_LD;
3782 }
3783
3784 a->x_csect.x_parmhash = 0;
3785 a->x_csect.x_snhash = 0;
3786 if (sym->sy_tc.class == -1)
3787 a->x_csect.x_smclas = XMC_PR;
3788 else
3789 a->x_csect.x_smclas = sym->sy_tc.class;
3790 a->x_csect.x_stab = 0;
3791 a->x_csect.x_snstab = 0;
3792
3793 /* Don't let the COFF backend resort these symbols. */
3794 sym->bsym->flags |= BSF_NOT_AT_END;
3795 }
3796 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
3797 {
3798 /* We want the value to be the symbol index of the referenced
3799 csect symbol. BFD will do that for us if we set the right
3800 flags. */
3801 S_SET_VALUE (sym,
3802 (valueT) coffsymbol (sym->sy_tc.within->bsym)->native);
3803 coffsymbol (sym->bsym)->native->fix_value = 1;
3804 }
3805 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
3806 {
3807 symbolS *block;
3808 symbolS *csect;
3809
3810 /* The value is the offset from the enclosing csect. */
3811 block = sym->sy_tc.within;
3812 csect = block->sy_tc.within;
3813 resolve_symbol_value (csect);
3814 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
3815 }
3816 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
3817 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
3818 {
3819 /* We want the value to be a file offset into the line numbers.
3820 BFD will do that for us if we set the right flags. We have
3821 already set the value correctly. */
3822 coffsymbol (sym->bsym)->native->fix_line = 1;
3823 }
3824
3825 return 0;
3826 }
3827
3828 /* Adjust the symbol table. This creates csect symbols for all
3829 absolute symbols. */
3830
3831 void
3832 ppc_adjust_symtab ()
3833 {
3834 symbolS *sym;
3835
3836 if (! ppc_saw_abs)
3837 return;
3838
3839 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
3840 {
3841 symbolS *csect;
3842 int i;
3843 union internal_auxent *a;
3844
3845 if (S_GET_SEGMENT (sym) != absolute_section)
3846 continue;
3847
3848 csect = symbol_create (".abs[XO]", absolute_section,
3849 S_GET_VALUE (sym), &zero_address_frag);
3850 csect->bsym->value = S_GET_VALUE (sym);
3851 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
3852 i = S_GET_NUMBER_AUXILIARY (csect);
3853 S_SET_NUMBER_AUXILIARY (csect, i + 1);
3854 a = &coffsymbol (csect->bsym)->native[i + 1].u.auxent;
3855 a->x_csect.x_scnlen.l = 0;
3856 a->x_csect.x_smtyp = XTY_SD;
3857 a->x_csect.x_parmhash = 0;
3858 a->x_csect.x_snhash = 0;
3859 a->x_csect.x_smclas = XMC_XO;
3860 a->x_csect.x_stab = 0;
3861 a->x_csect.x_snstab = 0;
3862
3863 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
3864
3865 i = S_GET_NUMBER_AUXILIARY (sym);
3866 a = &coffsymbol (sym->bsym)->native[i].u.auxent;
3867 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
3868 coffsymbol (sym->bsym)->native[i].fix_scnlen = 1;
3869 }
3870
3871 ppc_saw_abs = false;
3872 }
3873
3874 /* Set the VMA for a section. This is called on all the sections in
3875 turn. */
3876
3877 void
3878 ppc_frob_section (sec)
3879 asection *sec;
3880 {
3881 static bfd_size_type vma = 0;
3882
3883 bfd_set_section_vma (stdoutput, sec, vma);
3884 vma += bfd_section_size (stdoutput, sec);
3885 }
3886
3887 #endif /* OBJ_XCOFF */
3888 \f
3889 /* Turn a string in input_line_pointer into a floating point constant
3890 of type type, and store the appropriate bytes in *litp. The number
3891 of LITTLENUMS emitted is stored in *sizep . An error message is
3892 returned, or NULL on OK. */
3893
3894 char *
3895 md_atof (type, litp, sizep)
3896 int type;
3897 char *litp;
3898 int *sizep;
3899 {
3900 int prec;
3901 LITTLENUM_TYPE words[4];
3902 char *t;
3903 int i;
3904
3905 switch (type)
3906 {
3907 case 'f':
3908 prec = 2;
3909 break;
3910
3911 case 'd':
3912 prec = 4;
3913 break;
3914
3915 default:
3916 *sizep = 0;
3917 return "bad call to md_atof";
3918 }
3919
3920 t = atof_ieee (input_line_pointer, type, words);
3921 if (t)
3922 input_line_pointer = t;
3923
3924 *sizep = prec * 2;
3925
3926 if (target_big_endian)
3927 {
3928 for (i = 0; i < prec; i++)
3929 {
3930 md_number_to_chars (litp, (valueT) words[i], 2);
3931 litp += 2;
3932 }
3933 }
3934 else
3935 {
3936 for (i = prec - 1; i >= 0; i--)
3937 {
3938 md_number_to_chars (litp, (valueT) words[i], 2);
3939 litp += 2;
3940 }
3941 }
3942
3943 return NULL;
3944 }
3945
3946 /* Write a value out to the object file, using the appropriate
3947 endianness. */
3948
3949 void
3950 md_number_to_chars (buf, val, n)
3951 char *buf;
3952 valueT val;
3953 int n;
3954 {
3955 if (target_big_endian)
3956 number_to_chars_bigendian (buf, val, n);
3957 else
3958 number_to_chars_littleendian (buf, val, n);
3959 }
3960
3961 /* Align a section (I don't know why this is machine dependent). */
3962
3963 valueT
3964 md_section_align (seg, addr)
3965 asection *seg;
3966 valueT addr;
3967 {
3968 int align = bfd_get_section_alignment (stdoutput, seg);
3969
3970 return ((addr + (1 << align) - 1) & (-1 << align));
3971 }
3972
3973 /* We don't have any form of relaxing. */
3974
3975 int
3976 md_estimate_size_before_relax (fragp, seg)
3977 fragS *fragp;
3978 asection *seg;
3979 {
3980 abort ();
3981 return 0;
3982 }
3983
3984 /* Convert a machine dependent frag. We never generate these. */
3985
3986 void
3987 md_convert_frag (abfd, sec, fragp)
3988 bfd *abfd;
3989 asection *sec;
3990 fragS *fragp;
3991 {
3992 abort ();
3993 }
3994
3995 /* We have no need to default values of symbols. */
3996
3997 /*ARGSUSED*/
3998 symbolS *
3999 md_undefined_symbol (name)
4000 char *name;
4001 {
4002 return 0;
4003 }
4004 \f
4005 /* Functions concerning relocs. */
4006
4007 /* The location from which a PC relative jump should be calculated,
4008 given a PC relative reloc. */
4009
4010 long
4011 md_pcrel_from_section (fixp, sec)
4012 fixS *fixp;
4013 segT sec;
4014 {
4015 #ifdef OBJ_ELF
4016 if (fixp->fx_addsy != (symbolS *) NULL
4017 && (! S_IS_DEFINED (fixp->fx_addsy)
4018 || TC_FORCE_RELOCATION_SECTION (fixp, sec)))
4019 return 0;
4020 #endif
4021
4022 return fixp->fx_frag->fr_address + fixp->fx_where;
4023 }
4024
4025 #ifdef OBJ_XCOFF
4026
4027 /* This is called to see whether a fixup should be adjusted to use a
4028 section symbol. We take the opportunity to change a fixup against
4029 a symbol in the TOC subsegment into a reloc against the
4030 corresponding .tc symbol. */
4031
4032 int
4033 ppc_fix_adjustable (fix)
4034 fixS *fix;
4035 {
4036 valueT val;
4037
4038 resolve_symbol_value (fix->fx_addsy);
4039 val = S_GET_VALUE (fix->fx_addsy);
4040 if (ppc_toc_csect != (symbolS *) NULL
4041 && fix->fx_addsy != (symbolS *) NULL
4042 && fix->fx_addsy != ppc_toc_csect
4043 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4044 && val >= ppc_toc_frag->fr_address
4045 && (ppc_after_toc_frag == (fragS *) NULL
4046 || val < ppc_after_toc_frag->fr_address))
4047 {
4048 symbolS *sy;
4049
4050 for (sy = symbol_next (ppc_toc_csect);
4051 sy != (symbolS *) NULL;
4052 sy = symbol_next (sy))
4053 {
4054 if (sy->sy_tc.class == XMC_TC0)
4055 continue;
4056 if (sy->sy_tc.class != XMC_TC)
4057 break;
4058 resolve_symbol_value (sy);
4059 if (val == S_GET_VALUE (sy))
4060 {
4061 fix->fx_addsy = sy;
4062 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4063 return 0;
4064 }
4065 }
4066
4067 as_bad_where (fix->fx_file, fix->fx_line,
4068 "symbol in .toc does not match any .tc");
4069 }
4070
4071 /* Possibly adjust the reloc to be against the csect. */
4072 if (fix->fx_addsy != (symbolS *) NULL
4073 && fix->fx_addsy->sy_tc.subseg == 0
4074 && fix->fx_addsy->sy_tc.class != XMC_TC0
4075 && fix->fx_addsy->sy_tc.class != XMC_TC
4076 && S_GET_SEGMENT (fix->fx_addsy) != bss_section)
4077 {
4078 symbolS *csect;
4079
4080 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4081 csect = ppc_text_csects;
4082 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4083 csect = ppc_data_csects;
4084 else
4085 abort ();
4086
4087 /* Skip the initial dummy symbol. */
4088 csect = csect->sy_tc.next;
4089
4090 if (csect != (symbolS *) NULL)
4091 {
4092 while (csect->sy_tc.next != (symbolS *) NULL
4093 && (csect->sy_tc.next->sy_frag->fr_address
4094 <= fix->fx_addsy->sy_frag->fr_address))
4095 csect = csect->sy_tc.next;
4096
4097 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4098 - csect->sy_frag->fr_address);
4099 fix->fx_addsy = csect;
4100 }
4101 }
4102
4103 /* Adjust a reloc against a .lcomm symbol to be against the base
4104 .lcomm. */
4105 if (fix->fx_addsy != (symbolS *) NULL
4106 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
4107 && ! S_IS_EXTERNAL (fix->fx_addsy))
4108 {
4109 resolve_symbol_value (fix->fx_addsy->sy_frag->fr_symbol);
4110 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4111 - S_GET_VALUE (fix->fx_addsy->sy_frag->fr_symbol));
4112 fix->fx_addsy = fix->fx_addsy->sy_frag->fr_symbol;
4113 }
4114
4115 return 0;
4116 }
4117
4118 #endif
4119
4120 /* See whether a symbol is in the TOC section. */
4121
4122 static int
4123 ppc_is_toc_sym (sym)
4124 symbolS *sym;
4125 {
4126 #ifdef OBJ_XCOFF
4127 return sym->sy_tc.class == XMC_TC;
4128 #else
4129 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
4130 #endif
4131 }
4132
4133 /* Apply a fixup to the object code. This is called for all the
4134 fixups we generated by the call to fix_new_exp, above. In the call
4135 above we used a reloc code which was the largest legal reloc code
4136 plus the operand index. Here we undo that to recover the operand
4137 index. At this point all symbol values should be fully resolved,
4138 and we attempt to completely resolve the reloc. If we can not do
4139 that, we determine the correct reloc code and put it back in the
4140 fixup. */
4141
4142 int
4143 md_apply_fix3 (fixp, valuep, seg)
4144 fixS *fixp;
4145 valueT *valuep;
4146 segT seg;
4147 {
4148 valueT value;
4149
4150 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4151 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4152 doing this relocation the code in write.c is going to call
4153 bfd_perform_relocation, which is also going to use the symbol
4154 value. That means that if the reloc is fully resolved we want to
4155 use *valuep since bfd_perform_relocation is not being used.
4156 However, if the reloc is not fully resolved we do not want to use
4157 *valuep, and must use fx_offset instead. However, if the reloc
4158 is PC relative, we do want to use *valuep since it includes the
4159 result of md_pcrel_from. This is confusing. */
4160
4161 if (fixp->fx_addsy == (symbolS *) NULL)
4162 {
4163 value = *valuep;
4164 fixp->fx_done = 1;
4165 }
4166 else if (fixp->fx_pcrel)
4167 value = *valuep;
4168 else
4169 {
4170 value = fixp->fx_offset;
4171 if (fixp->fx_subsy != (symbolS *) NULL)
4172 {
4173 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
4174 value -= S_GET_VALUE (fixp->fx_subsy);
4175 else
4176 {
4177 /* We can't actually support subtracting a symbol. */
4178 as_bad_where (fixp->fx_file, fixp->fx_line,
4179 "expression too complex");
4180 }
4181 }
4182 }
4183
4184 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
4185 {
4186 int opindex;
4187 const struct powerpc_operand *operand;
4188 char *where;
4189 unsigned long insn;
4190
4191 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
4192
4193 operand = &powerpc_operands[opindex];
4194
4195 #ifdef OBJ_XCOFF
4196 /* It appears that an instruction like
4197 l 9,LC..1(30)
4198 when LC..1 is not a TOC symbol does not generate a reloc. It
4199 uses the offset of LC..1 within its csect. However, .long
4200 LC..1 will generate a reloc. I can't find any documentation
4201 on how these cases are to be distinguished, so this is a wild
4202 guess. These cases are generated by gcc -mminimal-toc. */
4203 if ((operand->flags & PPC_OPERAND_PARENS) != 0
4204 && operand->bits == 16
4205 && operand->shift == 0
4206 && operand->insert == NULL
4207 && fixp->fx_addsy != NULL
4208 && fixp->fx_addsy->sy_tc.subseg != 0
4209 && fixp->fx_addsy->sy_tc.class != XMC_TC
4210 && fixp->fx_addsy->sy_tc.class != XMC_TC0
4211 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
4212 {
4213 value = fixp->fx_offset;
4214 fixp->fx_done = 1;
4215 }
4216 #endif
4217
4218 /* Fetch the instruction, insert the fully resolved operand
4219 value, and stuff the instruction back again. */
4220 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4221 if (target_big_endian)
4222 insn = bfd_getb32 ((unsigned char *) where);
4223 else
4224 insn = bfd_getl32 ((unsigned char *) where);
4225 insn = ppc_insert_operand (insn, operand, (offsetT) value,
4226 fixp->fx_file, fixp->fx_line);
4227 if (target_big_endian)
4228 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4229 else
4230 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4231
4232 if (fixp->fx_done)
4233 {
4234 /* Nothing else to do here. */
4235 return 1;
4236 }
4237
4238 /* Determine a BFD reloc value based on the operand information.
4239 We are only prepared to turn a few of the operands into
4240 relocs.
4241 FIXME: We need to handle the DS field at the very least.
4242 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4243 there should be a new field in the operand table. */
4244 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4245 && operand->bits == 26
4246 && operand->shift == 0)
4247 fixp->fx_r_type = BFD_RELOC_PPC_B26;
4248 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4249 && operand->bits == 16
4250 && operand->shift == 0)
4251 fixp->fx_r_type = BFD_RELOC_PPC_B16;
4252 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4253 && operand->bits == 26
4254 && operand->shift == 0)
4255 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4256 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4257 && operand->bits == 16
4258 && operand->shift == 0)
4259 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4260 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4261 && operand->bits == 16
4262 && operand->shift == 0
4263 && operand->insert == NULL
4264 && fixp->fx_addsy != NULL
4265 && ppc_is_toc_sym (fixp->fx_addsy))
4266 {
4267 fixp->fx_size = 2;
4268 if (target_big_endian)
4269 fixp->fx_where += 2;
4270 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4271 }
4272 else
4273 {
4274 as_bad_where (fixp->fx_file, fixp->fx_line,
4275 "unresolved expression that must be resolved");
4276 fixp->fx_done = 1;
4277 return 1;
4278 }
4279 }
4280 else
4281 {
4282 #ifdef OBJ_ELF
4283 ppc_elf_validate_fix (fixp, seg);
4284 #endif
4285 switch (fixp->fx_r_type)
4286 {
4287 case BFD_RELOC_32:
4288 case BFD_RELOC_CTOR:
4289 if (fixp->fx_pcrel)
4290 fixp->fx_r_type = BFD_RELOC_32_PCREL;
4291 /* fall through */
4292
4293 case BFD_RELOC_RVA:
4294 case BFD_RELOC_32_PCREL:
4295 case BFD_RELOC_32_BASEREL:
4296 case BFD_RELOC_PPC_EMB_NADDR32:
4297 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4298 value, 4);
4299 break;
4300
4301 case BFD_RELOC_LO16:
4302 case BFD_RELOC_HI16:
4303 case BFD_RELOC_HI16_S:
4304 case BFD_RELOC_16:
4305 case BFD_RELOC_GPREL16:
4306 case BFD_RELOC_16_GOT_PCREL:
4307 case BFD_RELOC_16_GOTOFF:
4308 case BFD_RELOC_LO16_GOTOFF:
4309 case BFD_RELOC_HI16_GOTOFF:
4310 case BFD_RELOC_HI16_S_GOTOFF:
4311 case BFD_RELOC_LO16_BASEREL:
4312 case BFD_RELOC_HI16_BASEREL:
4313 case BFD_RELOC_HI16_S_BASEREL:
4314 case BFD_RELOC_PPC_EMB_NADDR16:
4315 case BFD_RELOC_PPC_EMB_NADDR16_LO:
4316 case BFD_RELOC_PPC_EMB_NADDR16_HI:
4317 case BFD_RELOC_PPC_EMB_NADDR16_HA:
4318 case BFD_RELOC_PPC_EMB_SDAI16:
4319 case BFD_RELOC_PPC_EMB_SDA21:
4320 case BFD_RELOC_PPC_EMB_SDA2REL:
4321 case BFD_RELOC_PPC_EMB_SDA2I16:
4322 case BFD_RELOC_PPC_EMB_RELSEC16:
4323 case BFD_RELOC_PPC_EMB_RELST_LO:
4324 case BFD_RELOC_PPC_EMB_RELST_HI:
4325 case BFD_RELOC_PPC_EMB_RELST_HA:
4326 case BFD_RELOC_PPC_EMB_RELSDA:
4327 case BFD_RELOC_PPC_TOC16:
4328 if (fixp->fx_pcrel)
4329 abort ();
4330
4331 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4332 value, 2);
4333 break;
4334
4335 case BFD_RELOC_8:
4336 if (fixp->fx_pcrel)
4337 abort ();
4338
4339 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4340 value, 1);
4341 break;
4342
4343 default:
4344 fprintf(stderr,
4345 "Gas failure, reloc value %d\n", fixp->fx_r_type);
4346 fflush(stderr);
4347 abort ();
4348 }
4349 }
4350
4351 #ifdef OBJ_ELF
4352 fixp->fx_addnumber = value;
4353 #else
4354 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
4355 fixp->fx_addnumber = 0;
4356 else
4357 {
4358 #ifdef TE_PE
4359 fixp->fx_addnumber = 0;
4360 #else
4361 /* We want to use the offset within the data segment of the
4362 symbol, not the actual VMA of the symbol. */
4363 fixp->fx_addnumber =
4364 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
4365 #endif
4366 }
4367 #endif
4368
4369 return 1;
4370 }
4371
4372 /* Generate a reloc for a fixup. */
4373
4374 arelent *
4375 tc_gen_reloc (seg, fixp)
4376 asection *seg;
4377 fixS *fixp;
4378 {
4379 arelent *reloc;
4380
4381 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
4382
4383 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
4384 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4385 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
4386 if (reloc->howto == (reloc_howto_type *) NULL)
4387 {
4388 as_bad_where (fixp->fx_file, fixp->fx_line,
4389 "reloc %d not supported by object file format", (int)fixp->fx_r_type);
4390 return NULL;
4391 }
4392 reloc->addend = fixp->fx_addnumber;
4393
4394 return reloc;
4395 }
This page took 0.117584 seconds and 5 git commands to generate.