1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of GAS, the GNU Assembler.
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)
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.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "opcode/ppc.h"
36 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
38 /* Tell the main code what the endianness is. */
39 extern int target_big_endian;
41 /* Whether or not, we've set target_big_endian. */
42 static int set_target_endian = 0;
44 static void ppc_set_cpu PARAMS ((void));
45 static unsigned long ppc_insert_operand
46 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
47 offsetT val, char *file, unsigned int line));
48 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
49 static void ppc_byte PARAMS ((int));
50 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
51 static void ppc_tc PARAMS ((int));
54 static void ppc_comm PARAMS ((int));
55 static void ppc_bb PARAMS ((int));
56 static void ppc_bf PARAMS ((int));
57 static void ppc_biei PARAMS ((int));
58 static void ppc_bs PARAMS ((int));
59 static void ppc_eb PARAMS ((int));
60 static void ppc_ef PARAMS ((int));
61 static void ppc_es PARAMS ((int));
62 static void ppc_csect PARAMS ((int));
63 static void ppc_function PARAMS ((int));
64 static void ppc_extern PARAMS ((int));
65 static void ppc_lglobl PARAMS ((int));
66 static void ppc_stabx PARAMS ((int));
67 static void ppc_rename PARAMS ((int));
68 static void ppc_toc PARAMS ((int));
72 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **));
73 static void ppc_elf_cons PARAMS ((int));
74 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
78 static void ppc_set_current_section PARAMS ((segT));
79 static void ppc_previous PARAMS ((int));
80 static void ppc_pdata PARAMS ((int));
81 static void ppc_ydata PARAMS ((int));
82 static void ppc_reldata PARAMS ((int));
83 static void ppc_rdata PARAMS ((int));
84 static void ppc_ualong PARAMS ((int));
85 static void ppc_znop PARAMS ((int));
86 static void ppc_pe_comm PARAMS ((int));
87 static void ppc_pe_section PARAMS ((int));
88 static void ppc_pe_function PARAMS ((int));
89 static void ppc_pe_tocd PARAMS ((int));
92 /* Generic assembler global variables which must be defined by all
95 /* Characters which always start a comment. */
96 const char comment_chars[] = "#";
98 /* Characters which start a comment at the beginning of a line. */
99 const char line_comment_chars[] = "#";
101 /* Characters which may be used to separate multiple commands on a
103 const char line_separator_chars[] = ";";
105 /* Characters which are used to indicate an exponent in a floating
107 const char EXP_CHARS[] = "eE";
109 /* Characters which mean that a number is a floating point constant,
111 const char FLT_CHARS[] = "dD";
113 /* The target specific pseudo-ops which we support. */
115 const pseudo_typeS md_pseudo_table[] =
117 /* Pseudo-ops which must be overridden. */
118 { "byte", ppc_byte, 0 },
121 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
122 legitimately belong in the obj-*.c file. However, XCOFF is based
123 on COFF, and is only implemented for the RS/6000. We just use
124 obj-coff.c, and add what we need here. */
125 { "comm", ppc_comm, 0 },
126 { "lcomm", ppc_comm, 1 },
129 { "bi", ppc_biei, 0 },
131 { "csect", ppc_csect, 0 },
134 { "ei", ppc_biei, 1 },
136 { "extern", ppc_extern, 0 },
137 { "function", ppc_function, 0 },
138 { "lglobl", ppc_lglobl, 0 },
139 { "rename", ppc_rename, 0 },
140 { "stabx", ppc_stabx, 0 },
141 { "toc", ppc_toc, 0 },
145 { "long", ppc_elf_cons, 4 },
146 { "word", ppc_elf_cons, 2 },
147 { "short", ppc_elf_cons, 2 },
151 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
152 { "previous", ppc_previous, 0 },
153 { "pdata", ppc_pdata, 0 },
154 { "ydata", ppc_ydata, 0 },
155 { "reldata", ppc_reldata, 0 },
156 { "rdata", ppc_rdata, 0 },
157 { "ualong", ppc_ualong, 0 },
158 { "znop", ppc_znop, 0 },
159 { "comm", ppc_pe_comm, 0 },
160 { "lcomm", ppc_pe_comm, 1 },
161 { "section", ppc_pe_section, 0 },
162 { "function", ppc_pe_function,0 },
163 { "tocd", ppc_pe_tocd, 0 },
166 /* This pseudo-op is used even when not generating XCOFF output. */
174 /* The Windows NT PowerPC assembler uses predefined names. */
176 /* In general, there are lots of them, in an attempt to be compatible */
177 /* with a number of other Windows NT assemblers. */
179 /* Structure to hold information about predefined registers. */
186 /* List of registers that are pre-defined:
188 Each general register has predefined names of the form:
189 1. r<reg_num> which has the value <reg_num>.
190 2. r.<reg_num> which has the value <reg_num>.
193 Each floating point register has predefined names of the form:
194 1. f<reg_num> which has the value <reg_num>.
195 2. f.<reg_num> which has the value <reg_num>.
197 Each condition register has predefined names of the form:
198 1. cr<reg_num> which has the value <reg_num>.
199 2. cr.<reg_num> which has the value <reg_num>.
201 There are individual registers as well:
202 sp or r.sp has the value 1
203 rtoc or r.toc has the value 2
204 fpscr has the value 0
210 dsisr has the value 18
212 sdr1 has the value 25
213 srr0 has the value 26
214 srr1 has the value 27
216 The table is sorted. Suitable for searching by a binary search. */
218 static const struct pd_reg pre_defined_registers[] =
220 { "cr.0", 0 }, /* Condition Registers */
240 { "dar", 19 }, /* Data Access Register */
241 { "dec", 22 }, /* Decrementer */
242 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
244 { "f.0", 0 }, /* Floating point registers */
312 { "lr", 8 }, /* Link Register */
316 { "r.0", 0 }, /* General Purpose Registers */
349 { "r.sp", 1 }, /* Stack Pointer */
351 { "r.toc", 2 }, /* Pointer to the table of contents */
353 { "r0", 0 }, /* More general purpose registers */
386 { "rtoc", 2 }, /* Table of contents */
388 { "sdr1", 25 }, /* Storage Description Register 1 */
392 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
393 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
399 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
401 /* Given NAME, find the register number associated with that name, return
402 the integer value associated with the given name or -1 on failure. */
404 static int reg_name_search PARAMS ( (char * name) );
407 reg_name_search (name)
410 int middle, low, high;
414 high = REG_NAME_CNT - 1;
418 middle = (low + high) / 2;
419 cmp = strcasecmp (name, pre_defined_registers[middle].name);
425 return pre_defined_registers[middle].value;
435 /* Local variables. */
437 /* The type of processor we are assembling for. This is one or more
438 of the PPC_OPCODE flags defined in opcode/ppc.h. */
439 static int ppc_cpu = 0;
441 /* The size of the processor we are assembling for. This is either
442 PPC_OPCODE_32 or PPC_OPCODE_64. */
443 static int ppc_size = PPC_OPCODE_32;
445 /* Opcode hash table. */
446 static struct hash_control *ppc_hash;
448 /* Macro hash table. */
449 static struct hash_control *ppc_macro_hash;
452 /* Whether to warn about non PC relative relocations that aren't
453 in the .got2 section. */
454 static boolean mrelocatable = false;
456 /* Flags to set in the elf header */
457 static flagword ppc_flags = 0;
462 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
463 using a bunch of different sections. These assembler sections,
464 however, are all encompassed within the .text or .data sections of
465 the final output file. We handle this by using different
466 subsegments within these main segments. */
468 /* Next subsegment to allocate within the .text segment. */
469 static subsegT ppc_text_subsegment = 2;
471 /* Linked list of csects in the text section. */
472 static symbolS *ppc_text_csects;
474 /* Next subsegment to allocate within the .data segment. */
475 static subsegT ppc_data_subsegment = 2;
477 /* Linked list of csects in the data section. */
478 static symbolS *ppc_data_csects;
480 /* The current csect. */
481 static symbolS *ppc_current_csect;
483 /* The RS/6000 assembler uses a TOC which holds addresses of functions
484 and variables. Symbols are put in the TOC with the .tc pseudo-op.
485 A special relocation is used when accessing TOC entries. We handle
486 the TOC as a subsegment within the .data segment. We set it up if
487 we see a .toc pseudo-op, and save the csect symbol here. */
488 static symbolS *ppc_toc_csect;
490 /* The first frag in the TOC subsegment. */
491 static fragS *ppc_toc_frag;
493 /* The first frag in the first subsegment after the TOC in the .data
494 segment. NULL if there are no subsegments after the TOC. */
495 static fragS *ppc_after_toc_frag;
497 /* The current static block. */
498 static symbolS *ppc_current_block;
500 /* The COFF debugging section; set by md_begin. This is not the
501 .debug section, but is instead the secret BFD section which will
502 cause BFD to set the section number of a symbol to N_DEBUG. */
503 static asection *ppc_coff_debug_section;
505 /* The size of the .debug section. */
506 static bfd_size_type ppc_debug_name_section_size;
508 #endif /* OBJ_XCOFF */
512 /* Various sections that we need for PE coff support. */
513 static segT ydata_section;
514 static segT pdata_section;
515 static segT reldata_section;
516 static segT rdata_section;
517 static segT tocdata_section;
519 /* The current section and the previous section. See ppc_previous. */
520 static segT ppc_previous_section;
521 static segT ppc_current_section;
526 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
529 #ifndef WORKING_DOT_WORD
530 const int md_short_jump_size = 4;
531 const int md_long_jump_size = 4;
535 CONST char *md_shortopts = "um:VQ:";
537 CONST char *md_shortopts = "um:";
539 struct option md_longopts[] = {
540 {NULL, no_argument, NULL, 0}
542 size_t md_longopts_size = sizeof(md_longopts);
545 md_parse_option (c, arg)
552 /* -u means that any undefined symbols should be treated as
553 external, which is the default for gas anyhow. */
557 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
559 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
560 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
561 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
562 else if (strcmp (arg, "pwr") == 0)
563 ppc_cpu = PPC_OPCODE_POWER;
564 /* -m601 means to assemble for the Motorola PowerPC 601. FIXME: We
565 ignore the option for now, but we should really use it to permit
566 instructions defined on the 601 that are not part of the standard
567 PowerPC architecture (mostly holdovers from the POWER). */
568 else if (strcmp (arg, "601") == 0)
569 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
570 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
571 Motorola PowerPC 603/604. */
572 else if (strcmp (arg, "ppc") == 0
573 || strcmp (arg, "ppc32") == 0
574 || strcmp (arg, "403") == 0
575 || strcmp (arg, "603") == 0
576 || strcmp (arg, "604") == 0)
577 ppc_cpu = PPC_OPCODE_PPC;
578 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
580 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
582 ppc_cpu = PPC_OPCODE_PPC;
583 ppc_size = PPC_OPCODE_64;
585 /* -mcom means assemble for the common intersection between Power
586 and PowerPC. At present, we just allow the union, rather
587 than the intersection. */
588 else if (strcmp (arg, "com") == 0)
589 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_PPC;
590 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
591 else if (strcmp (arg, "any") == 0)
592 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2 | PPC_OPCODE_PPC;
595 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
596 else if (strcmp (arg, "relocatable") == 0)
599 ppc_flags |= EF_PPC_RELOCATABLE;
602 else if (strcmp (arg, "relocatable-lib") == 0)
605 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
608 /* -memb, set embedded bit */
609 else if (strcmp (arg, "emb") == 0)
610 ppc_flags |= EF_PPC_EMB;
612 /* -mlittle/-mbig set the endianess */
613 else if (strcmp (arg, "little") == 0 || strcmp (arg, "little-endian") == 0)
615 target_big_endian = 0;
616 set_target_endian = 1;
619 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
621 target_big_endian = 1;
622 set_target_endian = 1;
627 as_bad ("invalid switch -m%s", arg);
633 /* -V: SVR4 argument to print version ID. */
638 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
639 should be emitted or not. FIXME: Not implemented. */
652 md_show_usage (stream)
658 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
659 -mpwr generate code for IBM POWER (RIOS1)\n\
660 -m601 generate code for Motorola PowerPC 601\n\
661 -mppc, -mppc32, -m403, -m603, -m604\n\
662 generate code for Motorola PowerPC 603/604\n\
663 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
664 -mcom generate code Power/PowerPC common instructions\n
665 -many generate code for any architecture (PWR/PWRX/PPC)\n");
668 -mrelocatable support for GCC's -mrelocatble option\n\
669 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
670 -memb set PPC_EMB bit in ELF flags\n\
671 -mlittle, -mlittle-endian\n\
672 generate code for a little endian machine\n\
673 -mbig, -mbig-endian generate code for a big endian machine\n\
674 -V print assembler version number\n\
675 -Qy, -Qn ignored\n");
679 /* Set ppc_cpu if it is not already set. */
684 const char *default_cpu = TARGET_CPU;
688 if (strcmp (default_cpu, "rs6000") == 0)
689 ppc_cpu = PPC_OPCODE_POWER;
690 else if (strcmp (default_cpu, "powerpc") == 0
691 || strcmp (default_cpu, "powerpcle") == 0)
692 ppc_cpu = PPC_OPCODE_PPC;
694 as_fatal ("Unknown default cpu = %s", default_cpu);
698 /* Figure out the BFD architecture to use. */
700 enum bfd_architecture
705 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
706 return bfd_arch_powerpc;
707 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
708 return bfd_arch_rs6000;
711 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
712 return bfd_arch_unknown;
716 /* This function is called when the assembler starts up. It is called
717 after the options have been parsed and the output file has been
723 register const struct powerpc_opcode *op;
724 const struct powerpc_opcode *op_end;
725 const struct powerpc_macro *macro;
726 const struct powerpc_macro *macro_end;
731 /* Set the ELF flags if desired. */
733 bfd_set_private_flags (stdoutput, ppc_flags);
736 /* Insert the opcodes into a hash table. */
737 ppc_hash = hash_new ();
739 op_end = powerpc_opcodes + powerpc_num_opcodes;
740 for (op = powerpc_opcodes; op < op_end; op++)
742 know ((op->opcode & op->mask) == op->opcode);
744 if ((op->flags & ppc_cpu) != 0
745 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
746 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size))
750 retval = hash_insert (ppc_hash, op->name, (PTR) op);
751 if (retval != (const char *) NULL)
753 /* We permit a duplication of the mfdec instruction on
754 the 601, because it seems to have one value on the
755 601 and a different value on other PowerPC
756 processors. It's easier to permit a duplication than
757 to define a new instruction type flag. When using
758 -many/-mcom, the comparison instructions are a harmless
760 if (strcmp (retval, "exists") != 0
761 || ((((ppc_cpu & PPC_OPCODE_601) == 0
762 && ((ppc_cpu & ~PPC_OPCODE_POWER2)
763 == (PPC_OPCODE_POWER | PPC_OPCODE_PPC)))
764 || strcmp (op->name, "mfdec") != 0)
765 && (((ppc_cpu & ~PPC_OPCODE_POWER2)
766 != (PPC_OPCODE_POWER | PPC_OPCODE_PPC))
767 || (strcmp (op->name, "cmpli") != 0
768 && strcmp (op->name, "cmpi") != 0
769 && strcmp (op->name, "cmp") != 0
770 && strcmp (op->name, "cmpl") != 0))))
772 as_bad ("Internal assembler error for instruction %s", op->name);
779 /* Insert the macros into a hash table. */
780 ppc_macro_hash = hash_new ();
782 macro_end = powerpc_macros + powerpc_num_macros;
783 for (macro = powerpc_macros; macro < macro_end; macro++)
785 if ((macro->flags & ppc_cpu) != 0)
789 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
790 if (retval != (const char *) NULL)
795 /* Tell the main code what the endianness is if it is not overidden by the user. */
796 if (!set_target_endian)
798 set_target_endian = 1;
799 target_big_endian = PPC_BIG_ENDIAN;
803 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
805 /* Create dummy symbols to serve as initial csects. This forces the
806 text csects to precede the data csects. These symbols will not
808 ppc_text_csects = symbol_make ("dummy\001");
809 ppc_text_csects->sy_tc.within = ppc_text_csects;
810 ppc_data_csects = symbol_make ("dummy\001");
811 ppc_data_csects->sy_tc.within = ppc_data_csects;
816 ppc_current_section = text_section;
817 ppc_previous_section = 0;
822 /* Insert an operand value into an instruction. */
825 ppc_insert_operand (insn, operand, val, file, line)
827 const struct powerpc_operand *operand;
832 if (operand->bits != 32)
837 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
839 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0
840 && ppc_size == PPC_OPCODE_32)
841 max = (1 << operand->bits) - 1;
843 max = (1 << (operand->bits - 1)) - 1;
844 min = - (1 << (operand->bits - 1));
848 max = (1 << operand->bits) - 1;
852 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
857 if (test < (offsetT) min || test > (offsetT) max)
860 "operand out of range (%s not between %ld and %ld)";
863 sprint_value (buf, test);
864 if (file == (char *) NULL)
865 as_warn (err, buf, min, max);
867 as_warn_where (file, line, err, buf, min, max);
876 insn = (*operand->insert) (insn, (long) val, &errmsg);
877 if (errmsg != (const char *) NULL)
881 insn |= (((long) val & ((1 << operand->bits) - 1))
888 /* Parse @got, etc. and return the desired relocation. */
889 static bfd_reloc_code_real_type
890 ppc_elf_suffix (str_p)
896 bfd_reloc_code_real_type reloc;
906 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
908 static struct map_bfd mapping[] = {
909 MAP ("got", BFD_RELOC_PPC_TOC16),
910 MAP ("l", BFD_RELOC_LO16),
911 MAP ("h", BFD_RELOC_HI16),
912 MAP ("ha", BFD_RELOC_HI16_S),
913 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
914 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
915 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
916 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
917 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
918 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
919 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
920 MAP ("copy", BFD_RELOC_PPC_COPY),
921 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
922 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
923 MAP ("plt", BFD_RELOC_32_PLTOFF),
924 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
925 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
926 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
927 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
928 MAP ("sdarel", BFD_RELOC_GPREL16),
929 MAP ("sectoff", BFD_RELOC_32_BASEREL),
930 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
931 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
932 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
934 { (char *)0, 0, BFD_RELOC_UNUSED }
938 return BFD_RELOC_UNUSED;
940 for (ch = *str, str2 = ident;
941 str2 < ident + sizeof(ident) - 1 && isalnum (ch) || ch == '@';
944 *str2++ = (islower (ch)) ? ch : tolower (ch);
951 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
952 if (ch == ptr->string[0] && len == ptr->length && memcmp (ident, ptr->string, ptr->length) == 0)
958 return BFD_RELOC_UNUSED;
961 /* Like normal .long/.short/.word, except support @got, etc. */
962 /* clobbers input_line_pointer, checks */
965 ppc_elf_cons (nbytes)
966 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
969 bfd_reloc_code_real_type reloc;
971 if (is_it_end_of_statement ())
973 demand_empty_rest_of_line ();
980 if (exp.X_op == O_symbol
981 && *input_line_pointer == '@'
982 && (reloc = ppc_elf_suffix (&input_line_pointer)) != BFD_RELOC_UNUSED)
984 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
985 int size = bfd_get_reloc_size (reloc_howto);
988 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto->name, nbytes);
992 register char *p = frag_more ((int) nbytes);
993 int offset = nbytes - size;
995 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
999 emit_expr (&exp, (unsigned int) nbytes);
1001 while (*input_line_pointer++ == ',');
1003 input_line_pointer--; /* Put terminator back into stream. */
1004 demand_empty_rest_of_line ();
1007 /* Validate any relocations emitted for -mrelocatable, possibly adding
1008 fixups for word relocations in writable segments, so we can adjust
1011 ppc_elf_validate_fix (fixp, seg)
1018 && fixp->fx_r_type <= BFD_RELOC_UNUSED
1019 && strcmp (segment_name (seg), ".got2") != 0
1020 && strcmp (segment_name (seg), ".dtors") != 0
1021 && strcmp (segment_name (seg), ".ctors") != 0
1022 && strcmp (segment_name (seg), ".fixup") != 0
1023 && strcmp (segment_name (seg), ".stab") != 0)
1025 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1026 || fixp->fx_r_type != BFD_RELOC_CTOR)
1028 as_warn_where (fixp->fx_file, fixp->fx_line,
1029 "Relocation cannot be done when using -mrelocatable");
1034 #endif /* OBJ_ELF */
1038 * Summary of register_name().
1040 * in: Input_line_pointer points to 1st char of operand.
1042 * out: A expressionS.
1043 * The operand may have been a register: in this case, X_op == O_register,
1044 * X_add_number is set to the register number, and truth is returned.
1045 * Input_line_pointer->(next non-blank) char after operand, or is in its
1050 register_name (expressionP)
1051 expressionS *expressionP;
1057 /* Find the spelling of the operand */
1058 name = input_line_pointer;
1059 c = get_symbol_end ();
1060 reg_number = reg_name_search (name);
1062 /* look to see if it's in the register table */
1063 if (reg_number >= 0)
1065 expressionP->X_op = O_register;
1066 expressionP->X_add_number = reg_number;
1068 /* make the rest nice */
1069 expressionP->X_add_symbol = NULL;
1070 expressionP->X_op_symbol = NULL;
1071 *input_line_pointer = c; /* put back the delimiting char */
1076 /* reset the line as if we had not done anything */
1077 *input_line_pointer = c; /* put back the delimiting char */
1078 input_line_pointer = name; /* reset input_line pointer */
1084 * Summary of parse_toc_entry().
1086 * in: Input_line_pointer points to the '[' in one of:
1088 * [toc] [tocv] [toc32] [toc64]
1090 * Anything else is an error of one kind or another.
1093 * return value: success or failure
1094 * toc_kind: kind of toc reference
1095 * input_line_pointer:
1096 * success: first char after the ']'
1097 * failure: unchanged
1101 * [toc] - rv == success, toc_kind = default_toc
1102 * [tocv] - rv == success, toc_kind = data_in_toc
1103 * [toc32] - rv == success, toc_kind = must_be_32
1104 * [toc64] - rv == success, toc_kind = must_be_64
1108 enum toc_size_qualifier
1110 default_toc, /* The toc cell constructed should be the system default size */
1111 data_in_toc, /* This is a direct reference to a toc cell */
1112 must_be_32, /* The toc cell constructed must be 32 bits wide */
1113 must_be_64 /* The toc cell constructed must be 64 bits wide */
1117 parse_toc_entry(toc_kind)
1118 enum toc_size_qualifier *toc_kind;
1123 enum toc_size_qualifier t;
1125 /* save the input_line_pointer */
1126 start = input_line_pointer;
1128 /* skip over the '[' , and whitespace */
1129 ++input_line_pointer;
1132 /* find the spelling of the operand */
1133 toc_spec = input_line_pointer;
1134 c = get_symbol_end ();
1136 if (strcmp(toc_spec, "toc") == 0)
1140 else if (strcmp(toc_spec, "tocv") == 0)
1144 else if (strcmp(toc_spec, "toc32") == 0)
1148 else if (strcmp(toc_spec, "toc64") == 0)
1154 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec);
1155 *input_line_pointer = c; /* put back the delimiting char */
1156 input_line_pointer = start; /* reset input_line pointer */
1160 /* now find the ']' */
1161 *input_line_pointer = c; /* put back the delimiting char */
1163 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1164 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1168 as_bad ("syntax error: expected `]', found `%c'", c);
1169 input_line_pointer = start; /* reset input_line pointer */
1173 *toc_kind = t; /* set return value */
1180 /* We need to keep a list of fixups. We can't simply generate them as
1181 we go, because that would require us to first create the frag, and
1182 that would screw up references to ``.''. */
1188 bfd_reloc_code_real_type reloc;
1191 #define MAX_INSN_FIXUPS (5)
1193 /* This routine is called for each instruction to be assembled. */
1200 const struct powerpc_opcode *opcode;
1202 const unsigned char *opindex_ptr;
1206 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1211 bfd_reloc_code_real_type reloc;
1214 /* Get the opcode. */
1215 for (s = str; *s != '\0' && ! isspace (*s); s++)
1220 /* Look up the opcode in the hash table. */
1221 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1222 if (opcode == (const struct powerpc_opcode *) NULL)
1224 const struct powerpc_macro *macro;
1226 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1227 if (macro == (const struct powerpc_macro *) NULL)
1228 as_bad ("Unrecognized opcode: `%s'", str);
1230 ppc_macro (s, macro);
1235 insn = opcode->opcode;
1238 while (isspace (*str))
1241 /* PowerPC operands are just expressions. The only real issue is
1242 that a few operand types are optional. All cases which might use
1243 an optional operand separate the operands only with commas (in
1244 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1245 cases never have optional operands). There is never more than
1246 one optional operand for an instruction. So, before we start
1247 seriously parsing the operands, we check to see if we have an
1248 optional operand, and, if we do, we count the number of commas to
1249 see whether the operand should be omitted. */
1251 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1253 const struct powerpc_operand *operand;
1255 operand = &powerpc_operands[*opindex_ptr];
1256 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1258 unsigned int opcount;
1260 /* There is an optional operand. Count the number of
1261 commas in the input line. */
1268 while ((s = strchr (s, ',')) != (char *) NULL)
1275 /* If there are fewer operands in the line then are called
1276 for by the instruction, we want to skip the optional
1278 if (opcount < strlen (opcode->operands))
1285 /* Gather the operands. */
1289 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1291 const struct powerpc_operand *operand;
1297 if (next_opindex == 0)
1298 operand = &powerpc_operands[*opindex_ptr];
1301 operand = &powerpc_operands[next_opindex];
1307 /* If this is a fake operand, then we do not expect anything
1309 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1311 insn = (*operand->insert) (insn, 0L, &errmsg);
1312 if (errmsg != (const char *) NULL)
1317 /* If this is an optional operand, and we are skipping it, just
1319 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1322 if (operand->insert)
1324 insn = (*operand->insert) (insn, 0L, &errmsg);
1325 if (errmsg != (const char *) NULL)
1328 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1329 next_opindex = *opindex_ptr + 1;
1333 /* Gather the operand. */
1334 hold = input_line_pointer;
1335 input_line_pointer = str;
1338 if (*input_line_pointer == '[')
1340 /* We are expecting something like the second argument here:
1342 lwz r4,[toc].GS.0.static_int(rtoc)
1343 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1344 The argument following the `]' must be a symbol name, and the
1345 register must be the toc register: 'rtoc' or '2'
1347 The effect is to 0 as the displacement field
1348 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1349 the appropriate variation) reloc against it based on the symbol.
1350 The linker will build the toc, and insert the resolved toc offset.
1353 o The size of the toc entry is currently assumed to be
1354 32 bits. This should not be assumed to be a hard coded
1356 o In an effort to cope with a change from 32 to 64 bits,
1357 there are also toc entries that are specified to be
1358 either 32 or 64 bits:
1359 lwz r4,[toc32].GS.0.static_int(rtoc)
1360 lwz r4,[toc64].GS.0.static_int(rtoc)
1361 These demand toc entries of the specified size, and the
1362 instruction probably requires it.
1366 enum toc_size_qualifier toc_kind;
1367 bfd_reloc_code_real_type toc_reloc;
1369 /* go parse off the [tocXX] part */
1370 valid_toc = parse_toc_entry(&toc_kind);
1374 /* Note: message has already been issued. */
1375 /* FIXME: what sort of recovery should we do? */
1376 /* demand_rest_of_line(); return; ? */
1379 /* Now get the symbol following the ']' */
1385 /* In this case, we may not have seen the symbol yet, since */
1386 /* it is allowed to appear on a .extern or .globl or just be */
1387 /* a label in the .data section. */
1388 toc_reloc = BFD_RELOC_PPC_TOC16;
1391 /* 1. The symbol must be defined and either in the toc */
1392 /* section, or a global. */
1393 /* 2. The reloc generated must have the TOCDEFN flag set in */
1394 /* upper bit mess of the reloc type. */
1395 /* FIXME: It's a little confusing what the tocv qualifier can */
1396 /* be used for. At the very least, I've seen three */
1397 /* uses, only one of which I'm sure I can explain. */
1398 if (ex.X_op == O_symbol)
1400 assert (ex.X_add_symbol != NULL);
1401 if (ex.X_add_symbol->bsym->section != tocdata_section)
1403 as_warn("[tocv] symbol is not a toc symbol");
1407 toc_reloc = BFD_RELOC_PPC_TOC16;
1410 /* FIXME: these next two specifically specify 32/64 bit toc */
1411 /* entries. We don't support them today. Is this the */
1412 /* right way to say that? */
1413 toc_reloc = BFD_RELOC_UNUSED;
1414 as_bad ("Unimplemented toc32 expression modifier");
1417 /* FIXME: see above */
1418 toc_reloc = BFD_RELOC_UNUSED;
1419 as_bad ("Unimplemented toc64 expression modifier");
1423 "Unexpected return value [%d] from parse_toc_entry!\n",
1429 /* We need to generate a fixup for this expression. */
1430 if (fc >= MAX_INSN_FIXUPS)
1431 as_fatal ("too many fixups");
1433 fixups[fc].reloc = toc_reloc;
1434 fixups[fc].exp = ex;
1435 fixups[fc].opindex = *opindex_ptr;
1438 /* Ok. We've set up the fixup for the instruction. Now make it
1439 look like the constant 0 was found here */
1441 ex.X_op = O_constant;
1442 ex.X_add_number = 0;
1443 ex.X_add_symbol = NULL;
1444 ex.X_op_symbol = NULL;
1448 if (!register_name(&ex))
1454 str = input_line_pointer;
1455 input_line_pointer = hold;
1458 str = input_line_pointer;
1459 input_line_pointer = hold;
1462 if (ex.X_op == O_illegal)
1463 as_bad ("illegal operand");
1464 else if (ex.X_op == O_absent)
1465 as_bad ("missing operand");
1466 else if (ex.X_op == O_constant)
1469 /* Allow @HA, @L, @H on constants. */
1470 char *orig_str = str;
1472 if ((reloc = ppc_elf_suffix (&str)) != BFD_RELOC_UNUSED)
1479 case BFD_RELOC_LO16:
1480 ex.X_add_number = ((ex.X_add_number & 0xffff) ^ 0x8000) - 0x8000;
1483 case BFD_RELOC_HI16:
1484 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
1487 case BFD_RELOC_HI16_S:
1488 ex.X_add_number = ((ex.X_add_number >> 16) & 0xffff)
1489 + ((ex.X_add_number >> 15) & 1);
1493 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1497 else if (ex.X_op == O_register)
1499 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1504 else if ((reloc = ppc_elf_suffix (&str)) != BFD_RELOC_UNUSED)
1506 /* For the absoulte forms of branchs, convert the PC relative form back into
1508 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
1511 case BFD_RELOC_PPC_B26: reloc = BFD_RELOC_PPC_BA26; break;
1512 case BFD_RELOC_PPC_B16: reloc = BFD_RELOC_PPC_BA16; break;
1513 case BFD_RELOC_PPC_B16_BRTAKEN: reloc = BFD_RELOC_PPC_BA16_BRTAKEN; break;
1514 case BFD_RELOC_PPC_B16_BRNTAKEN: reloc = BFD_RELOC_PPC_BA16_BRNTAKEN; break;
1517 /* We need to generate a fixup for this expression. */
1518 if (fc >= MAX_INSN_FIXUPS)
1519 as_fatal ("too many fixups");
1520 fixups[fc].exp = ex;
1521 fixups[fc].opindex = 0;
1522 fixups[fc].reloc = reloc;
1525 #endif /* OBJ_ELF */
1529 /* We need to generate a fixup for this expression. */
1530 if (fc >= MAX_INSN_FIXUPS)
1531 as_fatal ("too many fixups");
1532 fixups[fc].exp = ex;
1533 fixups[fc].opindex = *opindex_ptr;
1534 fixups[fc].reloc = BFD_RELOC_UNUSED;
1543 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
1551 /* The call to expression should have advanced str past any
1554 && (endc != ',' || *str != '\0'))
1556 as_bad ("syntax error; found `%c' but expected `%c'", *str, endc);
1564 while (isspace (*str))
1568 as_bad ("junk at end of line: `%s'", str);
1570 /* Write out the instruction. */
1572 md_number_to_chars (f, insn, 4);
1574 /* Create any fixups. At this point we do not use a
1575 bfd_reloc_code_real_type, but instead just use the
1576 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1577 handle fixups for any operand type, although that is admittedly
1578 not a very exciting feature. We pick a BFD reloc type in
1580 for (i = 0; i < fc; i++)
1582 const struct powerpc_operand *operand;
1584 operand = &powerpc_operands[fixups[i].opindex];
1585 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1587 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1595 size = bfd_get_reloc_size (reloc_howto);
1596 offset = target_big_endian ? (4 - size) : 0;
1598 if (size < 1 || size > 4)
1601 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, size,
1602 &fixups[i].exp, reloc_howto->pc_relative,
1605 /* Turn off complaints that the addend is too large for things like
1607 switch (fixups[i].reloc)
1609 case BFD_RELOC_LO16:
1610 case BFD_RELOC_HI16:
1611 case BFD_RELOC_HI16_S:
1612 fixP->fx_no_overflow = 1;
1619 fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1621 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
1622 ((bfd_reloc_code_real_type)
1623 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1627 #ifndef WORKING_DOT_WORD
1628 /* Handle long and short jumps */
1630 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1632 addressT from_addr, to_addr;
1640 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1642 addressT from_addr, to_addr;
1650 /* Handle a macro. Gather all the operands, transform them as
1651 described by the macro, and call md_assemble recursively. All the
1652 operands are separated by commas; we don't accept parentheses
1653 around operands here. */
1656 ppc_macro (str, macro)
1658 const struct powerpc_macro *macro;
1669 /* Gather the users operands into the operands array. */
1674 if (count >= sizeof operands / sizeof operands[0])
1676 operands[count++] = s;
1677 s = strchr (s, ',');
1678 if (s == (char *) NULL)
1683 if (count != macro->operands)
1685 as_bad ("wrong number of operands");
1689 /* Work out how large the string must be (the size is unbounded
1690 because it includes user input). */
1692 format = macro->format;
1693 while (*format != '\0')
1702 arg = strtol (format + 1, &send, 10);
1703 know (send != format && arg >= 0 && arg < count);
1704 len += strlen (operands[arg]);
1709 /* Put the string together. */
1710 complete = s = (char *) alloca (len + 1);
1711 format = macro->format;
1712 while (*format != '\0')
1718 arg = strtol (format + 1, &send, 10);
1719 strcpy (s, operands[arg]);
1726 /* Assemble the constructed instruction. */
1727 md_assemble (complete);
1730 /* Pseudo-op handling. */
1732 /* The .byte pseudo-op. This is similar to the normal .byte
1733 pseudo-op, but it can also take a single ASCII string. */
1739 if (*input_line_pointer != '\"')
1745 /* Gather characters. A real double quote is doubled. Unusual
1746 characters are not permitted. */
1747 ++input_line_pointer;
1752 c = *input_line_pointer++;
1756 if (*input_line_pointer != '\"')
1758 ++input_line_pointer;
1761 FRAG_APPEND_1_CHAR (c);
1764 demand_empty_rest_of_line ();
1769 /* XCOFF specific pseudo-op handling. */
1771 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1772 symbols in the .bss segment as though they were local common
1773 symbols, and uses a different smclas. */
1779 asection *current_seg = now_seg;
1780 subsegT current_subseg = now_subseg;
1786 symbolS *lcomm_sym = NULL;
1790 name = input_line_pointer;
1791 endc = get_symbol_end ();
1792 end_name = input_line_pointer;
1795 if (*input_line_pointer != ',')
1797 as_bad ("missing size");
1798 ignore_rest_of_line ();
1801 ++input_line_pointer;
1803 size = get_absolute_expression ();
1806 as_bad ("negative size");
1807 ignore_rest_of_line ();
1813 /* The third argument to .comm is the alignment. */
1814 if (*input_line_pointer != ',')
1818 ++input_line_pointer;
1819 align = get_absolute_expression ();
1822 as_warn ("ignoring bad alignment");
1841 /* The third argument to .lcomm appears to be the real local
1842 common symbol to create. References to the symbol named in
1843 the first argument are turned into references to the third
1845 if (*input_line_pointer != ',')
1847 as_bad ("missing real symbol name");
1848 ignore_rest_of_line ();
1851 ++input_line_pointer;
1853 lcomm_name = input_line_pointer;
1854 lcomm_endc = get_symbol_end ();
1856 lcomm_sym = symbol_find_or_make (lcomm_name);
1858 *input_line_pointer = lcomm_endc;
1862 sym = symbol_find_or_make (name);
1865 if (S_IS_DEFINED (sym)
1866 || S_GET_VALUE (sym) != 0)
1868 as_bad ("attempt to redefine symbol");
1869 ignore_rest_of_line ();
1873 record_alignment (bss_section, align);
1876 || ! S_IS_DEFINED (lcomm_sym))
1885 S_SET_EXTERNAL (sym);
1889 lcomm_sym->sy_tc.output = 1;
1890 def_sym = lcomm_sym;
1894 subseg_set (bss_section, 1);
1895 frag_align (align, 0);
1897 def_sym->sy_frag = frag_now;
1898 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
1899 def_size, (char *) NULL);
1901 S_SET_SEGMENT (def_sym, bss_section);
1902 def_sym->sy_tc.align = align;
1906 /* Align the size of lcomm_sym. */
1907 lcomm_sym->sy_frag->fr_offset =
1908 ((lcomm_sym->sy_frag->fr_offset + (1 << align) - 1)
1909 &~ ((1 << align) - 1));
1910 if (align > lcomm_sym->sy_tc.align)
1911 lcomm_sym->sy_tc.align = align;
1916 /* Make sym an offset from lcomm_sym. */
1917 S_SET_SEGMENT (sym, bss_section);
1918 sym->sy_frag = lcomm_sym->sy_frag;
1919 S_SET_VALUE (sym, lcomm_sym->sy_frag->fr_offset);
1920 lcomm_sym->sy_frag->fr_offset += size;
1923 subseg_set (current_seg, current_subseg);
1925 demand_empty_rest_of_line ();
1928 /* The .csect pseudo-op. This switches us into a different
1929 subsegment. The first argument is a symbol whose value is the
1930 start of the .csect. In COFF, csect symbols get special aux
1931 entries defined by the x_csect field of union internal_auxent. The
1932 optional second argument is the alignment (the default is 2). */
1942 name = input_line_pointer;
1943 endc = get_symbol_end ();
1945 sym = symbol_find_or_make (name);
1947 *input_line_pointer = endc;
1949 if (S_IS_DEFINED (sym))
1950 subseg_set (S_GET_SEGMENT (sym), sym->sy_tc.subseg);
1957 /* This is a new csect. We need to look at the symbol class to
1958 figure out whether it should go in the text section or the
1961 switch (sym->sy_tc.class)
1971 S_SET_SEGMENT (sym, text_section);
1972 sym->sy_tc.subseg = ppc_text_subsegment;
1973 ++ppc_text_subsegment;
1974 list_ptr = &ppc_text_csects;
1983 if (ppc_toc_csect->sy_tc.subseg + 1 == ppc_data_subsegment)
1985 S_SET_SEGMENT (sym, data_section);
1986 sym->sy_tc.subseg = ppc_data_subsegment;
1987 ++ppc_data_subsegment;
1988 list_ptr = &ppc_data_csects;
1994 subseg_new (segment_name (S_GET_SEGMENT (sym)), sym->sy_tc.subseg);
1996 ppc_after_toc_frag = frag_now;
1998 sym->sy_frag = frag_now;
1999 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2001 sym->sy_tc.align = 2;
2002 sym->sy_tc.output = 1;
2003 sym->sy_tc.within = sym;
2005 for (list = *list_ptr;
2006 list->sy_tc.next != (symbolS *) NULL;
2007 list = list->sy_tc.next)
2009 list->sy_tc.next = sym;
2011 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2012 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2015 if (*input_line_pointer == ',')
2017 ++input_line_pointer;
2018 sym->sy_tc.align = get_absolute_expression ();
2021 ppc_current_csect = sym;
2023 demand_empty_rest_of_line ();
2026 /* The .extern pseudo-op. We create an undefined symbol. */
2035 name = input_line_pointer;
2036 endc = get_symbol_end ();
2038 (void) symbol_find_or_make (name);
2040 *input_line_pointer = endc;
2042 demand_empty_rest_of_line ();
2045 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
2046 this because it can't handle undefined symbols. I think we can
2056 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2057 although I don't know why it bothers. */
2068 name = input_line_pointer;
2069 endc = get_symbol_end ();
2071 sym = symbol_find_or_make (name);
2073 *input_line_pointer = endc;
2075 if (*input_line_pointer != ',')
2077 as_bad ("missing rename string");
2078 ignore_rest_of_line ();
2081 ++input_line_pointer;
2083 sym->sy_tc.real_name = demand_copy_C_string (&len);
2085 demand_empty_rest_of_line ();
2088 /* The .stabx pseudo-op. This is similar to a normal .stabs
2089 pseudo-op, but slightly different. A sample is
2090 .stabx "main:F-1",.main,142,0
2091 The first argument is the symbol name to create. The second is the
2092 value, and the third is the storage class. The fourth seems to be
2093 always zero, and I am assuming it is the type. */
2104 name = demand_copy_C_string (&len);
2106 if (*input_line_pointer != ',')
2108 as_bad ("missing value");
2111 ++input_line_pointer;
2113 sym = symbol_make (name);
2115 (void) expression (&exp);
2122 as_bad ("illegal .stabx expression; zero assumed");
2123 exp.X_add_number = 0;
2126 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2127 sym->sy_frag = &zero_address_frag;
2131 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2132 sym->sy_value = exp;
2136 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2137 sym->sy_frag = exp.X_add_symbol->sy_frag;
2142 /* The value is some complex expression. This will probably
2143 fail at some later point, but this is probably the right
2144 thing to do here. */
2145 sym->sy_value = exp;
2149 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2150 sym->bsym->flags |= BSF_DEBUGGING;
2152 if (*input_line_pointer != ',')
2154 as_bad ("missing class");
2157 ++input_line_pointer;
2159 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2161 if (*input_line_pointer != ',')
2163 as_bad ("missing type");
2166 ++input_line_pointer;
2168 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2170 sym->sy_tc.output = 1;
2172 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
2173 sym->sy_tc.within = ppc_current_block;
2175 if (exp.X_op != O_symbol
2176 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2177 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2178 ppc_frob_label (sym);
2181 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2182 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2183 if (ppc_current_csect->sy_tc.within == exp.X_add_symbol)
2184 ppc_current_csect->sy_tc.within = sym;
2187 if (strlen (name) > SYMNMLEN)
2189 /* For some reason, each name is preceded by a two byte length
2190 and followed by a null byte. */
2191 ppc_debug_name_section_size += strlen (name) + 3;
2194 demand_empty_rest_of_line ();
2197 /* The .function pseudo-op. This takes several arguments. The first
2198 argument seems to be the external name of the symbol. The second
2199 argment seems to be the label for the start of the function. gcc
2200 uses the same name for both. I have no idea what the third and
2201 fourth arguments are meant to be. The optional fifth argument is
2202 an expression for the size of the function. In COFF this symbol
2203 gets an aux entry like that used for a csect. */
2206 ppc_function (ignore)
2215 name = input_line_pointer;
2216 endc = get_symbol_end ();
2218 /* Ignore any [PR] suffix. */
2219 name = ppc_canonicalize_symbol_name (name);
2220 s = strchr (name, '[');
2221 if (s != (char *) NULL
2222 && strcmp (s + 1, "PR]") == 0)
2225 ext_sym = symbol_find_or_make (name);
2227 *input_line_pointer = endc;
2229 if (*input_line_pointer != ',')
2231 as_bad ("missing symbol name");
2232 ignore_rest_of_line ();
2235 ++input_line_pointer;
2237 name = input_line_pointer;
2238 endc = get_symbol_end ();
2240 lab_sym = symbol_find_or_make (name);
2242 *input_line_pointer = endc;
2244 if (ext_sym != lab_sym)
2246 ext_sym->sy_value.X_op = O_symbol;
2247 ext_sym->sy_value.X_add_symbol = lab_sym;
2248 ext_sym->sy_value.X_op_symbol = NULL;
2249 ext_sym->sy_value.X_add_number = 0;
2252 if (ext_sym->sy_tc.class == -1)
2253 ext_sym->sy_tc.class = XMC_PR;
2254 ext_sym->sy_tc.output = 1;
2256 if (*input_line_pointer == ',')
2260 /* Ignore the third argument. */
2261 ++input_line_pointer;
2262 expression (&ignore);
2263 if (*input_line_pointer == ',')
2265 /* Ignore the fourth argument. */
2266 ++input_line_pointer;
2267 expression (&ignore);
2268 if (*input_line_pointer == ',')
2270 /* The fifth argument is the function size. */
2271 ++input_line_pointer;
2272 ext_sym->sy_tc.size = symbol_new ("L0\001",
2275 &zero_address_frag);
2276 pseudo_set (ext_sym->sy_tc.size);
2281 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2282 SF_SET_FUNCTION (ext_sym);
2283 SF_SET_PROCESS (ext_sym);
2284 coff_add_linesym (ext_sym);
2286 demand_empty_rest_of_line ();
2289 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2298 sym = symbol_make (".bf");
2299 S_SET_SEGMENT (sym, text_section);
2300 sym->sy_frag = frag_now;
2301 S_SET_VALUE (sym, frag_now_fix ());
2302 S_SET_STORAGE_CLASS (sym, C_FCN);
2304 coff_line_base = get_absolute_expression ();
2306 S_SET_NUMBER_AUXILIARY (sym, 1);
2307 SA_SET_SYM_LNNO (sym, coff_line_base);
2309 sym->sy_tc.output = 1;
2311 ppc_frob_label (sym);
2313 demand_empty_rest_of_line ();
2316 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2317 ".ef", except that the line number is absolute, not relative to the
2318 most recent ".bf" symbol. */
2326 sym = symbol_make (".ef");
2327 S_SET_SEGMENT (sym, text_section);
2328 sym->sy_frag = frag_now;
2329 S_SET_VALUE (sym, frag_now_fix ());
2330 S_SET_STORAGE_CLASS (sym, C_FCN);
2331 S_SET_NUMBER_AUXILIARY (sym, 1);
2332 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2333 sym->sy_tc.output = 1;
2335 ppc_frob_label (sym);
2337 demand_empty_rest_of_line ();
2340 /* The .bi and .ei pseudo-ops. These take a string argument and
2341 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2353 name = demand_copy_C_string (&len);
2355 /* The value of these symbols is actually file offset. Here we set
2356 the value to the index into the line number entries. In
2357 ppc_frob_symbols we set the fix_line field, which will cause BFD
2358 to do the right thing. */
2360 sym = symbol_make (name);
2361 S_SET_SEGMENT (sym, now_seg);
2362 S_SET_VALUE (sym, coff_n_line_nos);
2363 sym->bsym->flags |= BSF_DEBUGGING;
2365 /* obj-coff.c currently only handles line numbers correctly in the
2367 assert (now_seg == text_section);
2369 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
2370 sym->sy_tc.output = 1;
2372 for (look = symbol_rootP;
2373 (look != (symbolS *) NULL
2374 && (S_GET_STORAGE_CLASS (look) == C_FILE
2375 || S_GET_STORAGE_CLASS (look) == C_BINCL
2376 || S_GET_STORAGE_CLASS (look) == C_EINCL));
2377 look = symbol_next (look))
2379 if (look != (symbolS *) NULL)
2381 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2382 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
2385 demand_empty_rest_of_line ();
2388 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2389 There is one argument, which is a csect symbol. The value of the
2390 .bs symbol is the index of this csect symbol. */
2401 if (ppc_current_block != NULL)
2402 as_bad ("nested .bs blocks");
2404 name = input_line_pointer;
2405 endc = get_symbol_end ();
2407 csect = symbol_find_or_make (name);
2409 *input_line_pointer = endc;
2411 sym = symbol_make (".bs");
2412 S_SET_SEGMENT (sym, now_seg);
2413 S_SET_STORAGE_CLASS (sym, C_BSTAT);
2414 sym->bsym->flags |= BSF_DEBUGGING;
2415 sym->sy_tc.output = 1;
2417 sym->sy_tc.within = csect;
2419 ppc_frob_label (sym);
2421 ppc_current_block = sym;
2423 demand_empty_rest_of_line ();
2426 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2434 if (ppc_current_block == NULL)
2435 as_bad (".es without preceding .bs");
2437 sym = symbol_make (".es");
2438 S_SET_SEGMENT (sym, now_seg);
2439 S_SET_STORAGE_CLASS (sym, C_ESTAT);
2440 sym->bsym->flags |= BSF_DEBUGGING;
2441 sym->sy_tc.output = 1;
2443 ppc_frob_label (sym);
2445 ppc_current_block = NULL;
2447 demand_empty_rest_of_line ();
2450 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2459 sym = symbol_make (".bb");
2460 S_SET_SEGMENT (sym, text_section);
2461 sym->sy_frag = frag_now;
2462 S_SET_VALUE (sym, frag_now_fix ());
2463 S_SET_STORAGE_CLASS (sym, C_BLOCK);
2465 S_SET_NUMBER_AUXILIARY (sym, 1);
2466 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2468 sym->sy_tc.output = 1;
2470 ppc_frob_label (sym);
2472 demand_empty_rest_of_line ();
2475 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2484 sym = symbol_make (".eb");
2485 S_SET_SEGMENT (sym, text_section);
2486 sym->sy_frag = frag_now;
2487 S_SET_VALUE (sym, frag_now_fix ());
2488 S_SET_STORAGE_CLASS (sym, C_FCN);
2489 S_SET_NUMBER_AUXILIARY (sym, 1);
2490 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2491 sym->sy_tc.output = 1;
2493 ppc_frob_label (sym);
2495 demand_empty_rest_of_line ();
2498 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2504 if (ppc_toc_csect != (symbolS *) NULL)
2505 subseg_set (data_section, ppc_toc_csect->sy_tc.subseg);
2512 subseg = ppc_data_subsegment;
2513 ++ppc_data_subsegment;
2515 subseg_new (segment_name (data_section), subseg);
2516 ppc_toc_frag = frag_now;
2518 sym = symbol_find_or_make ("TOC[TC0]");
2519 sym->sy_frag = frag_now;
2520 S_SET_SEGMENT (sym, data_section);
2521 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2522 sym->sy_tc.subseg = subseg;
2523 sym->sy_tc.output = 1;
2524 sym->sy_tc.within = sym;
2526 ppc_toc_csect = sym;
2528 for (list = ppc_data_csects;
2529 list->sy_tc.next != (symbolS *) NULL;
2530 list = list->sy_tc.next)
2532 list->sy_tc.next = sym;
2534 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2535 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2538 ppc_current_csect = ppc_toc_csect;
2540 demand_empty_rest_of_line ();
2543 #endif /* OBJ_XCOFF */
2545 /* The .tc pseudo-op. This is used when generating either XCOFF or
2546 ELF. This takes two or more arguments.
2548 When generating XCOFF output, the first argument is the name to
2549 give to this location in the toc; this will be a symbol with class
2550 TC. The rest of the arguments are 4 byte values to actually put at
2551 this location in the TOC; often there is just one more argument, a
2552 relocateable symbol reference.
2554 When not generating XCOFF output, the arguments are the same, but
2555 the first argument is simply ignored. */
2563 /* Define the TOC symbol name. */
2569 if (ppc_toc_csect == (symbolS *) NULL
2570 || ppc_toc_csect != ppc_current_csect)
2572 as_bad (".tc not in .toc section");
2573 ignore_rest_of_line ();
2577 name = input_line_pointer;
2578 endc = get_symbol_end ();
2580 sym = symbol_find_or_make (name);
2582 *input_line_pointer = endc;
2584 if (S_IS_DEFINED (sym))
2588 label = ppc_current_csect->sy_tc.within;
2589 if (label->sy_tc.class != XMC_TC0)
2591 as_warn (".tc with no label");
2592 ignore_rest_of_line ();
2596 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
2597 label->sy_frag = sym->sy_frag;
2598 S_SET_VALUE (label, S_GET_VALUE (sym));
2600 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2601 ++input_line_pointer;
2606 S_SET_SEGMENT (sym, now_seg);
2607 sym->sy_frag = frag_now;
2608 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2609 sym->sy_tc.class = XMC_TC;
2610 sym->sy_tc.output = 1;
2612 ppc_frob_label (sym);
2615 #else /* ! defined (OBJ_XCOFF) */
2617 /* Skip the TOC symbol name. */
2618 while (is_part_of_name (*input_line_pointer)
2619 || *input_line_pointer == '['
2620 || *input_line_pointer == ']'
2621 || *input_line_pointer == '{'
2622 || *input_line_pointer == '}')
2623 ++input_line_pointer;
2625 /* Align to a four byte boundary. */
2627 record_alignment (now_seg, 2);
2629 #endif /* ! defined (OBJ_XCOFF) */
2631 if (*input_line_pointer != ',')
2632 demand_empty_rest_of_line ();
2635 ++input_line_pointer;
2642 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2644 /* Set the current section. */
2646 ppc_set_current_section (new)
2649 ppc_previous_section = ppc_current_section;
2650 ppc_current_section = new;
2653 /* pseudo-op: .previous
2654 behaviour: toggles the current section with the previous section.
2656 warnings: "No previous section"
2659 ppc_previous(ignore)
2664 if (ppc_previous_section == NULL)
2666 as_warn("No previous section to return to. Directive ignored.");
2670 subseg_set(ppc_previous_section, 0);
2672 ppc_set_current_section(ppc_previous_section);
2675 /* pseudo-op: .pdata
2676 behaviour: predefined read only data section
2680 initial: .section .pdata "adr3"
2681 a - don't know -- maybe a misprint
2682 d - initialized data
2684 3 - double word aligned (that would be 4 byte boundary)
2687 Tag index tables (also known as the function table) for exception
2688 handling, debugging, etc.
2695 if (pdata_section == 0)
2697 pdata_section = subseg_new (".pdata", 0);
2699 bfd_set_section_flags (stdoutput, pdata_section,
2700 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2701 | SEC_READONLY | SEC_DATA ));
2703 bfd_set_section_alignment (stdoutput, pdata_section, 3);
2707 pdata_section = subseg_new(".pdata", 0);
2709 ppc_set_current_section(pdata_section);
2712 /* pseudo-op: .ydata
2713 behaviour: predefined read only data section
2717 initial: .section .ydata "drw3"
2718 a - don't know -- maybe a misprint
2719 d - initialized data
2721 3 - double word aligned (that would be 4 byte boundary)
2723 Tag tables (also known as the scope table) for exception handling,
2730 if (ydata_section == 0)
2732 ydata_section = subseg_new (".ydata", 0);
2733 bfd_set_section_flags (stdoutput, ydata_section,
2734 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2735 | SEC_READONLY | SEC_DATA ));
2737 bfd_set_section_alignment (stdoutput, ydata_section, 3);
2741 ydata_section = subseg_new (".ydata", 0);
2743 ppc_set_current_section(ydata_section);
2746 /* pseudo-op: .reldata
2747 behaviour: predefined read write data section
2748 double word aligned (4-byte)
2749 FIXME: relocation is applied to it
2750 FIXME: what's the difference between this and .data?
2753 initial: .section .reldata "drw3"
2754 d - initialized data
2757 3 - double word aligned (that would be 8 byte boundary)
2760 Like .data, but intended to hold data subject to relocation, such as
2761 function descriptors, etc.
2767 if (reldata_section == 0)
2769 reldata_section = subseg_new (".reldata", 0);
2771 bfd_set_section_flags (stdoutput, reldata_section,
2772 ( SEC_ALLOC | SEC_LOAD | SEC_RELOC
2775 bfd_set_section_alignment (stdoutput, reldata_section, 3);
2779 reldata_section = subseg_new (".reldata", 0);
2781 ppc_set_current_section(reldata_section);
2784 /* pseudo-op: .rdata
2785 behaviour: predefined read only data section
2789 initial: .section .rdata "dr3"
2790 d - initialized data
2792 3 - double word aligned (that would be 4 byte boundary)
2798 if (rdata_section == 0)
2800 rdata_section = subseg_new (".rdata", 0);
2801 bfd_set_section_flags (stdoutput, rdata_section,
2802 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2803 | SEC_READONLY | SEC_DATA ));
2805 bfd_set_section_alignment (stdoutput, rdata_section, 2);
2809 rdata_section = subseg_new (".rdata", 0);
2811 ppc_set_current_section(rdata_section);
2814 /* pseudo-op: .ualong
2815 behaviour: much like .int, with the exception that no alignment is
2817 FIXME: test the alignment statement
2829 /* pseudo-op: .znop <symbol name>
2830 behaviour: Issue a nop instruction
2831 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2832 the supplied symbol name.
2834 warnings: Missing symbol name
2841 const struct powerpc_opcode *opcode;
2847 /* Strip out the symbol name */
2855 symbol_name = input_line_pointer;
2856 c = get_symbol_end ();
2858 name = xmalloc (input_line_pointer - symbol_name + 1);
2859 strcpy (name, symbol_name);
2861 sym = symbol_find_or_make (name);
2863 *input_line_pointer = c;
2867 /* Look up the opcode in the hash table. */
2868 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
2870 /* stick in the nop */
2871 insn = opcode->opcode;
2873 /* Write out the instruction. */
2875 md_number_to_chars (f, insn, 4);
2877 f - frag_now->fr_literal,
2882 BFD_RELOC_16_GOT_PCREL);
2895 register char *name;
2899 register symbolS *symbolP;
2902 name = input_line_pointer;
2903 c = get_symbol_end ();
2905 /* just after name is now '\0' */
2906 p = input_line_pointer;
2909 if (*input_line_pointer != ',')
2911 as_bad ("Expected comma after symbol-name: rest of line ignored.");
2912 ignore_rest_of_line ();
2916 input_line_pointer++; /* skip ',' */
2917 if ((temp = get_absolute_expression ()) < 0)
2919 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
2920 ignore_rest_of_line ();
2926 /* The third argument to .comm is the alignment. */
2927 if (*input_line_pointer != ',')
2931 ++input_line_pointer;
2932 align = get_absolute_expression ();
2935 as_warn ("ignoring bad alignment");
2942 symbolP = symbol_find_or_make (name);
2945 if (S_IS_DEFINED (symbolP))
2947 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2948 S_GET_NAME (symbolP));
2949 ignore_rest_of_line ();
2953 if (S_GET_VALUE (symbolP))
2955 if (S_GET_VALUE (symbolP) != (valueT) temp)
2956 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
2957 S_GET_NAME (symbolP),
2958 (long) S_GET_VALUE (symbolP),
2963 S_SET_VALUE (symbolP, (valueT) temp);
2964 S_SET_EXTERNAL (symbolP);
2967 demand_empty_rest_of_line ();
2971 * implement the .section pseudo op:
2972 * .section name {, "flags"}
2974 * | +--- optional flags: 'b' for bss
2976 * +-- section name 'l' for lib
2980 * 'd' (apparently m88k for data)
2982 * But if the argument is not a quoted string, treat it as a
2983 * subsegment number.
2985 * FIXME: this is a copy of the section processing from obj-coff.c, with
2986 * additions/changes for the moto-pas assembler support. There are three
2989 * FIXME: I just noticed this. This doesn't work at all really. It it
2990 * setting bits that bfd probably neither understands or uses. The
2991 * correct approach (?) will have to incorporate extra fields attached
2992 * to the section to hold the system specific stuff. (krk)
2995 * 'a' - unknown - referred to in documentation, but no definition supplied
2996 * 'c' - section has code
2997 * 'd' - section has initialized data
2998 * 'u' - section has uninitialized data
2999 * 'i' - section contains directives (info)
3000 * 'n' - section can be discarded
3001 * 'R' - remove section at link time
3003 * Section Protection:
3004 * 'r' - section is readable
3005 * 'w' - section is writeable
3006 * 'x' - section is executable
3007 * 's' - section is sharable
3009 * Section Alignment:
3010 * '0' - align to byte boundary
3011 * '1' - align to halfword undary
3012 * '2' - align to word boundary
3013 * '3' - align to doubleword boundary
3014 * '4' - align to quadword boundary
3015 * '5' - align to 32 byte boundary
3016 * '6' - align to 64 byte boundary
3021 ppc_pe_section (ignore)
3024 /* Strip out the section name */
3033 align = 4; /* default alignment to 16 byte boundary */
3035 section_name = input_line_pointer;
3036 c = get_symbol_end ();
3038 name = xmalloc (input_line_pointer - section_name + 1);
3039 strcpy (name, section_name);
3041 *input_line_pointer = c;
3046 flags = SEC_NO_FLAGS;
3048 if (*input_line_pointer == ',')
3050 ++input_line_pointer;
3052 if (*input_line_pointer != '"')
3053 exp = get_absolute_expression ();
3056 ++input_line_pointer;
3057 while (*input_line_pointer != '"'
3058 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3060 switch (*input_line_pointer)
3062 /* Section Contents */
3063 case 'a': /* unknown */
3064 as_warn ("Unsupported section attribute -- 'a'");
3066 case 'c': /* code section */
3069 case 'd': /* section has initialized data */
3072 case 'u': /* section has uninitialized data */
3073 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3077 case 'i': /* section contains directives (info) */
3078 /* FIXME: This is IMAGE_SCN_LNK_INFO
3080 flags |= SEC_HAS_CONTENTS;
3082 case 'n': /* section can be discarded */
3085 case 'R': /* Remove section at link time */
3086 flags |= SEC_NEVER_LOAD;
3089 /* Section Protection */
3090 case 'r': /* section is readable */
3091 flags |= IMAGE_SCN_MEM_READ;
3093 case 'w': /* section is writeable */
3094 flags |= IMAGE_SCN_MEM_WRITE;
3096 case 'x': /* section is executable */
3097 flags |= IMAGE_SCN_MEM_EXECUTE;
3099 case 's': /* section is sharable */
3100 flags |= IMAGE_SCN_MEM_SHARED;
3103 /* Section Alignment */
3104 case '0': /* align to byte boundary */
3105 flags |= IMAGE_SCN_ALIGN_1BYTES;
3108 case '1': /* align to halfword boundary */
3109 flags |= IMAGE_SCN_ALIGN_2BYTES;
3112 case '2': /* align to word boundary */
3113 flags |= IMAGE_SCN_ALIGN_4BYTES;
3116 case '3': /* align to doubleword boundary */
3117 flags |= IMAGE_SCN_ALIGN_8BYTES;
3120 case '4': /* align to quadword boundary */
3121 flags |= IMAGE_SCN_ALIGN_16BYTES;
3124 case '5': /* align to 32 byte boundary */
3125 flags |= IMAGE_SCN_ALIGN_32BYTES;
3128 case '6': /* align to 64 byte boundary */
3129 flags |= IMAGE_SCN_ALIGN_64BYTES;
3134 as_warn("unknown section attribute '%c'",
3135 *input_line_pointer);
3138 ++input_line_pointer;
3140 if (*input_line_pointer == '"')
3141 ++input_line_pointer;
3145 sec = subseg_new (name, (subsegT) exp);
3147 ppc_set_current_section(sec);
3149 if (flags != SEC_NO_FLAGS)
3151 if (! bfd_set_section_flags (stdoutput, sec, flags))
3152 as_warn ("error setting flags for \"%s\": %s",
3153 bfd_section_name (stdoutput, sec),
3154 bfd_errmsg (bfd_get_error ()));
3157 bfd_set_section_alignment(stdoutput, sec, align);
3162 ppc_pe_function (ignore)
3169 name = input_line_pointer;
3170 endc = get_symbol_end ();
3172 ext_sym = symbol_find_or_make (name);
3174 *input_line_pointer = endc;
3176 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3177 SF_SET_FUNCTION (ext_sym);
3178 SF_SET_PROCESS (ext_sym);
3179 coff_add_linesym (ext_sym);
3181 demand_empty_rest_of_line ();
3185 ppc_pe_tocd (ignore)
3188 if (tocdata_section == 0)
3190 tocdata_section = subseg_new (".tocd", 0);
3191 /* FIXME: section flags won't work */
3192 bfd_set_section_flags (stdoutput, tocdata_section,
3193 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3194 | SEC_READONLY | SEC_DATA ));
3196 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
3200 rdata_section = subseg_new (".tocd", 0);
3203 ppc_set_current_section(tocdata_section);
3205 demand_empty_rest_of_line ();
3208 /* Don't adjust TOC relocs to use the section symbol. */
3211 ppc_pe_fix_adjustable (fix)
3214 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
3221 /* XCOFF specific symbol and file handling. */
3223 /* Canonicalize the symbol name. We use the to force the suffix, if
3224 any, to use square brackets, and to be in upper case. */
3227 ppc_canonicalize_symbol_name (name)
3232 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
3246 for (s++; *s != '\0' && *s != brac; s++)
3250 if (*s == '\0' || s[1] != '\0')
3251 as_bad ("bad symbol suffix");
3259 /* Set the class of a symbol based on the suffix, if any. This is
3260 called whenever a new symbol is created. */
3263 ppc_symbol_new_hook (sym)
3268 sym->sy_tc.next = NULL;
3269 sym->sy_tc.output = 0;
3270 sym->sy_tc.class = -1;
3271 sym->sy_tc.real_name = NULL;
3272 sym->sy_tc.subseg = 0;
3273 sym->sy_tc.align = 0;
3274 sym->sy_tc.size = NULL;
3275 sym->sy_tc.within = NULL;
3277 s = strchr (S_GET_NAME (sym), '[');
3278 if (s == (const char *) NULL)
3280 /* There is no suffix. */
3289 if (strcmp (s, "BS]") == 0)
3290 sym->sy_tc.class = XMC_BS;
3293 if (strcmp (s, "DB]") == 0)
3294 sym->sy_tc.class = XMC_DB;
3295 else if (strcmp (s, "DS]") == 0)
3296 sym->sy_tc.class = XMC_DS;
3299 if (strcmp (s, "GL]") == 0)
3300 sym->sy_tc.class = XMC_GL;
3303 if (strcmp (s, "PR]") == 0)
3304 sym->sy_tc.class = XMC_PR;
3307 if (strcmp (s, "RO]") == 0)
3308 sym->sy_tc.class = XMC_RO;
3309 else if (strcmp (s, "RW]") == 0)
3310 sym->sy_tc.class = XMC_RW;
3313 if (strcmp (s, "SV]") == 0)
3314 sym->sy_tc.class = XMC_SV;
3317 if (strcmp (s, "TC]") == 0)
3318 sym->sy_tc.class = XMC_TC;
3319 else if (strcmp (s, "TI]") == 0)
3320 sym->sy_tc.class = XMC_TI;
3321 else if (strcmp (s, "TB]") == 0)
3322 sym->sy_tc.class = XMC_TB;
3323 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
3324 sym->sy_tc.class = XMC_TC0;
3327 if (strcmp (s, "UA]") == 0)
3328 sym->sy_tc.class = XMC_UA;
3329 else if (strcmp (s, "UC]") == 0)
3330 sym->sy_tc.class = XMC_UC;
3333 if (strcmp (s, "XO]") == 0)
3334 sym->sy_tc.class = XMC_XO;
3338 if (sym->sy_tc.class == -1)
3339 as_bad ("Unrecognized symbol suffix");
3342 /* Set the class of a label based on where it is defined. This
3343 handles symbols without suffixes. Also, move the symbol so that it
3344 follows the csect symbol. */
3347 ppc_frob_label (sym)
3350 if (ppc_current_csect != (symbolS *) NULL)
3352 if (sym->sy_tc.class == -1)
3353 sym->sy_tc.class = ppc_current_csect->sy_tc.class;
3355 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3356 symbol_append (sym, ppc_current_csect->sy_tc.within, &symbol_rootP,
3358 ppc_current_csect->sy_tc.within = sym;
3362 /* Change the name of a symbol just before writing it out. Set the
3363 real name if the .rename pseudo-op was used. Otherwise, remove any
3364 class suffix. Return 1 if the symbol should not be included in the
3368 ppc_frob_symbol (sym)
3371 static symbolS *ppc_last_function;
3372 static symbolS *set_end;
3374 /* Discard symbols that should not be included in the output symbol
3376 if (! sym->sy_used_in_reloc
3377 && ((sym->bsym->flags & BSF_SECTION_SYM) != 0
3378 || (! S_IS_EXTERNAL (sym)
3379 && ! sym->sy_tc.output
3380 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
3383 if (sym->sy_tc.real_name != (char *) NULL)
3384 S_SET_NAME (sym, sym->sy_tc.real_name);
3390 name = S_GET_NAME (sym);
3391 s = strchr (name, '[');
3392 if (s != (char *) NULL)
3398 snew = xmalloc (len + 1);
3399 memcpy (snew, name, len);
3402 S_SET_NAME (sym, snew);
3406 if (set_end != (symbolS *) NULL)
3408 SA_SET_SYM_ENDNDX (set_end, sym);
3412 if (SF_GET_FUNCTION (sym))
3414 if (ppc_last_function != (symbolS *) NULL)
3415 as_warn ("two .function pseudo-ops with no intervening .ef");
3416 ppc_last_function = sym;
3417 if (sym->sy_tc.size != (symbolS *) NULL)
3419 resolve_symbol_value (sym->sy_tc.size);
3420 SA_SET_SYM_FSIZE (sym, (long) S_GET_VALUE (sym->sy_tc.size));
3423 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
3424 && strcmp (S_GET_NAME (sym), ".ef") == 0)
3426 if (ppc_last_function == (symbolS *) NULL)
3427 as_warn (".ef with no preceding .function");
3430 set_end = ppc_last_function;
3431 ppc_last_function = NULL;
3433 /* We don't have a C_EFCN symbol, but we need to force the
3434 COFF backend to believe that it has seen one. */
3435 coff_last_function = NULL;
3439 if (! S_IS_EXTERNAL (sym)
3440 && (sym->bsym->flags & BSF_SECTION_SYM) == 0
3441 && S_GET_STORAGE_CLASS (sym) != C_FILE
3442 && S_GET_STORAGE_CLASS (sym) != C_FCN
3443 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
3444 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
3445 && S_GET_STORAGE_CLASS (sym) != C_BINCL
3446 && S_GET_STORAGE_CLASS (sym) != C_EINCL
3447 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
3448 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
3450 if ((S_GET_STORAGE_CLASS (sym) == C_EXT
3451 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
3452 && S_GET_SEGMENT (sym) != absolute_section)
3455 union internal_auxent *a;
3457 /* Create a csect aux. */
3458 i = S_GET_NUMBER_AUXILIARY (sym);
3459 S_SET_NUMBER_AUXILIARY (sym, i + 1);
3460 a = &coffsymbol (sym->bsym)->native[i + 1].u.auxent;
3461 if (sym->sy_tc.class == XMC_TC0)
3463 /* This is the TOC table. */
3464 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
3465 a->x_csect.x_scnlen.l = 0;
3466 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
3468 else if (sym->sy_tc.subseg != 0)
3470 /* This is a csect symbol. x_scnlen is the size of the
3472 if (sym->sy_tc.next == (symbolS *) NULL)
3473 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
3474 S_GET_SEGMENT (sym))
3475 - S_GET_VALUE (sym));
3478 resolve_symbol_value (sym->sy_tc.next);
3479 a->x_csect.x_scnlen.l = (S_GET_VALUE (sym->sy_tc.next)
3480 - S_GET_VALUE (sym));
3482 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_SD;
3484 else if (S_GET_SEGMENT (sym) == bss_section)
3486 /* This is a common symbol. */
3487 a->x_csect.x_scnlen.l = sym->sy_frag->fr_offset;
3488 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_CM;
3489 if (S_IS_EXTERNAL (sym))
3490 sym->sy_tc.class = XMC_RW;
3492 sym->sy_tc.class = XMC_BS;
3494 else if (! S_IS_DEFINED (sym))
3496 /* This is an external symbol. */
3497 a->x_csect.x_scnlen.l = 0;
3498 a->x_csect.x_smtyp = XTY_ER;
3500 else if (sym->sy_tc.class == XMC_TC)
3504 /* This is a TOC definition. x_scnlen is the size of the
3506 next = symbol_next (sym);
3507 while (next->sy_tc.class == XMC_TC0)
3508 next = symbol_next (next);
3509 if (next == (symbolS *) NULL
3510 || next->sy_tc.class != XMC_TC)
3512 if (ppc_after_toc_frag == (fragS *) NULL)
3513 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
3515 - S_GET_VALUE (sym));
3517 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
3518 - S_GET_VALUE (sym));
3522 resolve_symbol_value (next);
3523 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
3524 - S_GET_VALUE (sym));
3526 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
3532 /* This is a normal symbol definition. x_scnlen is the
3533 symbol index of the containing csect. */
3534 if (S_GET_SEGMENT (sym) == text_section)
3535 csect = ppc_text_csects;
3536 else if (S_GET_SEGMENT (sym) == data_section)
3537 csect = ppc_data_csects;
3541 /* Skip the initial dummy symbol. */
3542 csect = csect->sy_tc.next;
3544 if (csect == (symbolS *) NULL)
3545 a->x_csect.x_scnlen.l = 0;
3548 while (csect->sy_tc.next != (symbolS *) NULL)
3550 resolve_symbol_value (csect->sy_tc.next);
3551 if (S_GET_VALUE (csect->sy_tc.next) > S_GET_VALUE (sym))
3553 csect = csect->sy_tc.next;
3556 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
3557 coffsymbol (sym->bsym)->native[i + 1].fix_scnlen = 1;
3559 a->x_csect.x_smtyp = XTY_LD;
3562 a->x_csect.x_parmhash = 0;
3563 a->x_csect.x_snhash = 0;
3564 if (sym->sy_tc.class == -1)
3565 a->x_csect.x_smclas = XMC_PR;
3567 a->x_csect.x_smclas = sym->sy_tc.class;
3568 a->x_csect.x_stab = 0;
3569 a->x_csect.x_snstab = 0;
3571 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
3573 /* We want the value to be the symbol index of the referenced
3574 csect symbol. BFD will do that for us if we set the right
3577 (valueT) coffsymbol (sym->sy_tc.within->bsym)->native);
3578 coffsymbol (sym->bsym)->native->fix_value = 1;
3580 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
3585 /* The value is the offset from the enclosing csect. */
3586 block = sym->sy_tc.within;
3587 csect = block->sy_tc.within;
3588 resolve_symbol_value (csect);
3589 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
3591 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
3592 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
3594 /* We want the value to be a file offset into the line numbers.
3595 BFD will do that for us if we set the right flags. We have
3596 already set the value correctly. */
3597 coffsymbol (sym->bsym)->native->fix_line = 1;
3603 /* Set the VMA for a section. This is called on all the sections in
3607 ppc_frob_section (sec)
3610 static bfd_size_type vma = 0;
3612 bfd_set_section_vma (stdoutput, sec, vma);
3613 vma += bfd_section_size (stdoutput, sec);
3616 /* Adjust the file by adding a .debug section if needed. */
3621 if (ppc_debug_name_section_size > 0)
3625 sec = bfd_make_section (stdoutput, ".debug");
3626 if (sec == (asection *) NULL
3627 || ! bfd_set_section_size (stdoutput, sec,
3628 ppc_debug_name_section_size)
3629 || ! bfd_set_section_flags (stdoutput, sec,
3630 SEC_HAS_CONTENTS | SEC_LOAD))
3631 as_fatal ("can't make .debug section");
3635 #endif /* OBJ_XCOFF */
3637 /* Turn a string in input_line_pointer into a floating point constant
3638 of type type, and store the appropriate bytes in *litp. The number
3639 of LITTLENUMS emitted is stored in *sizep . An error message is
3640 returned, or NULL on OK. */
3643 md_atof (type, litp, sizep)
3649 LITTLENUM_TYPE words[4];
3665 return "bad call to md_atof";
3668 t = atof_ieee (input_line_pointer, type, words);
3670 input_line_pointer = t;
3674 if (target_big_endian)
3676 for (i = 0; i < prec; i++)
3678 md_number_to_chars (litp, (valueT) words[i], 2);
3684 for (i = prec - 1; i >= 0; i--)
3686 md_number_to_chars (litp, (valueT) words[i], 2);
3694 /* Write a value out to the object file, using the appropriate
3698 md_number_to_chars (buf, val, n)
3703 if (target_big_endian)
3704 number_to_chars_bigendian (buf, val, n);
3706 number_to_chars_littleendian (buf, val, n);
3709 /* Align a section (I don't know why this is machine dependent). */
3712 md_section_align (seg, addr)
3716 int align = bfd_get_section_alignment (stdoutput, seg);
3718 return ((addr + (1 << align) - 1) & (-1 << align));
3721 /* We don't have any form of relaxing. */
3724 md_estimate_size_before_relax (fragp, seg)
3732 /* Convert a machine dependent frag. We never generate these. */
3735 md_convert_frag (abfd, sec, fragp)
3743 /* We have no need to default values of symbols. */
3747 md_undefined_symbol (name)
3753 /* Functions concerning relocs. */
3755 /* The location from which a PC relative jump should be calculated,
3756 given a PC relative reloc. */
3759 md_pcrel_from (fixp)
3763 if (fixp->fx_addsy != (symbolS *) NULL
3764 && (! S_IS_DEFINED (fixp->fx_addsy)
3765 || TC_FORCE_RELOCATION (fixp)))
3769 return fixp->fx_frag->fr_address + fixp->fx_where;
3774 /* This is called to see whether a fixup should be adjusted to use a
3775 section symbol. We take the opportunity to change a fixup against
3776 a symbol in the TOC subsegment into a reloc against the
3777 corresponding .tc symbol. */
3780 ppc_fix_adjustable (fix)
3785 resolve_symbol_value (fix->fx_addsy);
3786 val = S_GET_VALUE (fix->fx_addsy);
3787 if (ppc_toc_csect != (symbolS *) NULL
3788 && fix->fx_addsy != (symbolS *) NULL
3789 && fix->fx_addsy != ppc_toc_csect
3790 && S_GET_SEGMENT (fix->fx_addsy) == data_section
3791 && val >= ppc_toc_frag->fr_address
3792 && (ppc_after_toc_frag == (fragS *) NULL
3793 || val < ppc_after_toc_frag->fr_address))
3797 for (sy = symbol_next (ppc_toc_csect);
3798 sy != (symbolS *) NULL;
3799 sy = symbol_next (sy))
3801 if (sy->sy_tc.class == XMC_TC0)
3803 if (sy->sy_tc.class != XMC_TC)
3805 resolve_symbol_value (sy);
3806 if (val == S_GET_VALUE (sy))
3809 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
3814 as_bad_where (fix->fx_file, fix->fx_line,
3815 "symbol in .toc does not match any .tc");
3818 /* Possibly adjust the reloc to be against the csect. */
3819 if (fix->fx_addsy != (symbolS *) NULL
3820 && fix->fx_addsy->sy_tc.subseg == 0
3821 && fix->fx_addsy->sy_tc.class != XMC_TC0
3822 && fix->fx_addsy->sy_tc.class != XMC_TC
3823 && S_GET_SEGMENT (fix->fx_addsy) != bss_section)
3827 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
3828 csect = ppc_text_csects;
3829 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
3830 csect = ppc_data_csects;
3834 /* Skip the initial dummy symbol. */
3835 csect = csect->sy_tc.next;
3837 if (csect != (symbolS *) NULL)
3839 while (csect->sy_tc.next != (symbolS *) NULL
3840 && (csect->sy_tc.next->sy_frag->fr_address
3841 <= fix->fx_addsy->sy_frag->fr_address))
3842 csect = csect->sy_tc.next;
3844 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
3845 - csect->sy_frag->fr_address);
3846 fix->fx_addsy = csect;
3850 /* Adjust a reloc against a .lcomm symbol to be against the base
3852 if (fix->fx_addsy != (symbolS *) NULL
3853 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
3854 && ! S_IS_EXTERNAL (fix->fx_addsy))
3856 resolve_symbol_value (fix->fx_addsy->sy_frag->fr_symbol);
3857 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
3858 - S_GET_VALUE (fix->fx_addsy->sy_frag->fr_symbol));
3859 fix->fx_addsy = fix->fx_addsy->sy_frag->fr_symbol;
3867 /* See whether a symbol is in the TOC section. */
3870 ppc_is_toc_sym (sym)
3874 return sym->sy_tc.class == XMC_TC;
3876 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
3880 /* Apply a fixup to the object code. This is called for all the
3881 fixups we generated by the call to fix_new_exp, above. In the call
3882 above we used a reloc code which was the largest legal reloc code
3883 plus the operand index. Here we undo that to recover the operand
3884 index. At this point all symbol values should be fully resolved,
3885 and we attempt to completely resolve the reloc. If we can not do
3886 that, we determine the correct reloc code and put it back in the
3890 md_apply_fix3 (fixp, valuep, seg)
3897 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
3898 the symbol values. Since we are using BFD_ASSEMBLER, if we are
3899 doing this relocation the code in write.c is going to call
3900 bfd_perform_relocation, which is also going to use the symbol
3901 value. That means that if the reloc is fully resolved we want to
3902 use *valuep since bfd_perform_relocation is not being used.
3903 However, if the reloc is not fully resolved we do not want to use
3904 *valuep, and must use fx_offset instead. However, if the reloc
3905 is PC relative, we do want to use *valuep since it includes the
3906 result of md_pcrel_from. This is confusing. */
3908 if (fixp->fx_addsy == (symbolS *) NULL)
3913 else if (fixp->fx_pcrel)
3917 value = fixp->fx_offset;
3918 if (fixp->fx_subsy != (symbolS *) NULL)
3920 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
3921 value -= S_GET_VALUE (fixp->fx_subsy);
3924 /* We can't actually support subtracting a symbol. */
3925 as_bad_where (fixp->fx_file, fixp->fx_line,
3926 "expression too complex");
3931 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
3934 const struct powerpc_operand *operand;
3938 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
3940 operand = &powerpc_operands[opindex];
3943 /* It appears that an instruction like
3945 when LC..1 is not a TOC symbol does not generate a reloc. It
3946 uses the offset of LC..1 within its csect. However, .long
3947 LC..1 will generate a reloc. I can't find any documentation
3948 on how these cases are to be distinguished, so this is a wild
3949 guess. These cases are generated by gcc -mminimal-toc. */
3950 if ((operand->flags & PPC_OPERAND_PARENS) != 0
3951 && operand->bits == 16
3952 && operand->shift == 0
3953 && operand->insert == NULL
3954 && fixp->fx_addsy != NULL
3955 && fixp->fx_addsy->sy_tc.subseg != 0
3956 && fixp->fx_addsy->sy_tc.class != XMC_TC
3957 && fixp->fx_addsy->sy_tc.class != XMC_TC0
3958 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
3960 value = fixp->fx_offset;
3965 /* Fetch the instruction, insert the fully resolved operand
3966 value, and stuff the instruction back again. */
3967 where = fixp->fx_frag->fr_literal + fixp->fx_where;
3968 if (target_big_endian)
3969 insn = bfd_getb32 ((unsigned char *) where);
3971 insn = bfd_getl32 ((unsigned char *) where);
3972 insn = ppc_insert_operand (insn, operand, (offsetT) value,
3973 fixp->fx_file, fixp->fx_line);
3974 if (target_big_endian)
3975 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
3977 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
3981 /* Nothing else to do here. */
3985 /* Determine a BFD reloc value based on the operand information.
3986 We are only prepared to turn a few of the operands into
3988 FIXME: We need to handle the DS field at the very least.
3989 FIXME: Selecting the reloc type is a bit haphazard; perhaps
3990 there should be a new field in the operand table. */
3991 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3992 && operand->bits == 26
3993 && operand->shift == 0)
3994 fixp->fx_r_type = BFD_RELOC_PPC_B26;
3995 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3996 && operand->bits == 16
3997 && operand->shift == 0)
3998 fixp->fx_r_type = BFD_RELOC_PPC_B16;
3999 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4000 && operand->bits == 26
4001 && operand->shift == 0)
4002 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4003 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4004 && operand->bits == 16
4005 && operand->shift == 0)
4006 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4007 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4008 && operand->bits == 16
4009 && operand->shift == 0
4010 && operand->insert == NULL
4011 && fixp->fx_addsy != NULL
4012 && ppc_is_toc_sym (fixp->fx_addsy))
4015 if (target_big_endian)
4016 fixp->fx_where += 2;
4017 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4021 as_bad_where (fixp->fx_file, fixp->fx_line,
4022 "unresolved expression that must be resolved");
4030 ppc_elf_validate_fix (fixp, seg);
4032 switch (fixp->fx_r_type)
4035 case BFD_RELOC_CTOR:
4038 fixp->fx_r_type = BFD_RELOC_32_PCREL;
4039 value += fixp->fx_frag->fr_address + fixp->fx_where;
4040 } /* fall through */
4042 case BFD_RELOC_32_PCREL:
4043 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4047 case BFD_RELOC_LO16:
4048 case BFD_RELOC_HI16:
4049 case BFD_RELOC_HI16_S:
4050 case BFD_RELOC_PPC_TOC16:
4052 case BFD_RELOC_GPREL16:
4053 case BFD_RELOC_16_GOT_PCREL:
4057 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4065 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4075 fixp->fx_addnumber = value;
4077 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
4078 fixp->fx_addnumber = 0;
4082 fixp->fx_addnumber = 0;
4084 /* We want to use the offset within the data segment of the
4085 symbol, not the actual VMA of the symbol. */
4086 fixp->fx_addnumber =
4087 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
4095 /* Generate a reloc for a fixup. */
4098 tc_gen_reloc (seg, fixp)
4104 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
4106 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
4107 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4108 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
4109 if (reloc->howto == (reloc_howto_type *) NULL)
4111 as_bad_where (fixp->fx_file, fixp->fx_line,
4112 "reloc %d not supported by object file format", (int)fixp->fx_r_type);
4115 reloc->addend = fixp->fx_addnumber;