1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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
25 #include "safe-ctype.h"
27 #include "dw2gencfi.h"
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 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
59 /* #lo(value) denotes the least significant 16 bits of the indicated. */
60 #define PPC_LO(v) ((v) & 0xffff)
62 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
63 #define PPC_HI(v) (((v) >> 16) & 0xffff)
65 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
66 the indicated value, compensating for #lo() being treated as a
68 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
70 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
71 #define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
73 /* #highera(value) denotes bits 32 through 47 of the indicated value,
74 compensating for #lo() being treated as a signed number. */
75 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
77 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
78 #define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
80 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
81 compensating for #lo being treated as a signed number. */
82 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
84 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
86 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
88 static bfd_boolean register_name PARAMS ((expressionS *));
89 static void ppc_set_cpu PARAMS ((void));
90 static unsigned long ppc_insert_operand
91 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
92 offsetT val, char *file, unsigned int line));
93 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
94 static void ppc_byte PARAMS ((int));
96 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
97 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
98 static void ppc_tc PARAMS ((int));
99 static void ppc_machine PARAMS ((int));
103 static void ppc_comm PARAMS ((int));
104 static void ppc_bb PARAMS ((int));
105 static void ppc_bc PARAMS ((int));
106 static void ppc_bf PARAMS ((int));
107 static void ppc_biei PARAMS ((int));
108 static void ppc_bs PARAMS ((int));
109 static void ppc_eb PARAMS ((int));
110 static void ppc_ec PARAMS ((int));
111 static void ppc_ef PARAMS ((int));
112 static void ppc_es PARAMS ((int));
113 static void ppc_csect PARAMS ((int));
114 static void ppc_change_csect PARAMS ((symbolS *, offsetT));
115 static void ppc_function PARAMS ((int));
116 static void ppc_extern PARAMS ((int));
117 static void ppc_lglobl PARAMS ((int));
118 static void ppc_section PARAMS ((int));
119 static void ppc_named_section PARAMS ((int));
120 static void ppc_stabx PARAMS ((int));
121 static void ppc_rename PARAMS ((int));
122 static void ppc_toc PARAMS ((int));
123 static void ppc_xcoff_cons PARAMS ((int));
124 static void ppc_vbyte PARAMS ((int));
128 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
129 static void ppc_elf_cons PARAMS ((int));
130 static void ppc_elf_rdata PARAMS ((int));
131 static void ppc_elf_lcomm PARAMS ((int));
132 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
133 static void ppc_apuinfo_section_add PARAMS ((unsigned int apu, unsigned int version));
137 static void ppc_set_current_section PARAMS ((segT));
138 static void ppc_previous PARAMS ((int));
139 static void ppc_pdata PARAMS ((int));
140 static void ppc_ydata PARAMS ((int));
141 static void ppc_reldata PARAMS ((int));
142 static void ppc_rdata PARAMS ((int));
143 static void ppc_ualong PARAMS ((int));
144 static void ppc_znop PARAMS ((int));
145 static void ppc_pe_comm PARAMS ((int));
146 static void ppc_pe_section PARAMS ((int));
147 static void ppc_pe_function PARAMS ((int));
148 static void ppc_pe_tocd PARAMS ((int));
151 /* Generic assembler global variables which must be defined by all
155 /* This string holds the chars that always start a comment. If the
156 pre-processor is disabled, these aren't very useful. The macro
157 tc_comment_chars points to this. We use this, rather than the
158 usual comment_chars, so that we can switch for Solaris conventions. */
159 static const char ppc_solaris_comment_chars[] = "#!";
160 static const char ppc_eabi_comment_chars[] = "#";
162 #ifdef TARGET_SOLARIS_COMMENT
163 const char *ppc_comment_chars = ppc_solaris_comment_chars;
165 const char *ppc_comment_chars = ppc_eabi_comment_chars;
168 const char comment_chars[] = "#";
171 /* Characters which start a comment at the beginning of a line. */
172 const char line_comment_chars[] = "#";
174 /* Characters which may be used to separate multiple commands on a
176 const char line_separator_chars[] = ";";
178 /* Characters which are used to indicate an exponent in a floating
180 const char EXP_CHARS[] = "eE";
182 /* Characters which mean that a number is a floating point constant,
184 const char FLT_CHARS[] = "dD";
186 /* '+' and '-' can be used as postfix predicate predictors for conditional
187 branches. So they need to be accepted as symbol characters. */
188 const char ppc_symbol_chars[] = "+-";
190 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
191 int ppc_cie_data_alignment;
193 /* The target specific pseudo-ops which we support. */
195 const pseudo_typeS md_pseudo_table[] =
197 /* Pseudo-ops which must be overridden. */
198 { "byte", ppc_byte, 0 },
201 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
202 legitimately belong in the obj-*.c file. However, XCOFF is based
203 on COFF, and is only implemented for the RS/6000. We just use
204 obj-coff.c, and add what we need here. */
205 { "comm", ppc_comm, 0 },
206 { "lcomm", ppc_comm, 1 },
210 { "bi", ppc_biei, 0 },
212 { "csect", ppc_csect, 0 },
213 { "data", ppc_section, 'd' },
217 { "ei", ppc_biei, 1 },
219 { "extern", ppc_extern, 0 },
220 { "function", ppc_function, 0 },
221 { "lglobl", ppc_lglobl, 0 },
222 { "rename", ppc_rename, 0 },
223 { "section", ppc_named_section, 0 },
224 { "stabx", ppc_stabx, 0 },
225 { "text", ppc_section, 't' },
226 { "toc", ppc_toc, 0 },
227 { "long", ppc_xcoff_cons, 2 },
228 { "llong", ppc_xcoff_cons, 3 },
229 { "word", ppc_xcoff_cons, 1 },
230 { "short", ppc_xcoff_cons, 1 },
231 { "vbyte", ppc_vbyte, 0 },
235 { "llong", ppc_elf_cons, 8 },
236 { "quad", ppc_elf_cons, 8 },
237 { "long", ppc_elf_cons, 4 },
238 { "word", ppc_elf_cons, 2 },
239 { "short", ppc_elf_cons, 2 },
240 { "rdata", ppc_elf_rdata, 0 },
241 { "rodata", ppc_elf_rdata, 0 },
242 { "lcomm", ppc_elf_lcomm, 0 },
246 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
247 { "previous", ppc_previous, 0 },
248 { "pdata", ppc_pdata, 0 },
249 { "ydata", ppc_ydata, 0 },
250 { "reldata", ppc_reldata, 0 },
251 { "rdata", ppc_rdata, 0 },
252 { "ualong", ppc_ualong, 0 },
253 { "znop", ppc_znop, 0 },
254 { "comm", ppc_pe_comm, 0 },
255 { "lcomm", ppc_pe_comm, 1 },
256 { "section", ppc_pe_section, 0 },
257 { "function", ppc_pe_function,0 },
258 { "tocd", ppc_pe_tocd, 0 },
261 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
263 { "machine", ppc_machine, 0 },
270 /* Predefined register names if -mregnames (or default for Windows NT).
271 In general, there are lots of them, in an attempt to be compatible
272 with a number of other Windows NT assemblers. */
274 /* Structure to hold information about predefined registers. */
281 /* List of registers that are pre-defined:
283 Each general register has predefined names of the form:
284 1. r<reg_num> which has the value <reg_num>.
285 2. r.<reg_num> which has the value <reg_num>.
287 Each floating point register has predefined names of the form:
288 1. f<reg_num> which has the value <reg_num>.
289 2. f.<reg_num> which has the value <reg_num>.
291 Each vector unit register has predefined names of the form:
292 1. v<reg_num> which has the value <reg_num>.
293 2. v.<reg_num> which has the value <reg_num>.
295 Each condition register has predefined names of the form:
296 1. cr<reg_num> which has the value <reg_num>.
297 2. cr.<reg_num> which has the value <reg_num>.
299 There are individual registers as well:
300 sp or r.sp has the value 1
301 rtoc or r.toc has the value 2
302 fpscr has the value 0
308 dsisr has the value 18
310 sdr1 has the value 25
311 srr0 has the value 26
312 srr1 has the value 27
314 The table is sorted. Suitable for searching by a binary search. */
316 static const struct pd_reg pre_defined_registers[] =
318 { "cr.0", 0 }, /* Condition Registers */
338 { "dar", 19 }, /* Data Access Register */
339 { "dec", 22 }, /* Decrementer */
340 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
342 { "f.0", 0 }, /* Floating point registers */
410 { "lr", 8 }, /* Link Register */
414 { "r.0", 0 }, /* General Purpose Registers */
447 { "r.sp", 1 }, /* Stack Pointer */
449 { "r.toc", 2 }, /* Pointer to the table of contents */
451 { "r0", 0 }, /* More general purpose registers */
484 { "rtoc", 2 }, /* Table of contents */
486 { "sdr1", 25 }, /* Storage Description Register 1 */
490 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
491 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
493 { "v.0", 0 }, /* Vector registers */
563 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
565 /* Given NAME, find the register number associated with that name, return
566 the integer value associated with the given name or -1 on failure. */
568 static int reg_name_search
569 PARAMS ((const struct pd_reg *, int, const char * name));
572 reg_name_search (regs, regcount, name)
573 const struct pd_reg *regs;
577 int middle, low, high;
585 middle = (low + high) / 2;
586 cmp = strcasecmp (name, regs[middle].name);
592 return regs[middle].value;
600 * Summary of register_name.
602 * in: Input_line_pointer points to 1st char of operand.
604 * out: A expressionS.
605 * The operand may have been a register: in this case, X_op == O_register,
606 * X_add_number is set to the register number, and truth is returned.
607 * Input_line_pointer->(next non-blank) char after operand, or is in its
612 register_name (expressionP)
613 expressionS *expressionP;
620 /* Find the spelling of the operand. */
621 start = name = input_line_pointer;
622 if (name[0] == '%' && ISALPHA (name[1]))
623 name = ++input_line_pointer;
625 else if (!reg_names_p || !ISALPHA (name[0]))
628 c = get_symbol_end ();
629 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
631 /* Put back the delimiting char. */
632 *input_line_pointer = c;
634 /* Look to see if it's in the register table. */
637 expressionP->X_op = O_register;
638 expressionP->X_add_number = reg_number;
640 /* Make the rest nice. */
641 expressionP->X_add_symbol = NULL;
642 expressionP->X_op_symbol = NULL;
646 /* Reset the line as if we had not done anything. */
647 input_line_pointer = start;
651 /* This function is called for each symbol seen in an expression. It
652 handles the special parsing which PowerPC assemblers are supposed
653 to use for condition codes. */
655 /* Whether to do the special parsing. */
656 static bfd_boolean cr_operand;
658 /* Names to recognize in a condition code. This table is sorted. */
659 static const struct pd_reg cr_names[] =
676 /* Parsing function. This returns non-zero if it recognized an
680 ppc_parse_name (name, expr)
689 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
694 expr->X_op = O_constant;
695 expr->X_add_number = val;
700 /* Local variables. */
702 /* The type of processor we are assembling for. This is one or more
703 of the PPC_OPCODE flags defined in opcode/ppc.h. */
704 static unsigned long ppc_cpu = 0;
706 /* Whether to target xcoff64/elf64. */
707 static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
709 /* Opcode hash table. */
710 static struct hash_control *ppc_hash;
712 /* Macro hash table. */
713 static struct hash_control *ppc_macro_hash;
716 /* What type of shared library support to use. */
717 static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE;
719 /* Flags to set in the elf header. */
720 static flagword ppc_flags = 0;
722 /* Whether this is Solaris or not. */
723 #ifdef TARGET_SOLARIS_COMMENT
724 #define SOLARIS_P TRUE
726 #define SOLARIS_P FALSE
729 static bfd_boolean msolaris = SOLARIS_P;
734 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
735 using a bunch of different sections. These assembler sections,
736 however, are all encompassed within the .text or .data sections of
737 the final output file. We handle this by using different
738 subsegments within these main segments. */
740 /* Next subsegment to allocate within the .text segment. */
741 static subsegT ppc_text_subsegment = 2;
743 /* Linked list of csects in the text section. */
744 static symbolS *ppc_text_csects;
746 /* Next subsegment to allocate within the .data segment. */
747 static subsegT ppc_data_subsegment = 2;
749 /* Linked list of csects in the data section. */
750 static symbolS *ppc_data_csects;
752 /* The current csect. */
753 static symbolS *ppc_current_csect;
755 /* The RS/6000 assembler uses a TOC which holds addresses of functions
756 and variables. Symbols are put in the TOC with the .tc pseudo-op.
757 A special relocation is used when accessing TOC entries. We handle
758 the TOC as a subsegment within the .data segment. We set it up if
759 we see a .toc pseudo-op, and save the csect symbol here. */
760 static symbolS *ppc_toc_csect;
762 /* The first frag in the TOC subsegment. */
763 static fragS *ppc_toc_frag;
765 /* The first frag in the first subsegment after the TOC in the .data
766 segment. NULL if there are no subsegments after the TOC. */
767 static fragS *ppc_after_toc_frag;
769 /* The current static block. */
770 static symbolS *ppc_current_block;
772 /* The COFF debugging section; set by md_begin. This is not the
773 .debug section, but is instead the secret BFD section which will
774 cause BFD to set the section number of a symbol to N_DEBUG. */
775 static asection *ppc_coff_debug_section;
777 #endif /* OBJ_XCOFF */
781 /* Various sections that we need for PE coff support. */
782 static segT ydata_section;
783 static segT pdata_section;
784 static segT reldata_section;
785 static segT rdata_section;
786 static segT tocdata_section;
788 /* The current section and the previous section. See ppc_previous. */
789 static segT ppc_previous_section;
790 static segT ppc_current_section;
795 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
796 #define PPC_APUINFO_ISEL 0x40
797 #define PPC_APUINFO_PMR 0x41
798 #define PPC_APUINFO_RFMCI 0x42
799 #define PPC_APUINFO_CACHELCK 0x43
800 #define PPC_APUINFO_SPE 0x100
801 #define PPC_APUINFO_EFS 0x101
802 #define PPC_APUINFO_BRLOCK 0x102
805 * We keep a list of APUinfo
807 unsigned long *ppc_apuinfo_list;
808 unsigned int ppc_apuinfo_num;
809 unsigned int ppc_apuinfo_num_alloc;
813 const char *const md_shortopts = "b:l:usm:K:VQ:";
815 const char *const md_shortopts = "um:";
817 const struct option md_longopts[] = {
818 {NULL, no_argument, NULL, 0}
820 const size_t md_longopts_size = sizeof (md_longopts);
823 md_parse_option (c, arg)
830 /* -u means that any undefined symbols should be treated as
831 external, which is the default for gas anyhow. */
836 /* Solaris as takes -le (presumably for little endian). For completeness
837 sake, recognize -be also. */
838 if (strcmp (arg, "e") == 0)
840 target_big_endian = 0;
841 set_target_endian = 1;
849 if (strcmp (arg, "e") == 0)
851 target_big_endian = 1;
852 set_target_endian = 1;
860 /* Recognize -K PIC. */
861 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
864 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
872 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
874 if (strcmp (arg, "64") == 0)
879 as_fatal (_("%s unsupported"), "-a64");
882 else if (strcmp (arg, "32") == 0)
889 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
891 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
892 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2 | PPC_OPCODE_32;
893 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
894 else if (strcmp (arg, "pwr") == 0)
895 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_32;
896 /* -m601 means to assemble for the PowerPC 601, which includes
897 instructions that are holdovers from the Power. */
898 else if (strcmp (arg, "601") == 0)
899 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
900 | PPC_OPCODE_601 | PPC_OPCODE_32);
901 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
903 else if (strcmp (arg, "ppc") == 0
904 || strcmp (arg, "ppc32") == 0
905 || strcmp (arg, "603") == 0
906 || strcmp (arg, "604") == 0)
907 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_32;
908 /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */
909 else if (strcmp (arg, "403") == 0
910 || strcmp (arg, "405") == 0)
911 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
912 | PPC_OPCODE_403 | PPC_OPCODE_32);
913 else if (strcmp (arg, "440") == 0)
914 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | PPC_OPCODE_32
916 else if (strcmp (arg, "7400") == 0
917 || strcmp (arg, "7410") == 0
918 || strcmp (arg, "7450") == 0
919 || strcmp (arg, "7455") == 0)
920 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
921 | PPC_OPCODE_ALTIVEC | PPC_OPCODE_32);
922 else if (strcmp (arg, "altivec") == 0)
925 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_ALTIVEC;
927 ppc_cpu |= PPC_OPCODE_ALTIVEC;
929 else if (strcmp (arg, "e500") == 0 || strcmp (arg, "e500x2") == 0)
931 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | PPC_OPCODE_SPE
932 | PPC_OPCODE_ISEL | PPC_OPCODE_EFS | PPC_OPCODE_BRLOCK
933 | PPC_OPCODE_PMR | PPC_OPCODE_CACHELCK
936 else if (strcmp (arg, "spe") == 0)
939 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_SPE | PPC_OPCODE_EFS;
941 ppc_cpu |= PPC_OPCODE_SPE;
943 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
945 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
947 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_64;
949 else if (strcmp (arg, "ppc64bridge") == 0)
951 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
952 | PPC_OPCODE_64_BRIDGE | PPC_OPCODE_64);
954 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
955 else if (strcmp (arg, "booke") == 0 || strcmp (arg, "booke32") == 0)
957 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | PPC_OPCODE_32;
959 /* -mbooke64 means enable 64-bit BookE support. */
960 else if (strcmp (arg, "booke64") == 0)
962 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_BOOKE
963 | PPC_OPCODE_BOOKE64 | PPC_OPCODE_64);
965 else if (strcmp (arg, "power4") == 0)
967 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
968 | PPC_OPCODE_64 | PPC_OPCODE_POWER4);
970 /* -mcom means assemble for the common intersection between Power
971 and PowerPC. At present, we just allow the union, rather
972 than the intersection. */
973 else if (strcmp (arg, "com") == 0)
974 ppc_cpu = PPC_OPCODE_COMMON | PPC_OPCODE_32;
975 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
976 else if (strcmp (arg, "any") == 0)
977 ppc_cpu = PPC_OPCODE_ANY | PPC_OPCODE_32;
979 else if (strcmp (arg, "regnames") == 0)
982 else if (strcmp (arg, "no-regnames") == 0)
986 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
987 that require relocation. */
988 else if (strcmp (arg, "relocatable") == 0)
990 shlib = SHLIB_MRELOCATABLE;
991 ppc_flags |= EF_PPC_RELOCATABLE;
994 else if (strcmp (arg, "relocatable-lib") == 0)
996 shlib = SHLIB_MRELOCATABLE;
997 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
1000 /* -memb, set embedded bit. */
1001 else if (strcmp (arg, "emb") == 0)
1002 ppc_flags |= EF_PPC_EMB;
1004 /* -mlittle/-mbig set the endianess. */
1005 else if (strcmp (arg, "little") == 0
1006 || strcmp (arg, "little-endian") == 0)
1008 target_big_endian = 0;
1009 set_target_endian = 1;
1012 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
1014 target_big_endian = 1;
1015 set_target_endian = 1;
1018 else if (strcmp (arg, "solaris") == 0)
1021 ppc_comment_chars = ppc_solaris_comment_chars;
1024 else if (strcmp (arg, "no-solaris") == 0)
1027 ppc_comment_chars = ppc_eabi_comment_chars;
1032 as_bad (_("invalid switch -m%s"), arg);
1038 /* -V: SVR4 argument to print version ID. */
1040 print_version_id ();
1043 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1044 should be emitted or not. FIXME: Not implemented. */
1048 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1049 rather than .stabs.excl, which is ignored by the linker.
1050 FIXME: Not implemented. */
1066 md_show_usage (stream)
1069 fprintf (stream, _("\
1071 -a32 generate ELF32/XCOFF32\n\
1072 -a64 generate ELF64/XCOFF64\n\
1074 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1075 -mpwr generate code for POWER (RIOS1)\n\
1076 -m601 generate code for PowerPC 601\n\
1077 -mppc, -mppc32, -m603, -m604\n\
1078 generate code for PowerPC 603/604\n\
1079 -m403, -m405 generate code for PowerPC 403/405\n\
1080 -m440 generate code for PowerPC 440\n\
1081 -m7400, -m7410, -m7450, -m7455\n\
1082 generate code For PowerPC 7400/7410/7450/7455\n"));
1083 fprintf (stream, _("\
1084 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1085 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1086 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1087 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1088 -mpower4 generate code for Power4 architecture\n\
1089 -mcom generate code Power/PowerPC common instructions\n\
1090 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1091 fprintf (stream, _("\
1092 -maltivec generate code for AltiVec\n\
1093 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1094 -mspe generate code for Motorola SPE instructions\n\
1095 -mregnames Allow symbolic names for registers\n\
1096 -mno-regnames Do not allow symbolic names for registers\n"));
1098 fprintf (stream, _("\
1099 -mrelocatable support for GCC's -mrelocatble option\n\
1100 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1101 -memb set PPC_EMB bit in ELF flags\n\
1102 -mlittle, -mlittle-endian, -l, -le\n\
1103 generate code for a little endian machine\n\
1104 -mbig, -mbig-endian, -b, -be\n\
1105 generate code for a big endian machine\n\
1106 -msolaris generate code for Solaris\n\
1107 -mno-solaris do not generate code for Solaris\n\
1108 -V print assembler version number\n\
1109 -Qy, -Qn ignored\n"));
1113 /* Set ppc_cpu if it is not already set. */
1118 const char *default_os = TARGET_OS;
1119 const char *default_cpu = TARGET_CPU;
1124 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_64;
1125 else if (strncmp (default_os, "aix", 3) == 0
1126 && default_os[3] >= '4' && default_os[3] <= '9')
1127 ppc_cpu = PPC_OPCODE_COMMON | PPC_OPCODE_32;
1128 else if (strncmp (default_os, "aix3", 4) == 0)
1129 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_32;
1130 else if (strcmp (default_cpu, "rs6000") == 0)
1131 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_32;
1132 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1134 if (default_cpu[7] == '6' && default_cpu[8] == '4')
1135 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_64;
1137 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_32;
1140 as_fatal (_("Unknown default cpu = %s, os = %s"),
1141 default_cpu, default_os);
1145 /* Figure out the BFD architecture to use. */
1147 enum bfd_architecture
1150 const char *default_cpu = TARGET_CPU;
1153 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
1154 return bfd_arch_powerpc;
1155 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
1156 return bfd_arch_rs6000;
1157 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
1159 if (strcmp (default_cpu, "rs6000") == 0)
1160 return bfd_arch_rs6000;
1161 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1162 return bfd_arch_powerpc;
1165 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1166 return bfd_arch_unknown;
1173 return bfd_mach_ppc64;
1174 else if (ppc_arch () == bfd_arch_rs6000)
1175 return bfd_mach_rs6k;
1177 return bfd_mach_ppc;
1181 ppc_target_format ()
1185 return target_big_endian ? "pe-powerpc" : "pe-powerpcle";
1187 return "xcoff-powermac";
1190 return (ppc_obj64 ? "aix5coff64-rs6000" : "aixcoff-rs6000");
1192 return (ppc_obj64 ? "aixcoff64-rs6000" : "aixcoff-rs6000");
1197 return (target_big_endian
1198 ? (ppc_obj64 ? "elf64-powerpc" : "elf32-powerpc")
1199 : (ppc_obj64 ? "elf64-powerpcle" : "elf32-powerpcle"));
1203 /* This function is called when the assembler starts up. It is called
1204 after the options have been parsed and the output file has been
1210 register const struct powerpc_opcode *op;
1211 const struct powerpc_opcode *op_end;
1212 const struct powerpc_macro *macro;
1213 const struct powerpc_macro *macro_end;
1214 bfd_boolean dup_insn = FALSE;
1218 ppc_cie_data_alignment = ppc_obj64 ? -8 : -4;
1221 /* Set the ELF flags if desired. */
1222 if (ppc_flags && !msolaris)
1223 bfd_set_private_flags (stdoutput, ppc_flags);
1226 /* Insert the opcodes into a hash table. */
1227 ppc_hash = hash_new ();
1229 op_end = powerpc_opcodes + powerpc_num_opcodes;
1230 for (op = powerpc_opcodes; op < op_end; op++)
1232 know ((op->opcode & op->mask) == op->opcode);
1234 if ((op->flags & ppc_cpu & ~(PPC_OPCODE_32 | PPC_OPCODE_64)) != 0
1235 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
1236 || ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64))
1237 == (ppc_cpu & (PPC_OPCODE_32 | PPC_OPCODE_64)))
1238 || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0)
1239 /* Certain instructions (eg: extsw) do not exist in the
1240 32-bit BookE instruction set, but they do exist in the
1241 64-bit BookE instruction set, and other PPC instruction
1242 sets. Check to see if the opcode has the BOOKE64 flag set.
1243 If it does make sure that the target CPU is not the BookE32. */
1244 && ((op->flags & PPC_OPCODE_BOOKE64) == 0
1245 || (ppc_cpu & PPC_OPCODE_BOOKE64) == PPC_OPCODE_BOOKE64
1246 || (ppc_cpu & PPC_OPCODE_BOOKE) == 0)
1247 && ((op->flags & (PPC_OPCODE_POWER4 | PPC_OPCODE_NOPOWER4)) == 0
1248 || ((op->flags & PPC_OPCODE_POWER4)
1249 == (ppc_cpu & PPC_OPCODE_POWER4))))
1253 retval = hash_insert (ppc_hash, op->name, (PTR) op);
1254 if (retval != (const char *) NULL)
1256 /* Ignore Power duplicates for -m601. */
1257 if ((ppc_cpu & PPC_OPCODE_601) != 0
1258 && (op->flags & PPC_OPCODE_POWER) != 0)
1261 as_bad (_("Internal assembler error for instruction %s"),
1268 /* Insert the macros into a hash table. */
1269 ppc_macro_hash = hash_new ();
1271 macro_end = powerpc_macros + powerpc_num_macros;
1272 for (macro = powerpc_macros; macro < macro_end; macro++)
1274 if ((macro->flags & ppc_cpu) != 0)
1278 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1279 if (retval != (const char *) NULL)
1281 as_bad (_("Internal assembler error for macro %s"), macro->name);
1290 /* Tell the main code what the endianness is if it is not overidden
1292 if (!set_target_endian)
1294 set_target_endian = 1;
1295 target_big_endian = PPC_BIG_ENDIAN;
1299 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1301 /* Create dummy symbols to serve as initial csects. This forces the
1302 text csects to precede the data csects. These symbols will not
1304 ppc_text_csects = symbol_make ("dummy\001");
1305 symbol_get_tc (ppc_text_csects)->within = ppc_text_csects;
1306 ppc_data_csects = symbol_make ("dummy\001");
1307 symbol_get_tc (ppc_data_csects)->within = ppc_data_csects;
1312 ppc_current_section = text_section;
1313 ppc_previous_section = 0;
1322 if (ppc_apuinfo_list == NULL)
1325 /* Ok, so write the section info out. We have this layout:
1329 0 8 length of "APUinfo\0"
1330 4 (n*4) number of APU's (4 bytes each)
1333 20 APU#1 first APU's info
1334 24 APU#2 second APU's info
1339 asection *seg = now_seg;
1340 subsegT subseg = now_subseg;
1341 asection *apuinfo_secp = (asection *) NULL;
1344 /* Create the .PPC.EMB.apuinfo section. */
1345 apuinfo_secp = subseg_new (".PPC.EMB.apuinfo", 0);
1346 bfd_set_section_flags (stdoutput,
1348 SEC_HAS_CONTENTS | SEC_READONLY);
1351 md_number_to_chars (p, (valueT) 8, 4);
1354 md_number_to_chars (p, (valueT) ppc_apuinfo_num * 4, 4);
1357 md_number_to_chars (p, (valueT) 2, 4);
1360 strcpy (p, "APUinfo");
1362 for (i = 0; i < ppc_apuinfo_num; i++)
1365 md_number_to_chars (p, (valueT) ppc_apuinfo_list[i], 4);
1368 frag_align (2, 0, 0);
1370 /* We probably can't restore the current segment, for there likely
1373 subseg_set (seg, subseg);
1378 /* Insert an operand value into an instruction. */
1380 static unsigned long
1381 ppc_insert_operand (insn, operand, val, file, line)
1383 const struct powerpc_operand *operand;
1388 if (operand->bits != 32)
1393 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1395 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0)
1396 max = (1 << operand->bits) - 1;
1398 max = (1 << (operand->bits - 1)) - 1;
1399 min = - (1 << (operand->bits - 1));
1403 /* Some people write 32 bit hex constants with the sign
1404 extension done by hand. This shouldn't really be
1405 valid, but, to permit this code to assemble on a 64
1406 bit host, we sign extend the 32 bit value. */
1408 && (val & (offsetT) 0x80000000) != 0
1409 && (val & (offsetT) 0xffffffff) == val)
1418 max = (1 << operand->bits) - 1;
1422 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1427 if (test < (offsetT) min || test > (offsetT) max)
1430 _("operand out of range (%s not between %ld and %ld)");
1433 sprint_value (buf, test);
1434 as_bad_where (file, line, err, buf, min, max);
1438 if (operand->insert)
1443 insn = (*operand->insert) (insn, (long) val, ppc_cpu, &errmsg);
1444 if (errmsg != (const char *) NULL)
1445 as_bad_where (file, line, errmsg);
1448 insn |= (((long) val & ((1 << operand->bits) - 1))
1456 /* Parse @got, etc. and return the desired relocation. */
1457 static bfd_reloc_code_real_type
1458 ppc_elf_suffix (str_p, exp_p)
1473 const struct map_bfd *ptr;
1475 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1477 static const struct map_bfd mapping[] = {
1478 MAP ("l", (int) BFD_RELOC_LO16),
1479 MAP ("h", (int) BFD_RELOC_HI16),
1480 MAP ("ha", (int) BFD_RELOC_HI16_S),
1481 MAP ("brtaken", (int) BFD_RELOC_PPC_B16_BRTAKEN),
1482 MAP ("brntaken", (int) BFD_RELOC_PPC_B16_BRNTAKEN),
1483 MAP ("got", (int) BFD_RELOC_16_GOTOFF),
1484 MAP ("got@l", (int) BFD_RELOC_LO16_GOTOFF),
1485 MAP ("got@h", (int) BFD_RELOC_HI16_GOTOFF),
1486 MAP ("got@ha", (int) BFD_RELOC_HI16_S_GOTOFF),
1487 MAP ("fixup", (int) BFD_RELOC_CTOR),
1488 MAP ("plt", (int) BFD_RELOC_24_PLT_PCREL),
1489 MAP ("pltrel24", (int) BFD_RELOC_24_PLT_PCREL),
1490 MAP ("copy", (int) BFD_RELOC_PPC_COPY),
1491 MAP ("globdat", (int) BFD_RELOC_PPC_GLOB_DAT),
1492 MAP ("local24pc", (int) BFD_RELOC_PPC_LOCAL24PC),
1493 MAP ("local", (int) BFD_RELOC_PPC_LOCAL24PC),
1494 MAP ("pltrel", (int) BFD_RELOC_32_PLT_PCREL),
1495 MAP ("plt@l", (int) BFD_RELOC_LO16_PLTOFF),
1496 MAP ("plt@h", (int) BFD_RELOC_HI16_PLTOFF),
1497 MAP ("plt@ha", (int) BFD_RELOC_HI16_S_PLTOFF),
1498 MAP ("sdarel", (int) BFD_RELOC_GPREL16),
1499 MAP ("sectoff", (int) BFD_RELOC_16_BASEREL),
1500 MAP ("sectoff@l", (int) BFD_RELOC_LO16_BASEREL),
1501 MAP ("sectoff@h", (int) BFD_RELOC_HI16_BASEREL),
1502 MAP ("sectoff@ha", (int) BFD_RELOC_HI16_S_BASEREL),
1503 MAP ("naddr", (int) BFD_RELOC_PPC_EMB_NADDR32),
1504 MAP ("naddr16", (int) BFD_RELOC_PPC_EMB_NADDR16),
1505 MAP ("naddr@l", (int) BFD_RELOC_PPC_EMB_NADDR16_LO),
1506 MAP ("naddr@h", (int) BFD_RELOC_PPC_EMB_NADDR16_HI),
1507 MAP ("naddr@ha", (int) BFD_RELOC_PPC_EMB_NADDR16_HA),
1508 MAP ("sdai16", (int) BFD_RELOC_PPC_EMB_SDAI16),
1509 MAP ("sda2rel", (int) BFD_RELOC_PPC_EMB_SDA2REL),
1510 MAP ("sda2i16", (int) BFD_RELOC_PPC_EMB_SDA2I16),
1511 MAP ("sda21", (int) BFD_RELOC_PPC_EMB_SDA21),
1512 MAP ("mrkref", (int) BFD_RELOC_PPC_EMB_MRKREF),
1513 MAP ("relsect", (int) BFD_RELOC_PPC_EMB_RELSEC16),
1514 MAP ("relsect@l", (int) BFD_RELOC_PPC_EMB_RELST_LO),
1515 MAP ("relsect@h", (int) BFD_RELOC_PPC_EMB_RELST_HI),
1516 MAP ("relsect@ha", (int) BFD_RELOC_PPC_EMB_RELST_HA),
1517 MAP ("bitfld", (int) BFD_RELOC_PPC_EMB_BIT_FLD),
1518 MAP ("relsda", (int) BFD_RELOC_PPC_EMB_RELSDA),
1519 MAP ("xgot", (int) BFD_RELOC_PPC_TOC16),
1520 MAP ("tls", (int) BFD_RELOC_PPC_TLS),
1521 MAP ("dtpmod", (int) BFD_RELOC_PPC_DTPMOD),
1522 MAP ("dtprel", (int) BFD_RELOC_PPC_DTPREL),
1523 MAP ("dtprel@l", (int) BFD_RELOC_PPC_DTPREL16_LO),
1524 MAP ("dtprel@h", (int) BFD_RELOC_PPC_DTPREL16_HI),
1525 MAP ("dtprel@ha", (int) BFD_RELOC_PPC_DTPREL16_HA),
1526 MAP ("tprel", (int) BFD_RELOC_PPC_TPREL),
1527 MAP ("tprel@l", (int) BFD_RELOC_PPC_TPREL16_LO),
1528 MAP ("tprel@h", (int) BFD_RELOC_PPC_TPREL16_HI),
1529 MAP ("tprel@ha", (int) BFD_RELOC_PPC_TPREL16_HA),
1530 MAP ("got@tlsgd", (int) BFD_RELOC_PPC_GOT_TLSGD16),
1531 MAP ("got@tlsgd@l", (int) BFD_RELOC_PPC_GOT_TLSGD16_LO),
1532 MAP ("got@tlsgd@h", (int) BFD_RELOC_PPC_GOT_TLSGD16_HI),
1533 MAP ("got@tlsgd@ha", (int) BFD_RELOC_PPC_GOT_TLSGD16_HA),
1534 MAP ("got@tlsld", (int) BFD_RELOC_PPC_GOT_TLSLD16),
1535 MAP ("got@tlsld@l", (int) BFD_RELOC_PPC_GOT_TLSLD16_LO),
1536 MAP ("got@tlsld@h", (int) BFD_RELOC_PPC_GOT_TLSLD16_HI),
1537 MAP ("got@tlsld@ha", (int) BFD_RELOC_PPC_GOT_TLSLD16_HA),
1538 MAP ("got@dtprel", (int) BFD_RELOC_PPC_GOT_DTPREL16),
1539 MAP ("got@dtprel@l", (int) BFD_RELOC_PPC_GOT_DTPREL16_LO),
1540 MAP ("got@dtprel@h", (int) BFD_RELOC_PPC_GOT_DTPREL16_HI),
1541 MAP ("got@dtprel@ha", (int) BFD_RELOC_PPC_GOT_DTPREL16_HA),
1542 MAP ("got@tprel", (int) BFD_RELOC_PPC_GOT_TPREL16),
1543 MAP ("got@tprel@l", (int) BFD_RELOC_PPC_GOT_TPREL16_LO),
1544 MAP ("got@tprel@h", (int) BFD_RELOC_PPC_GOT_TPREL16_HI),
1545 MAP ("got@tprel@ha", (int) BFD_RELOC_PPC_GOT_TPREL16_HA),
1546 /* The following are only valid for ppc64. Negative values are
1547 used instead of a flag. */
1548 MAP ("higher", - (int) BFD_RELOC_PPC64_HIGHER),
1549 MAP ("highera", - (int) BFD_RELOC_PPC64_HIGHER_S),
1550 MAP ("highest", - (int) BFD_RELOC_PPC64_HIGHEST),
1551 MAP ("highesta", - (int) BFD_RELOC_PPC64_HIGHEST_S),
1552 MAP ("tocbase", - (int) BFD_RELOC_PPC64_TOC),
1553 MAP ("toc", - (int) BFD_RELOC_PPC_TOC16),
1554 MAP ("toc@l", - (int) BFD_RELOC_PPC64_TOC16_LO),
1555 MAP ("toc@h", - (int) BFD_RELOC_PPC64_TOC16_HI),
1556 MAP ("toc@ha", - (int) BFD_RELOC_PPC64_TOC16_HA),
1557 MAP ("dtprel@higher", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHER),
1558 MAP ("dtprel@highera", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHERA),
1559 MAP ("dtprel@highest", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHEST),
1560 MAP ("dtprel@highesta", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHESTA),
1561 MAP ("tprel@higher", - (int) BFD_RELOC_PPC64_TPREL16_HIGHER),
1562 MAP ("tprel@highera", - (int) BFD_RELOC_PPC64_TPREL16_HIGHERA),
1563 MAP ("tprel@highest", - (int) BFD_RELOC_PPC64_TPREL16_HIGHEST),
1564 MAP ("tprel@highesta", - (int) BFD_RELOC_PPC64_TPREL16_HIGHESTA),
1565 { (char *) 0, 0, (int) BFD_RELOC_UNUSED }
1569 return BFD_RELOC_UNUSED;
1571 for (ch = *str, str2 = ident;
1572 (str2 < ident + sizeof (ident) - 1
1573 && (ISALNUM (ch) || ch == '@'));
1576 *str2++ = TOLOWER (ch);
1583 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1584 if (ch == ptr->string[0]
1585 && len == ptr->length
1586 && memcmp (ident, ptr->string, ptr->length) == 0)
1588 int reloc = ptr->reloc;
1593 return BFD_RELOC_UNUSED;
1598 if (exp_p->X_add_number != 0
1599 && (reloc == (int) BFD_RELOC_16_GOTOFF
1600 || reloc == (int) BFD_RELOC_LO16_GOTOFF
1601 || reloc == (int) BFD_RELOC_HI16_GOTOFF
1602 || reloc == (int) BFD_RELOC_HI16_S_GOTOFF))
1603 as_warn (_("identifier+constant@got means identifier@got+constant"));
1605 /* Now check for identifier@suffix+constant. */
1606 if (*str == '-' || *str == '+')
1608 char *orig_line = input_line_pointer;
1609 expressionS new_exp;
1611 input_line_pointer = str;
1612 expression (&new_exp);
1613 if (new_exp.X_op == O_constant)
1615 exp_p->X_add_number += new_exp.X_add_number;
1616 str = input_line_pointer;
1619 if (&input_line_pointer != str_p)
1620 input_line_pointer = orig_line;
1624 if (reloc == (int) BFD_RELOC_PPC64_TOC
1625 && exp_p->X_op == O_symbol
1626 && strcmp (S_GET_NAME (exp_p->X_add_symbol), ".TOC.") == 0)
1628 /* Change the symbol so that the dummy .TOC. symbol can be
1629 omitted from the object file. */
1630 exp_p->X_add_symbol = &abs_symbol;
1633 return (bfd_reloc_code_real_type) reloc;
1636 return BFD_RELOC_UNUSED;
1639 /* Like normal .long/.short/.word, except support @got, etc.
1640 Clobbers input_line_pointer, checks end-of-line. */
1642 ppc_elf_cons (nbytes)
1643 register int nbytes; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1646 bfd_reloc_code_real_type reloc;
1648 if (is_it_end_of_statement ())
1650 demand_empty_rest_of_line ();
1657 if (exp.X_op == O_symbol
1658 && *input_line_pointer == '@'
1659 && (reloc = ppc_elf_suffix (&input_line_pointer,
1660 &exp)) != BFD_RELOC_UNUSED)
1662 reloc_howto_type *reloc_howto;
1665 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1666 size = bfd_get_reloc_size (reloc_howto);
1670 as_bad (_("%s relocations do not fit in %d bytes\n"),
1671 reloc_howto->name, nbytes);
1678 p = frag_more (nbytes);
1680 if (target_big_endian)
1681 offset = nbytes - size;
1682 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
1687 emit_expr (&exp, (unsigned int) nbytes);
1689 while (*input_line_pointer++ == ',');
1691 /* Put terminator back into stream. */
1692 input_line_pointer--;
1693 demand_empty_rest_of_line ();
1696 /* Solaris pseduo op to change to the .rodata section. */
1701 char *save_line = input_line_pointer;
1702 static char section[] = ".rodata\n";
1704 /* Just pretend this is .section .rodata */
1705 input_line_pointer = section;
1706 obj_elf_section (xxx);
1708 input_line_pointer = save_line;
1711 /* Pseudo op to make file scope bss items. */
1714 int xxx ATTRIBUTE_UNUSED;
1716 register char *name;
1720 register symbolS *symbolP;
1727 name = input_line_pointer;
1728 c = get_symbol_end ();
1730 /* just after name is now '\0'. */
1731 p = input_line_pointer;
1734 if (*input_line_pointer != ',')
1736 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1737 ignore_rest_of_line ();
1741 input_line_pointer++; /* skip ',' */
1742 if ((size = get_absolute_expression ()) < 0)
1744 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
1745 ignore_rest_of_line ();
1749 /* The third argument to .lcomm is the alignment. */
1750 if (*input_line_pointer != ',')
1754 ++input_line_pointer;
1755 align = get_absolute_expression ();
1758 as_warn (_("ignoring bad alignment"));
1764 symbolP = symbol_find_or_make (name);
1767 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1769 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1770 S_GET_NAME (symbolP));
1771 ignore_rest_of_line ();
1775 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1777 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1778 S_GET_NAME (symbolP),
1779 (long) S_GET_VALUE (symbolP),
1782 ignore_rest_of_line ();
1788 old_subsec = now_subseg;
1791 /* Convert to a power of 2 alignment. */
1792 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1795 as_bad (_("Common alignment not a power of 2"));
1796 ignore_rest_of_line ();
1803 record_alignment (bss_section, align2);
1804 subseg_set (bss_section, 0);
1806 frag_align (align2, 0, 0);
1807 if (S_GET_SEGMENT (symbolP) == bss_section)
1808 symbol_get_frag (symbolP)->fr_symbol = 0;
1809 symbol_set_frag (symbolP, frag_now);
1810 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1813 S_SET_SIZE (symbolP, size);
1814 S_SET_SEGMENT (symbolP, bss_section);
1815 subseg_set (old_sec, old_subsec);
1816 demand_empty_rest_of_line ();
1819 /* Validate any relocations emitted for -mrelocatable, possibly adding
1820 fixups for word relocations in writable segments, so we can adjust
1823 ppc_elf_validate_fix (fixp, seg)
1827 if (fixp->fx_done || fixp->fx_pcrel)
1836 case SHLIB_MRELOCATABLE:
1837 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1838 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1839 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1840 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1841 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1842 && fixp->fx_r_type != BFD_RELOC_16_BASEREL
1843 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1844 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1845 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1846 && (seg->flags & SEC_LOAD) != 0
1847 && strcmp (segment_name (seg), ".got2") != 0
1848 && strcmp (segment_name (seg), ".dtors") != 0
1849 && strcmp (segment_name (seg), ".ctors") != 0
1850 && strcmp (segment_name (seg), ".fixup") != 0
1851 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1852 && strcmp (segment_name (seg), ".eh_frame") != 0
1853 && strcmp (segment_name (seg), ".ex_shared") != 0)
1855 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1856 || fixp->fx_r_type != BFD_RELOC_CTOR)
1858 as_bad_where (fixp->fx_file, fixp->fx_line,
1859 _("Relocation cannot be done when using -mrelocatable"));
1866 /* Prevent elf_frob_file_before_adjust removing a weak undefined
1867 function descriptor sym if the corresponding code sym is used. */
1870 ppc_frob_file_before_adjust ()
1877 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
1884 name = S_GET_NAME (symp);
1888 if (! S_IS_WEAK (symp)
1889 || S_IS_DEFINED (symp))
1892 len = strlen (name) + 1;
1893 dotname = xmalloc (len + 1);
1895 memcpy (dotname + 1, name, len);
1896 dotsym = symbol_find (dotname);
1898 if (dotsym != NULL && (symbol_used_p (dotsym)
1899 || symbol_used_in_reloc_p (dotsym)))
1901 symbol_mark_used (symp);
1905 /* Don't emit .TOC. symbol. */
1906 symp = symbol_find (".TOC.");
1908 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
1910 #endif /* OBJ_ELF */
1915 * Summary of parse_toc_entry.
1917 * in: Input_line_pointer points to the '[' in one of:
1919 * [toc] [tocv] [toc32] [toc64]
1921 * Anything else is an error of one kind or another.
1924 * return value: success or failure
1925 * toc_kind: kind of toc reference
1926 * input_line_pointer:
1927 * success: first char after the ']'
1928 * failure: unchanged
1932 * [toc] - rv == success, toc_kind = default_toc
1933 * [tocv] - rv == success, toc_kind = data_in_toc
1934 * [toc32] - rv == success, toc_kind = must_be_32
1935 * [toc64] - rv == success, toc_kind = must_be_64
1939 enum toc_size_qualifier
1941 default_toc, /* The toc cell constructed should be the system default size */
1942 data_in_toc, /* This is a direct reference to a toc cell */
1943 must_be_32, /* The toc cell constructed must be 32 bits wide */
1944 must_be_64 /* The toc cell constructed must be 64 bits wide */
1948 parse_toc_entry (toc_kind)
1949 enum toc_size_qualifier *toc_kind;
1954 enum toc_size_qualifier t;
1956 /* Save the input_line_pointer. */
1957 start = input_line_pointer;
1959 /* Skip over the '[' , and whitespace. */
1960 ++input_line_pointer;
1963 /* Find the spelling of the operand. */
1964 toc_spec = input_line_pointer;
1965 c = get_symbol_end ();
1967 if (strcmp (toc_spec, "toc") == 0)
1971 else if (strcmp (toc_spec, "tocv") == 0)
1975 else if (strcmp (toc_spec, "toc32") == 0)
1979 else if (strcmp (toc_spec, "toc64") == 0)
1985 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
1986 *input_line_pointer = c;
1987 input_line_pointer = start;
1991 /* Now find the ']'. */
1992 *input_line_pointer = c;
1994 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1995 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1999 as_bad (_("syntax error: expected `]', found `%c'"), c);
2000 input_line_pointer = start;
2011 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2013 ppc_apuinfo_section_add (apu, version)
2014 unsigned int apu, version;
2018 /* Check we don't already exist. */
2019 for (i = 0; i < ppc_apuinfo_num; i++)
2020 if (ppc_apuinfo_list[i] == APUID (apu, version))
2023 if (ppc_apuinfo_num == ppc_apuinfo_num_alloc)
2025 if (ppc_apuinfo_num_alloc == 0)
2027 ppc_apuinfo_num_alloc = 4;
2028 ppc_apuinfo_list = (unsigned long *)
2029 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2033 ppc_apuinfo_num_alloc += 4;
2034 ppc_apuinfo_list = (unsigned long *) xrealloc (ppc_apuinfo_list,
2035 sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2038 ppc_apuinfo_list[ppc_apuinfo_num++] = APUID (apu, version);
2044 /* We need to keep a list of fixups. We can't simply generate them as
2045 we go, because that would require us to first create the frag, and
2046 that would screw up references to ``.''. */
2052 bfd_reloc_code_real_type reloc;
2055 #define MAX_INSN_FIXUPS (5)
2057 /* This routine is called for each instruction to be assembled. */
2064 const struct powerpc_opcode *opcode;
2066 const unsigned char *opindex_ptr;
2070 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
2075 bfd_reloc_code_real_type reloc;
2078 /* Get the opcode. */
2079 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
2084 /* Look up the opcode in the hash table. */
2085 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
2086 if (opcode == (const struct powerpc_opcode *) NULL)
2088 const struct powerpc_macro *macro;
2090 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
2091 if (macro == (const struct powerpc_macro *) NULL)
2092 as_bad (_("Unrecognized opcode: `%s'"), str);
2094 ppc_macro (s, macro);
2099 insn = opcode->opcode;
2102 while (ISSPACE (*str))
2105 /* PowerPC operands are just expressions. The only real issue is
2106 that a few operand types are optional. All cases which might use
2107 an optional operand separate the operands only with commas (in
2108 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
2109 cases never have optional operands). There is never more than
2110 one optional operand for an instruction. So, before we start
2111 seriously parsing the operands, we check to see if we have an
2112 optional operand, and, if we do, we count the number of commas to
2113 see whether the operand should be omitted. */
2115 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2117 const struct powerpc_operand *operand;
2119 operand = &powerpc_operands[*opindex_ptr];
2120 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
2122 unsigned int opcount;
2123 unsigned int num_operands_expected;
2126 /* There is an optional operand. Count the number of
2127 commas in the input line. */
2134 while ((s = strchr (s, ',')) != (char *) NULL)
2141 /* Compute the number of expected operands.
2142 Do not count fake operands. */
2143 for (num_operands_expected = 0, i = 0; opcode->operands[i]; i ++)
2144 if ((powerpc_operands [opcode->operands[i]].flags & PPC_OPERAND_FAKE) == 0)
2145 ++ num_operands_expected;
2147 /* If there are fewer operands in the line then are called
2148 for by the instruction, we want to skip the optional
2150 if (opcount < num_operands_expected)
2157 /* Gather the operands. */
2161 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2163 const struct powerpc_operand *operand;
2169 if (next_opindex == 0)
2170 operand = &powerpc_operands[*opindex_ptr];
2173 operand = &powerpc_operands[next_opindex];
2178 /* If this is a fake operand, then we do not expect anything
2180 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
2182 insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2183 if (errmsg != (const char *) NULL)
2188 /* If this is an optional operand, and we are skipping it, just
2190 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
2193 if (operand->insert)
2195 insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2196 if (errmsg != (const char *) NULL)
2199 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
2200 next_opindex = *opindex_ptr + 1;
2204 /* Gather the operand. */
2205 hold = input_line_pointer;
2206 input_line_pointer = str;
2209 if (*input_line_pointer == '[')
2211 /* We are expecting something like the second argument here:
2213 * lwz r4,[toc].GS.0.static_int(rtoc)
2214 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2215 * The argument following the `]' must be a symbol name, and the
2216 * register must be the toc register: 'rtoc' or '2'
2218 * The effect is to 0 as the displacement field
2219 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2220 * the appropriate variation) reloc against it based on the symbol.
2221 * The linker will build the toc, and insert the resolved toc offset.
2224 * o The size of the toc entry is currently assumed to be
2225 * 32 bits. This should not be assumed to be a hard coded
2227 * o In an effort to cope with a change from 32 to 64 bits,
2228 * there are also toc entries that are specified to be
2229 * either 32 or 64 bits:
2230 * lwz r4,[toc32].GS.0.static_int(rtoc)
2231 * lwz r4,[toc64].GS.0.static_int(rtoc)
2232 * These demand toc entries of the specified size, and the
2233 * instruction probably requires it.
2237 enum toc_size_qualifier toc_kind;
2238 bfd_reloc_code_real_type toc_reloc;
2240 /* Go parse off the [tocXX] part. */
2241 valid_toc = parse_toc_entry (&toc_kind);
2245 /* Note: message has already been issued.
2246 FIXME: what sort of recovery should we do?
2247 demand_rest_of_line (); return; ? */
2250 /* Now get the symbol following the ']'. */
2256 /* In this case, we may not have seen the symbol yet,
2257 since it is allowed to appear on a .extern or .globl
2258 or just be a label in the .data section. */
2259 toc_reloc = BFD_RELOC_PPC_TOC16;
2262 /* 1. The symbol must be defined and either in the toc
2263 section, or a global.
2264 2. The reloc generated must have the TOCDEFN flag set
2265 in upper bit mess of the reloc type.
2266 FIXME: It's a little confusing what the tocv
2267 qualifier can be used for. At the very least, I've
2268 seen three uses, only one of which I'm sure I can
2270 if (ex.X_op == O_symbol)
2272 assert (ex.X_add_symbol != NULL);
2273 if (symbol_get_bfdsym (ex.X_add_symbol)->section
2276 as_bad (_("[tocv] symbol is not a toc symbol"));
2280 toc_reloc = BFD_RELOC_PPC_TOC16;
2283 /* FIXME: these next two specifically specify 32/64 bit
2284 toc entries. We don't support them today. Is this
2285 the right way to say that? */
2286 toc_reloc = BFD_RELOC_UNUSED;
2287 as_bad (_("Unimplemented toc32 expression modifier"));
2290 /* FIXME: see above. */
2291 toc_reloc = BFD_RELOC_UNUSED;
2292 as_bad (_("Unimplemented toc64 expression modifier"));
2296 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2302 /* We need to generate a fixup for this expression. */
2303 if (fc >= MAX_INSN_FIXUPS)
2304 as_fatal (_("too many fixups"));
2306 fixups[fc].reloc = toc_reloc;
2307 fixups[fc].exp = ex;
2308 fixups[fc].opindex = *opindex_ptr;
2311 /* Ok. We've set up the fixup for the instruction. Now make it
2312 look like the constant 0 was found here. */
2314 ex.X_op = O_constant;
2315 ex.X_add_number = 0;
2316 ex.X_add_symbol = NULL;
2317 ex.X_op_symbol = NULL;
2323 if (! register_name (&ex))
2325 if ((operand->flags & PPC_OPERAND_CR) != 0)
2332 str = input_line_pointer;
2333 input_line_pointer = hold;
2335 if (ex.X_op == O_illegal)
2336 as_bad (_("illegal operand"));
2337 else if (ex.X_op == O_absent)
2338 as_bad (_("missing operand"));
2339 else if (ex.X_op == O_register)
2341 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2344 else if (ex.X_op == O_constant)
2347 /* Allow @HA, @L, @H on constants. */
2348 char *orig_str = str;
2350 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2357 case BFD_RELOC_LO16:
2358 /* X_unsigned is the default, so if the user has done
2359 something which cleared it, we always produce a
2361 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2362 ex.X_add_number &= 0xffff;
2364 ex.X_add_number = SEX16 (ex.X_add_number);
2367 case BFD_RELOC_HI16:
2368 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2369 ex.X_add_number = PPC_HI (ex.X_add_number);
2371 ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number));
2374 case BFD_RELOC_HI16_S:
2375 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2376 ex.X_add_number = PPC_HA (ex.X_add_number);
2378 ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number));
2381 case BFD_RELOC_PPC64_HIGHER:
2382 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2383 ex.X_add_number = PPC_HIGHER (ex.X_add_number);
2385 ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number));
2388 case BFD_RELOC_PPC64_HIGHER_S:
2389 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2390 ex.X_add_number = PPC_HIGHERA (ex.X_add_number);
2392 ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number));
2395 case BFD_RELOC_PPC64_HIGHEST:
2396 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2397 ex.X_add_number = PPC_HIGHEST (ex.X_add_number);
2399 ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number));
2402 case BFD_RELOC_PPC64_HIGHEST_S:
2403 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2404 ex.X_add_number = PPC_HIGHESTA (ex.X_add_number);
2406 ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number));
2409 #endif /* OBJ_ELF */
2410 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2414 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2416 /* Some TLS tweaks. */
2421 case BFD_RELOC_PPC_TLS:
2422 insn = ppc_insert_operand (insn, operand, ppc_obj64 ? 13 : 2,
2425 /* We'll only use the 32 (or 64) bit form of these relocations
2426 in constants. Instructions get the 16 bit form. */
2427 case BFD_RELOC_PPC_DTPREL:
2428 reloc = BFD_RELOC_PPC_DTPREL16;
2430 case BFD_RELOC_PPC_TPREL:
2431 reloc = BFD_RELOC_PPC_TPREL16;
2435 /* For the absolute forms of branches, convert the PC
2436 relative form back into the absolute. */
2437 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
2441 case BFD_RELOC_PPC_B26:
2442 reloc = BFD_RELOC_PPC_BA26;
2444 case BFD_RELOC_PPC_B16:
2445 reloc = BFD_RELOC_PPC_BA16;
2447 case BFD_RELOC_PPC_B16_BRTAKEN:
2448 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
2450 case BFD_RELOC_PPC_B16_BRNTAKEN:
2451 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
2459 && (operand->flags & (PPC_OPERAND_DS | PPC_OPERAND_DQ)) != 0)
2464 reloc = BFD_RELOC_PPC64_ADDR16_DS;
2466 case BFD_RELOC_LO16:
2467 reloc = BFD_RELOC_PPC64_ADDR16_LO_DS;
2469 case BFD_RELOC_16_GOTOFF:
2470 reloc = BFD_RELOC_PPC64_GOT16_DS;
2472 case BFD_RELOC_LO16_GOTOFF:
2473 reloc = BFD_RELOC_PPC64_GOT16_LO_DS;
2475 case BFD_RELOC_LO16_PLTOFF:
2476 reloc = BFD_RELOC_PPC64_PLT16_LO_DS;
2478 case BFD_RELOC_16_BASEREL:
2479 reloc = BFD_RELOC_PPC64_SECTOFF_DS;
2481 case BFD_RELOC_LO16_BASEREL:
2482 reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS;
2484 case BFD_RELOC_PPC_TOC16:
2485 reloc = BFD_RELOC_PPC64_TOC16_DS;
2487 case BFD_RELOC_PPC64_TOC16_LO:
2488 reloc = BFD_RELOC_PPC64_TOC16_LO_DS;
2490 case BFD_RELOC_PPC64_PLTGOT16:
2491 reloc = BFD_RELOC_PPC64_PLTGOT16_DS;
2493 case BFD_RELOC_PPC64_PLTGOT16_LO:
2494 reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS;
2496 case BFD_RELOC_PPC_DTPREL16:
2497 reloc = BFD_RELOC_PPC64_DTPREL16_DS;
2499 case BFD_RELOC_PPC_DTPREL16_LO:
2500 reloc = BFD_RELOC_PPC64_DTPREL16_LO_DS;
2502 case BFD_RELOC_PPC_TPREL16:
2503 reloc = BFD_RELOC_PPC64_TPREL16_DS;
2505 case BFD_RELOC_PPC_TPREL16_LO:
2506 reloc = BFD_RELOC_PPC64_TPREL16_LO_DS;
2508 case BFD_RELOC_PPC_GOT_DTPREL16:
2509 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
2510 case BFD_RELOC_PPC_GOT_TPREL16:
2511 case BFD_RELOC_PPC_GOT_TPREL16_LO:
2514 as_bad (_("unsupported relocation for DS offset field"));
2519 /* We need to generate a fixup for this expression. */
2520 if (fc >= MAX_INSN_FIXUPS)
2521 as_fatal (_("too many fixups"));
2522 fixups[fc].exp = ex;
2523 fixups[fc].opindex = 0;
2524 fixups[fc].reloc = reloc;
2527 #endif /* OBJ_ELF */
2531 /* We need to generate a fixup for this expression. */
2532 if (fc >= MAX_INSN_FIXUPS)
2533 as_fatal (_("too many fixups"));
2534 fixups[fc].exp = ex;
2535 fixups[fc].opindex = *opindex_ptr;
2536 fixups[fc].reloc = BFD_RELOC_UNUSED;
2545 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
2553 /* The call to expression should have advanced str past any
2556 && (endc != ',' || *str != '\0'))
2558 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
2566 while (ISSPACE (*str))
2570 as_bad (_("junk at end of line: `%s'"), str);
2573 /* Do we need/want a APUinfo section? */
2574 if (ppc_cpu & (PPC_OPCODE_SPE
2575 | PPC_OPCODE_ISEL | PPC_OPCODE_EFS
2576 | PPC_OPCODE_BRLOCK | PPC_OPCODE_PMR | PPC_OPCODE_CACHELCK
2577 | PPC_OPCODE_RFMCI))
2579 /* These are all version "1". */
2580 if (opcode->flags & PPC_OPCODE_SPE)
2581 ppc_apuinfo_section_add (PPC_APUINFO_SPE, 1);
2582 if (opcode->flags & PPC_OPCODE_ISEL)
2583 ppc_apuinfo_section_add (PPC_APUINFO_ISEL, 1);
2584 if (opcode->flags & PPC_OPCODE_EFS)
2585 ppc_apuinfo_section_add (PPC_APUINFO_EFS, 1);
2586 if (opcode->flags & PPC_OPCODE_BRLOCK)
2587 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK, 1);
2588 if (opcode->flags & PPC_OPCODE_PMR)
2589 ppc_apuinfo_section_add (PPC_APUINFO_PMR, 1);
2590 if (opcode->flags & PPC_OPCODE_CACHELCK)
2591 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK, 1);
2592 if (opcode->flags & PPC_OPCODE_RFMCI)
2593 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI, 1);
2597 /* Write out the instruction. */
2599 md_number_to_chars (f, insn, 4);
2602 dwarf2_emit_insn (4);
2605 /* Create any fixups. At this point we do not use a
2606 bfd_reloc_code_real_type, but instead just use the
2607 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2608 handle fixups for any operand type, although that is admittedly
2609 not a very exciting feature. We pick a BFD reloc type in
2611 for (i = 0; i < fc; i++)
2613 const struct powerpc_operand *operand;
2615 operand = &powerpc_operands[fixups[i].opindex];
2616 if (fixups[i].reloc != BFD_RELOC_UNUSED)
2618 reloc_howto_type *reloc_howto;
2623 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2627 size = bfd_get_reloc_size (reloc_howto);
2628 offset = target_big_endian ? (4 - size) : 0;
2630 if (size < 1 || size > 4)
2633 fixP = fix_new_exp (frag_now,
2634 f - frag_now->fr_literal + offset,
2637 reloc_howto->pc_relative,
2640 /* Turn off complaints that the addend is too large for things like
2642 switch (fixups[i].reloc)
2644 case BFD_RELOC_16_GOTOFF:
2645 case BFD_RELOC_PPC_TOC16:
2646 case BFD_RELOC_LO16:
2647 case BFD_RELOC_HI16:
2648 case BFD_RELOC_HI16_S:
2650 case BFD_RELOC_PPC64_HIGHER:
2651 case BFD_RELOC_PPC64_HIGHER_S:
2652 case BFD_RELOC_PPC64_HIGHEST:
2653 case BFD_RELOC_PPC64_HIGHEST_S:
2655 fixP->fx_no_overflow = 1;
2662 fix_new_exp (frag_now,
2663 f - frag_now->fr_literal,
2666 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2667 ((bfd_reloc_code_real_type)
2668 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2672 /* Handle a macro. Gather all the operands, transform them as
2673 described by the macro, and call md_assemble recursively. All the
2674 operands are separated by commas; we don't accept parentheses
2675 around operands here. */
2678 ppc_macro (str, macro)
2680 const struct powerpc_macro *macro;
2691 /* Gather the users operands into the operands array. */
2696 if (count >= sizeof operands / sizeof operands[0])
2698 operands[count++] = s;
2699 s = strchr (s, ',');
2700 if (s == (char *) NULL)
2705 if (count != macro->operands)
2707 as_bad (_("wrong number of operands"));
2711 /* Work out how large the string must be (the size is unbounded
2712 because it includes user input). */
2714 format = macro->format;
2715 while (*format != '\0')
2724 arg = strtol (format + 1, &send, 10);
2725 know (send != format && arg >= 0 && arg < count);
2726 len += strlen (operands[arg]);
2731 /* Put the string together. */
2732 complete = s = (char *) alloca (len + 1);
2733 format = macro->format;
2734 while (*format != '\0')
2740 arg = strtol (format + 1, &send, 10);
2741 strcpy (s, operands[arg]);
2748 /* Assemble the constructed instruction. */
2749 md_assemble (complete);
2753 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2756 ppc_section_letter (letter, ptr_msg)
2763 *ptr_msg = _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
2768 ppc_section_word (str, len)
2772 if (len == 7 && strncmp (str, "exclude", 7) == 0)
2779 ppc_section_type (str, len)
2783 if (len == 7 && strncmp (str, "ordered", 7) == 0)
2790 ppc_section_flags (flags, attr, type)
2795 if (type == SHT_ORDERED)
2796 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2798 if (attr & SHF_EXCLUDE)
2799 flags |= SEC_EXCLUDE;
2803 #endif /* OBJ_ELF */
2806 /* Pseudo-op handling. */
2808 /* The .byte pseudo-op. This is similar to the normal .byte
2809 pseudo-op, but it can also take a single ASCII string. */
2813 int ignore ATTRIBUTE_UNUSED;
2815 if (*input_line_pointer != '\"')
2821 /* Gather characters. A real double quote is doubled. Unusual
2822 characters are not permitted. */
2823 ++input_line_pointer;
2828 c = *input_line_pointer++;
2832 if (*input_line_pointer != '\"')
2834 ++input_line_pointer;
2837 FRAG_APPEND_1_CHAR (c);
2840 demand_empty_rest_of_line ();
2845 /* XCOFF specific pseudo-op handling. */
2847 /* This is set if we are creating a .stabx symbol, since we don't want
2848 to handle symbol suffixes for such symbols. */
2849 static bfd_boolean ppc_stab_symbol;
2851 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2852 symbols in the .bss segment as though they were local common
2853 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2854 aligns .comm and .lcomm to 4 bytes. */
2860 asection *current_seg = now_seg;
2861 subsegT current_subseg = now_subseg;
2867 symbolS *lcomm_sym = NULL;
2871 name = input_line_pointer;
2872 endc = get_symbol_end ();
2873 end_name = input_line_pointer;
2876 if (*input_line_pointer != ',')
2878 as_bad (_("missing size"));
2879 ignore_rest_of_line ();
2882 ++input_line_pointer;
2884 size = get_absolute_expression ();
2887 as_bad (_("negative size"));
2888 ignore_rest_of_line ();
2894 /* The third argument to .comm is the alignment. */
2895 if (*input_line_pointer != ',')
2899 ++input_line_pointer;
2900 align = get_absolute_expression ();
2903 as_warn (_("ignoring bad alignment"));
2918 /* The third argument to .lcomm appears to be the real local
2919 common symbol to create. References to the symbol named in
2920 the first argument are turned into references to the third
2922 if (*input_line_pointer != ',')
2924 as_bad (_("missing real symbol name"));
2925 ignore_rest_of_line ();
2928 ++input_line_pointer;
2930 lcomm_name = input_line_pointer;
2931 lcomm_endc = get_symbol_end ();
2933 lcomm_sym = symbol_find_or_make (lcomm_name);
2935 *input_line_pointer = lcomm_endc;
2939 sym = symbol_find_or_make (name);
2942 if (S_IS_DEFINED (sym)
2943 || S_GET_VALUE (sym) != 0)
2945 as_bad (_("attempt to redefine symbol"));
2946 ignore_rest_of_line ();
2950 record_alignment (bss_section, align);
2953 || ! S_IS_DEFINED (lcomm_sym))
2962 S_SET_EXTERNAL (sym);
2966 symbol_get_tc (lcomm_sym)->output = 1;
2967 def_sym = lcomm_sym;
2971 subseg_set (bss_section, 1);
2972 frag_align (align, 0, 0);
2974 symbol_set_frag (def_sym, frag_now);
2975 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2976 def_size, (char *) NULL);
2978 S_SET_SEGMENT (def_sym, bss_section);
2979 symbol_get_tc (def_sym)->align = align;
2983 /* Align the size of lcomm_sym. */
2984 symbol_get_frag (lcomm_sym)->fr_offset =
2985 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
2986 &~ ((1 << align) - 1));
2987 if (align > symbol_get_tc (lcomm_sym)->align)
2988 symbol_get_tc (lcomm_sym)->align = align;
2993 /* Make sym an offset from lcomm_sym. */
2994 S_SET_SEGMENT (sym, bss_section);
2995 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
2996 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
2997 symbol_get_frag (lcomm_sym)->fr_offset += size;
3000 subseg_set (current_seg, current_subseg);
3002 demand_empty_rest_of_line ();
3005 /* The .csect pseudo-op. This switches us into a different
3006 subsegment. The first argument is a symbol whose value is the
3007 start of the .csect. In COFF, csect symbols get special aux
3008 entries defined by the x_csect field of union internal_auxent. The
3009 optional second argument is the alignment (the default is 2). */
3013 int ignore ATTRIBUTE_UNUSED;
3020 name = input_line_pointer;
3021 endc = get_symbol_end ();
3023 sym = symbol_find_or_make (name);
3025 *input_line_pointer = endc;
3027 if (S_GET_NAME (sym)[0] == '\0')
3029 /* An unnamed csect is assumed to be [PR]. */
3030 symbol_get_tc (sym)->class = XMC_PR;
3034 if (*input_line_pointer == ',')
3036 ++input_line_pointer;
3037 align = get_absolute_expression ();
3040 ppc_change_csect (sym, align);
3042 demand_empty_rest_of_line ();
3045 /* Change to a different csect. */
3048 ppc_change_csect (sym, align)
3052 if (S_IS_DEFINED (sym))
3053 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
3063 /* This is a new csect. We need to look at the symbol class to
3064 figure out whether it should go in the text section or the
3068 switch (symbol_get_tc (sym)->class)
3078 S_SET_SEGMENT (sym, text_section);
3079 symbol_get_tc (sym)->subseg = ppc_text_subsegment;
3080 ++ppc_text_subsegment;
3081 list_ptr = &ppc_text_csects;
3091 if (ppc_toc_csect != NULL
3092 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
3093 == ppc_data_subsegment))
3095 S_SET_SEGMENT (sym, data_section);
3096 symbol_get_tc (sym)->subseg = ppc_data_subsegment;
3097 ++ppc_data_subsegment;
3098 list_ptr = &ppc_data_csects;
3104 /* We set the obstack chunk size to a small value before
3105 changing subsegments, so that we don't use a lot of memory
3106 space for what may be a small section. */
3107 hold_chunksize = chunksize;
3110 sec = subseg_new (segment_name (S_GET_SEGMENT (sym)),
3111 symbol_get_tc (sym)->subseg);
3113 chunksize = hold_chunksize;
3116 ppc_after_toc_frag = frag_now;
3118 record_alignment (sec, align);
3120 frag_align_code (align, 0);
3122 frag_align (align, 0, 0);
3124 symbol_set_frag (sym, frag_now);
3125 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3127 symbol_get_tc (sym)->align = align;
3128 symbol_get_tc (sym)->output = 1;
3129 symbol_get_tc (sym)->within = sym;
3131 for (list = *list_ptr;
3132 symbol_get_tc (list)->next != (symbolS *) NULL;
3133 list = symbol_get_tc (list)->next)
3135 symbol_get_tc (list)->next = sym;
3137 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3138 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3142 ppc_current_csect = sym;
3145 /* This function handles the .text and .data pseudo-ops. These
3146 pseudo-ops aren't really used by XCOFF; we implement them for the
3147 convenience of people who aren't used to XCOFF. */
3158 else if (type == 'd')
3163 sym = symbol_find_or_make (name);
3165 ppc_change_csect (sym, 2);
3167 demand_empty_rest_of_line ();
3170 /* This function handles the .section pseudo-op. This is mostly to
3171 give an error, since XCOFF only supports .text, .data and .bss, but
3172 we do permit the user to name the text or data section. */
3175 ppc_named_section (ignore)
3176 int ignore ATTRIBUTE_UNUSED;
3179 const char *real_name;
3183 user_name = input_line_pointer;
3184 c = get_symbol_end ();
3186 if (strcmp (user_name, ".text") == 0)
3187 real_name = ".text[PR]";
3188 else if (strcmp (user_name, ".data") == 0)
3189 real_name = ".data[RW]";
3192 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3193 *input_line_pointer = c;
3194 ignore_rest_of_line ();
3198 *input_line_pointer = c;
3200 sym = symbol_find_or_make (real_name);
3202 ppc_change_csect (sym, 2);
3204 demand_empty_rest_of_line ();
3207 /* The .extern pseudo-op. We create an undefined symbol. */
3211 int ignore ATTRIBUTE_UNUSED;
3216 name = input_line_pointer;
3217 endc = get_symbol_end ();
3219 (void) symbol_find_or_make (name);
3221 *input_line_pointer = endc;
3223 demand_empty_rest_of_line ();
3226 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3230 int ignore ATTRIBUTE_UNUSED;
3236 name = input_line_pointer;
3237 endc = get_symbol_end ();
3239 sym = symbol_find_or_make (name);
3241 *input_line_pointer = endc;
3243 symbol_get_tc (sym)->output = 1;
3245 demand_empty_rest_of_line ();
3248 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3249 although I don't know why it bothers. */
3253 int ignore ATTRIBUTE_UNUSED;
3260 name = input_line_pointer;
3261 endc = get_symbol_end ();
3263 sym = symbol_find_or_make (name);
3265 *input_line_pointer = endc;
3267 if (*input_line_pointer != ',')
3269 as_bad (_("missing rename string"));
3270 ignore_rest_of_line ();
3273 ++input_line_pointer;
3275 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
3277 demand_empty_rest_of_line ();
3280 /* The .stabx pseudo-op. This is similar to a normal .stabs
3281 pseudo-op, but slightly different. A sample is
3282 .stabx "main:F-1",.main,142,0
3283 The first argument is the symbol name to create. The second is the
3284 value, and the third is the storage class. The fourth seems to be
3285 always zero, and I am assuming it is the type. */
3289 int ignore ATTRIBUTE_UNUSED;
3296 name = demand_copy_C_string (&len);
3298 if (*input_line_pointer != ',')
3300 as_bad (_("missing value"));
3303 ++input_line_pointer;
3305 ppc_stab_symbol = TRUE;
3306 sym = symbol_make (name);
3307 ppc_stab_symbol = FALSE;
3309 symbol_get_tc (sym)->real_name = name;
3311 (void) expression (&exp);
3318 as_bad (_("illegal .stabx expression; zero assumed"));
3319 exp.X_add_number = 0;
3322 S_SET_VALUE (sym, (valueT) exp.X_add_number);
3323 symbol_set_frag (sym, &zero_address_frag);
3327 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
3328 symbol_set_value_expression (sym, &exp);
3332 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
3333 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
3338 /* The value is some complex expression. This will probably
3339 fail at some later point, but this is probably the right
3340 thing to do here. */
3341 symbol_set_value_expression (sym, &exp);
3345 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3346 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3348 if (*input_line_pointer != ',')
3350 as_bad (_("missing class"));
3353 ++input_line_pointer;
3355 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
3357 if (*input_line_pointer != ',')
3359 as_bad (_("missing type"));
3362 ++input_line_pointer;
3364 S_SET_DATA_TYPE (sym, get_absolute_expression ());
3366 symbol_get_tc (sym)->output = 1;
3368 if (S_GET_STORAGE_CLASS (sym) == C_STSYM) {
3370 symbol_get_tc (sym)->within = ppc_current_block;
3375 .stabx "z",arrays_,133,0
3378 .comm arrays_,13768,3
3380 resolve_symbol_value will copy the exp's "within" into sym's when the
3381 offset is 0. Since this seems to be corner case problem,
3382 only do the correction for storage class C_STSYM. A better solution
3383 would be to have the tc field updated in ppc_symbol_new_hook. */
3385 if (exp.X_op == O_symbol)
3387 symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block;
3391 if (exp.X_op != O_symbol
3392 || ! S_IS_EXTERNAL (exp.X_add_symbol)
3393 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
3394 ppc_frob_label (sym);
3397 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3398 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
3399 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
3400 symbol_get_tc (ppc_current_csect)->within = sym;
3403 demand_empty_rest_of_line ();
3406 /* The .function pseudo-op. This takes several arguments. The first
3407 argument seems to be the external name of the symbol. The second
3408 argment seems to be the label for the start of the function. gcc
3409 uses the same name for both. I have no idea what the third and
3410 fourth arguments are meant to be. The optional fifth argument is
3411 an expression for the size of the function. In COFF this symbol
3412 gets an aux entry like that used for a csect. */
3415 ppc_function (ignore)
3416 int ignore ATTRIBUTE_UNUSED;
3424 name = input_line_pointer;
3425 endc = get_symbol_end ();
3427 /* Ignore any [PR] suffix. */
3428 name = ppc_canonicalize_symbol_name (name);
3429 s = strchr (name, '[');
3430 if (s != (char *) NULL
3431 && strcmp (s + 1, "PR]") == 0)
3434 ext_sym = symbol_find_or_make (name);
3436 *input_line_pointer = endc;
3438 if (*input_line_pointer != ',')
3440 as_bad (_("missing symbol name"));
3441 ignore_rest_of_line ();
3444 ++input_line_pointer;
3446 name = input_line_pointer;
3447 endc = get_symbol_end ();
3449 lab_sym = symbol_find_or_make (name);
3451 *input_line_pointer = endc;
3453 if (ext_sym != lab_sym)
3457 exp.X_op = O_symbol;
3458 exp.X_add_symbol = lab_sym;
3459 exp.X_op_symbol = NULL;
3460 exp.X_add_number = 0;
3462 symbol_set_value_expression (ext_sym, &exp);
3465 if (symbol_get_tc (ext_sym)->class == -1)
3466 symbol_get_tc (ext_sym)->class = XMC_PR;
3467 symbol_get_tc (ext_sym)->output = 1;
3469 if (*input_line_pointer == ',')
3473 /* Ignore the third argument. */
3474 ++input_line_pointer;
3475 expression (&ignore);
3476 if (*input_line_pointer == ',')
3478 /* Ignore the fourth argument. */
3479 ++input_line_pointer;
3480 expression (&ignore);
3481 if (*input_line_pointer == ',')
3483 /* The fifth argument is the function size. */
3484 ++input_line_pointer;
3485 symbol_get_tc (ext_sym)->size = symbol_new ("L0\001",
3488 &zero_address_frag);
3489 pseudo_set (symbol_get_tc (ext_sym)->size);
3494 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3495 SF_SET_FUNCTION (ext_sym);
3496 SF_SET_PROCESS (ext_sym);
3497 coff_add_linesym (ext_sym);
3499 demand_empty_rest_of_line ();
3502 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3503 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3504 with the correct line number */
3506 static symbolS *saved_bi_sym = 0;
3510 int ignore ATTRIBUTE_UNUSED;
3514 sym = symbol_make (".bf");
3515 S_SET_SEGMENT (sym, text_section);
3516 symbol_set_frag (sym, frag_now);
3517 S_SET_VALUE (sym, frag_now_fix ());
3518 S_SET_STORAGE_CLASS (sym, C_FCN);
3520 coff_line_base = get_absolute_expression ();
3522 S_SET_NUMBER_AUXILIARY (sym, 1);
3523 SA_SET_SYM_LNNO (sym, coff_line_base);
3525 /* Line number for bi. */
3528 S_SET_VALUE (saved_bi_sym, coff_n_line_nos);
3533 symbol_get_tc (sym)->output = 1;
3535 ppc_frob_label (sym);
3537 demand_empty_rest_of_line ();
3540 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3541 ".ef", except that the line number is absolute, not relative to the
3542 most recent ".bf" symbol. */
3546 int ignore ATTRIBUTE_UNUSED;
3550 sym = symbol_make (".ef");
3551 S_SET_SEGMENT (sym, text_section);
3552 symbol_set_frag (sym, frag_now);
3553 S_SET_VALUE (sym, frag_now_fix ());
3554 S_SET_STORAGE_CLASS (sym, C_FCN);
3555 S_SET_NUMBER_AUXILIARY (sym, 1);
3556 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3557 symbol_get_tc (sym)->output = 1;
3559 ppc_frob_label (sym);
3561 demand_empty_rest_of_line ();
3564 /* The .bi and .ei pseudo-ops. These take a string argument and
3565 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3566 the symbol list. The value of .bi will be know when the next .bf
3573 static symbolS *last_biei;
3580 name = demand_copy_C_string (&len);
3582 /* The value of these symbols is actually file offset. Here we set
3583 the value to the index into the line number entries. In
3584 ppc_frob_symbols we set the fix_line field, which will cause BFD
3585 to do the right thing. */
3587 sym = symbol_make (name);
3588 /* obj-coff.c currently only handles line numbers correctly in the
3590 S_SET_SEGMENT (sym, text_section);
3591 S_SET_VALUE (sym, coff_n_line_nos);
3592 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3594 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
3595 symbol_get_tc (sym)->output = 1;
3603 for (look = last_biei ? last_biei : symbol_rootP;
3604 (look != (symbolS *) NULL
3605 && (S_GET_STORAGE_CLASS (look) == C_FILE
3606 || S_GET_STORAGE_CLASS (look) == C_BINCL
3607 || S_GET_STORAGE_CLASS (look) == C_EINCL));
3608 look = symbol_next (look))
3610 if (look != (symbolS *) NULL)
3612 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3613 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
3617 demand_empty_rest_of_line ();
3620 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3621 There is one argument, which is a csect symbol. The value of the
3622 .bs symbol is the index of this csect symbol. */
3626 int ignore ATTRIBUTE_UNUSED;
3633 if (ppc_current_block != NULL)
3634 as_bad (_("nested .bs blocks"));
3636 name = input_line_pointer;
3637 endc = get_symbol_end ();
3639 csect = symbol_find_or_make (name);
3641 *input_line_pointer = endc;
3643 sym = symbol_make (".bs");
3644 S_SET_SEGMENT (sym, now_seg);
3645 S_SET_STORAGE_CLASS (sym, C_BSTAT);
3646 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3647 symbol_get_tc (sym)->output = 1;
3649 symbol_get_tc (sym)->within = csect;
3651 ppc_frob_label (sym);
3653 ppc_current_block = sym;
3655 demand_empty_rest_of_line ();
3658 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3662 int ignore ATTRIBUTE_UNUSED;
3666 if (ppc_current_block == NULL)
3667 as_bad (_(".es without preceding .bs"));
3669 sym = symbol_make (".es");
3670 S_SET_SEGMENT (sym, now_seg);
3671 S_SET_STORAGE_CLASS (sym, C_ESTAT);
3672 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3673 symbol_get_tc (sym)->output = 1;
3675 ppc_frob_label (sym);
3677 ppc_current_block = NULL;
3679 demand_empty_rest_of_line ();
3682 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3687 int ignore ATTRIBUTE_UNUSED;
3691 sym = symbol_make (".bb");
3692 S_SET_SEGMENT (sym, text_section);
3693 symbol_set_frag (sym, frag_now);
3694 S_SET_VALUE (sym, frag_now_fix ());
3695 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3697 S_SET_NUMBER_AUXILIARY (sym, 1);
3698 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3700 symbol_get_tc (sym)->output = 1;
3702 SF_SET_PROCESS (sym);
3704 ppc_frob_label (sym);
3706 demand_empty_rest_of_line ();
3709 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3714 int ignore ATTRIBUTE_UNUSED;
3718 sym = symbol_make (".eb");
3719 S_SET_SEGMENT (sym, text_section);
3720 symbol_set_frag (sym, frag_now);
3721 S_SET_VALUE (sym, frag_now_fix ());
3722 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3723 S_SET_NUMBER_AUXILIARY (sym, 1);
3724 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3725 symbol_get_tc (sym)->output = 1;
3727 SF_SET_PROCESS (sym);
3729 ppc_frob_label (sym);
3731 demand_empty_rest_of_line ();
3734 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3739 int ignore ATTRIBUTE_UNUSED;
3745 name = demand_copy_C_string (&len);
3746 sym = symbol_make (name);
3747 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3748 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3749 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3750 S_SET_VALUE (sym, 0);
3751 symbol_get_tc (sym)->output = 1;
3753 ppc_frob_label (sym);
3755 demand_empty_rest_of_line ();
3758 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3762 int ignore ATTRIBUTE_UNUSED;
3766 sym = symbol_make (".ec");
3767 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3768 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3769 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3770 S_SET_VALUE (sym, 0);
3771 symbol_get_tc (sym)->output = 1;
3773 ppc_frob_label (sym);
3775 demand_empty_rest_of_line ();
3778 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3782 int ignore ATTRIBUTE_UNUSED;
3784 if (ppc_toc_csect != (symbolS *) NULL)
3785 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
3792 subseg = ppc_data_subsegment;
3793 ++ppc_data_subsegment;
3795 subseg_new (segment_name (data_section), subseg);
3796 ppc_toc_frag = frag_now;
3798 sym = symbol_find_or_make ("TOC[TC0]");
3799 symbol_set_frag (sym, frag_now);
3800 S_SET_SEGMENT (sym, data_section);
3801 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3802 symbol_get_tc (sym)->subseg = subseg;
3803 symbol_get_tc (sym)->output = 1;
3804 symbol_get_tc (sym)->within = sym;
3806 ppc_toc_csect = sym;
3808 for (list = ppc_data_csects;
3809 symbol_get_tc (list)->next != (symbolS *) NULL;
3810 list = symbol_get_tc (list)->next)
3812 symbol_get_tc (list)->next = sym;
3814 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3815 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3819 ppc_current_csect = ppc_toc_csect;
3821 demand_empty_rest_of_line ();
3824 /* The AIX assembler automatically aligns the operands of a .long or
3825 .short pseudo-op, and we want to be compatible. */
3828 ppc_xcoff_cons (log_size)
3831 frag_align (log_size, 0, 0);
3832 record_alignment (now_seg, log_size);
3833 cons (1 << log_size);
3838 int dummy ATTRIBUTE_UNUSED;
3843 (void) expression (&exp);
3845 if (exp.X_op != O_constant)
3847 as_bad (_("non-constant byte count"));
3851 byte_count = exp.X_add_number;
3853 if (*input_line_pointer != ',')
3855 as_bad (_("missing value"));
3859 ++input_line_pointer;
3863 #endif /* OBJ_XCOFF */
3864 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3866 /* The .tc pseudo-op. This is used when generating either XCOFF or
3867 ELF. This takes two or more arguments.
3869 When generating XCOFF output, the first argument is the name to
3870 give to this location in the toc; this will be a symbol with class
3871 TC. The rest of the arguments are N-byte values to actually put at
3872 this location in the TOC; often there is just one more argument, a
3873 relocatable symbol reference. The size of the value to store
3874 depends on target word size. A 32-bit target uses 4-byte values, a
3875 64-bit target uses 8-byte values.
3877 When not generating XCOFF output, the arguments are the same, but
3878 the first argument is simply ignored. */
3882 int ignore ATTRIBUTE_UNUSED;
3886 /* Define the TOC symbol name. */
3892 if (ppc_toc_csect == (symbolS *) NULL
3893 || ppc_toc_csect != ppc_current_csect)
3895 as_bad (_(".tc not in .toc section"));
3896 ignore_rest_of_line ();
3900 name = input_line_pointer;
3901 endc = get_symbol_end ();
3903 sym = symbol_find_or_make (name);
3905 *input_line_pointer = endc;
3907 if (S_IS_DEFINED (sym))
3911 label = symbol_get_tc (ppc_current_csect)->within;
3912 if (symbol_get_tc (label)->class != XMC_TC0)
3914 as_bad (_(".tc with no label"));
3915 ignore_rest_of_line ();
3919 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3920 symbol_set_frag (label, symbol_get_frag (sym));
3921 S_SET_VALUE (label, S_GET_VALUE (sym));
3923 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3924 ++input_line_pointer;
3929 S_SET_SEGMENT (sym, now_seg);
3930 symbol_set_frag (sym, frag_now);
3931 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3932 symbol_get_tc (sym)->class = XMC_TC;
3933 symbol_get_tc (sym)->output = 1;
3935 ppc_frob_label (sym);
3938 #endif /* OBJ_XCOFF */
3942 /* Skip the TOC symbol name. */
3943 while (is_part_of_name (*input_line_pointer)
3944 || *input_line_pointer == '['
3945 || *input_line_pointer == ']'
3946 || *input_line_pointer == '{'
3947 || *input_line_pointer == '}')
3948 ++input_line_pointer;
3950 /* Align to a four/eight byte boundary. */
3951 align = ppc_obj64 ? 3 : 2;
3952 frag_align (align, 0, 0);
3953 record_alignment (now_seg, align);
3954 #endif /* OBJ_ELF */
3956 if (*input_line_pointer != ',')
3957 demand_empty_rest_of_line ();
3960 ++input_line_pointer;
3961 cons (ppc_obj64 ? 8 : 4);
3965 /* Pseudo-op .machine. */
3966 /* FIXME: `.machine' is a nop for the moment. It would be nice to
3967 accept this directive on the first line of input and set ppc_obj64
3968 and the target format accordingly. Unfortunately, the target
3969 format is selected in output-file.c:output_file_create before we
3970 even get to md_begin, so it's not possible without changing
3974 ppc_machine (ignore)
3975 int ignore ATTRIBUTE_UNUSED;
3977 discard_rest_of_line ();
3980 /* See whether a symbol is in the TOC section. */
3983 ppc_is_toc_sym (sym)
3987 return symbol_get_tc (sym)->class == XMC_TC;
3990 const char *sname = segment_name (S_GET_SEGMENT (sym));
3992 return strcmp (sname, ".toc") == 0;
3994 return strcmp (sname, ".got") == 0;
3997 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4001 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4003 /* Set the current section. */
4005 ppc_set_current_section (new)
4008 ppc_previous_section = ppc_current_section;
4009 ppc_current_section = new;
4012 /* pseudo-op: .previous
4013 behaviour: toggles the current section with the previous section.
4015 warnings: "No previous section" */
4018 ppc_previous (ignore)
4019 int ignore ATTRIBUTE_UNUSED;
4023 if (ppc_previous_section == NULL)
4025 as_warn (_("No previous section to return to. Directive ignored."));
4029 subseg_set (ppc_previous_section, 0);
4031 ppc_set_current_section (ppc_previous_section);
4034 /* pseudo-op: .pdata
4035 behaviour: predefined read only data section
4039 initial: .section .pdata "adr3"
4040 a - don't know -- maybe a misprint
4041 d - initialized data
4043 3 - double word aligned (that would be 4 byte boundary)
4046 Tag index tables (also known as the function table) for exception
4047 handling, debugging, etc. */
4051 int ignore ATTRIBUTE_UNUSED;
4053 if (pdata_section == 0)
4055 pdata_section = subseg_new (".pdata", 0);
4057 bfd_set_section_flags (stdoutput, pdata_section,
4058 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4059 | SEC_READONLY | SEC_DATA ));
4061 bfd_set_section_alignment (stdoutput, pdata_section, 2);
4065 pdata_section = subseg_new (".pdata", 0);
4067 ppc_set_current_section (pdata_section);
4070 /* pseudo-op: .ydata
4071 behaviour: predefined read only data section
4075 initial: .section .ydata "drw3"
4076 a - don't know -- maybe a misprint
4077 d - initialized data
4079 3 - double word aligned (that would be 4 byte boundary)
4081 Tag tables (also known as the scope table) for exception handling,
4086 int ignore ATTRIBUTE_UNUSED;
4088 if (ydata_section == 0)
4090 ydata_section = subseg_new (".ydata", 0);
4091 bfd_set_section_flags (stdoutput, ydata_section,
4092 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4093 | SEC_READONLY | SEC_DATA ));
4095 bfd_set_section_alignment (stdoutput, ydata_section, 3);
4099 ydata_section = subseg_new (".ydata", 0);
4101 ppc_set_current_section (ydata_section);
4104 /* pseudo-op: .reldata
4105 behaviour: predefined read write data section
4106 double word aligned (4-byte)
4107 FIXME: relocation is applied to it
4108 FIXME: what's the difference between this and .data?
4111 initial: .section .reldata "drw3"
4112 d - initialized data
4115 3 - double word aligned (that would be 8 byte boundary)
4118 Like .data, but intended to hold data subject to relocation, such as
4119 function descriptors, etc. */
4122 ppc_reldata (ignore)
4123 int ignore ATTRIBUTE_UNUSED;
4125 if (reldata_section == 0)
4127 reldata_section = subseg_new (".reldata", 0);
4129 bfd_set_section_flags (stdoutput, reldata_section,
4130 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4133 bfd_set_section_alignment (stdoutput, reldata_section, 2);
4137 reldata_section = subseg_new (".reldata", 0);
4139 ppc_set_current_section (reldata_section);
4142 /* pseudo-op: .rdata
4143 behaviour: predefined read only data section
4147 initial: .section .rdata "dr3"
4148 d - initialized data
4150 3 - double word aligned (that would be 4 byte boundary) */
4154 int ignore ATTRIBUTE_UNUSED;
4156 if (rdata_section == 0)
4158 rdata_section = subseg_new (".rdata", 0);
4159 bfd_set_section_flags (stdoutput, rdata_section,
4160 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4161 | SEC_READONLY | SEC_DATA ));
4163 bfd_set_section_alignment (stdoutput, rdata_section, 2);
4167 rdata_section = subseg_new (".rdata", 0);
4169 ppc_set_current_section (rdata_section);
4172 /* pseudo-op: .ualong
4173 behaviour: much like .int, with the exception that no alignment is
4175 FIXME: test the alignment statement
4181 int ignore ATTRIBUTE_UNUSED;
4187 /* pseudo-op: .znop <symbol name>
4188 behaviour: Issue a nop instruction
4189 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4190 the supplied symbol name.
4192 warnings: Missing symbol name */
4196 int ignore ATTRIBUTE_UNUSED;
4199 const struct powerpc_opcode *opcode;
4210 /* Strip out the symbol name. */
4211 symbol_name = input_line_pointer;
4212 c = get_symbol_end ();
4214 name = xmalloc (input_line_pointer - symbol_name + 1);
4215 strcpy (name, symbol_name);
4217 sym = symbol_find_or_make (name);
4219 *input_line_pointer = c;
4223 /* Look up the opcode in the hash table. */
4224 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
4226 /* Stick in the nop. */
4227 insn = opcode->opcode;
4229 /* Write out the instruction. */
4231 md_number_to_chars (f, insn, 4);
4233 f - frag_now->fr_literal,
4238 BFD_RELOC_16_GOT_PCREL);
4251 register char *name;
4255 register symbolS *symbolP;
4258 name = input_line_pointer;
4259 c = get_symbol_end ();
4261 /* just after name is now '\0'. */
4262 p = input_line_pointer;
4265 if (*input_line_pointer != ',')
4267 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4268 ignore_rest_of_line ();
4272 input_line_pointer++; /* skip ',' */
4273 if ((temp = get_absolute_expression ()) < 0)
4275 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
4276 ignore_rest_of_line ();
4282 /* The third argument to .comm is the alignment. */
4283 if (*input_line_pointer != ',')
4287 ++input_line_pointer;
4288 align = get_absolute_expression ();
4291 as_warn (_("ignoring bad alignment"));
4298 symbolP = symbol_find_or_make (name);
4301 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
4303 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4304 S_GET_NAME (symbolP));
4305 ignore_rest_of_line ();
4309 if (S_GET_VALUE (symbolP))
4311 if (S_GET_VALUE (symbolP) != (valueT) temp)
4312 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4313 S_GET_NAME (symbolP),
4314 (long) S_GET_VALUE (symbolP),
4319 S_SET_VALUE (symbolP, (valueT) temp);
4320 S_SET_EXTERNAL (symbolP);
4323 demand_empty_rest_of_line ();
4327 * implement the .section pseudo op:
4328 * .section name {, "flags"}
4330 * | +--- optional flags: 'b' for bss
4332 * +-- section name 'l' for lib
4336 * 'd' (apparently m88k for data)
4338 * But if the argument is not a quoted string, treat it as a
4339 * subsegment number.
4341 * FIXME: this is a copy of the section processing from obj-coff.c, with
4342 * additions/changes for the moto-pas assembler support. There are three
4345 * FIXME: I just noticed this. This doesn't work at all really. It it
4346 * setting bits that bfd probably neither understands or uses. The
4347 * correct approach (?) will have to incorporate extra fields attached
4348 * to the section to hold the system specific stuff. (krk)
4351 * 'a' - unknown - referred to in documentation, but no definition supplied
4352 * 'c' - section has code
4353 * 'd' - section has initialized data
4354 * 'u' - section has uninitialized data
4355 * 'i' - section contains directives (info)
4356 * 'n' - section can be discarded
4357 * 'R' - remove section at link time
4359 * Section Protection:
4360 * 'r' - section is readable
4361 * 'w' - section is writeable
4362 * 'x' - section is executable
4363 * 's' - section is sharable
4365 * Section Alignment:
4366 * '0' - align to byte boundary
4367 * '1' - align to halfword undary
4368 * '2' - align to word boundary
4369 * '3' - align to doubleword boundary
4370 * '4' - align to quadword boundary
4371 * '5' - align to 32 byte boundary
4372 * '6' - align to 64 byte boundary
4377 ppc_pe_section (ignore)
4378 int ignore ATTRIBUTE_UNUSED;
4380 /* Strip out the section name. */
4389 section_name = input_line_pointer;
4390 c = get_symbol_end ();
4392 name = xmalloc (input_line_pointer - section_name + 1);
4393 strcpy (name, section_name);
4395 *input_line_pointer = c;
4400 flags = SEC_NO_FLAGS;
4402 if (strcmp (name, ".idata$2") == 0)
4406 else if (strcmp (name, ".idata$3") == 0)
4410 else if (strcmp (name, ".idata$4") == 0)
4414 else if (strcmp (name, ".idata$5") == 0)
4418 else if (strcmp (name, ".idata$6") == 0)
4423 /* Default alignment to 16 byte boundary. */
4426 if (*input_line_pointer == ',')
4428 ++input_line_pointer;
4430 if (*input_line_pointer != '"')
4431 exp = get_absolute_expression ();
4434 ++input_line_pointer;
4435 while (*input_line_pointer != '"'
4436 && ! is_end_of_line[(unsigned char) *input_line_pointer])
4438 switch (*input_line_pointer)
4440 /* Section Contents */
4441 case 'a': /* unknown */
4442 as_bad (_("Unsupported section attribute -- 'a'"));
4444 case 'c': /* code section */
4447 case 'd': /* section has initialized data */
4450 case 'u': /* section has uninitialized data */
4451 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4455 case 'i': /* section contains directives (info) */
4456 /* FIXME: This is IMAGE_SCN_LNK_INFO
4458 flags |= SEC_HAS_CONTENTS;
4460 case 'n': /* section can be discarded */
4463 case 'R': /* Remove section at link time */
4464 flags |= SEC_NEVER_LOAD;
4467 /* Section Protection */
4468 case 'r': /* section is readable */
4469 flags |= IMAGE_SCN_MEM_READ;
4471 case 'w': /* section is writeable */
4472 flags |= IMAGE_SCN_MEM_WRITE;
4474 case 'x': /* section is executable */
4475 flags |= IMAGE_SCN_MEM_EXECUTE;
4477 case 's': /* section is sharable */
4478 flags |= IMAGE_SCN_MEM_SHARED;
4481 /* Section Alignment */
4482 case '0': /* align to byte boundary */
4483 flags |= IMAGE_SCN_ALIGN_1BYTES;
4486 case '1': /* align to halfword boundary */
4487 flags |= IMAGE_SCN_ALIGN_2BYTES;
4490 case '2': /* align to word boundary */
4491 flags |= IMAGE_SCN_ALIGN_4BYTES;
4494 case '3': /* align to doubleword boundary */
4495 flags |= IMAGE_SCN_ALIGN_8BYTES;
4498 case '4': /* align to quadword boundary */
4499 flags |= IMAGE_SCN_ALIGN_16BYTES;
4502 case '5': /* align to 32 byte boundary */
4503 flags |= IMAGE_SCN_ALIGN_32BYTES;
4506 case '6': /* align to 64 byte boundary */
4507 flags |= IMAGE_SCN_ALIGN_64BYTES;
4512 as_bad (_("unknown section attribute '%c'"),
4513 *input_line_pointer);
4516 ++input_line_pointer;
4518 if (*input_line_pointer == '"')
4519 ++input_line_pointer;
4523 sec = subseg_new (name, (subsegT) exp);
4525 ppc_set_current_section (sec);
4527 if (flags != SEC_NO_FLAGS)
4529 if (! bfd_set_section_flags (stdoutput, sec, flags))
4530 as_bad (_("error setting flags for \"%s\": %s"),
4531 bfd_section_name (stdoutput, sec),
4532 bfd_errmsg (bfd_get_error ()));
4535 bfd_set_section_alignment (stdoutput, sec, align);
4540 ppc_pe_function (ignore)
4541 int ignore ATTRIBUTE_UNUSED;
4547 name = input_line_pointer;
4548 endc = get_symbol_end ();
4550 ext_sym = symbol_find_or_make (name);
4552 *input_line_pointer = endc;
4554 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
4555 SF_SET_FUNCTION (ext_sym);
4556 SF_SET_PROCESS (ext_sym);
4557 coff_add_linesym (ext_sym);
4559 demand_empty_rest_of_line ();
4563 ppc_pe_tocd (ignore)
4564 int ignore ATTRIBUTE_UNUSED;
4566 if (tocdata_section == 0)
4568 tocdata_section = subseg_new (".tocd", 0);
4569 /* FIXME: section flags won't work. */
4570 bfd_set_section_flags (stdoutput, tocdata_section,
4571 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4572 | SEC_READONLY | SEC_DATA));
4574 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
4578 rdata_section = subseg_new (".tocd", 0);
4581 ppc_set_current_section (tocdata_section);
4583 demand_empty_rest_of_line ();
4586 /* Don't adjust TOC relocs to use the section symbol. */
4589 ppc_pe_fix_adjustable (fix)
4592 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
4599 /* XCOFF specific symbol and file handling. */
4601 /* Canonicalize the symbol name. We use the to force the suffix, if
4602 any, to use square brackets, and to be in upper case. */
4605 ppc_canonicalize_symbol_name (name)
4610 if (ppc_stab_symbol)
4613 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
4627 for (s++; *s != '\0' && *s != brac; s++)
4630 if (*s == '\0' || s[1] != '\0')
4631 as_bad (_("bad symbol suffix"));
4639 /* Set the class of a symbol based on the suffix, if any. This is
4640 called whenever a new symbol is created. */
4643 ppc_symbol_new_hook (sym)
4646 struct ppc_tc_sy *tc;
4649 tc = symbol_get_tc (sym);
4653 tc->real_name = NULL;
4659 if (ppc_stab_symbol)
4662 s = strchr (S_GET_NAME (sym), '[');
4663 if (s == (const char *) NULL)
4665 /* There is no suffix. */
4674 if (strcmp (s, "BS]") == 0)
4678 if (strcmp (s, "DB]") == 0)
4680 else if (strcmp (s, "DS]") == 0)
4684 if (strcmp (s, "GL]") == 0)
4688 if (strcmp (s, "PR]") == 0)
4692 if (strcmp (s, "RO]") == 0)
4694 else if (strcmp (s, "RW]") == 0)
4698 if (strcmp (s, "SV]") == 0)
4702 if (strcmp (s, "TC]") == 0)
4704 else if (strcmp (s, "TI]") == 0)
4706 else if (strcmp (s, "TB]") == 0)
4708 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
4709 tc->class = XMC_TC0;
4712 if (strcmp (s, "UA]") == 0)
4714 else if (strcmp (s, "UC]") == 0)
4718 if (strcmp (s, "XO]") == 0)
4723 if (tc->class == -1)
4724 as_bad (_("Unrecognized symbol suffix"));
4727 /* Set the class of a label based on where it is defined. This
4728 handles symbols without suffixes. Also, move the symbol so that it
4729 follows the csect symbol. */
4732 ppc_frob_label (sym)
4735 if (ppc_current_csect != (symbolS *) NULL)
4737 if (symbol_get_tc (sym)->class == -1)
4738 symbol_get_tc (sym)->class = symbol_get_tc (ppc_current_csect)->class;
4740 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4741 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
4742 &symbol_rootP, &symbol_lastP);
4743 symbol_get_tc (ppc_current_csect)->within = sym;
4747 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4748 seen. It tells ppc_adjust_symtab whether it needs to look through
4751 static bfd_boolean ppc_saw_abs;
4753 /* Change the name of a symbol just before writing it out. Set the
4754 real name if the .rename pseudo-op was used. Otherwise, remove any
4755 class suffix. Return 1 if the symbol should not be included in the
4759 ppc_frob_symbol (sym)
4762 static symbolS *ppc_last_function;
4763 static symbolS *set_end;
4765 /* Discard symbols that should not be included in the output symbol
4767 if (! symbol_used_in_reloc_p (sym)
4768 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
4769 || (! S_IS_EXTERNAL (sym)
4770 && ! symbol_get_tc (sym)->output
4771 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
4774 /* This one will disappear anyway. Don't make a csect sym for it. */
4775 if (sym == abs_section_sym)
4778 if (symbol_get_tc (sym)->real_name != (char *) NULL)
4779 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
4785 name = S_GET_NAME (sym);
4786 s = strchr (name, '[');
4787 if (s != (char *) NULL)
4793 snew = xmalloc (len + 1);
4794 memcpy (snew, name, len);
4797 S_SET_NAME (sym, snew);
4801 if (set_end != (symbolS *) NULL)
4803 SA_SET_SYM_ENDNDX (set_end, sym);
4807 if (SF_GET_FUNCTION (sym))
4809 if (ppc_last_function != (symbolS *) NULL)
4810 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4811 ppc_last_function = sym;
4812 if (symbol_get_tc (sym)->size != (symbolS *) NULL)
4814 resolve_symbol_value (symbol_get_tc (sym)->size);
4815 SA_SET_SYM_FSIZE (sym,
4816 (long) S_GET_VALUE (symbol_get_tc (sym)->size));
4819 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4820 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4822 if (ppc_last_function == (symbolS *) NULL)
4823 as_bad (_(".ef with no preceding .function"));
4826 set_end = ppc_last_function;
4827 ppc_last_function = NULL;
4829 /* We don't have a C_EFCN symbol, but we need to force the
4830 COFF backend to believe that it has seen one. */
4831 coff_last_function = NULL;
4835 if (! S_IS_EXTERNAL (sym)
4836 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
4837 && S_GET_STORAGE_CLASS (sym) != C_FILE
4838 && S_GET_STORAGE_CLASS (sym) != C_FCN
4839 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4840 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4841 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4842 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4843 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4844 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4845 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4847 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4848 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4851 union internal_auxent *a;
4853 /* Create a csect aux. */
4854 i = S_GET_NUMBER_AUXILIARY (sym);
4855 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4856 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
4857 if (symbol_get_tc (sym)->class == XMC_TC0)
4859 /* This is the TOC table. */
4860 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4861 a->x_csect.x_scnlen.l = 0;
4862 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4864 else if (symbol_get_tc (sym)->subseg != 0)
4866 /* This is a csect symbol. x_scnlen is the size of the
4868 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
4869 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4870 S_GET_SEGMENT (sym))
4871 - S_GET_VALUE (sym));
4874 resolve_symbol_value (symbol_get_tc (sym)->next);
4875 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
4876 - S_GET_VALUE (sym));
4878 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
4880 else if (S_GET_SEGMENT (sym) == bss_section)
4882 /* This is a common symbol. */
4883 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
4884 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
4885 if (S_IS_EXTERNAL (sym))
4886 symbol_get_tc (sym)->class = XMC_RW;
4888 symbol_get_tc (sym)->class = XMC_BS;
4890 else if (S_GET_SEGMENT (sym) == absolute_section)
4892 /* This is an absolute symbol. The csect will be created by
4893 ppc_adjust_symtab. */
4895 a->x_csect.x_smtyp = XTY_LD;
4896 if (symbol_get_tc (sym)->class == -1)
4897 symbol_get_tc (sym)->class = XMC_XO;
4899 else if (! S_IS_DEFINED (sym))
4901 /* This is an external symbol. */
4902 a->x_csect.x_scnlen.l = 0;
4903 a->x_csect.x_smtyp = XTY_ER;
4905 else if (symbol_get_tc (sym)->class == XMC_TC)
4909 /* This is a TOC definition. x_scnlen is the size of the
4911 next = symbol_next (sym);
4912 while (symbol_get_tc (next)->class == XMC_TC0)
4913 next = symbol_next (next);
4914 if (next == (symbolS *) NULL
4915 || symbol_get_tc (next)->class != XMC_TC)
4917 if (ppc_after_toc_frag == (fragS *) NULL)
4918 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4920 - S_GET_VALUE (sym));
4922 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
4923 - S_GET_VALUE (sym));
4927 resolve_symbol_value (next);
4928 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
4929 - S_GET_VALUE (sym));
4931 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4937 /* This is a normal symbol definition. x_scnlen is the
4938 symbol index of the containing csect. */
4939 if (S_GET_SEGMENT (sym) == text_section)
4940 csect = ppc_text_csects;
4941 else if (S_GET_SEGMENT (sym) == data_section)
4942 csect = ppc_data_csects;
4946 /* Skip the initial dummy symbol. */
4947 csect = symbol_get_tc (csect)->next;
4949 if (csect == (symbolS *) NULL)
4951 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
4952 a->x_csect.x_scnlen.l = 0;
4956 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
4958 resolve_symbol_value (symbol_get_tc (csect)->next);
4959 if (S_GET_VALUE (symbol_get_tc (csect)->next)
4960 > S_GET_VALUE (sym))
4962 csect = symbol_get_tc (csect)->next;
4965 a->x_csect.x_scnlen.p =
4966 coffsymbol (symbol_get_bfdsym (csect))->native;
4967 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
4970 a->x_csect.x_smtyp = XTY_LD;
4973 a->x_csect.x_parmhash = 0;
4974 a->x_csect.x_snhash = 0;
4975 if (symbol_get_tc (sym)->class == -1)
4976 a->x_csect.x_smclas = XMC_PR;
4978 a->x_csect.x_smclas = symbol_get_tc (sym)->class;
4979 a->x_csect.x_stab = 0;
4980 a->x_csect.x_snstab = 0;
4982 /* Don't let the COFF backend resort these symbols. */
4983 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
4985 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4987 /* We want the value to be the symbol index of the referenced
4988 csect symbol. BFD will do that for us if we set the right
4990 asymbol *bsym = symbol_get_bfdsym (symbol_get_tc (sym)->within);
4991 combined_entry_type *c = coffsymbol (bsym)->native;
4993 S_SET_VALUE (sym, (valueT) (size_t) c);
4994 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
4996 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
5001 /* The value is the offset from the enclosing csect. */
5002 block = symbol_get_tc (sym)->within;
5003 csect = symbol_get_tc (block)->within;
5004 resolve_symbol_value (csect);
5005 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
5007 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
5008 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
5010 /* We want the value to be a file offset into the line numbers.
5011 BFD will do that for us if we set the right flags. We have
5012 already set the value correctly. */
5013 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
5019 /* Adjust the symbol table. This creates csect symbols for all
5020 absolute symbols. */
5023 ppc_adjust_symtab ()
5030 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
5034 union internal_auxent *a;
5036 if (S_GET_SEGMENT (sym) != absolute_section)
5039 csect = symbol_create (".abs[XO]", absolute_section,
5040 S_GET_VALUE (sym), &zero_address_frag);
5041 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
5042 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
5043 i = S_GET_NUMBER_AUXILIARY (csect);
5044 S_SET_NUMBER_AUXILIARY (csect, i + 1);
5045 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
5046 a->x_csect.x_scnlen.l = 0;
5047 a->x_csect.x_smtyp = XTY_SD;
5048 a->x_csect.x_parmhash = 0;
5049 a->x_csect.x_snhash = 0;
5050 a->x_csect.x_smclas = XMC_XO;
5051 a->x_csect.x_stab = 0;
5052 a->x_csect.x_snstab = 0;
5054 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
5056 i = S_GET_NUMBER_AUXILIARY (sym);
5057 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
5058 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
5059 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
5062 ppc_saw_abs = FALSE;
5065 /* Set the VMA for a section. This is called on all the sections in
5069 ppc_frob_section (sec)
5072 static bfd_vma vma = 0;
5074 vma = md_section_align (sec, vma);
5075 bfd_set_section_vma (stdoutput, sec, vma);
5076 vma += bfd_section_size (stdoutput, sec);
5079 #endif /* OBJ_XCOFF */
5081 /* Turn a string in input_line_pointer into a floating point constant
5082 of type TYPE, and store the appropriate bytes in *LITP. The number
5083 of LITTLENUMS emitted is stored in *SIZEP. An error message is
5084 returned, or NULL on OK. */
5087 md_atof (type, litp, sizep)
5093 LITTLENUM_TYPE words[4];
5109 return _("bad call to md_atof");
5112 t = atof_ieee (input_line_pointer, type, words);
5114 input_line_pointer = t;
5118 if (target_big_endian)
5120 for (i = 0; i < prec; i++)
5122 md_number_to_chars (litp, (valueT) words[i], 2);
5128 for (i = prec - 1; i >= 0; i--)
5130 md_number_to_chars (litp, (valueT) words[i], 2);
5138 /* Write a value out to the object file, using the appropriate
5142 md_number_to_chars (buf, val, n)
5147 if (target_big_endian)
5148 number_to_chars_bigendian (buf, val, n);
5150 number_to_chars_littleendian (buf, val, n);
5153 /* Align a section (I don't know why this is machine dependent). */
5156 md_section_align (seg, addr)
5160 int align = bfd_get_section_alignment (stdoutput, seg);
5162 return ((addr + (1 << align) - 1) & (-1 << align));
5165 /* We don't have any form of relaxing. */
5168 md_estimate_size_before_relax (fragp, seg)
5169 fragS *fragp ATTRIBUTE_UNUSED;
5170 asection *seg ATTRIBUTE_UNUSED;
5176 /* Convert a machine dependent frag. We never generate these. */
5179 md_convert_frag (abfd, sec, fragp)
5180 bfd *abfd ATTRIBUTE_UNUSED;
5181 asection *sec ATTRIBUTE_UNUSED;
5182 fragS *fragp ATTRIBUTE_UNUSED;
5187 /* We have no need to default values of symbols. */
5190 md_undefined_symbol (name)
5191 char *name ATTRIBUTE_UNUSED;
5196 /* Functions concerning relocs. */
5198 /* The location from which a PC relative jump should be calculated,
5199 given a PC relative reloc. */
5202 md_pcrel_from_section (fixp, sec)
5204 segT sec ATTRIBUTE_UNUSED;
5206 return fixp->fx_frag->fr_address + fixp->fx_where;
5211 /* This is called to see whether a fixup should be adjusted to use a
5212 section symbol. We take the opportunity to change a fixup against
5213 a symbol in the TOC subsegment into a reloc against the
5214 corresponding .tc symbol. */
5217 ppc_fix_adjustable (fix)
5220 valueT val = resolve_symbol_value (fix->fx_addsy);
5221 segT symseg = S_GET_SEGMENT (fix->fx_addsy);
5222 TC_SYMFIELD_TYPE *tc;
5224 if (symseg == absolute_section)
5227 if (ppc_toc_csect != (symbolS *) NULL
5228 && fix->fx_addsy != ppc_toc_csect
5229 && symseg == data_section
5230 && val >= ppc_toc_frag->fr_address
5231 && (ppc_after_toc_frag == (fragS *) NULL
5232 || val < ppc_after_toc_frag->fr_address))
5236 for (sy = symbol_next (ppc_toc_csect);
5237 sy != (symbolS *) NULL;
5238 sy = symbol_next (sy))
5240 TC_SYMFIELD_TYPE *sy_tc = symbol_get_tc (sy);
5242 if (sy_tc->class == XMC_TC0)
5244 if (sy_tc->class != XMC_TC)
5246 if (val == resolve_symbol_value (sy))
5249 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
5254 as_bad_where (fix->fx_file, fix->fx_line,
5255 _("symbol in .toc does not match any .tc"));
5258 /* Possibly adjust the reloc to be against the csect. */
5259 tc = symbol_get_tc (fix->fx_addsy);
5261 && tc->class != XMC_TC0
5262 && tc->class != XMC_TC
5263 && symseg != bss_section
5264 /* Don't adjust if this is a reloc in the toc section. */
5265 && (symseg != data_section
5266 || ppc_toc_csect == NULL
5267 || val < ppc_toc_frag->fr_address
5268 || (ppc_after_toc_frag != NULL
5269 && val >= ppc_after_toc_frag->fr_address)))
5272 symbolS *next_csect;
5274 if (symseg == text_section)
5275 csect = ppc_text_csects;
5276 else if (symseg == data_section)
5277 csect = ppc_data_csects;
5281 /* Skip the initial dummy symbol. */
5282 csect = symbol_get_tc (csect)->next;
5284 if (csect != (symbolS *) NULL)
5286 while ((next_csect = symbol_get_tc (csect)->next) != (symbolS *) NULL
5287 && (symbol_get_frag (next_csect)->fr_address <= val))
5289 /* If the csect address equals the symbol value, then we
5290 have to look through the full symbol table to see
5291 whether this is the csect we want. Note that we will
5292 only get here if the csect has zero length. */
5293 if (symbol_get_frag (csect)->fr_address == val
5294 && S_GET_VALUE (csect) == val)
5298 for (scan = symbol_next (csect);
5300 scan = symbol_next (scan))
5302 if (symbol_get_tc (scan)->subseg != 0)
5304 if (scan == fix->fx_addsy)
5308 /* If we found the symbol before the next csect
5309 symbol, then this is the csect we want. */
5310 if (scan == fix->fx_addsy)
5317 fix->fx_offset += val - symbol_get_frag (csect)->fr_address;
5318 fix->fx_addsy = csect;
5323 /* Adjust a reloc against a .lcomm symbol to be against the base
5325 if (symseg == bss_section
5326 && ! S_IS_EXTERNAL (fix->fx_addsy))
5328 symbolS *sy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
5330 fix->fx_offset += val - resolve_symbol_value (sy);
5337 /* A reloc from one csect to another must be kept. The assembler
5338 will, of course, keep relocs between sections, and it will keep
5339 absolute relocs, but we need to force it to keep PC relative relocs
5340 between two csects in the same section. */
5343 ppc_force_relocation (fix)
5346 /* At this point fix->fx_addsy should already have been converted to
5347 a csect symbol. If the csect does not include the fragment, then
5348 we need to force the relocation. */
5350 && fix->fx_addsy != NULL
5351 && symbol_get_tc (fix->fx_addsy)->subseg != 0
5352 && ((symbol_get_frag (fix->fx_addsy)->fr_address
5353 > fix->fx_frag->fr_address)
5354 || (symbol_get_tc (fix->fx_addsy)->next != NULL
5355 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
5356 <= fix->fx_frag->fr_address))))
5359 return generic_force_reloc (fix);
5362 #endif /* OBJ_XCOFF */
5365 /* If this function returns non-zero, it guarantees that a relocation
5366 will be emitted for a fixup. */
5369 ppc_force_relocation (fix)
5372 /* Branch prediction relocations must force a relocation, as must
5373 the vtable description relocs. */
5374 switch (fix->fx_r_type)
5376 case BFD_RELOC_PPC_B16_BRTAKEN:
5377 case BFD_RELOC_PPC_B16_BRNTAKEN:
5378 case BFD_RELOC_PPC_BA16_BRTAKEN:
5379 case BFD_RELOC_PPC_BA16_BRNTAKEN:
5380 case BFD_RELOC_PPC64_TOC:
5386 if (fix->fx_r_type >= BFD_RELOC_PPC_TLS
5387 && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA)
5390 return generic_force_reloc (fix);
5394 ppc_fix_adjustable (fix)
5397 return (fix->fx_r_type != BFD_RELOC_16_GOTOFF
5398 && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF
5399 && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF
5400 && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
5401 && fix->fx_r_type != BFD_RELOC_GPREL16
5402 && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
5403 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY
5404 && !(fix->fx_r_type >= BFD_RELOC_PPC_TLS
5405 && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA)
5407 || (fix->fx_subsy != NULL
5408 && (S_GET_SEGMENT (fix->fx_subsy)
5409 == S_GET_SEGMENT (fix->fx_addsy)))
5410 || S_IS_LOCAL (fix->fx_addsy)));
5414 /* Apply a fixup to the object code. This is called for all the
5415 fixups we generated by the call to fix_new_exp, above. In the call
5416 above we used a reloc code which was the largest legal reloc code
5417 plus the operand index. Here we undo that to recover the operand
5418 index. At this point all symbol values should be fully resolved,
5419 and we attempt to completely resolve the reloc. If we can not do
5420 that, we determine the correct reloc code and put it back in the
5424 md_apply_fix3 (fixP, valP, seg)
5427 segT seg ATTRIBUTE_UNUSED;
5429 valueT value = * valP;
5432 if (fixP->fx_addsy != NULL)
5434 /* Hack around bfd_install_relocation brain damage. */
5436 value += fixP->fx_frag->fr_address + fixP->fx_where;
5441 /* FIXME FIXME FIXME: The value we are passed in *valP includes
5442 the symbol values. Since we are using BFD_ASSEMBLER, if we are
5443 doing this relocation the code in write.c is going to call
5444 bfd_install_relocation, which is also going to use the symbol
5445 value. That means that if the reloc is fully resolved we want to
5446 use *valP since bfd_install_relocation is not being used.
5447 However, if the reloc is not fully resolved we do not want to use
5448 *valP, and must use fx_offset instead. However, if the reloc
5449 is PC relative, we do want to use *valP since it includes the
5450 result of md_pcrel_from. This is confusing. */
5451 if (fixP->fx_addsy == (symbolS *) NULL)
5454 else if (fixP->fx_pcrel)
5458 value = fixP->fx_offset;
5461 if (fixP->fx_subsy != (symbolS *) NULL)
5463 /* We can't actually support subtracting a symbol. */
5464 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
5467 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
5470 const struct powerpc_operand *operand;
5474 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
5476 operand = &powerpc_operands[opindex];
5479 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5480 does not generate a reloc. It uses the offset of `sym' within its
5481 csect. Other usages, such as `.long sym', generate relocs. This
5482 is the documented behaviour of non-TOC symbols. */
5483 if ((operand->flags & PPC_OPERAND_PARENS) != 0
5484 && operand->bits == 16
5485 && operand->shift == 0
5486 && (operand->insert == NULL || ppc_obj64)
5487 && fixP->fx_addsy != NULL
5488 && symbol_get_tc (fixP->fx_addsy)->subseg != 0
5489 && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC
5490 && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC0
5491 && S_GET_SEGMENT (fixP->fx_addsy) != bss_section)
5493 value = fixP->fx_offset;
5498 /* Fetch the instruction, insert the fully resolved operand
5499 value, and stuff the instruction back again. */
5500 where = fixP->fx_frag->fr_literal + fixP->fx_where;
5501 if (target_big_endian)
5502 insn = bfd_getb32 ((unsigned char *) where);
5504 insn = bfd_getl32 ((unsigned char *) where);
5505 insn = ppc_insert_operand (insn, operand, (offsetT) value,
5506 fixP->fx_file, fixP->fx_line);
5507 if (target_big_endian)
5508 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5510 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5513 /* Nothing else to do here. */
5516 assert (fixP->fx_addsy != NULL);
5518 /* Determine a BFD reloc value based on the operand information.
5519 We are only prepared to turn a few of the operands into
5521 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5522 && operand->bits == 26
5523 && operand->shift == 0)
5524 fixP->fx_r_type = BFD_RELOC_PPC_B26;
5525 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5526 && operand->bits == 16
5527 && operand->shift == 0)
5529 fixP->fx_r_type = BFD_RELOC_PPC_B16;
5532 if (target_big_endian)
5533 fixP->fx_where += 2;
5536 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5537 && operand->bits == 26
5538 && operand->shift == 0)
5539 fixP->fx_r_type = BFD_RELOC_PPC_BA26;
5540 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5541 && operand->bits == 16
5542 && operand->shift == 0)
5544 fixP->fx_r_type = BFD_RELOC_PPC_BA16;
5547 if (target_big_endian)
5548 fixP->fx_where += 2;
5551 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5552 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
5553 && operand->bits == 16
5554 && operand->shift == 0)
5556 if (ppc_is_toc_sym (fixP->fx_addsy))
5558 fixP->fx_r_type = BFD_RELOC_PPC_TOC16;
5561 && (operand->flags & PPC_OPERAND_DS) != 0)
5562 fixP->fx_r_type = BFD_RELOC_PPC64_TOC16_DS;
5567 fixP->fx_r_type = BFD_RELOC_16;
5570 && (operand->flags & PPC_OPERAND_DS) != 0)
5571 fixP->fx_r_type = BFD_RELOC_PPC64_ADDR16_DS;
5575 if (target_big_endian)
5576 fixP->fx_where += 2;
5578 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5584 /* Use expr_symbol_where to see if this is an expression
5586 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
5587 as_bad_where (fixP->fx_file, fixP->fx_line,
5588 _("unresolved expression that must be resolved"));
5590 as_bad_where (fixP->fx_file, fixP->fx_line,
5591 _("unsupported relocation against %s"),
5592 S_GET_NAME (fixP->fx_addsy));
5600 ppc_elf_validate_fix (fixP, seg);
5602 switch (fixP->fx_r_type)
5604 case BFD_RELOC_CTOR:
5611 fixP->fx_r_type = BFD_RELOC_32_PCREL;
5615 case BFD_RELOC_32_PCREL:
5616 case BFD_RELOC_PPC_EMB_NADDR32:
5617 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5624 fixP->fx_r_type = BFD_RELOC_64_PCREL;
5627 case BFD_RELOC_64_PCREL:
5628 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5632 case BFD_RELOC_LO16:
5634 case BFD_RELOC_GPREL16:
5635 case BFD_RELOC_16_GOT_PCREL:
5636 case BFD_RELOC_16_GOTOFF:
5637 case BFD_RELOC_LO16_GOTOFF:
5638 case BFD_RELOC_HI16_GOTOFF:
5639 case BFD_RELOC_HI16_S_GOTOFF:
5640 case BFD_RELOC_16_BASEREL:
5641 case BFD_RELOC_LO16_BASEREL:
5642 case BFD_RELOC_HI16_BASEREL:
5643 case BFD_RELOC_HI16_S_BASEREL:
5644 case BFD_RELOC_PPC_EMB_NADDR16:
5645 case BFD_RELOC_PPC_EMB_NADDR16_LO:
5646 case BFD_RELOC_PPC_EMB_NADDR16_HI:
5647 case BFD_RELOC_PPC_EMB_NADDR16_HA:
5648 case BFD_RELOC_PPC_EMB_SDAI16:
5649 case BFD_RELOC_PPC_EMB_SDA2REL:
5650 case BFD_RELOC_PPC_EMB_SDA2I16:
5651 case BFD_RELOC_PPC_EMB_RELSEC16:
5652 case BFD_RELOC_PPC_EMB_RELST_LO:
5653 case BFD_RELOC_PPC_EMB_RELST_HI:
5654 case BFD_RELOC_PPC_EMB_RELST_HA:
5655 case BFD_RELOC_PPC_EMB_RELSDA:
5656 case BFD_RELOC_PPC_TOC16:
5658 case BFD_RELOC_PPC64_TOC16_LO:
5659 case BFD_RELOC_PPC64_TOC16_HI:
5660 case BFD_RELOC_PPC64_TOC16_HA:
5664 if (fixP->fx_addsy != NULL)
5665 as_bad_where (fixP->fx_file, fixP->fx_line,
5666 _("cannot emit PC relative %s relocation against %s"),
5667 bfd_get_reloc_code_name (fixP->fx_r_type),
5668 S_GET_NAME (fixP->fx_addsy));
5670 as_bad_where (fixP->fx_file, fixP->fx_line,
5671 _("cannot emit PC relative %s relocation"),
5672 bfd_get_reloc_code_name (fixP->fx_r_type));
5675 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5679 /* This case happens when you write, for example,
5681 where L1 and L2 are defined later. */
5682 case BFD_RELOC_HI16:
5685 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5689 case BFD_RELOC_HI16_S:
5692 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5697 case BFD_RELOC_PPC64_HIGHER:
5700 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5701 PPC_HIGHER (value), 2);
5704 case BFD_RELOC_PPC64_HIGHER_S:
5707 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5708 PPC_HIGHERA (value), 2);
5711 case BFD_RELOC_PPC64_HIGHEST:
5714 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5715 PPC_HIGHEST (value), 2);
5718 case BFD_RELOC_PPC64_HIGHEST_S:
5721 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5722 PPC_HIGHESTA (value), 2);
5725 case BFD_RELOC_PPC64_ADDR16_DS:
5726 case BFD_RELOC_PPC64_ADDR16_LO_DS:
5727 case BFD_RELOC_PPC64_GOT16_DS:
5728 case BFD_RELOC_PPC64_GOT16_LO_DS:
5729 case BFD_RELOC_PPC64_PLT16_LO_DS:
5730 case BFD_RELOC_PPC64_SECTOFF_DS:
5731 case BFD_RELOC_PPC64_SECTOFF_LO_DS:
5732 case BFD_RELOC_PPC64_TOC16_DS:
5733 case BFD_RELOC_PPC64_TOC16_LO_DS:
5734 case BFD_RELOC_PPC64_PLTGOT16_DS:
5735 case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
5739 unsigned char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
5740 unsigned long val, mask;
5742 if (target_big_endian)
5743 val = bfd_getb32 (where - 2);
5745 val = bfd_getl32 (where);
5747 /* lq insns reserve the four lsbs. */
5748 if ((ppc_cpu & PPC_OPCODE_POWER4) != 0
5749 && (val & (0x3f << 26)) == (56u << 26))
5751 val |= value & mask;
5752 if (target_big_endian)
5753 bfd_putb16 ((bfd_vma) val, where);
5755 bfd_putl16 ((bfd_vma) val, where);
5759 case BFD_RELOC_PPC_B16_BRTAKEN:
5760 case BFD_RELOC_PPC_B16_BRNTAKEN:
5761 case BFD_RELOC_PPC_BA16_BRTAKEN:
5762 case BFD_RELOC_PPC_BA16_BRNTAKEN:
5765 case BFD_RELOC_PPC_TLS:
5766 case BFD_RELOC_PPC_DTPMOD:
5767 case BFD_RELOC_PPC_TPREL16:
5768 case BFD_RELOC_PPC_TPREL16_LO:
5769 case BFD_RELOC_PPC_TPREL16_HI:
5770 case BFD_RELOC_PPC_TPREL16_HA:
5771 case BFD_RELOC_PPC_TPREL:
5772 case BFD_RELOC_PPC_DTPREL16:
5773 case BFD_RELOC_PPC_DTPREL16_LO:
5774 case BFD_RELOC_PPC_DTPREL16_HI:
5775 case BFD_RELOC_PPC_DTPREL16_HA:
5776 case BFD_RELOC_PPC_DTPREL:
5777 case BFD_RELOC_PPC_GOT_TLSGD16:
5778 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
5779 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
5780 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
5781 case BFD_RELOC_PPC_GOT_TLSLD16:
5782 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
5783 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
5784 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
5785 case BFD_RELOC_PPC_GOT_TPREL16:
5786 case BFD_RELOC_PPC_GOT_TPREL16_LO:
5787 case BFD_RELOC_PPC_GOT_TPREL16_HI:
5788 case BFD_RELOC_PPC_GOT_TPREL16_HA:
5789 case BFD_RELOC_PPC_GOT_DTPREL16:
5790 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
5791 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
5792 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
5793 case BFD_RELOC_PPC64_TPREL16_DS:
5794 case BFD_RELOC_PPC64_TPREL16_LO_DS:
5795 case BFD_RELOC_PPC64_TPREL16_HIGHER:
5796 case BFD_RELOC_PPC64_TPREL16_HIGHERA:
5797 case BFD_RELOC_PPC64_TPREL16_HIGHEST:
5798 case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
5799 case BFD_RELOC_PPC64_DTPREL16_DS:
5800 case BFD_RELOC_PPC64_DTPREL16_LO_DS:
5801 case BFD_RELOC_PPC64_DTPREL16_HIGHER:
5802 case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
5803 case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
5804 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
5807 /* Because SDA21 modifies the register field, the size is set to 4
5808 bytes, rather than 2, so offset it here appropriately. */
5809 case BFD_RELOC_PPC_EMB_SDA21:
5813 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where
5814 + ((target_big_endian) ? 2 : 0),
5822 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5826 case BFD_RELOC_24_PLT_PCREL:
5827 case BFD_RELOC_PPC_LOCAL24PC:
5828 if (!fixP->fx_pcrel && !fixP->fx_done)
5836 /* Fetch the instruction, insert the fully resolved operand
5837 value, and stuff the instruction back again. */
5838 where = fixP->fx_frag->fr_literal + fixP->fx_where;
5839 if (target_big_endian)
5840 insn = bfd_getb32 ((unsigned char *) where);
5842 insn = bfd_getl32 ((unsigned char *) where);
5843 if ((value & 3) != 0)
5844 as_bad_where (fixP->fx_file, fixP->fx_line,
5845 _("must branch to an address a multiple of 4"));
5846 if ((offsetT) value < -0x40000000
5847 || (offsetT) value >= 0x40000000)
5848 as_bad_where (fixP->fx_file, fixP->fx_line,
5849 _("@local or @plt branch destination is too far away, %ld bytes"),
5851 insn = insn | (value & 0x03fffffc);
5852 if (target_big_endian)
5853 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5855 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5859 case BFD_RELOC_VTABLE_INHERIT:
5862 && !S_IS_DEFINED (fixP->fx_addsy)
5863 && !S_IS_WEAK (fixP->fx_addsy))
5864 S_SET_WEAK (fixP->fx_addsy);
5867 case BFD_RELOC_VTABLE_ENTRY:
5872 /* Generated by reference to `sym@tocbase'. The sym is
5873 ignored by the linker. */
5874 case BFD_RELOC_PPC64_TOC:
5880 _("Gas failure, reloc value %d\n"), fixP->fx_r_type);
5887 fixP->fx_addnumber = value;
5889 if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16)
5890 fixP->fx_addnumber = 0;
5894 fixP->fx_addnumber = 0;
5896 /* We want to use the offset within the data segment of the
5897 symbol, not the actual VMA of the symbol. */
5898 fixP->fx_addnumber =
5899 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy));
5905 /* Generate a reloc for a fixup. */
5908 tc_gen_reloc (seg, fixp)
5909 asection *seg ATTRIBUTE_UNUSED;
5914 reloc = (arelent *) xmalloc (sizeof (arelent));
5916 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
5917 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
5918 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
5919 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
5920 if (reloc->howto == (reloc_howto_type *) NULL)
5922 as_bad_where (fixp->fx_file, fixp->fx_line,
5923 _("reloc %d not supported by object file format"),
5924 (int) fixp->fx_r_type);
5927 reloc->addend = fixp->fx_addnumber;
5933 ppc_cfi_frame_initial_instructions ()
5935 cfi_add_CFA_def_cfa (1, 0);
5939 tc_ppc_regname_to_dw2regnum (const char *regname)
5941 unsigned int regnum = -1;
5945 static struct { char *name; int dw2regnum; } regnames[] =
5947 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
5948 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
5949 { "cc", 68 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
5950 { "spe_acc", 111 }, { "spefscr", 112 }
5953 for (i = 0; i < ARRAY_SIZE (regnames); ++i)
5954 if (strcmp (regnames[i].name, regname) == 0)
5955 return regnames[i].dw2regnum;
5957 if (regname[0] == 'r' || regname[0] == 'f' || regname[0] == 'v')
5959 p = regname + 1 + (regname[1] == '.');
5960 regnum = strtoul (p, &q, 10);
5961 if (p == q || *q || regnum >= 32)
5963 if (regname[0] == 'f')
5965 else if (regname[0] == 'v')
5968 else if (regname[0] == 'c' && regname[1] == 'r')
5970 p = regname + 2 + (regname[2] == '.');
5971 if (p[0] < '0' || p[0] > '7' || p[1])
5973 regnum = p[0] - '0' + 68;