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