1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #include "opcode/ppc.h"
32 #include "dwarf2dbg.h"
39 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
41 /* Tell the main code what the endianness is. */
42 extern int target_big_endian;
44 /* Whether or not, we've set target_big_endian. */
45 static int set_target_endian = 0;
47 /* Whether to use user friendly register names. */
48 #ifndef TARGET_REG_NAMES_P
50 #define TARGET_REG_NAMES_P true
52 #define TARGET_REG_NAMES_P false
56 static boolean reg_names_p = TARGET_REG_NAMES_P;
58 static boolean register_name PARAMS ((expressionS *));
59 static void ppc_set_cpu PARAMS ((void));
60 static unsigned long ppc_insert_operand
61 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
62 offsetT val, char *file, unsigned int line));
63 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
64 static void ppc_byte PARAMS ((int));
65 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
66 static void ppc_tc PARAMS ((int));
69 static void ppc_comm PARAMS ((int));
70 static void ppc_bb PARAMS ((int));
71 static void ppc_bc PARAMS ((int));
72 static void ppc_bf PARAMS ((int));
73 static void ppc_biei PARAMS ((int));
74 static void ppc_bs PARAMS ((int));
75 static void ppc_eb PARAMS ((int));
76 static void ppc_ec PARAMS ((int));
77 static void ppc_ef PARAMS ((int));
78 static void ppc_es PARAMS ((int));
79 static void ppc_csect PARAMS ((int));
80 static void ppc_change_csect PARAMS ((symbolS *));
81 static void ppc_function PARAMS ((int));
82 static void ppc_extern PARAMS ((int));
83 static void ppc_lglobl PARAMS ((int));
84 static void ppc_section PARAMS ((int));
85 static void ppc_named_section PARAMS ((int));
86 static void ppc_stabx PARAMS ((int));
87 static void ppc_rename PARAMS ((int));
88 static void ppc_toc PARAMS ((int));
89 static void ppc_xcoff_cons PARAMS ((int));
90 static void ppc_machine PARAMS ((int));
91 static void ppc_vbyte PARAMS ((int));
95 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
96 static void ppc_elf_cons PARAMS ((int));
97 static void ppc_elf_rdata PARAMS ((int));
98 static void ppc_elf_lcomm PARAMS ((int));
99 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
103 static void ppc_set_current_section PARAMS ((segT));
104 static void ppc_previous PARAMS ((int));
105 static void ppc_pdata PARAMS ((int));
106 static void ppc_ydata PARAMS ((int));
107 static void ppc_reldata PARAMS ((int));
108 static void ppc_rdata PARAMS ((int));
109 static void ppc_ualong PARAMS ((int));
110 static void ppc_znop PARAMS ((int));
111 static void ppc_pe_comm PARAMS ((int));
112 static void ppc_pe_section PARAMS ((int));
113 static void ppc_pe_function PARAMS ((int));
114 static void ppc_pe_tocd PARAMS ((int));
117 /* Generic assembler global variables which must be defined by all
121 /* This string holds the chars that always start a comment. If the
122 pre-processor is disabled, these aren't very useful. The macro
123 tc_comment_chars points to this. We use this, rather than the
124 usual comment_chars, so that we can switch for Solaris conventions. */
125 static const char ppc_solaris_comment_chars[] = "#!";
126 static const char ppc_eabi_comment_chars[] = "#";
128 #ifdef TARGET_SOLARIS_COMMENT
129 const char *ppc_comment_chars = ppc_solaris_comment_chars;
131 const char *ppc_comment_chars = ppc_eabi_comment_chars;
134 const char comment_chars[] = "#";
137 /* Characters which start a comment at the beginning of a line. */
138 const char line_comment_chars[] = "#";
140 /* Characters which may be used to separate multiple commands on a
142 const char line_separator_chars[] = ";";
144 /* Characters which are used to indicate an exponent in a floating
146 const char EXP_CHARS[] = "eE";
148 /* Characters which mean that a number is a floating point constant,
150 const char FLT_CHARS[] = "dD";
152 /* The target specific pseudo-ops which we support. */
154 const pseudo_typeS md_pseudo_table[] =
156 /* Pseudo-ops which must be overridden. */
157 { "byte", ppc_byte, 0 },
160 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
161 legitimately belong in the obj-*.c file. However, XCOFF is based
162 on COFF, and is only implemented for the RS/6000. We just use
163 obj-coff.c, and add what we need here. */
164 { "comm", ppc_comm, 0 },
165 { "lcomm", ppc_comm, 1 },
169 { "bi", ppc_biei, 0 },
171 { "csect", ppc_csect, 0 },
172 { "data", ppc_section, 'd' },
176 { "ei", ppc_biei, 1 },
178 { "extern", ppc_extern, 0 },
179 { "function", ppc_function, 0 },
180 { "lglobl", ppc_lglobl, 0 },
181 { "rename", ppc_rename, 0 },
182 { "section", ppc_named_section, 0 },
183 { "stabx", ppc_stabx, 0 },
184 { "text", ppc_section, 't' },
185 { "toc", ppc_toc, 0 },
186 { "long", ppc_xcoff_cons, 2 },
187 { "llong", ppc_xcoff_cons, 3 },
188 { "word", ppc_xcoff_cons, 1 },
189 { "short", ppc_xcoff_cons, 1 },
190 { "vbyte", ppc_vbyte, 0 },
191 { "machine", ppc_machine, 0 },
195 { "long", ppc_elf_cons, 4 },
196 { "word", ppc_elf_cons, 2 },
197 { "short", ppc_elf_cons, 2 },
198 { "rdata", ppc_elf_rdata, 0 },
199 { "rodata", ppc_elf_rdata, 0 },
200 { "lcomm", ppc_elf_lcomm, 0 },
201 { "file", dwarf2_directive_file, 0 },
202 { "loc", dwarf2_directive_loc, 0 },
206 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
207 { "previous", ppc_previous, 0 },
208 { "pdata", ppc_pdata, 0 },
209 { "ydata", ppc_ydata, 0 },
210 { "reldata", ppc_reldata, 0 },
211 { "rdata", ppc_rdata, 0 },
212 { "ualong", ppc_ualong, 0 },
213 { "znop", ppc_znop, 0 },
214 { "comm", ppc_pe_comm, 0 },
215 { "lcomm", ppc_pe_comm, 1 },
216 { "section", ppc_pe_section, 0 },
217 { "function", ppc_pe_function,0 },
218 { "tocd", ppc_pe_tocd, 0 },
221 /* This pseudo-op is used even when not generating XCOFF output. */
228 /* Predefined register names if -mregnames (or default for Windows NT).
229 In general, there are lots of them, in an attempt to be compatible
230 with a number of other Windows NT assemblers. */
232 /* Structure to hold information about predefined registers. */
239 /* List of registers that are pre-defined:
241 Each general register has predefined names of the form:
242 1. r<reg_num> which has the value <reg_num>.
243 2. r.<reg_num> which has the value <reg_num>.
245 Each floating point register has predefined names of the form:
246 1. f<reg_num> which has the value <reg_num>.
247 2. f.<reg_num> which has the value <reg_num>.
249 Each vector unit register has predefined names of the form:
250 1. v<reg_num> which has the value <reg_num>.
251 2. v.<reg_num> which has the value <reg_num>.
253 Each condition register has predefined names of the form:
254 1. cr<reg_num> which has the value <reg_num>.
255 2. cr.<reg_num> which has the value <reg_num>.
257 There are individual registers as well:
258 sp or r.sp has the value 1
259 rtoc or r.toc has the value 2
260 fpscr has the value 0
266 dsisr has the value 18
268 sdr1 has the value 25
269 srr0 has the value 26
270 srr1 has the value 27
272 The table is sorted. Suitable for searching by a binary search. */
274 static const struct pd_reg pre_defined_registers[] =
276 { "cr.0", 0 }, /* Condition Registers */
296 { "dar", 19 }, /* Data Access Register */
297 { "dec", 22 }, /* Decrementer */
298 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
300 { "f.0", 0 }, /* Floating point registers */
368 { "lr", 8 }, /* Link Register */
372 { "r.0", 0 }, /* General Purpose Registers */
405 { "r.sp", 1 }, /* Stack Pointer */
407 { "r.toc", 2 }, /* Pointer to the table of contents */
409 { "r0", 0 }, /* More general purpose registers */
442 { "rtoc", 2 }, /* Table of contents */
444 { "sdr1", 25 }, /* Storage Description Register 1 */
448 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
449 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
451 { "v.0", 0 }, /* Vector registers */
521 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
523 /* Given NAME, find the register number associated with that name, return
524 the integer value associated with the given name or -1 on failure. */
526 static int reg_name_search
527 PARAMS ((const struct pd_reg *, int, const char * name));
530 reg_name_search (regs, regcount, name)
531 const struct pd_reg *regs;
535 int middle, low, high;
543 middle = (low + high) / 2;
544 cmp = strcasecmp (name, regs[middle].name);
550 return regs[middle].value;
558 * Summary of register_name.
560 * in: Input_line_pointer points to 1st char of operand.
562 * out: A expressionS.
563 * The operand may have been a register: in this case, X_op == O_register,
564 * X_add_number is set to the register number, and truth is returned.
565 * Input_line_pointer->(next non-blank) char after operand, or is in its
570 register_name (expressionP)
571 expressionS *expressionP;
578 /* Find the spelling of the operand. */
579 start = name = input_line_pointer;
580 if (name[0] == '%' && isalpha (name[1]))
581 name = ++input_line_pointer;
583 else if (!reg_names_p || !isalpha (name[0]))
586 c = get_symbol_end ();
587 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
589 /* Look to see if it's in the register table. */
592 expressionP->X_op = O_register;
593 expressionP->X_add_number = reg_number;
595 /* Make the rest nice. */
596 expressionP->X_add_symbol = NULL;
597 expressionP->X_op_symbol = NULL;
598 /* Put back the delimiting char. */
599 *input_line_pointer = c;
604 /* Reset the line as if we had not done anything. */
605 *input_line_pointer = c;
606 input_line_pointer = start;
611 /* This function is called for each symbol seen in an expression. It
612 handles the special parsing which PowerPC assemblers are supposed
613 to use for condition codes. */
615 /* Whether to do the special parsing. */
616 static boolean cr_operand;
618 /* Names to recognize in a condition code. This table is sorted. */
619 static const struct pd_reg cr_names[] =
636 /* Parsing function. This returns non-zero if it recognized an
640 ppc_parse_name (name, expr)
649 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
654 expr->X_op = O_constant;
655 expr->X_add_number = val;
660 /* Local variables. */
662 /* The type of processor we are assembling for. This is one or more
663 of the PPC_OPCODE flags defined in opcode/ppc.h. */
664 static int ppc_cpu = 0;
666 /* The size of the processor we are assembling for. This is either
667 PPC_OPCODE_32 or PPC_OPCODE_64. */
668 static unsigned long ppc_size = PPC_OPCODE_32;
670 /* Whether to target xcoff64. */
671 static int ppc_xcoff64 = 0;
673 /* Opcode hash table. */
674 static struct hash_control *ppc_hash;
676 /* Macro hash table. */
677 static struct hash_control *ppc_macro_hash;
680 /* What type of shared library support to use. */
681 static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE;
683 /* Flags to set in the elf header. */
684 static flagword ppc_flags = 0;
686 /* Whether this is Solaris or not. */
687 #ifdef TARGET_SOLARIS_COMMENT
688 #define SOLARIS_P true
690 #define SOLARIS_P false
693 static boolean msolaris = SOLARIS_P;
698 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
699 using a bunch of different sections. These assembler sections,
700 however, are all encompassed within the .text or .data sections of
701 the final output file. We handle this by using different
702 subsegments within these main segments. */
704 /* Next subsegment to allocate within the .text segment. */
705 static subsegT ppc_text_subsegment = 2;
707 /* Linked list of csects in the text section. */
708 static symbolS *ppc_text_csects;
710 /* Next subsegment to allocate within the .data segment. */
711 static subsegT ppc_data_subsegment = 2;
713 /* Linked list of csects in the data section. */
714 static symbolS *ppc_data_csects;
716 /* The current csect. */
717 static symbolS *ppc_current_csect;
719 /* The RS/6000 assembler uses a TOC which holds addresses of functions
720 and variables. Symbols are put in the TOC with the .tc pseudo-op.
721 A special relocation is used when accessing TOC entries. We handle
722 the TOC as a subsegment within the .data segment. We set it up if
723 we see a .toc pseudo-op, and save the csect symbol here. */
724 static symbolS *ppc_toc_csect;
726 /* The first frag in the TOC subsegment. */
727 static fragS *ppc_toc_frag;
729 /* The first frag in the first subsegment after the TOC in the .data
730 segment. NULL if there are no subsegments after the TOC. */
731 static fragS *ppc_after_toc_frag;
733 /* The current static block. */
734 static symbolS *ppc_current_block;
736 /* The COFF debugging section; set by md_begin. This is not the
737 .debug section, but is instead the secret BFD section which will
738 cause BFD to set the section number of a symbol to N_DEBUG. */
739 static asection *ppc_coff_debug_section;
741 #endif /* OBJ_XCOFF */
745 /* Various sections that we need for PE coff support. */
746 static segT ydata_section;
747 static segT pdata_section;
748 static segT reldata_section;
749 static segT rdata_section;
750 static segT tocdata_section;
752 /* The current section and the previous section. See ppc_previous. */
753 static segT ppc_previous_section;
754 static segT ppc_current_section;
759 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
763 CONST char *md_shortopts = "b:l:usm:K:VQ:";
765 CONST char *md_shortopts = "um:";
767 struct option md_longopts[] = {
768 {NULL, no_argument, NULL, 0}
770 size_t md_longopts_size = sizeof (md_longopts);
773 md_parse_option (c, arg)
780 /* -u means that any undefined symbols should be treated as
781 external, which is the default for gas anyhow. */
786 /* Solaris as takes -le (presumably for little endian). For completeness
787 sake, recognize -be also. */
788 if (strcmp (arg, "e") == 0)
790 target_big_endian = 0;
791 set_target_endian = 1;
799 if (strcmp (arg, "e") == 0)
801 target_big_endian = 1;
802 set_target_endian = 1;
810 /* Recognize -K PIC. */
811 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
814 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
822 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
824 if (strcmp (arg, "64") == 0)
826 else if (strcmp (arg, "32") == 0)
833 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
835 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
836 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
837 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
838 else if (strcmp (arg, "pwr") == 0)
839 ppc_cpu = PPC_OPCODE_POWER;
840 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
841 instructions that are holdovers from the Power. */
842 else if (strcmp (arg, "601") == 0)
843 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
844 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
845 Motorola PowerPC 603/604. */
846 else if (strcmp (arg, "ppc") == 0
847 || strcmp (arg, "ppc32") == 0
848 || strcmp (arg, "403") == 0
849 || strcmp (arg, "405") == 0
850 || strcmp (arg, "603") == 0
851 || strcmp (arg, "604") == 0)
852 ppc_cpu = PPC_OPCODE_PPC;
853 else if (strcmp (arg, "7400") == 0)
854 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_ALTIVEC;
855 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
857 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
859 ppc_cpu = PPC_OPCODE_PPC;
860 ppc_size = PPC_OPCODE_64;
862 else if (strcmp (arg, "ppc64bridge") == 0)
864 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64_BRIDGE;
865 ppc_size = PPC_OPCODE_64;
867 /* -mcom means assemble for the common intersection between Power
868 and PowerPC. At present, we just allow the union, rather
869 than the intersection. */
870 else if (strcmp (arg, "com") == 0)
871 ppc_cpu = PPC_OPCODE_COMMON;
872 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
873 else if (strcmp (arg, "any") == 0)
874 ppc_cpu = PPC_OPCODE_ANY;
876 else if (strcmp (arg, "regnames") == 0)
879 else if (strcmp (arg, "no-regnames") == 0)
883 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
884 that require relocation. */
885 else if (strcmp (arg, "relocatable") == 0)
887 shlib = SHLIB_MRELOCATABLE;
888 ppc_flags |= EF_PPC_RELOCATABLE;
891 else if (strcmp (arg, "relocatable-lib") == 0)
893 shlib = SHLIB_MRELOCATABLE;
894 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
897 /* -memb, set embedded bit. */
898 else if (strcmp (arg, "emb") == 0)
899 ppc_flags |= EF_PPC_EMB;
901 /* -mlittle/-mbig set the endianess. */
902 else if (strcmp (arg, "little") == 0
903 || strcmp (arg, "little-endian") == 0)
905 target_big_endian = 0;
906 set_target_endian = 1;
909 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
911 target_big_endian = 1;
912 set_target_endian = 1;
915 else if (strcmp (arg, "solaris") == 0)
918 ppc_comment_chars = ppc_solaris_comment_chars;
921 else if (strcmp (arg, "no-solaris") == 0)
924 ppc_comment_chars = ppc_eabi_comment_chars;
929 as_bad (_("invalid switch -m%s"), arg);
935 /* -V: SVR4 argument to print version ID. */
940 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
941 should be emitted or not. FIXME: Not implemented. */
945 /* Solaris takes -s to specify that .stabs go in a .stabs section,
946 rather than .stabs.excl, which is ignored by the linker.
947 FIXME: Not implemented. */
963 md_show_usage (stream)
966 fprintf (stream, _("\
969 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
970 -mpwr generate code for IBM POWER (RIOS1)\n\
971 -m601 generate code for Motorola PowerPC 601\n\
972 -mppc, -mppc32, -m403, -m405, -m603, -m604\n\
973 generate code for Motorola PowerPC 603/604\n\
974 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
975 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
976 -mcom generate code Power/PowerPC common instructions\n\
977 -many generate code for any architecture (PWR/PWRX/PPC)\n\
978 -mregnames Allow symbolic names for registers\n\
979 -mno-regnames Do not allow symbolic names for registers\n"));
981 fprintf (stream, _("\
982 -mrelocatable support for GCC's -mrelocatble option\n\
983 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
984 -memb set PPC_EMB bit in ELF flags\n\
985 -mlittle, -mlittle-endian\n\
986 generate code for a little endian machine\n\
987 -mbig, -mbig-endian generate code for a big endian machine\n\
988 -msolaris generate code for Solaris\n\
989 -mno-solaris do not generate code for Solaris\n\
990 -V print assembler version number\n\
991 -Qy, -Qn ignored\n"));
995 /* Set ppc_cpu if it is not already set. */
1000 const char *default_os = TARGET_OS;
1001 const char *default_cpu = TARGET_CPU;
1005 if (strncmp (default_os, "aix", 3) == 0
1006 && default_os[3] >= '4' && default_os[3] <= '9')
1007 ppc_cpu = PPC_OPCODE_COMMON;
1008 else if (strncmp (default_os, "aix3", 4) == 0)
1009 ppc_cpu = PPC_OPCODE_POWER;
1010 else if (strcmp (default_cpu, "rs6000") == 0)
1011 ppc_cpu = PPC_OPCODE_POWER;
1012 else if (strcmp (default_cpu, "powerpc") == 0
1013 || strcmp (default_cpu, "powerpcle") == 0)
1014 ppc_cpu = PPC_OPCODE_PPC;
1016 as_fatal (_("Unknown default cpu = %s, os = %s"),
1017 default_cpu, default_os);
1021 /* Figure out the BFD architecture to use. */
1023 enum bfd_architecture
1026 const char *default_cpu = TARGET_CPU;
1029 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
1030 return bfd_arch_powerpc;
1031 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
1032 return bfd_arch_rs6000;
1033 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
1035 if (strcmp (default_cpu, "rs6000") == 0)
1036 return bfd_arch_rs6000;
1037 else if (strcmp (default_cpu, "powerpc") == 0
1038 || strcmp (default_cpu, "powerpcle") == 0)
1039 return bfd_arch_powerpc;
1042 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1043 return bfd_arch_unknown;
1049 return ppc_size == PPC_OPCODE_64 ? 620 : 0;
1055 return ppc_xcoff64 ? 3 : 2;
1059 ppc_target_format ()
1063 return target_big_endian ? "pe-powerpc" : "pe-powerpcle";
1066 return ppc_xcoff64 ? "aixcoff64-rs6000" : "aixcoff-rs6000";
1069 return "xcoff-powermac";
1073 return target_big_endian ? "elf32-powerpc" : "elf32-powerpcle";
1077 /* This function is called when the assembler starts up. It is called
1078 after the options have been parsed and the output file has been
1084 register const struct powerpc_opcode *op;
1085 const struct powerpc_opcode *op_end;
1086 const struct powerpc_macro *macro;
1087 const struct powerpc_macro *macro_end;
1088 boolean dup_insn = false;
1093 /* Set the ELF flags if desired. */
1094 if (ppc_flags && !msolaris)
1095 bfd_set_private_flags (stdoutput, ppc_flags);
1098 /* Insert the opcodes into a hash table. */
1099 ppc_hash = hash_new ();
1101 op_end = powerpc_opcodes + powerpc_num_opcodes;
1102 for (op = powerpc_opcodes; op < op_end; op++)
1104 know ((op->opcode & op->mask) == op->opcode);
1106 if ((op->flags & ppc_cpu) != 0
1107 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
1108 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size
1109 || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0))
1113 retval = hash_insert (ppc_hash, op->name, (PTR) op);
1114 if (retval != (const char *) NULL)
1116 /* Ignore Power duplicates for -m601. */
1117 if ((ppc_cpu & PPC_OPCODE_601) != 0
1118 && (op->flags & PPC_OPCODE_POWER) != 0)
1121 as_bad (_("Internal assembler error for instruction %s"),
1128 /* Insert the macros into a hash table. */
1129 ppc_macro_hash = hash_new ();
1131 macro_end = powerpc_macros + powerpc_num_macros;
1132 for (macro = powerpc_macros; macro < macro_end; macro++)
1134 if ((macro->flags & ppc_cpu) != 0)
1138 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1139 if (retval != (const char *) NULL)
1141 as_bad (_("Internal assembler error for macro %s"), macro->name);
1150 /* Tell the main code what the endianness is if it is not overidden
1152 if (!set_target_endian)
1154 set_target_endian = 1;
1155 target_big_endian = PPC_BIG_ENDIAN;
1159 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1161 /* Create dummy symbols to serve as initial csects. This forces the
1162 text csects to precede the data csects. These symbols will not
1164 ppc_text_csects = symbol_make ("dummy\001");
1165 symbol_get_tc (ppc_text_csects)->within = ppc_text_csects;
1166 ppc_data_csects = symbol_make ("dummy\001");
1167 symbol_get_tc (ppc_data_csects)->within = ppc_data_csects;
1172 ppc_current_section = text_section;
1173 ppc_previous_section = 0;
1178 /* Insert an operand value into an instruction. */
1180 static unsigned long
1181 ppc_insert_operand (insn, operand, val, file, line)
1183 const struct powerpc_operand *operand;
1188 if (operand->bits != 32)
1193 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1195 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0)
1196 max = (1 << operand->bits) - 1;
1198 max = (1 << (operand->bits - 1)) - 1;
1199 min = - (1 << (operand->bits - 1));
1201 if (ppc_size == PPC_OPCODE_32)
1203 /* Some people write 32 bit hex constants with the sign
1204 extension done by hand. This shouldn't really be
1205 valid, but, to permit this code to assemble on a 64
1206 bit host, we sign extend the 32 bit value. */
1208 && (val & (offsetT) 0x80000000) != 0
1209 && (val & (offsetT) 0xffffffff) == val)
1218 max = (1 << operand->bits) - 1;
1222 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1227 if (test < (offsetT) min || test > (offsetT) max)
1230 _("operand out of range (%s not between %ld and %ld)");
1233 sprint_value (buf, test);
1234 if (file == (char *) NULL)
1235 as_bad (err, buf, min, max);
1237 as_bad_where (file, line, err, buf, min, max);
1241 if (operand->insert)
1246 insn = (*operand->insert) (insn, (long) val, &errmsg);
1247 if (errmsg != (const char *) NULL)
1251 insn |= (((long) val & ((1 << operand->bits) - 1))
1259 /* Parse @got, etc. and return the desired relocation. */
1260 static bfd_reloc_code_real_type
1261 ppc_elf_suffix (str_p, exp_p)
1268 bfd_reloc_code_real_type reloc;
1276 struct map_bfd *ptr;
1278 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1280 static struct map_bfd mapping[] = {
1281 MAP ("l", BFD_RELOC_LO16),
1282 MAP ("h", BFD_RELOC_HI16),
1283 MAP ("ha", BFD_RELOC_HI16_S),
1284 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1285 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1286 MAP ("got", BFD_RELOC_16_GOTOFF),
1287 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1288 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1289 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1290 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
1291 MAP ("plt", BFD_RELOC_24_PLT_PCREL),
1292 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1293 MAP ("copy", BFD_RELOC_PPC_COPY),
1294 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1295 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1296 MAP ("local", BFD_RELOC_PPC_LOCAL24PC),
1297 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
1298 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1299 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1300 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1301 MAP ("sdarel", BFD_RELOC_GPREL16),
1302 MAP ("sectoff", BFD_RELOC_32_BASEREL),
1303 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1304 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1305 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1306 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1307 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1308 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1309 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1310 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1311 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1312 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1313 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1314 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1315 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1316 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1317 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1318 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1319 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1320 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1321 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1322 MAP ("xgot", BFD_RELOC_PPC_TOC16),
1324 { (char *) 0, 0, BFD_RELOC_UNUSED }
1328 return BFD_RELOC_UNUSED;
1330 for (ch = *str, str2 = ident;
1331 (str2 < ident + sizeof (ident) - 1
1332 && (isalnum (ch) || ch == '@'));
1335 *str2++ = (islower (ch)) ? ch : tolower (ch);
1342 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1343 if (ch == ptr->string[0]
1344 && len == ptr->length
1345 && memcmp (ident, ptr->string, ptr->length) == 0)
1347 if (exp_p->X_add_number != 0
1348 && (ptr->reloc == BFD_RELOC_16_GOTOFF
1349 || ptr->reloc == BFD_RELOC_LO16_GOTOFF
1350 || ptr->reloc == BFD_RELOC_HI16_GOTOFF
1351 || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
1352 as_warn (_("identifier+constant@got means identifier@got+constant"));
1354 /* Now check for identifier@suffix+constant. */
1355 if (*str == '-' || *str == '+')
1357 char *orig_line = input_line_pointer;
1358 expressionS new_exp;
1360 input_line_pointer = str;
1361 expression (&new_exp);
1362 if (new_exp.X_op == O_constant)
1364 exp_p->X_add_number += new_exp.X_add_number;
1365 str = input_line_pointer;
1368 if (&input_line_pointer != str_p)
1369 input_line_pointer = orig_line;
1376 return BFD_RELOC_UNUSED;
1379 /* Like normal .long/.short/.word, except support @got, etc.
1380 Clobbers input_line_pointer, checks end-of-line. */
1382 ppc_elf_cons (nbytes)
1383 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1386 bfd_reloc_code_real_type reloc;
1388 if (is_it_end_of_statement ())
1390 demand_empty_rest_of_line ();
1397 if (exp.X_op == O_symbol
1398 && *input_line_pointer == '@'
1399 && (reloc = ppc_elf_suffix (&input_line_pointer,
1400 &exp)) != BFD_RELOC_UNUSED)
1402 reloc_howto_type *reloc_howto;
1405 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1406 size = bfd_get_reloc_size (reloc_howto);
1409 as_bad (_("%s relocations do not fit in %d bytes\n"),
1410 reloc_howto->name, nbytes);
1414 register char *p = frag_more ((int) nbytes);
1415 int offset = nbytes - size;
1417 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
1422 emit_expr (&exp, (unsigned int) nbytes);
1424 while (*input_line_pointer++ == ',');
1426 /* Put terminator back into stream. */
1427 input_line_pointer--;
1428 demand_empty_rest_of_line ();
1431 /* Solaris pseduo op to change to the .rodata section. */
1436 char *save_line = input_line_pointer;
1437 static char section[] = ".rodata\n";
1439 /* Just pretend this is .section .rodata */
1440 input_line_pointer = section;
1441 obj_elf_section (xxx);
1443 input_line_pointer = save_line;
1446 /* Pseudo op to make file scope bss items. */
1449 int xxx ATTRIBUTE_UNUSED;
1451 register char *name;
1455 register symbolS *symbolP;
1462 name = input_line_pointer;
1463 c = get_symbol_end ();
1465 /* just after name is now '\0'. */
1466 p = input_line_pointer;
1469 if (*input_line_pointer != ',')
1471 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1472 ignore_rest_of_line ();
1476 input_line_pointer++; /* skip ',' */
1477 if ((size = get_absolute_expression ()) < 0)
1479 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
1480 ignore_rest_of_line ();
1484 /* The third argument to .lcomm is the alignment. */
1485 if (*input_line_pointer != ',')
1489 ++input_line_pointer;
1490 align = get_absolute_expression ();
1493 as_warn (_("ignoring bad alignment"));
1499 symbolP = symbol_find_or_make (name);
1502 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1504 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1505 S_GET_NAME (symbolP));
1506 ignore_rest_of_line ();
1510 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1512 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1513 S_GET_NAME (symbolP),
1514 (long) S_GET_VALUE (symbolP),
1517 ignore_rest_of_line ();
1523 old_subsec = now_subseg;
1526 /* Convert to a power of 2 alignment. */
1527 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1530 as_bad (_("Common alignment not a power of 2"));
1531 ignore_rest_of_line ();
1538 record_alignment (bss_section, align2);
1539 subseg_set (bss_section, 0);
1541 frag_align (align2, 0, 0);
1542 if (S_GET_SEGMENT (symbolP) == bss_section)
1543 symbol_get_frag (symbolP)->fr_symbol = 0;
1544 symbol_set_frag (symbolP, frag_now);
1545 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1548 S_SET_SIZE (symbolP, size);
1549 S_SET_SEGMENT (symbolP, bss_section);
1550 subseg_set (old_sec, old_subsec);
1551 demand_empty_rest_of_line ();
1554 /* Validate any relocations emitted for -mrelocatable, possibly adding
1555 fixups for word relocations in writable segments, so we can adjust
1558 ppc_elf_validate_fix (fixp, seg)
1562 if (fixp->fx_done || fixp->fx_pcrel)
1571 case SHLIB_MRELOCATABLE:
1572 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1573 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1574 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1575 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1576 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1577 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1578 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1579 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1580 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1581 && strcmp (segment_name (seg), ".got2") != 0
1582 && strcmp (segment_name (seg), ".dtors") != 0
1583 && strcmp (segment_name (seg), ".ctors") != 0
1584 && strcmp (segment_name (seg), ".fixup") != 0
1585 && strcmp (segment_name (seg), ".stab") != 0
1586 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1587 && strcmp (segment_name (seg), ".eh_frame") != 0
1588 && strcmp (segment_name (seg), ".ex_shared") != 0)
1590 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1591 || fixp->fx_r_type != BFD_RELOC_CTOR)
1593 as_bad_where (fixp->fx_file, fixp->fx_line,
1594 _("Relocation cannot be done when using -mrelocatable"));
1600 #endif /* OBJ_ELF */
1605 * Summary of parse_toc_entry.
1607 * in: Input_line_pointer points to the '[' in one of:
1609 * [toc] [tocv] [toc32] [toc64]
1611 * Anything else is an error of one kind or another.
1614 * return value: success or failure
1615 * toc_kind: kind of toc reference
1616 * input_line_pointer:
1617 * success: first char after the ']'
1618 * failure: unchanged
1622 * [toc] - rv == success, toc_kind = default_toc
1623 * [tocv] - rv == success, toc_kind = data_in_toc
1624 * [toc32] - rv == success, toc_kind = must_be_32
1625 * [toc64] - rv == success, toc_kind = must_be_64
1629 enum toc_size_qualifier
1631 default_toc, /* The toc cell constructed should be the system default size */
1632 data_in_toc, /* This is a direct reference to a toc cell */
1633 must_be_32, /* The toc cell constructed must be 32 bits wide */
1634 must_be_64 /* The toc cell constructed must be 64 bits wide */
1638 parse_toc_entry (toc_kind)
1639 enum toc_size_qualifier *toc_kind;
1644 enum toc_size_qualifier t;
1646 /* Save the input_line_pointer. */
1647 start = input_line_pointer;
1649 /* Skip over the '[' , and whitespace. */
1650 ++input_line_pointer;
1653 /* Find the spelling of the operand. */
1654 toc_spec = input_line_pointer;
1655 c = get_symbol_end ();
1657 if (strcmp (toc_spec, "toc") == 0)
1661 else if (strcmp (toc_spec, "tocv") == 0)
1665 else if (strcmp (toc_spec, "toc32") == 0)
1669 else if (strcmp (toc_spec, "toc64") == 0)
1675 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
1676 *input_line_pointer = c;
1677 input_line_pointer = start;
1681 /* Now find the ']'. */
1682 *input_line_pointer = c;
1684 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1685 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1689 as_bad (_("syntax error: expected `]', found `%c'"), c);
1690 input_line_pointer = start;
1700 /* We need to keep a list of fixups. We can't simply generate them as
1701 we go, because that would require us to first create the frag, and
1702 that would screw up references to ``.''. */
1708 bfd_reloc_code_real_type reloc;
1711 #define MAX_INSN_FIXUPS (5)
1713 /* This routine is called for each instruction to be assembled. */
1720 const struct powerpc_opcode *opcode;
1722 const unsigned char *opindex_ptr;
1726 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1731 bfd_reloc_code_real_type reloc;
1734 /* Get the opcode. */
1735 for (s = str; *s != '\0' && ! isspace (*s); s++)
1740 /* Look up the opcode in the hash table. */
1741 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1742 if (opcode == (const struct powerpc_opcode *) NULL)
1744 const struct powerpc_macro *macro;
1746 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1747 if (macro == (const struct powerpc_macro *) NULL)
1748 as_bad (_("Unrecognized opcode: `%s'"), str);
1750 ppc_macro (s, macro);
1755 insn = opcode->opcode;
1758 while (isspace (*str))
1761 /* PowerPC operands are just expressions. The only real issue is
1762 that a few operand types are optional. All cases which might use
1763 an optional operand separate the operands only with commas (in
1764 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1765 cases never have optional operands). There is never more than
1766 one optional operand for an instruction. So, before we start
1767 seriously parsing the operands, we check to see if we have an
1768 optional operand, and, if we do, we count the number of commas to
1769 see whether the operand should be omitted. */
1771 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1773 const struct powerpc_operand *operand;
1775 operand = &powerpc_operands[*opindex_ptr];
1776 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1778 unsigned int opcount;
1780 /* There is an optional operand. Count the number of
1781 commas in the input line. */
1788 while ((s = strchr (s, ',')) != (char *) NULL)
1795 /* If there are fewer operands in the line then are called
1796 for by the instruction, we want to skip the optional
1798 if (opcount < strlen (opcode->operands))
1805 /* Gather the operands. */
1809 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1811 const struct powerpc_operand *operand;
1817 if (next_opindex == 0)
1818 operand = &powerpc_operands[*opindex_ptr];
1821 operand = &powerpc_operands[next_opindex];
1827 /* If this is a fake operand, then we do not expect anything
1829 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1831 insn = (*operand->insert) (insn, 0L, &errmsg);
1832 if (errmsg != (const char *) NULL)
1837 /* If this is an optional operand, and we are skipping it, just
1839 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1842 if (operand->insert)
1844 insn = (*operand->insert) (insn, 0L, &errmsg);
1845 if (errmsg != (const char *) NULL)
1848 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1849 next_opindex = *opindex_ptr + 1;
1853 /* Gather the operand. */
1854 hold = input_line_pointer;
1855 input_line_pointer = str;
1858 if (*input_line_pointer == '[')
1860 /* We are expecting something like the second argument here:
1862 * lwz r4,[toc].GS.0.static_int(rtoc)
1863 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1864 * The argument following the `]' must be a symbol name, and the
1865 * register must be the toc register: 'rtoc' or '2'
1867 * The effect is to 0 as the displacement field
1868 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1869 * the appropriate variation) reloc against it based on the symbol.
1870 * The linker will build the toc, and insert the resolved toc offset.
1873 * o The size of the toc entry is currently assumed to be
1874 * 32 bits. This should not be assumed to be a hard coded
1876 * o In an effort to cope with a change from 32 to 64 bits,
1877 * there are also toc entries that are specified to be
1878 * either 32 or 64 bits:
1879 * lwz r4,[toc32].GS.0.static_int(rtoc)
1880 * lwz r4,[toc64].GS.0.static_int(rtoc)
1881 * These demand toc entries of the specified size, and the
1882 * instruction probably requires it.
1886 enum toc_size_qualifier toc_kind;
1887 bfd_reloc_code_real_type toc_reloc;
1889 /* Go parse off the [tocXX] part. */
1890 valid_toc = parse_toc_entry (&toc_kind);
1894 /* Note: message has already been issued.
1895 FIXME: what sort of recovery should we do?
1896 demand_rest_of_line (); return; ? */
1899 /* Now get the symbol following the ']'. */
1905 /* In this case, we may not have seen the symbol yet,
1906 since it is allowed to appear on a .extern or .globl
1907 or just be a label in the .data section. */
1908 toc_reloc = BFD_RELOC_PPC_TOC16;
1911 /* 1. The symbol must be defined and either in the toc
1912 section, or a global.
1913 2. The reloc generated must have the TOCDEFN flag set
1914 in upper bit mess of the reloc type.
1915 FIXME: It's a little confusing what the tocv
1916 qualifier can be used for. At the very least, I've
1917 seen three uses, only one of which I'm sure I can
1919 if (ex.X_op == O_symbol)
1921 assert (ex.X_add_symbol != NULL);
1922 if (symbol_get_bfdsym (ex.X_add_symbol)->section
1925 as_bad (_("[tocv] symbol is not a toc symbol"));
1929 toc_reloc = BFD_RELOC_PPC_TOC16;
1932 /* FIXME: these next two specifically specify 32/64 bit
1933 toc entries. We don't support them today. Is this
1934 the right way to say that? */
1935 toc_reloc = BFD_RELOC_UNUSED;
1936 as_bad (_("Unimplemented toc32 expression modifier"));
1939 /* FIXME: see above. */
1940 toc_reloc = BFD_RELOC_UNUSED;
1941 as_bad (_("Unimplemented toc64 expression modifier"));
1945 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1951 /* We need to generate a fixup for this expression. */
1952 if (fc >= MAX_INSN_FIXUPS)
1953 as_fatal (_("too many fixups"));
1955 fixups[fc].reloc = toc_reloc;
1956 fixups[fc].exp = ex;
1957 fixups[fc].opindex = *opindex_ptr;
1960 /* Ok. We've set up the fixup for the instruction. Now make it
1961 look like the constant 0 was found here. */
1963 ex.X_op = O_constant;
1964 ex.X_add_number = 0;
1965 ex.X_add_symbol = NULL;
1966 ex.X_op_symbol = NULL;
1972 if (! register_name (&ex))
1974 if ((operand->flags & PPC_OPERAND_CR) != 0)
1981 str = input_line_pointer;
1982 input_line_pointer = hold;
1984 if (ex.X_op == O_illegal)
1985 as_bad (_("illegal operand"));
1986 else if (ex.X_op == O_absent)
1987 as_bad (_("missing operand"));
1988 else if (ex.X_op == O_register)
1990 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1993 else if (ex.X_op == O_constant)
1996 /* Allow @HA, @L, @H on constants. */
1997 char *orig_str = str;
1999 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2006 case BFD_RELOC_LO16:
2007 /* X_unsigned is the default, so if the user has done
2008 something which cleared it, we always produce a
2011 && (operand->flags & PPC_OPERAND_SIGNED) == 0)
2012 ex.X_add_number &= 0xffff;
2014 ex.X_add_number = (((ex.X_add_number & 0xffff)
2019 case BFD_RELOC_HI16:
2020 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
2023 case BFD_RELOC_HI16_S:
2024 ex.X_add_number = ((((ex.X_add_number >> 16) & 0xffff)
2025 + ((ex.X_add_number >> 15) & 1))
2030 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2034 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2036 /* For the absolute forms of branches, convert the PC
2037 relative form back into the absolute. */
2038 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
2042 case BFD_RELOC_PPC_B26:
2043 reloc = BFD_RELOC_PPC_BA26;
2045 case BFD_RELOC_PPC_B16:
2046 reloc = BFD_RELOC_PPC_BA16;
2048 case BFD_RELOC_PPC_B16_BRTAKEN:
2049 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
2051 case BFD_RELOC_PPC_B16_BRNTAKEN:
2052 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
2059 /* We need to generate a fixup for this expression. */
2060 if (fc >= MAX_INSN_FIXUPS)
2061 as_fatal (_("too many fixups"));
2062 fixups[fc].exp = ex;
2063 fixups[fc].opindex = 0;
2064 fixups[fc].reloc = reloc;
2067 #endif /* OBJ_ELF */
2071 /* We need to generate a fixup for this expression. */
2072 if (fc >= MAX_INSN_FIXUPS)
2073 as_fatal (_("too many fixups"));
2074 fixups[fc].exp = ex;
2075 fixups[fc].opindex = *opindex_ptr;
2076 fixups[fc].reloc = BFD_RELOC_UNUSED;
2085 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
2093 /* The call to expression should have advanced str past any
2096 && (endc != ',' || *str != '\0'))
2098 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
2106 while (isspace (*str))
2110 as_bad (_("junk at end of line: `%s'"), str);
2112 /* Write out the instruction. */
2114 md_number_to_chars (f, insn, 4);
2117 dwarf2_emit_insn (4);
2120 /* Create any fixups. At this point we do not use a
2121 bfd_reloc_code_real_type, but instead just use the
2122 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2123 handle fixups for any operand type, although that is admittedly
2124 not a very exciting feature. We pick a BFD reloc type in
2126 for (i = 0; i < fc; i++)
2128 const struct powerpc_operand *operand;
2130 operand = &powerpc_operands[fixups[i].opindex];
2131 if (fixups[i].reloc != BFD_RELOC_UNUSED)
2133 reloc_howto_type *reloc_howto;
2138 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2142 size = bfd_get_reloc_size (reloc_howto);
2143 offset = target_big_endian ? (4 - size) : 0;
2145 if (size < 1 || size > 4)
2148 fixP = fix_new_exp (frag_now,
2149 f - frag_now->fr_literal + offset,
2152 reloc_howto->pc_relative,
2155 /* Turn off complaints that the addend is too large for things like
2157 switch (fixups[i].reloc)
2159 case BFD_RELOC_16_GOTOFF:
2160 case BFD_RELOC_PPC_TOC16:
2161 case BFD_RELOC_LO16:
2162 case BFD_RELOC_HI16:
2163 case BFD_RELOC_HI16_S:
2164 fixP->fx_no_overflow = 1;
2171 fix_new_exp (frag_now,
2172 f - frag_now->fr_literal,
2175 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2176 ((bfd_reloc_code_real_type)
2177 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2181 /* Handle a macro. Gather all the operands, transform them as
2182 described by the macro, and call md_assemble recursively. All the
2183 operands are separated by commas; we don't accept parentheses
2184 around operands here. */
2187 ppc_macro (str, macro)
2189 const struct powerpc_macro *macro;
2200 /* Gather the users operands into the operands array. */
2205 if (count >= sizeof operands / sizeof operands[0])
2207 operands[count++] = s;
2208 s = strchr (s, ',');
2209 if (s == (char *) NULL)
2214 if (count != macro->operands)
2216 as_bad (_("wrong number of operands"));
2220 /* Work out how large the string must be (the size is unbounded
2221 because it includes user input). */
2223 format = macro->format;
2224 while (*format != '\0')
2233 arg = strtol (format + 1, &send, 10);
2234 know (send != format && arg >= 0 && arg < count);
2235 len += strlen (operands[arg]);
2240 /* Put the string together. */
2241 complete = s = (char *) alloca (len + 1);
2242 format = macro->format;
2243 while (*format != '\0')
2249 arg = strtol (format + 1, &send, 10);
2250 strcpy (s, operands[arg]);
2257 /* Assemble the constructed instruction. */
2258 md_assemble (complete);
2262 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2265 ppc_section_letter (letter, ptr_msg)
2272 *ptr_msg = _("Bad .section directive: want a,w,x,e in string");
2277 ppc_section_word (str, len)
2281 if (len == 7 && strncmp (str, "exclude", 7) == 0)
2288 ppc_section_type (str, len)
2292 if (len == 7 && strncmp (str, "ordered", 7) == 0)
2299 ppc_section_flags (flags, attr, type)
2304 if (type == SHT_ORDERED)
2305 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2307 if (attr & SHF_EXCLUDE)
2308 flags |= SEC_EXCLUDE;
2312 #endif /* OBJ_ELF */
2315 /* Pseudo-op handling. */
2317 /* The .byte pseudo-op. This is similar to the normal .byte
2318 pseudo-op, but it can also take a single ASCII string. */
2322 int ignore ATTRIBUTE_UNUSED;
2324 if (*input_line_pointer != '\"')
2330 /* Gather characters. A real double quote is doubled. Unusual
2331 characters are not permitted. */
2332 ++input_line_pointer;
2337 c = *input_line_pointer++;
2341 if (*input_line_pointer != '\"')
2343 ++input_line_pointer;
2346 FRAG_APPEND_1_CHAR (c);
2349 demand_empty_rest_of_line ();
2354 /* XCOFF specific pseudo-op handling. */
2356 /* This is set if we are creating a .stabx symbol, since we don't want
2357 to handle symbol suffixes for such symbols. */
2358 static boolean ppc_stab_symbol;
2360 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2361 symbols in the .bss segment as though they were local common
2362 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2363 aligns .comm and .lcomm to 4 bytes. */
2369 asection *current_seg = now_seg;
2370 subsegT current_subseg = now_subseg;
2376 symbolS *lcomm_sym = NULL;
2380 name = input_line_pointer;
2381 endc = get_symbol_end ();
2382 end_name = input_line_pointer;
2385 if (*input_line_pointer != ',')
2387 as_bad (_("missing size"));
2388 ignore_rest_of_line ();
2391 ++input_line_pointer;
2393 size = get_absolute_expression ();
2396 as_bad (_("negative size"));
2397 ignore_rest_of_line ();
2403 /* The third argument to .comm is the alignment. */
2404 if (*input_line_pointer != ',')
2408 ++input_line_pointer;
2409 align = get_absolute_expression ();
2412 as_warn (_("ignoring bad alignment"));
2427 /* The third argument to .lcomm appears to be the real local
2428 common symbol to create. References to the symbol named in
2429 the first argument are turned into references to the third
2431 if (*input_line_pointer != ',')
2433 as_bad (_("missing real symbol name"));
2434 ignore_rest_of_line ();
2437 ++input_line_pointer;
2439 lcomm_name = input_line_pointer;
2440 lcomm_endc = get_symbol_end ();
2442 lcomm_sym = symbol_find_or_make (lcomm_name);
2444 *input_line_pointer = lcomm_endc;
2448 sym = symbol_find_or_make (name);
2451 if (S_IS_DEFINED (sym)
2452 || S_GET_VALUE (sym) != 0)
2454 as_bad (_("attempt to redefine symbol"));
2455 ignore_rest_of_line ();
2459 record_alignment (bss_section, align);
2462 || ! S_IS_DEFINED (lcomm_sym))
2471 S_SET_EXTERNAL (sym);
2475 symbol_get_tc (lcomm_sym)->output = 1;
2476 def_sym = lcomm_sym;
2480 subseg_set (bss_section, 1);
2481 frag_align (align, 0, 0);
2483 symbol_set_frag (def_sym, frag_now);
2484 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2485 def_size, (char *) NULL);
2487 S_SET_SEGMENT (def_sym, bss_section);
2488 symbol_get_tc (def_sym)->align = align;
2492 /* Align the size of lcomm_sym. */
2493 symbol_get_frag (lcomm_sym)->fr_offset =
2494 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
2495 &~ ((1 << align) - 1));
2496 if (align > symbol_get_tc (lcomm_sym)->align)
2497 symbol_get_tc (lcomm_sym)->align = align;
2502 /* Make sym an offset from lcomm_sym. */
2503 S_SET_SEGMENT (sym, bss_section);
2504 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
2505 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
2506 symbol_get_frag (lcomm_sym)->fr_offset += size;
2509 subseg_set (current_seg, current_subseg);
2511 demand_empty_rest_of_line ();
2514 /* The .csect pseudo-op. This switches us into a different
2515 subsegment. The first argument is a symbol whose value is the
2516 start of the .csect. In COFF, csect symbols get special aux
2517 entries defined by the x_csect field of union internal_auxent. The
2518 optional second argument is the alignment (the default is 2). */
2522 int ignore ATTRIBUTE_UNUSED;
2528 name = input_line_pointer;
2529 endc = get_symbol_end ();
2531 sym = symbol_find_or_make (name);
2533 *input_line_pointer = endc;
2535 if (S_GET_NAME (sym)[0] == '\0')
2537 /* An unnamed csect is assumed to be [PR]. */
2538 symbol_get_tc (sym)->class = XMC_PR;
2541 ppc_change_csect (sym);
2543 if (*input_line_pointer == ',')
2545 ++input_line_pointer;
2546 symbol_get_tc (sym)->align = get_absolute_expression ();
2549 demand_empty_rest_of_line ();
2552 /* Change to a different csect. */
2555 ppc_change_csect (sym)
2558 if (S_IS_DEFINED (sym))
2559 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
2567 /* This is a new csect. We need to look at the symbol class to
2568 figure out whether it should go in the text section or the
2571 switch (symbol_get_tc (sym)->class)
2581 S_SET_SEGMENT (sym, text_section);
2582 symbol_get_tc (sym)->subseg = ppc_text_subsegment;
2583 ++ppc_text_subsegment;
2584 list_ptr = &ppc_text_csects;
2593 if (ppc_toc_csect != NULL
2594 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
2595 == ppc_data_subsegment))
2597 S_SET_SEGMENT (sym, data_section);
2598 symbol_get_tc (sym)->subseg = ppc_data_subsegment;
2599 ++ppc_data_subsegment;
2600 list_ptr = &ppc_data_csects;
2606 /* We set the obstack chunk size to a small value before
2607 changing subsegments, so that we don't use a lot of memory
2608 space for what may be a small section. */
2609 hold_chunksize = chunksize;
2612 subseg_new (segment_name (S_GET_SEGMENT (sym)),
2613 symbol_get_tc (sym)->subseg);
2615 chunksize = hold_chunksize;
2618 ppc_after_toc_frag = frag_now;
2620 symbol_set_frag (sym, frag_now);
2621 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2623 symbol_get_tc (sym)->align = (ppc_xcoff64) ? 3 : 2;
2624 symbol_get_tc (sym)->output = 1;
2625 symbol_get_tc (sym)->within = sym;
2627 for (list = *list_ptr;
2628 symbol_get_tc (list)->next != (symbolS *) NULL;
2629 list = symbol_get_tc (list)->next)
2631 symbol_get_tc (list)->next = sym;
2633 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2634 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
2638 ppc_current_csect = sym;
2641 /* This function handles the .text and .data pseudo-ops. These
2642 pseudo-ops aren't really used by XCOFF; we implement them for the
2643 convenience of people who aren't used to XCOFF. */
2654 else if (type == 'd')
2659 sym = symbol_find_or_make (name);
2661 ppc_change_csect (sym);
2663 demand_empty_rest_of_line ();
2666 /* This function handles the .section pseudo-op. This is mostly to
2667 give an error, since XCOFF only supports .text, .data and .bss, but
2668 we do permit the user to name the text or data section. */
2671 ppc_named_section (ignore)
2672 int ignore ATTRIBUTE_UNUSED;
2675 const char *real_name;
2679 user_name = input_line_pointer;
2680 c = get_symbol_end ();
2682 if (strcmp (user_name, ".text") == 0)
2683 real_name = ".text[PR]";
2684 else if (strcmp (user_name, ".data") == 0)
2685 real_name = ".data[RW]";
2688 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2689 *input_line_pointer = c;
2690 ignore_rest_of_line ();
2694 *input_line_pointer = c;
2696 sym = symbol_find_or_make (real_name);
2698 ppc_change_csect (sym);
2700 demand_empty_rest_of_line ();
2703 /* The .extern pseudo-op. We create an undefined symbol. */
2707 int ignore ATTRIBUTE_UNUSED;
2712 name = input_line_pointer;
2713 endc = get_symbol_end ();
2715 (void) symbol_find_or_make (name);
2717 *input_line_pointer = endc;
2719 demand_empty_rest_of_line ();
2722 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2726 int ignore ATTRIBUTE_UNUSED;
2732 name = input_line_pointer;
2733 endc = get_symbol_end ();
2735 sym = symbol_find_or_make (name);
2737 *input_line_pointer = endc;
2739 symbol_get_tc (sym)->output = 1;
2741 demand_empty_rest_of_line ();
2744 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2745 although I don't know why it bothers. */
2749 int ignore ATTRIBUTE_UNUSED;
2756 name = input_line_pointer;
2757 endc = get_symbol_end ();
2759 sym = symbol_find_or_make (name);
2761 *input_line_pointer = endc;
2763 if (*input_line_pointer != ',')
2765 as_bad (_("missing rename string"));
2766 ignore_rest_of_line ();
2769 ++input_line_pointer;
2771 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
2773 demand_empty_rest_of_line ();
2776 /* The .stabx pseudo-op. This is similar to a normal .stabs
2777 pseudo-op, but slightly different. A sample is
2778 .stabx "main:F-1",.main,142,0
2779 The first argument is the symbol name to create. The second is the
2780 value, and the third is the storage class. The fourth seems to be
2781 always zero, and I am assuming it is the type. */
2785 int ignore ATTRIBUTE_UNUSED;
2792 name = demand_copy_C_string (&len);
2794 if (*input_line_pointer != ',')
2796 as_bad (_("missing value"));
2799 ++input_line_pointer;
2801 ppc_stab_symbol = true;
2802 sym = symbol_make (name);
2803 ppc_stab_symbol = false;
2805 symbol_get_tc (sym)->real_name = name;
2807 (void) expression (&exp);
2814 as_bad (_("illegal .stabx expression; zero assumed"));
2815 exp.X_add_number = 0;
2818 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2819 symbol_set_frag (sym, &zero_address_frag);
2823 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2824 symbol_set_value_expression (sym, &exp);
2828 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2829 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
2834 /* The value is some complex expression. This will probably
2835 fail at some later point, but this is probably the right
2836 thing to do here. */
2837 symbol_set_value_expression (sym, &exp);
2841 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2842 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
2844 if (*input_line_pointer != ',')
2846 as_bad (_("missing class"));
2849 ++input_line_pointer;
2851 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2853 if (*input_line_pointer != ',')
2855 as_bad (_("missing type"));
2858 ++input_line_pointer;
2860 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2862 symbol_get_tc (sym)->output = 1;
2864 if (S_GET_STORAGE_CLASS (sym) == C_STSYM) {
2866 symbol_get_tc (sym)->within = ppc_current_block;
2871 .stabx "z",arrays_,133,0
2874 .comm arrays_,13768,3
2876 resolve_symbol_value will copy the exp's "within" into sym's when the
2877 offset is 0. Since this seems to be corner case problem,
2878 only do the correction for storage class C_STSYM. A better solution
2879 would be to have the tc field updated in ppc_symbol_new_hook. */
2881 if (exp.X_op == O_symbol)
2883 symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block;
2887 if (exp.X_op != O_symbol
2888 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2889 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2890 ppc_frob_label (sym);
2893 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2894 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2895 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
2896 symbol_get_tc (ppc_current_csect)->within = sym;
2899 demand_empty_rest_of_line ();
2902 /* The .function pseudo-op. This takes several arguments. The first
2903 argument seems to be the external name of the symbol. The second
2904 argment seems to be the label for the start of the function. gcc
2905 uses the same name for both. I have no idea what the third and
2906 fourth arguments are meant to be. The optional fifth argument is
2907 an expression for the size of the function. In COFF this symbol
2908 gets an aux entry like that used for a csect. */
2911 ppc_function (ignore)
2912 int ignore ATTRIBUTE_UNUSED;
2920 name = input_line_pointer;
2921 endc = get_symbol_end ();
2923 /* Ignore any [PR] suffix. */
2924 name = ppc_canonicalize_symbol_name (name);
2925 s = strchr (name, '[');
2926 if (s != (char *) NULL
2927 && strcmp (s + 1, "PR]") == 0)
2930 ext_sym = symbol_find_or_make (name);
2932 *input_line_pointer = endc;
2934 if (*input_line_pointer != ',')
2936 as_bad (_("missing symbol name"));
2937 ignore_rest_of_line ();
2940 ++input_line_pointer;
2942 name = input_line_pointer;
2943 endc = get_symbol_end ();
2945 lab_sym = symbol_find_or_make (name);
2947 *input_line_pointer = endc;
2949 if (ext_sym != lab_sym)
2953 exp.X_op = O_symbol;
2954 exp.X_add_symbol = lab_sym;
2955 exp.X_op_symbol = NULL;
2956 exp.X_add_number = 0;
2958 symbol_set_value_expression (ext_sym, &exp);
2961 if (symbol_get_tc (ext_sym)->class == -1)
2962 symbol_get_tc (ext_sym)->class = XMC_PR;
2963 symbol_get_tc (ext_sym)->output = 1;
2965 if (*input_line_pointer == ',')
2969 /* Ignore the third argument. */
2970 ++input_line_pointer;
2971 expression (&ignore);
2972 if (*input_line_pointer == ',')
2974 /* Ignore the fourth argument. */
2975 ++input_line_pointer;
2976 expression (&ignore);
2977 if (*input_line_pointer == ',')
2979 /* The fifth argument is the function size. */
2980 ++input_line_pointer;
2981 symbol_get_tc (ext_sym)->size = symbol_new ("L0\001",
2984 &zero_address_frag);
2985 pseudo_set (symbol_get_tc (ext_sym)->size);
2990 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2991 SF_SET_FUNCTION (ext_sym);
2992 SF_SET_PROCESS (ext_sym);
2993 coff_add_linesym (ext_sym);
2995 demand_empty_rest_of_line ();
2998 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3003 int ignore ATTRIBUTE_UNUSED;
3007 sym = symbol_make (".bf");
3008 S_SET_SEGMENT (sym, text_section);
3009 symbol_set_frag (sym, frag_now);
3010 S_SET_VALUE (sym, frag_now_fix ());
3011 S_SET_STORAGE_CLASS (sym, C_FCN);
3013 coff_line_base = get_absolute_expression ();
3015 S_SET_NUMBER_AUXILIARY (sym, 1);
3016 SA_SET_SYM_LNNO (sym, coff_line_base);
3018 symbol_get_tc (sym)->output = 1;
3020 ppc_frob_label (sym);
3022 demand_empty_rest_of_line ();
3025 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3026 ".ef", except that the line number is absolute, not relative to the
3027 most recent ".bf" symbol. */
3031 int ignore ATTRIBUTE_UNUSED;
3035 sym = symbol_make (".ef");
3036 S_SET_SEGMENT (sym, text_section);
3037 symbol_set_frag (sym, frag_now);
3038 S_SET_VALUE (sym, frag_now_fix ());
3039 S_SET_STORAGE_CLASS (sym, C_FCN);
3040 S_SET_NUMBER_AUXILIARY (sym, 1);
3041 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3042 symbol_get_tc (sym)->output = 1;
3044 ppc_frob_label (sym);
3046 demand_empty_rest_of_line ();
3049 /* The .bi and .ei pseudo-ops. These take a string argument and
3050 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3057 static symbolS *last_biei;
3064 name = demand_copy_C_string (&len);
3066 /* The value of these symbols is actually file offset. Here we set
3067 the value to the index into the line number entries. In
3068 ppc_frob_symbols we set the fix_line field, which will cause BFD
3069 to do the right thing. */
3071 sym = symbol_make (name);
3072 /* obj-coff.c currently only handles line numbers correctly in the
3074 S_SET_SEGMENT (sym, text_section);
3075 S_SET_VALUE (sym, coff_n_line_nos);
3076 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3078 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
3079 symbol_get_tc (sym)->output = 1;
3081 for (look = last_biei ? last_biei : symbol_rootP;
3082 (look != (symbolS *) NULL
3083 && (S_GET_STORAGE_CLASS (look) == C_FILE
3084 || S_GET_STORAGE_CLASS (look) == C_BINCL
3085 || S_GET_STORAGE_CLASS (look) == C_EINCL));
3086 look = symbol_next (look))
3088 if (look != (symbolS *) NULL)
3090 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3091 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
3095 demand_empty_rest_of_line ();
3098 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3099 There is one argument, which is a csect symbol. The value of the
3100 .bs symbol is the index of this csect symbol. */
3104 int ignore ATTRIBUTE_UNUSED;
3111 if (ppc_current_block != NULL)
3112 as_bad (_("nested .bs blocks"));
3114 name = input_line_pointer;
3115 endc = get_symbol_end ();
3117 csect = symbol_find_or_make (name);
3119 *input_line_pointer = endc;
3121 sym = symbol_make (".bs");
3122 S_SET_SEGMENT (sym, now_seg);
3123 S_SET_STORAGE_CLASS (sym, C_BSTAT);
3124 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3125 symbol_get_tc (sym)->output = 1;
3127 symbol_get_tc (sym)->within = csect;
3129 ppc_frob_label (sym);
3131 ppc_current_block = sym;
3133 demand_empty_rest_of_line ();
3136 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3140 int ignore ATTRIBUTE_UNUSED;
3144 if (ppc_current_block == NULL)
3145 as_bad (_(".es without preceding .bs"));
3147 sym = symbol_make (".es");
3148 S_SET_SEGMENT (sym, now_seg);
3149 S_SET_STORAGE_CLASS (sym, C_ESTAT);
3150 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3151 symbol_get_tc (sym)->output = 1;
3153 ppc_frob_label (sym);
3155 ppc_current_block = NULL;
3157 demand_empty_rest_of_line ();
3160 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3165 int ignore ATTRIBUTE_UNUSED;
3169 sym = symbol_make (".bb");
3170 S_SET_SEGMENT (sym, text_section);
3171 symbol_set_frag (sym, frag_now);
3172 S_SET_VALUE (sym, frag_now_fix ());
3173 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3175 S_SET_NUMBER_AUXILIARY (sym, 1);
3176 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3178 symbol_get_tc (sym)->output = 1;
3180 SF_SET_PROCESS (sym);
3182 ppc_frob_label (sym);
3184 demand_empty_rest_of_line ();
3187 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3192 int ignore ATTRIBUTE_UNUSED;
3196 sym = symbol_make (".eb");
3197 S_SET_SEGMENT (sym, text_section);
3198 symbol_set_frag (sym, frag_now);
3199 S_SET_VALUE (sym, frag_now_fix ());
3200 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3201 S_SET_NUMBER_AUXILIARY (sym, 1);
3202 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3203 symbol_get_tc (sym)->output = 1;
3205 SF_SET_PROCESS (sym);
3207 ppc_frob_label (sym);
3209 demand_empty_rest_of_line ();
3212 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3217 int ignore ATTRIBUTE_UNUSED;
3223 name = demand_copy_C_string (&len);
3224 sym = symbol_make (name);
3225 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3226 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3227 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3228 S_SET_VALUE (sym, 0);
3229 symbol_get_tc (sym)->output = 1;
3231 ppc_frob_label (sym);
3233 demand_empty_rest_of_line ();
3236 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3240 int ignore ATTRIBUTE_UNUSED;
3244 sym = symbol_make (".ec");
3245 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3246 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3247 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3248 S_SET_VALUE (sym, 0);
3249 symbol_get_tc (sym)->output = 1;
3251 ppc_frob_label (sym);
3253 demand_empty_rest_of_line ();
3256 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3260 int ignore ATTRIBUTE_UNUSED;
3262 if (ppc_toc_csect != (symbolS *) NULL)
3263 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
3270 subseg = ppc_data_subsegment;
3271 ++ppc_data_subsegment;
3273 subseg_new (segment_name (data_section), subseg);
3274 ppc_toc_frag = frag_now;
3276 sym = symbol_find_or_make ("TOC[TC0]");
3277 symbol_set_frag (sym, frag_now);
3278 S_SET_SEGMENT (sym, data_section);
3279 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3280 symbol_get_tc (sym)->subseg = subseg;
3281 symbol_get_tc (sym)->output = 1;
3282 symbol_get_tc (sym)->within = sym;
3284 ppc_toc_csect = sym;
3286 for (list = ppc_data_csects;
3287 symbol_get_tc (list)->next != (symbolS *) NULL;
3288 list = symbol_get_tc (list)->next)
3290 symbol_get_tc (list)->next = sym;
3292 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3293 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3297 ppc_current_csect = ppc_toc_csect;
3299 demand_empty_rest_of_line ();
3302 /* The AIX assembler automatically aligns the operands of a .long or
3303 .short pseudo-op, and we want to be compatible. */
3306 ppc_xcoff_cons (log_size)
3309 frag_align (log_size, 0, 0);
3310 record_alignment (now_seg, log_size);
3311 cons (1 << log_size);
3316 int dummy ATTRIBUTE_UNUSED;
3318 discard_rest_of_line();
3319 /* What does aix use this for? */
3324 int dummy ATTRIBUTE_UNUSED;
3329 (void) expression (&exp);
3331 if (exp.X_op != O_constant)
3333 as_bad (_("non-constant byte count"));
3337 byte_count = exp.X_add_number;
3339 if (*input_line_pointer != ',')
3341 as_bad (_("missing value"));
3345 ++input_line_pointer;
3349 #endif /* OBJ_XCOFF */
3351 /* The .tc pseudo-op. This is used when generating either XCOFF or
3352 ELF. This takes two or more arguments.
3354 When generating XCOFF output, the first argument is the name to
3355 give to this location in the toc; this will be a symbol with class
3356 TC. The rest of the arguments are 4 byte values to actually put at
3357 this location in the TOC; often there is just one more argument, a
3358 relocateable symbol reference.
3360 When not generating XCOFF output, the arguments are the same, but
3361 the first argument is simply ignored. */
3365 int ignore ATTRIBUTE_UNUSED;
3369 /* Define the TOC symbol name. */
3375 if (ppc_toc_csect == (symbolS *) NULL
3376 || ppc_toc_csect != ppc_current_csect)
3378 as_bad (_(".tc not in .toc section"));
3379 ignore_rest_of_line ();
3383 name = input_line_pointer;
3384 endc = get_symbol_end ();
3386 sym = symbol_find_or_make (name);
3388 *input_line_pointer = endc;
3390 if (S_IS_DEFINED (sym))
3394 label = symbol_get_tc (ppc_current_csect)->within;
3395 if (symbol_get_tc (label)->class != XMC_TC0)
3397 as_bad (_(".tc with no label"));
3398 ignore_rest_of_line ();
3402 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3403 symbol_set_frag (label, symbol_get_frag (sym));
3404 S_SET_VALUE (label, S_GET_VALUE (sym));
3406 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3407 ++input_line_pointer;
3412 S_SET_SEGMENT (sym, now_seg);
3413 symbol_set_frag (sym, frag_now);
3414 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3415 symbol_get_tc (sym)->class = XMC_TC;
3416 symbol_get_tc (sym)->output = 1;
3418 ppc_frob_label (sym);
3421 #else /* ! defined (OBJ_XCOFF) */
3423 /* Skip the TOC symbol name. */
3424 while (is_part_of_name (*input_line_pointer)
3425 || *input_line_pointer == '['
3426 || *input_line_pointer == ']'
3427 || *input_line_pointer == '{'
3428 || *input_line_pointer == '}')
3429 ++input_line_pointer;
3431 /* Align to a four byte boundary. */
3432 frag_align (2, 0, 0);
3433 record_alignment (now_seg, 2);
3435 #endif /* ! defined (OBJ_XCOFF) */
3437 if (*input_line_pointer != ',')
3438 demand_empty_rest_of_line ();
3441 ++input_line_pointer;
3442 cons ((ppc_size == PPC_OPCODE_64) ? 8 : 4);
3448 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
3450 /* Set the current section. */
3452 ppc_set_current_section (new)
3455 ppc_previous_section = ppc_current_section;
3456 ppc_current_section = new;
3459 /* pseudo-op: .previous
3460 behaviour: toggles the current section with the previous section.
3462 warnings: "No previous section" */
3465 ppc_previous (ignore)
3466 int ignore ATTRIBUTE_UNUSED;
3470 if (ppc_previous_section == NULL)
3472 as_warn (_("No previous section to return to. Directive ignored."));
3476 subseg_set (ppc_previous_section, 0);
3478 ppc_set_current_section (ppc_previous_section);
3481 /* pseudo-op: .pdata
3482 behaviour: predefined read only data section
3486 initial: .section .pdata "adr3"
3487 a - don't know -- maybe a misprint
3488 d - initialized data
3490 3 - double word aligned (that would be 4 byte boundary)
3493 Tag index tables (also known as the function table) for exception
3494 handling, debugging, etc. */
3498 int ignore ATTRIBUTE_UNUSED;
3500 if (pdata_section == 0)
3502 pdata_section = subseg_new (".pdata", 0);
3504 bfd_set_section_flags (stdoutput, pdata_section,
3505 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3506 | SEC_READONLY | SEC_DATA ));
3508 bfd_set_section_alignment (stdoutput, pdata_section, 2);
3512 pdata_section = subseg_new (".pdata", 0);
3514 ppc_set_current_section (pdata_section);
3517 /* pseudo-op: .ydata
3518 behaviour: predefined read only data section
3522 initial: .section .ydata "drw3"
3523 a - don't know -- maybe a misprint
3524 d - initialized data
3526 3 - double word aligned (that would be 4 byte boundary)
3528 Tag tables (also known as the scope table) for exception handling,
3533 int ignore ATTRIBUTE_UNUSED;
3535 if (ydata_section == 0)
3537 ydata_section = subseg_new (".ydata", 0);
3538 bfd_set_section_flags (stdoutput, ydata_section,
3539 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3540 | SEC_READONLY | SEC_DATA ));
3542 bfd_set_section_alignment (stdoutput, ydata_section, 3);
3546 ydata_section = subseg_new (".ydata", 0);
3548 ppc_set_current_section (ydata_section);
3551 /* pseudo-op: .reldata
3552 behaviour: predefined read write data section
3553 double word aligned (4-byte)
3554 FIXME: relocation is applied to it
3555 FIXME: what's the difference between this and .data?
3558 initial: .section .reldata "drw3"
3559 d - initialized data
3562 3 - double word aligned (that would be 8 byte boundary)
3565 Like .data, but intended to hold data subject to relocation, such as
3566 function descriptors, etc. */
3569 ppc_reldata (ignore)
3570 int ignore ATTRIBUTE_UNUSED;
3572 if (reldata_section == 0)
3574 reldata_section = subseg_new (".reldata", 0);
3576 bfd_set_section_flags (stdoutput, reldata_section,
3577 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3580 bfd_set_section_alignment (stdoutput, reldata_section, 2);
3584 reldata_section = subseg_new (".reldata", 0);
3586 ppc_set_current_section (reldata_section);
3589 /* pseudo-op: .rdata
3590 behaviour: predefined read only data section
3594 initial: .section .rdata "dr3"
3595 d - initialized data
3597 3 - double word aligned (that would be 4 byte boundary) */
3601 int ignore ATTRIBUTE_UNUSED;
3603 if (rdata_section == 0)
3605 rdata_section = subseg_new (".rdata", 0);
3606 bfd_set_section_flags (stdoutput, rdata_section,
3607 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3608 | SEC_READONLY | SEC_DATA ));
3610 bfd_set_section_alignment (stdoutput, rdata_section, 2);
3614 rdata_section = subseg_new (".rdata", 0);
3616 ppc_set_current_section (rdata_section);
3619 /* pseudo-op: .ualong
3620 behaviour: much like .int, with the exception that no alignment is
3622 FIXME: test the alignment statement
3628 int ignore ATTRIBUTE_UNUSED;
3634 /* pseudo-op: .znop <symbol name>
3635 behaviour: Issue a nop instruction
3636 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3637 the supplied symbol name.
3639 warnings: Missing symbol name */
3643 int ignore ATTRIBUTE_UNUSED;
3646 const struct powerpc_opcode *opcode;
3657 /* Strip out the symbol name. */
3658 symbol_name = input_line_pointer;
3659 c = get_symbol_end ();
3661 name = xmalloc (input_line_pointer - symbol_name + 1);
3662 strcpy (name, symbol_name);
3664 sym = symbol_find_or_make (name);
3666 *input_line_pointer = c;
3670 /* Look up the opcode in the hash table. */
3671 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3673 /* Stick in the nop. */
3674 insn = opcode->opcode;
3676 /* Write out the instruction. */
3678 md_number_to_chars (f, insn, 4);
3680 f - frag_now->fr_literal,
3685 BFD_RELOC_16_GOT_PCREL);
3698 register char *name;
3702 register symbolS *symbolP;
3705 name = input_line_pointer;
3706 c = get_symbol_end ();
3708 /* just after name is now '\0'. */
3709 p = input_line_pointer;
3712 if (*input_line_pointer != ',')
3714 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3715 ignore_rest_of_line ();
3719 input_line_pointer++; /* skip ',' */
3720 if ((temp = get_absolute_expression ()) < 0)
3722 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
3723 ignore_rest_of_line ();
3729 /* The third argument to .comm is the alignment. */
3730 if (*input_line_pointer != ',')
3734 ++input_line_pointer;
3735 align = get_absolute_expression ();
3738 as_warn (_("ignoring bad alignment"));
3745 symbolP = symbol_find_or_make (name);
3748 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
3750 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3751 S_GET_NAME (symbolP));
3752 ignore_rest_of_line ();
3756 if (S_GET_VALUE (symbolP))
3758 if (S_GET_VALUE (symbolP) != (valueT) temp)
3759 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3760 S_GET_NAME (symbolP),
3761 (long) S_GET_VALUE (symbolP),
3766 S_SET_VALUE (symbolP, (valueT) temp);
3767 S_SET_EXTERNAL (symbolP);
3770 demand_empty_rest_of_line ();
3774 * implement the .section pseudo op:
3775 * .section name {, "flags"}
3777 * | +--- optional flags: 'b' for bss
3779 * +-- section name 'l' for lib
3783 * 'd' (apparently m88k for data)
3785 * But if the argument is not a quoted string, treat it as a
3786 * subsegment number.
3788 * FIXME: this is a copy of the section processing from obj-coff.c, with
3789 * additions/changes for the moto-pas assembler support. There are three
3792 * FIXME: I just noticed this. This doesn't work at all really. It it
3793 * setting bits that bfd probably neither understands or uses. The
3794 * correct approach (?) will have to incorporate extra fields attached
3795 * to the section to hold the system specific stuff. (krk)
3798 * 'a' - unknown - referred to in documentation, but no definition supplied
3799 * 'c' - section has code
3800 * 'd' - section has initialized data
3801 * 'u' - section has uninitialized data
3802 * 'i' - section contains directives (info)
3803 * 'n' - section can be discarded
3804 * 'R' - remove section at link time
3806 * Section Protection:
3807 * 'r' - section is readable
3808 * 'w' - section is writeable
3809 * 'x' - section is executable
3810 * 's' - section is sharable
3812 * Section Alignment:
3813 * '0' - align to byte boundary
3814 * '1' - align to halfword undary
3815 * '2' - align to word boundary
3816 * '3' - align to doubleword boundary
3817 * '4' - align to quadword boundary
3818 * '5' - align to 32 byte boundary
3819 * '6' - align to 64 byte boundary
3824 ppc_pe_section (ignore)
3825 int ignore ATTRIBUTE_UNUSED;
3827 /* Strip out the section name. */
3836 section_name = input_line_pointer;
3837 c = get_symbol_end ();
3839 name = xmalloc (input_line_pointer - section_name + 1);
3840 strcpy (name, section_name);
3842 *input_line_pointer = c;
3847 flags = SEC_NO_FLAGS;
3849 if (strcmp (name, ".idata$2") == 0)
3853 else if (strcmp (name, ".idata$3") == 0)
3857 else if (strcmp (name, ".idata$4") == 0)
3861 else if (strcmp (name, ".idata$5") == 0)
3865 else if (strcmp (name, ".idata$6") == 0)
3870 /* Default alignment to 16 byte boundary. */
3873 if (*input_line_pointer == ',')
3875 ++input_line_pointer;
3877 if (*input_line_pointer != '"')
3878 exp = get_absolute_expression ();
3881 ++input_line_pointer;
3882 while (*input_line_pointer != '"'
3883 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3885 switch (*input_line_pointer)
3887 /* Section Contents */
3888 case 'a': /* unknown */
3889 as_bad (_("Unsupported section attribute -- 'a'"));
3891 case 'c': /* code section */
3894 case 'd': /* section has initialized data */
3897 case 'u': /* section has uninitialized data */
3898 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3902 case 'i': /* section contains directives (info) */
3903 /* FIXME: This is IMAGE_SCN_LNK_INFO
3905 flags |= SEC_HAS_CONTENTS;
3907 case 'n': /* section can be discarded */
3910 case 'R': /* Remove section at link time */
3911 flags |= SEC_NEVER_LOAD;
3914 /* Section Protection */
3915 case 'r': /* section is readable */
3916 flags |= IMAGE_SCN_MEM_READ;
3918 case 'w': /* section is writeable */
3919 flags |= IMAGE_SCN_MEM_WRITE;
3921 case 'x': /* section is executable */
3922 flags |= IMAGE_SCN_MEM_EXECUTE;
3924 case 's': /* section is sharable */
3925 flags |= IMAGE_SCN_MEM_SHARED;
3928 /* Section Alignment */
3929 case '0': /* align to byte boundary */
3930 flags |= IMAGE_SCN_ALIGN_1BYTES;
3933 case '1': /* align to halfword boundary */
3934 flags |= IMAGE_SCN_ALIGN_2BYTES;
3937 case '2': /* align to word boundary */
3938 flags |= IMAGE_SCN_ALIGN_4BYTES;
3941 case '3': /* align to doubleword boundary */
3942 flags |= IMAGE_SCN_ALIGN_8BYTES;
3945 case '4': /* align to quadword boundary */
3946 flags |= IMAGE_SCN_ALIGN_16BYTES;
3949 case '5': /* align to 32 byte boundary */
3950 flags |= IMAGE_SCN_ALIGN_32BYTES;
3953 case '6': /* align to 64 byte boundary */
3954 flags |= IMAGE_SCN_ALIGN_64BYTES;
3959 as_bad (_("unknown section attribute '%c'"),
3960 *input_line_pointer);
3963 ++input_line_pointer;
3965 if (*input_line_pointer == '"')
3966 ++input_line_pointer;
3970 sec = subseg_new (name, (subsegT) exp);
3972 ppc_set_current_section (sec);
3974 if (flags != SEC_NO_FLAGS)
3976 if (! bfd_set_section_flags (stdoutput, sec, flags))
3977 as_bad (_("error setting flags for \"%s\": %s"),
3978 bfd_section_name (stdoutput, sec),
3979 bfd_errmsg (bfd_get_error ()));
3982 bfd_set_section_alignment (stdoutput, sec, align);
3987 ppc_pe_function (ignore)
3988 int ignore ATTRIBUTE_UNUSED;
3994 name = input_line_pointer;
3995 endc = get_symbol_end ();
3997 ext_sym = symbol_find_or_make (name);
3999 *input_line_pointer = endc;
4001 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
4002 SF_SET_FUNCTION (ext_sym);
4003 SF_SET_PROCESS (ext_sym);
4004 coff_add_linesym (ext_sym);
4006 demand_empty_rest_of_line ();
4010 ppc_pe_tocd (ignore)
4011 int ignore ATTRIBUTE_UNUSED;
4013 if (tocdata_section == 0)
4015 tocdata_section = subseg_new (".tocd", 0);
4016 /* FIXME: section flags won't work. */
4017 bfd_set_section_flags (stdoutput, tocdata_section,
4018 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4019 | SEC_READONLY | SEC_DATA));
4021 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
4025 rdata_section = subseg_new (".tocd", 0);
4028 ppc_set_current_section (tocdata_section);
4030 demand_empty_rest_of_line ();
4033 /* Don't adjust TOC relocs to use the section symbol. */
4036 ppc_pe_fix_adjustable (fix)
4039 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
4046 /* XCOFF specific symbol and file handling. */
4048 /* Canonicalize the symbol name. We use the to force the suffix, if
4049 any, to use square brackets, and to be in upper case. */
4052 ppc_canonicalize_symbol_name (name)
4057 if (ppc_stab_symbol)
4060 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
4074 for (s++; *s != '\0' && *s != brac; s++)
4078 if (*s == '\0' || s[1] != '\0')
4079 as_bad (_("bad symbol suffix"));
4087 /* Set the class of a symbol based on the suffix, if any. This is
4088 called whenever a new symbol is created. */
4091 ppc_symbol_new_hook (sym)
4094 struct ppc_tc_sy *tc;
4097 tc = symbol_get_tc (sym);
4101 tc->real_name = NULL;
4107 if (ppc_stab_symbol)
4110 s = strchr (S_GET_NAME (sym), '[');
4111 if (s == (const char *) NULL)
4113 /* There is no suffix. */
4122 if (strcmp (s, "BS]") == 0)
4126 if (strcmp (s, "DB]") == 0)
4128 else if (strcmp (s, "DS]") == 0)
4132 if (strcmp (s, "GL]") == 0)
4136 if (strcmp (s, "PR]") == 0)
4140 if (strcmp (s, "RO]") == 0)
4142 else if (strcmp (s, "RW]") == 0)
4146 if (strcmp (s, "SV]") == 0)
4150 if (strcmp (s, "TC]") == 0)
4152 else if (strcmp (s, "TI]") == 0)
4154 else if (strcmp (s, "TB]") == 0)
4156 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
4157 tc->class = XMC_TC0;
4160 if (strcmp (s, "UA]") == 0)
4162 else if (strcmp (s, "UC]") == 0)
4166 if (strcmp (s, "XO]") == 0)
4171 if (tc->class == -1)
4172 as_bad (_("Unrecognized symbol suffix"));
4175 /* Set the class of a label based on where it is defined. This
4176 handles symbols without suffixes. Also, move the symbol so that it
4177 follows the csect symbol. */
4180 ppc_frob_label (sym)
4183 if (ppc_current_csect != (symbolS *) NULL)
4185 if (symbol_get_tc (sym)->class == -1)
4186 symbol_get_tc (sym)->class = symbol_get_tc (ppc_current_csect)->class;
4188 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4189 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
4190 &symbol_rootP, &symbol_lastP);
4191 symbol_get_tc (ppc_current_csect)->within = sym;
4195 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4196 seen. It tells ppc_adjust_symtab whether it needs to look through
4199 static boolean ppc_saw_abs;
4201 /* Change the name of a symbol just before writing it out. Set the
4202 real name if the .rename pseudo-op was used. Otherwise, remove any
4203 class suffix. Return 1 if the symbol should not be included in the
4207 ppc_frob_symbol (sym)
4210 static symbolS *ppc_last_function;
4211 static symbolS *set_end;
4213 /* Discard symbols that should not be included in the output symbol
4215 if (! symbol_used_in_reloc_p (sym)
4216 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
4217 || (! S_IS_EXTERNAL (sym)
4218 && ! symbol_get_tc (sym)->output
4219 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
4222 if (symbol_get_tc (sym)->real_name != (char *) NULL)
4223 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
4229 name = S_GET_NAME (sym);
4230 s = strchr (name, '[');
4231 if (s != (char *) NULL)
4237 snew = xmalloc (len + 1);
4238 memcpy (snew, name, len);
4241 S_SET_NAME (sym, snew);
4245 if (set_end != (symbolS *) NULL)
4247 SA_SET_SYM_ENDNDX (set_end, sym);
4251 if (SF_GET_FUNCTION (sym))
4253 if (ppc_last_function != (symbolS *) NULL)
4254 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4255 ppc_last_function = sym;
4256 if (symbol_get_tc (sym)->size != (symbolS *) NULL)
4258 resolve_symbol_value (symbol_get_tc (sym)->size);
4259 SA_SET_SYM_FSIZE (sym,
4260 (long) S_GET_VALUE (symbol_get_tc (sym)->size));
4263 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4264 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4266 if (ppc_last_function == (symbolS *) NULL)
4267 as_bad (_(".ef with no preceding .function"));
4270 set_end = ppc_last_function;
4271 ppc_last_function = NULL;
4273 /* We don't have a C_EFCN symbol, but we need to force the
4274 COFF backend to believe that it has seen one. */
4275 coff_last_function = NULL;
4279 if (! S_IS_EXTERNAL (sym)
4280 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
4281 && S_GET_STORAGE_CLASS (sym) != C_FILE
4282 && S_GET_STORAGE_CLASS (sym) != C_FCN
4283 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4284 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4285 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4286 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4287 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4288 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4289 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4291 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4292 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4295 union internal_auxent *a;
4297 /* Create a csect aux. */
4298 i = S_GET_NUMBER_AUXILIARY (sym);
4299 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4300 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
4301 if (symbol_get_tc (sym)->class == XMC_TC0)
4303 /* This is the TOC table. */
4304 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4305 a->x_csect.x_scnlen.l = 0;
4306 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4308 else if (symbol_get_tc (sym)->subseg != 0)
4310 /* This is a csect symbol. x_scnlen is the size of the
4312 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
4313 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4314 S_GET_SEGMENT (sym))
4315 - S_GET_VALUE (sym));
4318 resolve_symbol_value (symbol_get_tc (sym)->next);
4319 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
4320 - S_GET_VALUE (sym));
4322 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
4324 else if (S_GET_SEGMENT (sym) == bss_section)
4326 /* This is a common symbol. */
4327 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
4328 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
4329 if (S_IS_EXTERNAL (sym))
4330 symbol_get_tc (sym)->class = XMC_RW;
4332 symbol_get_tc (sym)->class = XMC_BS;
4334 else if (S_GET_SEGMENT (sym) == absolute_section)
4336 /* This is an absolute symbol. The csect will be created by
4337 ppc_adjust_symtab. */
4339 a->x_csect.x_smtyp = XTY_LD;
4340 if (symbol_get_tc (sym)->class == -1)
4341 symbol_get_tc (sym)->class = XMC_XO;
4343 else if (! S_IS_DEFINED (sym))
4345 /* This is an external symbol. */
4346 a->x_csect.x_scnlen.l = 0;
4347 a->x_csect.x_smtyp = XTY_ER;
4349 else if (symbol_get_tc (sym)->class == XMC_TC)
4353 /* This is a TOC definition. x_scnlen is the size of the
4355 next = symbol_next (sym);
4356 while (symbol_get_tc (next)->class == XMC_TC0)
4357 next = symbol_next (next);
4358 if (next == (symbolS *) NULL
4359 || symbol_get_tc (next)->class != XMC_TC)
4361 if (ppc_after_toc_frag == (fragS *) NULL)
4362 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4364 - S_GET_VALUE (sym));
4366 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
4367 - S_GET_VALUE (sym));
4371 resolve_symbol_value (next);
4372 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
4373 - S_GET_VALUE (sym));
4375 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4381 /* This is a normal symbol definition. x_scnlen is the
4382 symbol index of the containing csect. */
4383 if (S_GET_SEGMENT (sym) == text_section)
4384 csect = ppc_text_csects;
4385 else if (S_GET_SEGMENT (sym) == data_section)
4386 csect = ppc_data_csects;
4390 /* Skip the initial dummy symbol. */
4391 csect = symbol_get_tc (csect)->next;
4393 if (csect == (symbolS *) NULL)
4395 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
4396 a->x_csect.x_scnlen.l = 0;
4400 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
4402 resolve_symbol_value (symbol_get_tc (csect)->next);
4403 if (S_GET_VALUE (symbol_get_tc (csect)->next)
4404 > S_GET_VALUE (sym))
4406 csect = symbol_get_tc (csect)->next;
4409 a->x_csect.x_scnlen.p =
4410 coffsymbol (symbol_get_bfdsym (csect))->native;
4411 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
4414 a->x_csect.x_smtyp = XTY_LD;
4417 a->x_csect.x_parmhash = 0;
4418 a->x_csect.x_snhash = 0;
4419 if (symbol_get_tc (sym)->class == -1)
4420 a->x_csect.x_smclas = XMC_PR;
4422 a->x_csect.x_smclas = symbol_get_tc (sym)->class;
4423 a->x_csect.x_stab = 0;
4424 a->x_csect.x_snstab = 0;
4426 /* Don't let the COFF backend resort these symbols. */
4427 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
4429 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4431 /* We want the value to be the symbol index of the referenced
4432 csect symbol. BFD will do that for us if we set the right
4436 coffsymbol (symbol_get_bfdsym
4437 (symbol_get_tc (sym)->within))->native));
4438 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
4440 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4445 /* The value is the offset from the enclosing csect. */
4446 block = symbol_get_tc (sym)->within;
4447 csect = symbol_get_tc (block)->within;
4448 resolve_symbol_value (csect);
4449 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
4451 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
4452 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
4454 /* We want the value to be a file offset into the line numbers.
4455 BFD will do that for us if we set the right flags. We have
4456 already set the value correctly. */
4457 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
4463 /* Adjust the symbol table. This creates csect symbols for all
4464 absolute symbols. */
4467 ppc_adjust_symtab ()
4474 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4478 union internal_auxent *a;
4480 if (S_GET_SEGMENT (sym) != absolute_section)
4483 csect = symbol_create (".abs[XO]", absolute_section,
4484 S_GET_VALUE (sym), &zero_address_frag);
4485 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
4486 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
4487 i = S_GET_NUMBER_AUXILIARY (csect);
4488 S_SET_NUMBER_AUXILIARY (csect, i + 1);
4489 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
4490 a->x_csect.x_scnlen.l = 0;
4491 a->x_csect.x_smtyp = XTY_SD;
4492 a->x_csect.x_parmhash = 0;
4493 a->x_csect.x_snhash = 0;
4494 a->x_csect.x_smclas = XMC_XO;
4495 a->x_csect.x_stab = 0;
4496 a->x_csect.x_snstab = 0;
4498 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
4500 i = S_GET_NUMBER_AUXILIARY (sym);
4501 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
4502 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
4503 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
4506 ppc_saw_abs = false;
4509 /* Set the VMA for a section. This is called on all the sections in
4513 ppc_frob_section (sec)
4516 static bfd_size_type vma = 0;
4518 bfd_set_section_vma (stdoutput, sec, vma);
4519 vma += bfd_section_size (stdoutput, sec);
4522 #endif /* OBJ_XCOFF */
4524 /* Turn a string in input_line_pointer into a floating point constant
4525 of type TYPE, and store the appropriate bytes in *LITP. The number
4526 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4527 returned, or NULL on OK. */
4530 md_atof (type, litp, sizep)
4536 LITTLENUM_TYPE words[4];
4552 return _("bad call to md_atof");
4555 t = atof_ieee (input_line_pointer, type, words);
4557 input_line_pointer = t;
4561 if (target_big_endian)
4563 for (i = 0; i < prec; i++)
4565 md_number_to_chars (litp, (valueT) words[i], 2);
4571 for (i = prec - 1; i >= 0; i--)
4573 md_number_to_chars (litp, (valueT) words[i], 2);
4581 /* Write a value out to the object file, using the appropriate
4585 md_number_to_chars (buf, val, n)
4590 if (target_big_endian)
4591 number_to_chars_bigendian (buf, val, n);
4593 number_to_chars_littleendian (buf, val, n);
4596 /* Align a section (I don't know why this is machine dependent). */
4599 md_section_align (seg, addr)
4603 int align = bfd_get_section_alignment (stdoutput, seg);
4605 return ((addr + (1 << align) - 1) & (-1 << align));
4608 /* We don't have any form of relaxing. */
4611 md_estimate_size_before_relax (fragp, seg)
4612 fragS *fragp ATTRIBUTE_UNUSED;
4613 asection *seg ATTRIBUTE_UNUSED;
4619 /* Convert a machine dependent frag. We never generate these. */
4622 md_convert_frag (abfd, sec, fragp)
4623 bfd *abfd ATTRIBUTE_UNUSED;
4624 asection *sec ATTRIBUTE_UNUSED;
4625 fragS *fragp ATTRIBUTE_UNUSED;
4630 /* We have no need to default values of symbols. */
4633 md_undefined_symbol (name)
4634 char *name ATTRIBUTE_UNUSED;
4639 /* Functions concerning relocs. */
4641 /* The location from which a PC relative jump should be calculated,
4642 given a PC relative reloc. */
4645 md_pcrel_from_section (fixp, sec)
4647 segT sec ATTRIBUTE_UNUSED;
4649 return fixp->fx_frag->fr_address + fixp->fx_where;
4654 /* This is called to see whether a fixup should be adjusted to use a
4655 section symbol. We take the opportunity to change a fixup against
4656 a symbol in the TOC subsegment into a reloc against the
4657 corresponding .tc symbol. */
4660 ppc_fix_adjustable (fix)
4665 resolve_symbol_value (fix->fx_addsy);
4666 val = S_GET_VALUE (fix->fx_addsy);
4667 if (ppc_toc_csect != (symbolS *) NULL
4668 && fix->fx_addsy != (symbolS *) NULL
4669 && fix->fx_addsy != ppc_toc_csect
4670 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4671 && val >= ppc_toc_frag->fr_address
4672 && (ppc_after_toc_frag == (fragS *) NULL
4673 || val < ppc_after_toc_frag->fr_address))
4677 for (sy = symbol_next (ppc_toc_csect);
4678 sy != (symbolS *) NULL;
4679 sy = symbol_next (sy))
4681 if (symbol_get_tc (sy)->class == XMC_TC0)
4683 if (symbol_get_tc (sy)->class != XMC_TC)
4685 resolve_symbol_value (sy);
4686 if (val == S_GET_VALUE (sy))
4689 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4694 as_bad_where (fix->fx_file, fix->fx_line,
4695 _("symbol in .toc does not match any .tc"));
4698 /* Possibly adjust the reloc to be against the csect. */
4699 if (fix->fx_addsy != (symbolS *) NULL
4700 && symbol_get_tc (fix->fx_addsy)->subseg == 0
4701 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC0
4702 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC
4703 && S_GET_SEGMENT (fix->fx_addsy) != bss_section
4704 /* Don't adjust if this is a reloc in the toc section. */
4705 && (S_GET_SEGMENT (fix->fx_addsy) != data_section
4706 || ppc_toc_csect == NULL
4707 || val < ppc_toc_frag->fr_address
4708 || (ppc_after_toc_frag != NULL
4709 && val >= ppc_after_toc_frag->fr_address)))
4713 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4714 csect = ppc_text_csects;
4715 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4716 csect = ppc_data_csects;
4720 /* Skip the initial dummy symbol. */
4721 csect = symbol_get_tc (csect)->next;
4723 if (csect != (symbolS *) NULL)
4725 while (symbol_get_tc (csect)->next != (symbolS *) NULL
4726 && (symbol_get_frag (symbol_get_tc (csect)->next)->fr_address
4729 /* If the csect address equals the symbol value, then we
4730 have to look through the full symbol table to see
4731 whether this is the csect we want. Note that we will
4732 only get here if the csect has zero length. */
4733 if ((symbol_get_frag (csect)->fr_address == val)
4734 && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy))
4738 for (scan = symbol_next (csect);
4740 scan = symbol_next (scan))
4742 if (symbol_get_tc (scan)->subseg != 0)
4744 if (scan == fix->fx_addsy)
4748 /* If we found the symbol before the next csect
4749 symbol, then this is the csect we want. */
4750 if (scan == fix->fx_addsy)
4754 csect = symbol_get_tc (csect)->next;
4757 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4758 - symbol_get_frag (csect)->fr_address);
4759 fix->fx_addsy = csect;
4763 /* Adjust a reloc against a .lcomm symbol to be against the base
4765 if (fix->fx_addsy != (symbolS *) NULL
4766 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
4767 && ! S_IS_EXTERNAL (fix->fx_addsy))
4769 resolve_symbol_value (symbol_get_frag (fix->fx_addsy)->fr_symbol);
4771 (S_GET_VALUE (fix->fx_addsy)
4772 - S_GET_VALUE (symbol_get_frag (fix->fx_addsy)->fr_symbol));
4773 fix->fx_addsy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
4779 /* A reloc from one csect to another must be kept. The assembler
4780 will, of course, keep relocs between sections, and it will keep
4781 absolute relocs, but we need to force it to keep PC relative relocs
4782 between two csects in the same section. */
4785 ppc_force_relocation (fix)
4788 /* At this point fix->fx_addsy should already have been converted to
4789 a csect symbol. If the csect does not include the fragment, then
4790 we need to force the relocation. */
4792 && fix->fx_addsy != NULL
4793 && symbol_get_tc (fix->fx_addsy)->subseg != 0
4794 && ((symbol_get_frag (fix->fx_addsy)->fr_address
4795 > fix->fx_frag->fr_address)
4796 || (symbol_get_tc (fix->fx_addsy)->next != NULL
4797 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
4798 <= fix->fx_frag->fr_address))))
4804 #endif /* OBJ_XCOFF */
4806 /* See whether a symbol is in the TOC section. */
4809 ppc_is_toc_sym (sym)
4813 return symbol_get_tc (sym)->class == XMC_TC;
4815 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
4819 /* Apply a fixup to the object code. This is called for all the
4820 fixups we generated by the call to fix_new_exp, above. In the call
4821 above we used a reloc code which was the largest legal reloc code
4822 plus the operand index. Here we undo that to recover the operand
4823 index. At this point all symbol values should be fully resolved,
4824 and we attempt to completely resolve the reloc. If we can not do
4825 that, we determine the correct reloc code and put it back in the
4829 md_apply_fix3 (fixp, valuep, seg)
4838 if (fixp->fx_addsy != NULL)
4840 /* `*valuep' may contain the value of the symbol on which the reloc
4841 will be based; we have to remove it. */
4842 if (symbol_used_in_reloc_p (fixp->fx_addsy)
4843 && S_GET_SEGMENT (fixp->fx_addsy) != absolute_section
4844 && S_GET_SEGMENT (fixp->fx_addsy) != undefined_section
4845 && ! bfd_is_com_section (S_GET_SEGMENT (fixp->fx_addsy)))
4846 value -= S_GET_VALUE (fixp->fx_addsy);
4848 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4849 supposed to be? I think this is related to various similar
4850 FIXMEs in tc-i386.c and tc-sparc.c. */
4852 value += fixp->fx_frag->fr_address + fixp->fx_where;
4859 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4860 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4861 doing this relocation the code in write.c is going to call
4862 bfd_install_relocation, which is also going to use the symbol
4863 value. That means that if the reloc is fully resolved we want to
4864 use *valuep since bfd_install_relocation is not being used.
4865 However, if the reloc is not fully resolved we do not want to use
4866 *valuep, and must use fx_offset instead. However, if the reloc
4867 is PC relative, we do want to use *valuep since it includes the
4868 result of md_pcrel_from. This is confusing. */
4869 if (fixp->fx_addsy == (symbolS *) NULL)
4874 else if (fixp->fx_pcrel)
4878 value = fixp->fx_offset;
4879 if (fixp->fx_subsy != (symbolS *) NULL)
4881 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
4882 value -= S_GET_VALUE (fixp->fx_subsy);
4885 /* We can't actually support subtracting a symbol. */
4886 as_bad_where (fixp->fx_file, fixp->fx_line,
4887 _("expression too complex"));
4893 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
4896 const struct powerpc_operand *operand;
4900 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
4902 operand = &powerpc_operands[opindex];
4905 /* It appears that an instruction like
4907 when LC..1 is not a TOC symbol does not generate a reloc. It
4908 uses the offset of LC..1 within its csect. However, .long
4909 LC..1 will generate a reloc. I can't find any documentation
4910 on how these cases are to be distinguished, so this is a wild
4911 guess. These cases are generated by gcc -mminimal-toc. */
4912 if ((operand->flags & PPC_OPERAND_PARENS) != 0
4913 && operand->bits == 16
4914 && operand->shift == 0
4915 && operand->insert == NULL
4916 && fixp->fx_addsy != NULL
4917 && symbol_get_tc (fixp->fx_addsy)->subseg != 0
4918 && symbol_get_tc (fixp->fx_addsy)->class != XMC_TC
4919 && symbol_get_tc (fixp->fx_addsy)->class != XMC_TC0
4920 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
4922 value = fixp->fx_offset;
4927 /* Fetch the instruction, insert the fully resolved operand
4928 value, and stuff the instruction back again. */
4929 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4930 if (target_big_endian)
4931 insn = bfd_getb32 ((unsigned char *) where);
4933 insn = bfd_getl32 ((unsigned char *) where);
4934 insn = ppc_insert_operand (insn, operand, (offsetT) value,
4935 fixp->fx_file, fixp->fx_line);
4936 if (target_big_endian)
4937 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4939 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4943 /* Nothing else to do here. */
4947 /* Determine a BFD reloc value based on the operand information.
4948 We are only prepared to turn a few of the operands into
4950 FIXME: We need to handle the DS field at the very least.
4951 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4952 there should be a new field in the operand table. */
4953 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4954 && operand->bits == 26
4955 && operand->shift == 0)
4956 fixp->fx_r_type = BFD_RELOC_PPC_B26;
4957 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4958 && operand->bits == 16
4959 && operand->shift == 0)
4960 fixp->fx_r_type = BFD_RELOC_PPC_B16;
4961 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4962 && operand->bits == 26
4963 && operand->shift == 0)
4964 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4965 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4966 && operand->bits == 16
4967 && operand->shift == 0)
4968 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4969 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4970 && operand->bits == 16
4971 && operand->shift == 0
4972 && fixp->fx_addsy != NULL
4973 && ppc_is_toc_sym (fixp->fx_addsy))
4976 if (target_big_endian)
4977 fixp->fx_where += 2;
4978 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4985 /* Use expr_symbol_where to see if this is an expression
4987 if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline))
4988 as_bad_where (fixp->fx_file, fixp->fx_line,
4989 _("unresolved expression that must be resolved"));
4991 as_bad_where (fixp->fx_file, fixp->fx_line,
4992 _("unsupported relocation type"));
5000 ppc_elf_validate_fix (fixp, seg);
5002 switch (fixp->fx_r_type)
5005 case BFD_RELOC_CTOR:
5007 fixp->fx_r_type = BFD_RELOC_32_PCREL;
5011 case BFD_RELOC_32_PCREL:
5012 case BFD_RELOC_32_BASEREL:
5013 case BFD_RELOC_PPC_EMB_NADDR32:
5014 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5020 fixp->fx_r_type = BFD_RELOC_64_PCREL;
5022 case BFD_RELOC_64_PCREL:
5023 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5026 case BFD_RELOC_LO16:
5028 case BFD_RELOC_GPREL16:
5029 case BFD_RELOC_16_GOT_PCREL:
5030 case BFD_RELOC_16_GOTOFF:
5031 case BFD_RELOC_LO16_GOTOFF:
5032 case BFD_RELOC_HI16_GOTOFF:
5033 case BFD_RELOC_HI16_S_GOTOFF:
5034 case BFD_RELOC_LO16_BASEREL:
5035 case BFD_RELOC_HI16_BASEREL:
5036 case BFD_RELOC_HI16_S_BASEREL:
5037 case BFD_RELOC_PPC_EMB_NADDR16:
5038 case BFD_RELOC_PPC_EMB_NADDR16_LO:
5039 case BFD_RELOC_PPC_EMB_NADDR16_HI:
5040 case BFD_RELOC_PPC_EMB_NADDR16_HA:
5041 case BFD_RELOC_PPC_EMB_SDAI16:
5042 case BFD_RELOC_PPC_EMB_SDA2REL:
5043 case BFD_RELOC_PPC_EMB_SDA2I16:
5044 case BFD_RELOC_PPC_EMB_RELSEC16:
5045 case BFD_RELOC_PPC_EMB_RELST_LO:
5046 case BFD_RELOC_PPC_EMB_RELST_HI:
5047 case BFD_RELOC_PPC_EMB_RELST_HA:
5048 case BFD_RELOC_PPC_EMB_RELSDA:
5049 case BFD_RELOC_PPC_TOC16:
5052 if (fixp->fx_addsy != NULL)
5053 as_bad_where (fixp->fx_file, fixp->fx_line,
5054 _("cannot emit PC relative %s relocation against %s"),
5055 bfd_get_reloc_code_name (fixp->fx_r_type),
5056 S_GET_NAME (fixp->fx_addsy));
5058 as_bad_where (fixp->fx_file, fixp->fx_line,
5059 _("cannot emit PC relative %s relocation"),
5060 bfd_get_reloc_code_name (fixp->fx_r_type));
5063 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5067 /* This case happens when you write, for example,
5069 where L1 and L2 are defined later. */
5070 case BFD_RELOC_HI16:
5073 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5076 case BFD_RELOC_HI16_S:
5079 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5080 (value + 0x8000) >> 16, 2);
5083 /* Because SDA21 modifies the register field, the size is set to 4
5084 bytes, rather than 2, so offset it here appropriately. */
5085 case BFD_RELOC_PPC_EMB_SDA21:
5089 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where
5090 + ((target_big_endian) ? 2 : 0),
5098 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5102 case BFD_RELOC_24_PLT_PCREL:
5103 case BFD_RELOC_PPC_LOCAL24PC:
5104 if (!fixp->fx_pcrel && !fixp->fx_done)
5112 /* Fetch the instruction, insert the fully resolved operand
5113 value, and stuff the instruction back again. */
5114 where = fixp->fx_frag->fr_literal + fixp->fx_where;
5115 if (target_big_endian)
5116 insn = bfd_getb32 ((unsigned char *) where);
5118 insn = bfd_getl32 ((unsigned char *) where);
5119 if ((value & 3) != 0)
5120 as_bad_where (fixp->fx_file, fixp->fx_line,
5121 _("must branch to an address a multiple of 4"));
5122 if ((offsetT) value < -0x40000000
5123 || (offsetT) value >= 0x40000000)
5124 as_bad_where (fixp->fx_file, fixp->fx_line,
5125 _("@local or @plt branch destination is too far away, %ld bytes"),
5127 insn = insn | (value & 0x03fffffc);
5128 if (target_big_endian)
5129 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5131 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5135 case BFD_RELOC_VTABLE_INHERIT:
5138 && !S_IS_DEFINED (fixp->fx_addsy)
5139 && !S_IS_WEAK (fixp->fx_addsy))
5140 S_SET_WEAK (fixp->fx_addsy);
5143 case BFD_RELOC_VTABLE_ENTRY:
5149 _("Gas failure, reloc value %d\n"), fixp->fx_r_type);
5156 fixp->fx_addnumber = value;
5158 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
5159 fixp->fx_addnumber = 0;
5163 fixp->fx_addnumber = 0;
5165 /* We want to use the offset within the data segment of the
5166 symbol, not the actual VMA of the symbol. */
5167 fixp->fx_addnumber =
5168 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
5176 /* Generate a reloc for a fixup. */
5179 tc_gen_reloc (seg, fixp)
5180 asection *seg ATTRIBUTE_UNUSED;
5185 reloc = (arelent *) xmalloc (sizeof (arelent));
5187 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
5188 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
5189 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
5190 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
5191 if (reloc->howto == (reloc_howto_type *) NULL)
5193 as_bad_where (fixp->fx_file, fixp->fx_line,
5194 _("reloc %d not supported by object file format"),
5195 (int) fixp->fx_r_type);
5198 reloc->addend = fixp->fx_addnumber;