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 2004, 2005, 2006 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, 51 Franklin Street - Fifth Floor, 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 Also, anything that can start an operand needs to be mentioned here,
189 to stop the input scrubber eating whitespace. */
190 const char ppc_symbol_chars
[] = "+-%[";
192 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
193 int ppc_cie_data_alignment
;
195 /* The target specific pseudo-ops which we support. */
197 const pseudo_typeS md_pseudo_table
[] =
199 /* Pseudo-ops which must be overridden. */
200 { "byte", ppc_byte
, 0 },
203 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
204 legitimately belong in the obj-*.c file. However, XCOFF is based
205 on COFF, and is only implemented for the RS/6000. We just use
206 obj-coff.c, and add what we need here. */
207 { "comm", ppc_comm
, 0 },
208 { "lcomm", ppc_comm
, 1 },
212 { "bi", ppc_biei
, 0 },
214 { "csect", ppc_csect
, 0 },
215 { "data", ppc_section
, 'd' },
219 { "ei", ppc_biei
, 1 },
221 { "extern", ppc_extern
, 0 },
222 { "function", ppc_function
, 0 },
223 { "lglobl", ppc_lglobl
, 0 },
224 { "rename", ppc_rename
, 0 },
225 { "section", ppc_named_section
, 0 },
226 { "stabx", ppc_stabx
, 0 },
227 { "text", ppc_section
, 't' },
228 { "toc", ppc_toc
, 0 },
229 { "long", ppc_xcoff_cons
, 2 },
230 { "llong", ppc_xcoff_cons
, 3 },
231 { "word", ppc_xcoff_cons
, 1 },
232 { "short", ppc_xcoff_cons
, 1 },
233 { "vbyte", ppc_vbyte
, 0 },
237 { "llong", ppc_elf_cons
, 8 },
238 { "quad", ppc_elf_cons
, 8 },
239 { "long", ppc_elf_cons
, 4 },
240 { "word", ppc_elf_cons
, 2 },
241 { "short", ppc_elf_cons
, 2 },
242 { "rdata", ppc_elf_rdata
, 0 },
243 { "rodata", ppc_elf_rdata
, 0 },
244 { "lcomm", ppc_elf_lcomm
, 0 },
248 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
249 { "previous", ppc_previous
, 0 },
250 { "pdata", ppc_pdata
, 0 },
251 { "ydata", ppc_ydata
, 0 },
252 { "reldata", ppc_reldata
, 0 },
253 { "rdata", ppc_rdata
, 0 },
254 { "ualong", ppc_ualong
, 0 },
255 { "znop", ppc_znop
, 0 },
256 { "comm", ppc_pe_comm
, 0 },
257 { "lcomm", ppc_pe_comm
, 1 },
258 { "section", ppc_pe_section
, 0 },
259 { "function", ppc_pe_function
,0 },
260 { "tocd", ppc_pe_tocd
, 0 },
263 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
265 { "machine", ppc_machine
, 0 },
272 /* Predefined register names if -mregnames (or default for Windows NT).
273 In general, there are lots of them, in an attempt to be compatible
274 with a number of other Windows NT assemblers. */
276 /* Structure to hold information about predefined registers. */
283 /* List of registers that are pre-defined:
285 Each general register has predefined names of the form:
286 1. r<reg_num> which has the value <reg_num>.
287 2. r.<reg_num> which has the value <reg_num>.
289 Each floating point register has predefined names of the form:
290 1. f<reg_num> which has the value <reg_num>.
291 2. f.<reg_num> which has the value <reg_num>.
293 Each vector unit register has predefined names of the form:
294 1. v<reg_num> which has the value <reg_num>.
295 2. v.<reg_num> which has the value <reg_num>.
297 Each condition register has predefined names of the form:
298 1. cr<reg_num> which has the value <reg_num>.
299 2. cr.<reg_num> which has the value <reg_num>.
301 There are individual registers as well:
302 sp or r.sp has the value 1
303 rtoc or r.toc has the value 2
304 fpscr has the value 0
310 dsisr has the value 18
312 sdr1 has the value 25
313 srr0 has the value 26
314 srr1 has the value 27
316 The table is sorted. Suitable for searching by a binary search. */
318 static const struct pd_reg pre_defined_registers
[] =
320 { "cr.0", 0 }, /* Condition Registers */
340 { "dar", 19 }, /* Data Access Register */
341 { "dec", 22 }, /* Decrementer */
342 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
344 { "f.0", 0 }, /* Floating point registers */
412 { "lr", 8 }, /* Link Register */
416 { "r.0", 0 }, /* General Purpose Registers */
449 { "r.sp", 1 }, /* Stack Pointer */
451 { "r.toc", 2 }, /* Pointer to the table of contents */
453 { "r0", 0 }, /* More general purpose registers */
486 { "rtoc", 2 }, /* Table of contents */
488 { "sdr1", 25 }, /* Storage Description Register 1 */
492 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
493 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
495 { "v.0", 0 }, /* Vector registers */
565 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
567 /* Given NAME, find the register number associated with that name, return
568 the integer value associated with the given name or -1 on failure. */
570 static int reg_name_search
571 PARAMS ((const struct pd_reg
*, int, const char * name
));
574 reg_name_search (regs
, regcount
, name
)
575 const struct pd_reg
*regs
;
579 int middle
, low
, high
;
587 middle
= (low
+ high
) / 2;
588 cmp
= strcasecmp (name
, regs
[middle
].name
);
594 return regs
[middle
].value
;
602 * Summary of register_name.
604 * in: Input_line_pointer points to 1st char of operand.
606 * out: A expressionS.
607 * The operand may have been a register: in this case, X_op == O_register,
608 * X_add_number is set to the register number, and truth is returned.
609 * Input_line_pointer->(next non-blank) char after operand, or is in its
614 register_name (expressionP
)
615 expressionS
*expressionP
;
622 /* Find the spelling of the operand. */
623 start
= name
= input_line_pointer
;
624 if (name
[0] == '%' && ISALPHA (name
[1]))
625 name
= ++input_line_pointer
;
627 else if (!reg_names_p
|| !ISALPHA (name
[0]))
630 c
= get_symbol_end ();
631 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
633 /* Put back the delimiting char. */
634 *input_line_pointer
= c
;
636 /* Look to see if it's in the register table. */
639 expressionP
->X_op
= O_register
;
640 expressionP
->X_add_number
= reg_number
;
642 /* Make the rest nice. */
643 expressionP
->X_add_symbol
= NULL
;
644 expressionP
->X_op_symbol
= NULL
;
648 /* Reset the line as if we had not done anything. */
649 input_line_pointer
= start
;
653 /* This function is called for each symbol seen in an expression. It
654 handles the special parsing which PowerPC assemblers are supposed
655 to use for condition codes. */
657 /* Whether to do the special parsing. */
658 static bfd_boolean cr_operand
;
660 /* Names to recognize in a condition code. This table is sorted. */
661 static const struct pd_reg cr_names
[] =
678 /* Parsing function. This returns non-zero if it recognized an
682 ppc_parse_name (name
, expr
)
691 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
696 expr
->X_op
= O_constant
;
697 expr
->X_add_number
= val
;
702 /* Local variables. */
704 /* The type of processor we are assembling for. This is one or more
705 of the PPC_OPCODE flags defined in opcode/ppc.h. */
706 static unsigned long ppc_cpu
= 0;
708 /* Whether to target xcoff64/elf64. */
709 static unsigned int ppc_obj64
= BFD_DEFAULT_TARGET_SIZE
== 64;
711 /* Opcode hash table. */
712 static struct hash_control
*ppc_hash
;
714 /* Macro hash table. */
715 static struct hash_control
*ppc_macro_hash
;
718 /* What type of shared library support to use. */
719 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
721 /* Flags to set in the elf header. */
722 static flagword ppc_flags
= 0;
724 /* Whether this is Solaris or not. */
725 #ifdef TARGET_SOLARIS_COMMENT
726 #define SOLARIS_P TRUE
728 #define SOLARIS_P FALSE
731 static bfd_boolean msolaris
= SOLARIS_P
;
736 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
737 using a bunch of different sections. These assembler sections,
738 however, are all encompassed within the .text or .data sections of
739 the final output file. We handle this by using different
740 subsegments within these main segments. */
742 /* Next subsegment to allocate within the .text segment. */
743 static subsegT ppc_text_subsegment
= 2;
745 /* Linked list of csects in the text section. */
746 static symbolS
*ppc_text_csects
;
748 /* Next subsegment to allocate within the .data segment. */
749 static subsegT ppc_data_subsegment
= 2;
751 /* Linked list of csects in the data section. */
752 static symbolS
*ppc_data_csects
;
754 /* The current csect. */
755 static symbolS
*ppc_current_csect
;
757 /* The RS/6000 assembler uses a TOC which holds addresses of functions
758 and variables. Symbols are put in the TOC with the .tc pseudo-op.
759 A special relocation is used when accessing TOC entries. We handle
760 the TOC as a subsegment within the .data segment. We set it up if
761 we see a .toc pseudo-op, and save the csect symbol here. */
762 static symbolS
*ppc_toc_csect
;
764 /* The first frag in the TOC subsegment. */
765 static fragS
*ppc_toc_frag
;
767 /* The first frag in the first subsegment after the TOC in the .data
768 segment. NULL if there are no subsegments after the TOC. */
769 static fragS
*ppc_after_toc_frag
;
771 /* The current static block. */
772 static symbolS
*ppc_current_block
;
774 /* The COFF debugging section; set by md_begin. This is not the
775 .debug section, but is instead the secret BFD section which will
776 cause BFD to set the section number of a symbol to N_DEBUG. */
777 static asection
*ppc_coff_debug_section
;
779 #endif /* OBJ_XCOFF */
783 /* Various sections that we need for PE coff support. */
784 static segT ydata_section
;
785 static segT pdata_section
;
786 static segT reldata_section
;
787 static segT rdata_section
;
788 static segT tocdata_section
;
790 /* The current section and the previous section. See ppc_previous. */
791 static segT ppc_previous_section
;
792 static segT ppc_current_section
;
797 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
798 #define PPC_APUINFO_ISEL 0x40
799 #define PPC_APUINFO_PMR 0x41
800 #define PPC_APUINFO_RFMCI 0x42
801 #define PPC_APUINFO_CACHELCK 0x43
802 #define PPC_APUINFO_SPE 0x100
803 #define PPC_APUINFO_EFS 0x101
804 #define PPC_APUINFO_BRLOCK 0x102
807 * We keep a list of APUinfo
809 unsigned long *ppc_apuinfo_list
;
810 unsigned int ppc_apuinfo_num
;
811 unsigned int ppc_apuinfo_num_alloc
;
815 const char *const md_shortopts
= "b:l:usm:K:VQ:";
817 const char *const md_shortopts
= "um:";
819 const struct option md_longopts
[] = {
820 {NULL
, no_argument
, NULL
, 0}
822 const size_t md_longopts_size
= sizeof (md_longopts
);
825 /* Handle -m options that set cpu type, and .machine arg. */
828 parse_cpu (const char *arg
)
830 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
832 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
833 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_32
;
834 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
835 else if (strcmp (arg
, "pwr") == 0)
836 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
837 /* -m601 means to assemble for the PowerPC 601, which includes
838 instructions that are holdovers from the Power. */
839 else if (strcmp (arg
, "601") == 0)
840 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
841 | PPC_OPCODE_601
| PPC_OPCODE_32
);
842 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
844 else if (strcmp (arg
, "ppc") == 0
845 || strcmp (arg
, "ppc32") == 0
846 || strcmp (arg
, "603") == 0
847 || strcmp (arg
, "604") == 0)
848 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
849 /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */
850 else if (strcmp (arg
, "403") == 0
851 || strcmp (arg
, "405") == 0)
852 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
853 | PPC_OPCODE_403
| PPC_OPCODE_32
);
854 else if (strcmp (arg
, "440") == 0)
855 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
856 | PPC_OPCODE_440
| PPC_OPCODE_ISEL
| PPC_OPCODE_RFMCI
);
857 else if (strcmp (arg
, "7400") == 0
858 || strcmp (arg
, "7410") == 0
859 || strcmp (arg
, "7450") == 0
860 || strcmp (arg
, "7455") == 0)
861 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
862 | PPC_OPCODE_ALTIVEC
| PPC_OPCODE_32
);
863 else if (strcmp (arg
, "e300") == 0)
864 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
866 else if (strcmp (arg
, "altivec") == 0)
869 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_ALTIVEC
;
871 ppc_cpu
|= PPC_OPCODE_ALTIVEC
;
873 else if (strcmp (arg
, "e500") == 0 || strcmp (arg
, "e500x2") == 0)
875 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
876 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
877 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
880 else if (strcmp (arg
, "spe") == 0)
883 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_SPE
| PPC_OPCODE_EFS
;
885 ppc_cpu
|= PPC_OPCODE_SPE
;
887 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
889 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
891 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
893 else if (strcmp (arg
, "ppc64bridge") == 0)
895 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
896 | PPC_OPCODE_64_BRIDGE
| PPC_OPCODE_64
);
898 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
899 else if (strcmp (arg
, "booke") == 0 || strcmp (arg
, "booke32") == 0)
901 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
;
903 /* -mbooke64 means enable 64-bit BookE support. */
904 else if (strcmp (arg
, "booke64") == 0)
906 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
907 | PPC_OPCODE_BOOKE64
| PPC_OPCODE_64
);
909 else if (strcmp (arg
, "power4") == 0)
911 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
912 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
);
914 else if (strcmp (arg
, "power5") == 0)
916 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
917 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
918 | PPC_OPCODE_POWER5
);
920 else if (strcmp (arg
, "power6") == 0)
922 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
923 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
924 | PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
);
926 /* -mcom means assemble for the common intersection between Power
927 and PowerPC. At present, we just allow the union, rather
928 than the intersection. */
929 else if (strcmp (arg
, "com") == 0)
930 ppc_cpu
= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
931 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
932 else if (strcmp (arg
, "any") == 0)
933 ppc_cpu
|= PPC_OPCODE_ANY
;
941 md_parse_option (c
, arg
)
948 /* -u means that any undefined symbols should be treated as
949 external, which is the default for gas anyhow. */
954 /* Solaris as takes -le (presumably for little endian). For completeness
955 sake, recognize -be also. */
956 if (strcmp (arg
, "e") == 0)
958 target_big_endian
= 0;
959 set_target_endian
= 1;
967 if (strcmp (arg
, "e") == 0)
969 target_big_endian
= 1;
970 set_target_endian
= 1;
978 /* Recognize -K PIC. */
979 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
982 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
990 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
992 if (strcmp (arg
, "64") == 0)
997 as_fatal (_("%s unsupported"), "-a64");
1000 else if (strcmp (arg
, "32") == 0)
1007 if (parse_cpu (arg
))
1010 else if (strcmp (arg
, "regnames") == 0)
1013 else if (strcmp (arg
, "no-regnames") == 0)
1014 reg_names_p
= FALSE
;
1017 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1018 that require relocation. */
1019 else if (strcmp (arg
, "relocatable") == 0)
1021 shlib
= SHLIB_MRELOCATABLE
;
1022 ppc_flags
|= EF_PPC_RELOCATABLE
;
1025 else if (strcmp (arg
, "relocatable-lib") == 0)
1027 shlib
= SHLIB_MRELOCATABLE
;
1028 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
1031 /* -memb, set embedded bit. */
1032 else if (strcmp (arg
, "emb") == 0)
1033 ppc_flags
|= EF_PPC_EMB
;
1035 /* -mlittle/-mbig set the endianess. */
1036 else if (strcmp (arg
, "little") == 0
1037 || strcmp (arg
, "little-endian") == 0)
1039 target_big_endian
= 0;
1040 set_target_endian
= 1;
1043 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
1045 target_big_endian
= 1;
1046 set_target_endian
= 1;
1049 else if (strcmp (arg
, "solaris") == 0)
1052 ppc_comment_chars
= ppc_solaris_comment_chars
;
1055 else if (strcmp (arg
, "no-solaris") == 0)
1058 ppc_comment_chars
= ppc_eabi_comment_chars
;
1063 as_bad (_("invalid switch -m%s"), arg
);
1069 /* -V: SVR4 argument to print version ID. */
1071 print_version_id ();
1074 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1075 should be emitted or not. FIXME: Not implemented. */
1079 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1080 rather than .stabs.excl, which is ignored by the linker.
1081 FIXME: Not implemented. */
1097 md_show_usage (stream
)
1100 fprintf (stream
, _("\
1102 -a32 generate ELF32/XCOFF32\n\
1103 -a64 generate ELF64/XCOFF64\n\
1105 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1106 -mpwr generate code for POWER (RIOS1)\n\
1107 -m601 generate code for PowerPC 601\n\
1108 -mppc, -mppc32, -m603, -m604\n\
1109 generate code for PowerPC 603/604\n\
1110 -m403, -m405 generate code for PowerPC 403/405\n\
1111 -m440 generate code for PowerPC 440\n\
1112 -m7400, -m7410, -m7450, -m7455\n\
1113 generate code For PowerPC 7400/7410/7450/7455\n"));
1114 fprintf (stream
, _("\
1115 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1116 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1117 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1118 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1119 -mpower4 generate code for Power4 architecture\n\
1120 -mpower5 generate code for Power5 architecture\n\
1121 -mpower6 generate code for Power6 architecture\n\
1122 -mcom generate code Power/PowerPC common instructions\n\
1123 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1124 fprintf (stream
, _("\
1125 -maltivec generate code for AltiVec\n\
1126 -me300 generate code for PowerPC e300 family\n\
1127 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1128 -mspe generate code for Motorola SPE instructions\n\
1129 -mregnames Allow symbolic names for registers\n\
1130 -mno-regnames Do not allow symbolic names for registers\n"));
1132 fprintf (stream
, _("\
1133 -mrelocatable support for GCC's -mrelocatble option\n\
1134 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1135 -memb set PPC_EMB bit in ELF flags\n\
1136 -mlittle, -mlittle-endian, -l, -le\n\
1137 generate code for a little endian machine\n\
1138 -mbig, -mbig-endian, -b, -be\n\
1139 generate code for a big endian machine\n\
1140 -msolaris generate code for Solaris\n\
1141 -mno-solaris do not generate code for Solaris\n\
1142 -V print assembler version number\n\
1143 -Qy, -Qn ignored\n"));
1147 /* Set ppc_cpu if it is not already set. */
1152 const char *default_os
= TARGET_OS
;
1153 const char *default_cpu
= TARGET_CPU
;
1155 if ((ppc_cpu
& ~PPC_OPCODE_ANY
) == 0)
1158 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
1159 else if (strncmp (default_os
, "aix", 3) == 0
1160 && default_os
[3] >= '4' && default_os
[3] <= '9')
1161 ppc_cpu
|= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
1162 else if (strncmp (default_os
, "aix3", 4) == 0)
1163 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1164 else if (strcmp (default_cpu
, "rs6000") == 0)
1165 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1166 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1167 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
1169 as_fatal (_("Unknown default cpu = %s, os = %s"),
1170 default_cpu
, default_os
);
1174 /* Figure out the BFD architecture to use. This function and ppc_mach
1175 are called well before md_begin, when the output file is opened. */
1177 enum bfd_architecture
1180 const char *default_cpu
= TARGET_CPU
;
1183 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1184 return bfd_arch_powerpc
;
1185 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1186 return bfd_arch_rs6000
;
1187 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1189 if (strcmp (default_cpu
, "rs6000") == 0)
1190 return bfd_arch_rs6000
;
1191 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1192 return bfd_arch_powerpc
;
1195 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1196 return bfd_arch_unknown
;
1203 return bfd_mach_ppc64
;
1204 else if (ppc_arch () == bfd_arch_rs6000
)
1205 return bfd_mach_rs6k
;
1207 return bfd_mach_ppc
;
1211 ppc_target_format ()
1215 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1217 return "xcoff-powermac";
1220 return (ppc_obj64
? "aix5coff64-rs6000" : "aixcoff-rs6000");
1222 return (ppc_obj64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1228 return "elf32-powerpc-vxworks";
1230 return (target_big_endian
1231 ? (ppc_obj64
? "elf64-powerpc" : "elf32-powerpc")
1232 : (ppc_obj64
? "elf64-powerpcle" : "elf32-powerpcle"));
1237 /* Insert opcodes and macros into hash tables. Called at startup and
1241 ppc_setup_opcodes (void)
1243 register const struct powerpc_opcode
*op
;
1244 const struct powerpc_opcode
*op_end
;
1245 const struct powerpc_macro
*macro
;
1246 const struct powerpc_macro
*macro_end
;
1247 bfd_boolean dup_insn
= FALSE
;
1249 if (ppc_hash
!= NULL
)
1250 hash_die (ppc_hash
);
1251 if (ppc_macro_hash
!= NULL
)
1252 hash_die (ppc_macro_hash
);
1254 /* Insert the opcodes into a hash table. */
1255 ppc_hash
= hash_new ();
1257 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1258 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1260 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1262 if ((op
->flags
& ppc_cpu
& ~(PPC_OPCODE_32
| PPC_OPCODE_64
)) != 0
1263 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1264 || ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
))
1265 == (ppc_cpu
& (PPC_OPCODE_32
| PPC_OPCODE_64
)))
1266 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0)
1267 /* Certain instructions (eg: extsw) do not exist in the
1268 32-bit BookE instruction set, but they do exist in the
1269 64-bit BookE instruction set, and other PPC instruction
1270 sets. Check to see if the opcode has the BOOKE64 flag set.
1271 If it does make sure that the target CPU is not the BookE32. */
1272 && ((op
->flags
& PPC_OPCODE_BOOKE64
) == 0
1273 || (ppc_cpu
& PPC_OPCODE_BOOKE64
) == PPC_OPCODE_BOOKE64
1274 || (ppc_cpu
& PPC_OPCODE_BOOKE
) == 0)
1275 && ((op
->flags
& (PPC_OPCODE_POWER4
| PPC_OPCODE_NOPOWER4
)) == 0
1276 || ((op
->flags
& PPC_OPCODE_POWER4
)
1277 == (ppc_cpu
& PPC_OPCODE_POWER4
)))
1278 && ((op
->flags
& PPC_OPCODE_POWER5
) == 0
1279 || ((op
->flags
& PPC_OPCODE_POWER5
)
1280 == (ppc_cpu
& PPC_OPCODE_POWER5
)))
1281 && ((op
->flags
& PPC_OPCODE_POWER6
) == 0
1282 || ((op
->flags
& PPC_OPCODE_POWER6
)
1283 == (ppc_cpu
& PPC_OPCODE_POWER6
))))
1287 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1290 /* Ignore Power duplicates for -m601. */
1291 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1292 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1295 as_bad (_("Internal assembler error for instruction %s"),
1302 if ((ppc_cpu
& PPC_OPCODE_ANY
) != 0)
1303 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1304 hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1306 /* Insert the macros into a hash table. */
1307 ppc_macro_hash
= hash_new ();
1309 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1310 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1312 if ((macro
->flags
& ppc_cpu
) != 0)
1316 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1317 if (retval
!= (const char *) NULL
)
1319 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1329 /* This function is called when the assembler starts up. It is called
1330 after the options have been parsed and the output file has been
1338 ppc_cie_data_alignment
= ppc_obj64
? -8 : -4;
1341 /* Set the ELF flags if desired. */
1342 if (ppc_flags
&& !msolaris
)
1343 bfd_set_private_flags (stdoutput
, ppc_flags
);
1346 ppc_setup_opcodes ();
1348 /* Tell the main code what the endianness is if it is not overridden
1350 if (!set_target_endian
)
1352 set_target_endian
= 1;
1353 target_big_endian
= PPC_BIG_ENDIAN
;
1357 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1359 /* Create dummy symbols to serve as initial csects. This forces the
1360 text csects to precede the data csects. These symbols will not
1362 ppc_text_csects
= symbol_make ("dummy\001");
1363 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1364 ppc_data_csects
= symbol_make ("dummy\001");
1365 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1370 ppc_current_section
= text_section
;
1371 ppc_previous_section
= 0;
1380 if (ppc_apuinfo_list
== NULL
)
1383 /* Ok, so write the section info out. We have this layout:
1387 0 8 length of "APUinfo\0"
1388 4 (n*4) number of APU's (4 bytes each)
1391 20 APU#1 first APU's info
1392 24 APU#2 second APU's info
1397 asection
*seg
= now_seg
;
1398 subsegT subseg
= now_subseg
;
1399 asection
*apuinfo_secp
= (asection
*) NULL
;
1402 /* Create the .PPC.EMB.apuinfo section. */
1403 apuinfo_secp
= subseg_new (".PPC.EMB.apuinfo", 0);
1404 bfd_set_section_flags (stdoutput
,
1406 SEC_HAS_CONTENTS
| SEC_READONLY
);
1409 md_number_to_chars (p
, (valueT
) 8, 4);
1412 md_number_to_chars (p
, (valueT
) ppc_apuinfo_num
* 4, 4);
1415 md_number_to_chars (p
, (valueT
) 2, 4);
1418 strcpy (p
, "APUinfo");
1420 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
1423 md_number_to_chars (p
, (valueT
) ppc_apuinfo_list
[i
], 4);
1426 frag_align (2, 0, 0);
1428 /* We probably can't restore the current segment, for there likely
1431 subseg_set (seg
, subseg
);
1436 /* Insert an operand value into an instruction. */
1438 static unsigned long
1439 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1441 const struct powerpc_operand
*operand
;
1446 if (operand
->bits
!= 32)
1451 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1453 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1454 max
= (1 << operand
->bits
) - 1;
1456 max
= (1 << (operand
->bits
- 1)) - 1;
1457 min
= - (1 << (operand
->bits
- 1));
1461 /* Some people write 32 bit hex constants with the sign
1462 extension done by hand. This shouldn't really be
1463 valid, but, to permit this code to assemble on a 64
1464 bit host, we sign extend the 32 bit value. */
1466 && (val
& (offsetT
) 0x80000000) != 0
1467 && (val
& (offsetT
) 0xffffffff) == val
)
1476 max
= (1 << operand
->bits
) - 1;
1480 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1485 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1486 as_bad_value_out_of_range (_("operand"), test
, (offsetT
) min
, (offsetT
) max
, file
, line
);
1489 if (operand
->insert
)
1494 insn
= (*operand
->insert
) (insn
, (long) val
, ppc_cpu
, &errmsg
);
1495 if (errmsg
!= (const char *) NULL
)
1496 as_bad_where (file
, line
, errmsg
);
1499 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1507 /* Parse @got, etc. and return the desired relocation. */
1508 static bfd_reloc_code_real_type
1509 ppc_elf_suffix (str_p
, exp_p
)
1515 unsigned int length
: 8;
1516 unsigned int valid32
: 1;
1517 unsigned int valid64
: 1;
1526 const struct map_bfd
*ptr
;
1528 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
1529 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
1530 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
1532 static const struct map_bfd mapping
[] = {
1533 MAP ("l", BFD_RELOC_LO16
),
1534 MAP ("h", BFD_RELOC_HI16
),
1535 MAP ("ha", BFD_RELOC_HI16_S
),
1536 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1537 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1538 MAP ("got", BFD_RELOC_16_GOTOFF
),
1539 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1540 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1541 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1542 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1543 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1544 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1545 MAP ("copy", BFD_RELOC_PPC_COPY
),
1546 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1547 MAP ("sectoff", BFD_RELOC_16_BASEREL
),
1548 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1549 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1550 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1551 MAP ("tls", BFD_RELOC_PPC_TLS
),
1552 MAP ("dtpmod", BFD_RELOC_PPC_DTPMOD
),
1553 MAP ("dtprel", BFD_RELOC_PPC_DTPREL
),
1554 MAP ("dtprel@l", BFD_RELOC_PPC_DTPREL16_LO
),
1555 MAP ("dtprel@h", BFD_RELOC_PPC_DTPREL16_HI
),
1556 MAP ("dtprel@ha", BFD_RELOC_PPC_DTPREL16_HA
),
1557 MAP ("tprel", BFD_RELOC_PPC_TPREL
),
1558 MAP ("tprel@l", BFD_RELOC_PPC_TPREL16_LO
),
1559 MAP ("tprel@h", BFD_RELOC_PPC_TPREL16_HI
),
1560 MAP ("tprel@ha", BFD_RELOC_PPC_TPREL16_HA
),
1561 MAP ("got@tlsgd", BFD_RELOC_PPC_GOT_TLSGD16
),
1562 MAP ("got@tlsgd@l", BFD_RELOC_PPC_GOT_TLSGD16_LO
),
1563 MAP ("got@tlsgd@h", BFD_RELOC_PPC_GOT_TLSGD16_HI
),
1564 MAP ("got@tlsgd@ha", BFD_RELOC_PPC_GOT_TLSGD16_HA
),
1565 MAP ("got@tlsld", BFD_RELOC_PPC_GOT_TLSLD16
),
1566 MAP ("got@tlsld@l", BFD_RELOC_PPC_GOT_TLSLD16_LO
),
1567 MAP ("got@tlsld@h", BFD_RELOC_PPC_GOT_TLSLD16_HI
),
1568 MAP ("got@tlsld@ha", BFD_RELOC_PPC_GOT_TLSLD16_HA
),
1569 MAP ("got@dtprel", BFD_RELOC_PPC_GOT_DTPREL16
),
1570 MAP ("got@dtprel@l", BFD_RELOC_PPC_GOT_DTPREL16_LO
),
1571 MAP ("got@dtprel@h", BFD_RELOC_PPC_GOT_DTPREL16_HI
),
1572 MAP ("got@dtprel@ha", BFD_RELOC_PPC_GOT_DTPREL16_HA
),
1573 MAP ("got@tprel", BFD_RELOC_PPC_GOT_TPREL16
),
1574 MAP ("got@tprel@l", BFD_RELOC_PPC_GOT_TPREL16_LO
),
1575 MAP ("got@tprel@h", BFD_RELOC_PPC_GOT_TPREL16_HI
),
1576 MAP ("got@tprel@ha", BFD_RELOC_PPC_GOT_TPREL16_HA
),
1577 MAP32 ("fixup", BFD_RELOC_CTOR
),
1578 MAP32 ("plt", BFD_RELOC_24_PLT_PCREL
),
1579 MAP32 ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1580 MAP32 ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1581 MAP32 ("local", BFD_RELOC_PPC_LOCAL24PC
),
1582 MAP32 ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1583 MAP32 ("sdarel", BFD_RELOC_GPREL16
),
1584 MAP32 ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1585 MAP32 ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1586 MAP32 ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1587 MAP32 ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1588 MAP32 ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1589 MAP32 ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1590 MAP32 ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1591 MAP32 ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1592 MAP32 ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1593 MAP32 ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1594 MAP32 ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1595 MAP32 ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1596 MAP32 ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1597 MAP32 ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1598 MAP32 ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1599 MAP32 ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1600 MAP32 ("xgot", BFD_RELOC_PPC_TOC16
),
1601 MAP64 ("higher", BFD_RELOC_PPC64_HIGHER
),
1602 MAP64 ("highera", BFD_RELOC_PPC64_HIGHER_S
),
1603 MAP64 ("highest", BFD_RELOC_PPC64_HIGHEST
),
1604 MAP64 ("highesta", BFD_RELOC_PPC64_HIGHEST_S
),
1605 MAP64 ("tocbase", BFD_RELOC_PPC64_TOC
),
1606 MAP64 ("toc", BFD_RELOC_PPC_TOC16
),
1607 MAP64 ("toc@l", BFD_RELOC_PPC64_TOC16_LO
),
1608 MAP64 ("toc@h", BFD_RELOC_PPC64_TOC16_HI
),
1609 MAP64 ("toc@ha", BFD_RELOC_PPC64_TOC16_HA
),
1610 MAP64 ("dtprel@higher", BFD_RELOC_PPC64_DTPREL16_HIGHER
),
1611 MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA
),
1612 MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST
),
1613 MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA
),
1614 MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER
),
1615 MAP64 ("tprel@highera", BFD_RELOC_PPC64_TPREL16_HIGHERA
),
1616 MAP64 ("tprel@highest", BFD_RELOC_PPC64_TPREL16_HIGHEST
),
1617 MAP64 ("tprel@highesta", BFD_RELOC_PPC64_TPREL16_HIGHESTA
),
1618 { (char *) 0, 0, 0, 0, BFD_RELOC_UNUSED
}
1622 return BFD_RELOC_UNUSED
;
1624 for (ch
= *str
, str2
= ident
;
1625 (str2
< ident
+ sizeof (ident
) - 1
1626 && (ISALNUM (ch
) || ch
== '@'));
1629 *str2
++ = TOLOWER (ch
);
1636 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1637 if (ch
== ptr
->string
[0]
1638 && len
== ptr
->length
1639 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0
1640 && (ppc_obj64
? ptr
->valid64
: ptr
->valid32
))
1642 int reloc
= ptr
->reloc
;
1645 if (exp_p
->X_add_number
!= 0
1646 && (reloc
== (int) BFD_RELOC_16_GOTOFF
1647 || reloc
== (int) BFD_RELOC_LO16_GOTOFF
1648 || reloc
== (int) BFD_RELOC_HI16_GOTOFF
1649 || reloc
== (int) BFD_RELOC_HI16_S_GOTOFF
))
1650 as_warn (_("identifier+constant@got means identifier@got+constant"));
1652 /* Now check for identifier@suffix+constant. */
1653 if (*str
== '-' || *str
== '+')
1655 char *orig_line
= input_line_pointer
;
1656 expressionS new_exp
;
1658 input_line_pointer
= str
;
1659 expression (&new_exp
);
1660 if (new_exp
.X_op
== O_constant
)
1662 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1663 str
= input_line_pointer
;
1666 if (&input_line_pointer
!= str_p
)
1667 input_line_pointer
= orig_line
;
1671 if (reloc
== (int) BFD_RELOC_PPC64_TOC
1672 && exp_p
->X_op
== O_symbol
1673 && strcmp (S_GET_NAME (exp_p
->X_add_symbol
), ".TOC.") == 0)
1675 /* Change the symbol so that the dummy .TOC. symbol can be
1676 omitted from the object file. */
1677 exp_p
->X_add_symbol
= &abs_symbol
;
1680 return (bfd_reloc_code_real_type
) reloc
;
1683 return BFD_RELOC_UNUSED
;
1686 /* Like normal .long/.short/.word, except support @got, etc.
1687 Clobbers input_line_pointer, checks end-of-line. */
1689 ppc_elf_cons (nbytes
)
1690 register int nbytes
; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1693 bfd_reloc_code_real_type reloc
;
1695 if (is_it_end_of_statement ())
1697 demand_empty_rest_of_line ();
1704 if (exp
.X_op
== O_symbol
1705 && *input_line_pointer
== '@'
1706 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1707 &exp
)) != BFD_RELOC_UNUSED
)
1709 reloc_howto_type
*reloc_howto
;
1712 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1713 size
= bfd_get_reloc_size (reloc_howto
);
1717 as_bad (_("%s relocations do not fit in %d bytes\n"),
1718 reloc_howto
->name
, nbytes
);
1725 p
= frag_more (nbytes
);
1727 if (target_big_endian
)
1728 offset
= nbytes
- size
;
1729 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1734 emit_expr (&exp
, (unsigned int) nbytes
);
1736 while (*input_line_pointer
++ == ',');
1738 /* Put terminator back into stream. */
1739 input_line_pointer
--;
1740 demand_empty_rest_of_line ();
1743 /* Solaris pseduo op to change to the .rodata section. */
1748 char *save_line
= input_line_pointer
;
1749 static char section
[] = ".rodata\n";
1751 /* Just pretend this is .section .rodata */
1752 input_line_pointer
= section
;
1753 obj_elf_section (xxx
);
1755 input_line_pointer
= save_line
;
1758 /* Pseudo op to make file scope bss items. */
1761 int xxx ATTRIBUTE_UNUSED
;
1763 register char *name
;
1767 register symbolS
*symbolP
;
1774 name
= input_line_pointer
;
1775 c
= get_symbol_end ();
1777 /* just after name is now '\0'. */
1778 p
= input_line_pointer
;
1781 if (*input_line_pointer
!= ',')
1783 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1784 ignore_rest_of_line ();
1788 input_line_pointer
++; /* skip ',' */
1789 if ((size
= get_absolute_expression ()) < 0)
1791 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1792 ignore_rest_of_line ();
1796 /* The third argument to .lcomm is the alignment. */
1797 if (*input_line_pointer
!= ',')
1801 ++input_line_pointer
;
1802 align
= get_absolute_expression ();
1805 as_warn (_("ignoring bad alignment"));
1811 symbolP
= symbol_find_or_make (name
);
1814 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1816 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1817 S_GET_NAME (symbolP
));
1818 ignore_rest_of_line ();
1822 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1824 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1825 S_GET_NAME (symbolP
),
1826 (long) S_GET_VALUE (symbolP
),
1829 ignore_rest_of_line ();
1835 old_subsec
= now_subseg
;
1838 /* Convert to a power of 2 alignment. */
1839 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1842 as_bad (_("Common alignment not a power of 2"));
1843 ignore_rest_of_line ();
1850 record_alignment (bss_section
, align2
);
1851 subseg_set (bss_section
, 0);
1853 frag_align (align2
, 0, 0);
1854 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1855 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1856 symbol_set_frag (symbolP
, frag_now
);
1857 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1860 S_SET_SIZE (symbolP
, size
);
1861 S_SET_SEGMENT (symbolP
, bss_section
);
1862 subseg_set (old_sec
, old_subsec
);
1863 demand_empty_rest_of_line ();
1866 /* Validate any relocations emitted for -mrelocatable, possibly adding
1867 fixups for word relocations in writable segments, so we can adjust
1870 ppc_elf_validate_fix (fixp
, seg
)
1874 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1883 case SHLIB_MRELOCATABLE
:
1884 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1885 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1886 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1887 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1888 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1889 && fixp
->fx_r_type
!= BFD_RELOC_16_BASEREL
1890 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1891 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1892 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1893 && (seg
->flags
& SEC_LOAD
) != 0
1894 && strcmp (segment_name (seg
), ".got2") != 0
1895 && strcmp (segment_name (seg
), ".dtors") != 0
1896 && strcmp (segment_name (seg
), ".ctors") != 0
1897 && strcmp (segment_name (seg
), ".fixup") != 0
1898 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1899 && strcmp (segment_name (seg
), ".eh_frame") != 0
1900 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1902 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1903 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1905 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1906 _("Relocation cannot be done when using -mrelocatable"));
1913 /* Prevent elf_frob_file_before_adjust removing a weak undefined
1914 function descriptor sym if the corresponding code sym is used. */
1917 ppc_frob_file_before_adjust ()
1925 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1932 name
= S_GET_NAME (symp
);
1936 if (! S_IS_WEAK (symp
)
1937 || S_IS_DEFINED (symp
))
1940 len
= strlen (name
) + 1;
1941 dotname
= xmalloc (len
+ 1);
1943 memcpy (dotname
+ 1, name
, len
);
1944 dotsym
= symbol_find_noref (dotname
, 1);
1946 if (dotsym
!= NULL
&& (symbol_used_p (dotsym
)
1947 || symbol_used_in_reloc_p (dotsym
)))
1948 symbol_mark_used (symp
);
1952 toc
= bfd_get_section_by_name (stdoutput
, ".toc");
1954 && bfd_section_size (stdoutput
, toc
) > 0x10000)
1955 as_warn (_("TOC section size exceeds 64k"));
1957 /* Don't emit .TOC. symbol. */
1958 symp
= symbol_find (".TOC.");
1960 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1962 #endif /* OBJ_ELF */
1967 * Summary of parse_toc_entry.
1969 * in: Input_line_pointer points to the '[' in one of:
1971 * [toc] [tocv] [toc32] [toc64]
1973 * Anything else is an error of one kind or another.
1976 * return value: success or failure
1977 * toc_kind: kind of toc reference
1978 * input_line_pointer:
1979 * success: first char after the ']'
1980 * failure: unchanged
1984 * [toc] - rv == success, toc_kind = default_toc
1985 * [tocv] - rv == success, toc_kind = data_in_toc
1986 * [toc32] - rv == success, toc_kind = must_be_32
1987 * [toc64] - rv == success, toc_kind = must_be_64
1991 enum toc_size_qualifier
1993 default_toc
, /* The toc cell constructed should be the system default size */
1994 data_in_toc
, /* This is a direct reference to a toc cell */
1995 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1996 must_be_64
/* The toc cell constructed must be 64 bits wide */
2000 parse_toc_entry (toc_kind
)
2001 enum toc_size_qualifier
*toc_kind
;
2006 enum toc_size_qualifier t
;
2008 /* Save the input_line_pointer. */
2009 start
= input_line_pointer
;
2011 /* Skip over the '[' , and whitespace. */
2012 ++input_line_pointer
;
2015 /* Find the spelling of the operand. */
2016 toc_spec
= input_line_pointer
;
2017 c
= get_symbol_end ();
2019 if (strcmp (toc_spec
, "toc") == 0)
2023 else if (strcmp (toc_spec
, "tocv") == 0)
2027 else if (strcmp (toc_spec
, "toc32") == 0)
2031 else if (strcmp (toc_spec
, "toc64") == 0)
2037 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
2038 *input_line_pointer
= c
;
2039 input_line_pointer
= start
;
2043 /* Now find the ']'. */
2044 *input_line_pointer
= c
;
2046 SKIP_WHITESPACE (); /* leading whitespace could be there. */
2047 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
2051 as_bad (_("syntax error: expected `]', found `%c'"), c
);
2052 input_line_pointer
= start
;
2063 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2065 ppc_apuinfo_section_add (apu
, version
)
2066 unsigned int apu
, version
;
2070 /* Check we don't already exist. */
2071 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
2072 if (ppc_apuinfo_list
[i
] == APUID (apu
, version
))
2075 if (ppc_apuinfo_num
== ppc_apuinfo_num_alloc
)
2077 if (ppc_apuinfo_num_alloc
== 0)
2079 ppc_apuinfo_num_alloc
= 4;
2080 ppc_apuinfo_list
= (unsigned long *)
2081 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2085 ppc_apuinfo_num_alloc
+= 4;
2086 ppc_apuinfo_list
= (unsigned long *) xrealloc (ppc_apuinfo_list
,
2087 sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2090 ppc_apuinfo_list
[ppc_apuinfo_num
++] = APUID (apu
, version
);
2096 /* We need to keep a list of fixups. We can't simply generate them as
2097 we go, because that would require us to first create the frag, and
2098 that would screw up references to ``.''. */
2104 bfd_reloc_code_real_type reloc
;
2107 #define MAX_INSN_FIXUPS (5)
2109 /* This routine is called for each instruction to be assembled. */
2116 const struct powerpc_opcode
*opcode
;
2118 const unsigned char *opindex_ptr
;
2122 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
2128 bfd_reloc_code_real_type reloc
;
2131 /* Get the opcode. */
2132 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
2137 /* Look up the opcode in the hash table. */
2138 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
2139 if (opcode
== (const struct powerpc_opcode
*) NULL
)
2141 const struct powerpc_macro
*macro
;
2143 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
2144 if (macro
== (const struct powerpc_macro
*) NULL
)
2145 as_bad (_("Unrecognized opcode: `%s'"), str
);
2147 ppc_macro (s
, macro
);
2152 insn
= opcode
->opcode
;
2155 while (ISSPACE (*str
))
2158 /* PowerPC operands are just expressions. The only real issue is
2159 that a few operand types are optional. All cases which might use
2160 an optional operand separate the operands only with commas (in some
2161 cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2162 have optional operands). Most instructions with optional operands
2163 have only one. Those that have more than one optional operand can
2164 take either all their operands or none. So, before we start seriously
2165 parsing the operands, we check to see if we have optional operands,
2166 and if we do, we count the number of commas to see which operands
2167 have been omitted. */
2169 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2171 const struct powerpc_operand
*operand
;
2173 operand
= &powerpc_operands
[*opindex_ptr
];
2174 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
2176 unsigned int opcount
;
2177 unsigned int num_operands_expected
;
2180 /* There is an optional operand. Count the number of
2181 commas in the input line. */
2188 while ((s
= strchr (s
, ',')) != (char *) NULL
)
2195 /* Compute the number of expected operands.
2196 Do not count fake operands. */
2197 for (num_operands_expected
= 0, i
= 0; opcode
->operands
[i
]; i
++)
2198 if ((powerpc_operands
[opcode
->operands
[i
]].flags
& PPC_OPERAND_FAKE
) == 0)
2199 ++ num_operands_expected
;
2201 /* If there are fewer operands in the line then are called
2202 for by the instruction, we want to skip the optional
2204 if (opcount
< num_operands_expected
)
2211 /* Gather the operands. */
2215 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2217 const struct powerpc_operand
*operand
;
2223 if (next_opindex
== 0)
2224 operand
= &powerpc_operands
[*opindex_ptr
];
2227 operand
= &powerpc_operands
[next_opindex
];
2232 /* If this is a fake operand, then we do not expect anything
2234 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
2236 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2237 if (errmsg
!= (const char *) NULL
)
2242 /* If this is an optional operand, and we are skipping it, just
2244 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
2247 if (operand
->insert
)
2249 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2250 if (errmsg
!= (const char *) NULL
)
2253 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
2254 next_opindex
= *opindex_ptr
+ 1;
2258 /* Gather the operand. */
2259 hold
= input_line_pointer
;
2260 input_line_pointer
= str
;
2263 if (*input_line_pointer
== '[')
2265 /* We are expecting something like the second argument here:
2267 * lwz r4,[toc].GS.0.static_int(rtoc)
2268 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2269 * The argument following the `]' must be a symbol name, and the
2270 * register must be the toc register: 'rtoc' or '2'
2272 * The effect is to 0 as the displacement field
2273 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2274 * the appropriate variation) reloc against it based on the symbol.
2275 * The linker will build the toc, and insert the resolved toc offset.
2278 * o The size of the toc entry is currently assumed to be
2279 * 32 bits. This should not be assumed to be a hard coded
2281 * o In an effort to cope with a change from 32 to 64 bits,
2282 * there are also toc entries that are specified to be
2283 * either 32 or 64 bits:
2284 * lwz r4,[toc32].GS.0.static_int(rtoc)
2285 * lwz r4,[toc64].GS.0.static_int(rtoc)
2286 * These demand toc entries of the specified size, and the
2287 * instruction probably requires it.
2291 enum toc_size_qualifier toc_kind
;
2292 bfd_reloc_code_real_type toc_reloc
;
2294 /* Go parse off the [tocXX] part. */
2295 valid_toc
= parse_toc_entry (&toc_kind
);
2299 /* Note: message has already been issued.
2300 FIXME: what sort of recovery should we do?
2301 demand_rest_of_line (); return; ? */
2304 /* Now get the symbol following the ']'. */
2310 /* In this case, we may not have seen the symbol yet,
2311 since it is allowed to appear on a .extern or .globl
2312 or just be a label in the .data section. */
2313 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2316 /* 1. The symbol must be defined and either in the toc
2317 section, or a global.
2318 2. The reloc generated must have the TOCDEFN flag set
2319 in upper bit mess of the reloc type.
2320 FIXME: It's a little confusing what the tocv
2321 qualifier can be used for. At the very least, I've
2322 seen three uses, only one of which I'm sure I can
2324 if (ex
.X_op
== O_symbol
)
2326 assert (ex
.X_add_symbol
!= NULL
);
2327 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2330 as_bad (_("[tocv] symbol is not a toc symbol"));
2334 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2337 /* FIXME: these next two specifically specify 32/64 bit
2338 toc entries. We don't support them today. Is this
2339 the right way to say that? */
2340 toc_reloc
= BFD_RELOC_UNUSED
;
2341 as_bad (_("Unimplemented toc32 expression modifier"));
2344 /* FIXME: see above. */
2345 toc_reloc
= BFD_RELOC_UNUSED
;
2346 as_bad (_("Unimplemented toc64 expression modifier"));
2350 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2356 /* We need to generate a fixup for this expression. */
2357 if (fc
>= MAX_INSN_FIXUPS
)
2358 as_fatal (_("too many fixups"));
2360 fixups
[fc
].reloc
= toc_reloc
;
2361 fixups
[fc
].exp
= ex
;
2362 fixups
[fc
].opindex
= *opindex_ptr
;
2365 /* Ok. We've set up the fixup for the instruction. Now make it
2366 look like the constant 0 was found here. */
2368 ex
.X_op
= O_constant
;
2369 ex
.X_add_number
= 0;
2370 ex
.X_add_symbol
= NULL
;
2371 ex
.X_op_symbol
= NULL
;
2377 if (! register_name (&ex
))
2379 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
2386 str
= input_line_pointer
;
2387 input_line_pointer
= hold
;
2389 if (ex
.X_op
== O_illegal
)
2390 as_bad (_("illegal operand"));
2391 else if (ex
.X_op
== O_absent
)
2392 as_bad (_("missing operand"));
2393 else if (ex
.X_op
== O_register
)
2395 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2398 else if (ex
.X_op
== O_constant
)
2401 /* Allow @HA, @L, @H on constants. */
2402 char *orig_str
= str
;
2404 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2411 case BFD_RELOC_LO16
:
2412 /* X_unsigned is the default, so if the user has done
2413 something which cleared it, we always produce a
2415 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2416 ex
.X_add_number
&= 0xffff;
2418 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2421 case BFD_RELOC_HI16
:
2422 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2423 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2425 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2428 case BFD_RELOC_HI16_S
:
2429 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2430 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2432 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2435 case BFD_RELOC_PPC64_HIGHER
:
2436 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2437 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2439 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2442 case BFD_RELOC_PPC64_HIGHER_S
:
2443 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2444 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2446 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2449 case BFD_RELOC_PPC64_HIGHEST
:
2450 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2451 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2453 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2456 case BFD_RELOC_PPC64_HIGHEST_S
:
2457 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2458 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2460 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2463 #endif /* OBJ_ELF */
2464 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2468 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2470 /* Some TLS tweaks. */
2475 case BFD_RELOC_PPC_TLS
:
2476 insn
= ppc_insert_operand (insn
, operand
, ppc_obj64
? 13 : 2,
2479 /* We'll only use the 32 (or 64) bit form of these relocations
2480 in constants. Instructions get the 16 bit form. */
2481 case BFD_RELOC_PPC_DTPREL
:
2482 reloc
= BFD_RELOC_PPC_DTPREL16
;
2484 case BFD_RELOC_PPC_TPREL
:
2485 reloc
= BFD_RELOC_PPC_TPREL16
;
2489 /* For the absolute forms of branches, convert the PC
2490 relative form back into the absolute. */
2491 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2495 case BFD_RELOC_PPC_B26
:
2496 reloc
= BFD_RELOC_PPC_BA26
;
2498 case BFD_RELOC_PPC_B16
:
2499 reloc
= BFD_RELOC_PPC_BA16
;
2501 case BFD_RELOC_PPC_B16_BRTAKEN
:
2502 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2504 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2505 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2513 && (operand
->flags
& (PPC_OPERAND_DS
| PPC_OPERAND_DQ
)) != 0)
2518 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
2520 case BFD_RELOC_LO16
:
2521 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
2523 case BFD_RELOC_16_GOTOFF
:
2524 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
2526 case BFD_RELOC_LO16_GOTOFF
:
2527 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
2529 case BFD_RELOC_LO16_PLTOFF
:
2530 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
2532 case BFD_RELOC_16_BASEREL
:
2533 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
2535 case BFD_RELOC_LO16_BASEREL
:
2536 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
2538 case BFD_RELOC_PPC_TOC16
:
2539 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
2541 case BFD_RELOC_PPC64_TOC16_LO
:
2542 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
2544 case BFD_RELOC_PPC64_PLTGOT16
:
2545 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
2547 case BFD_RELOC_PPC64_PLTGOT16_LO
:
2548 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
2550 case BFD_RELOC_PPC_DTPREL16
:
2551 reloc
= BFD_RELOC_PPC64_DTPREL16_DS
;
2553 case BFD_RELOC_PPC_DTPREL16_LO
:
2554 reloc
= BFD_RELOC_PPC64_DTPREL16_LO_DS
;
2556 case BFD_RELOC_PPC_TPREL16
:
2557 reloc
= BFD_RELOC_PPC64_TPREL16_DS
;
2559 case BFD_RELOC_PPC_TPREL16_LO
:
2560 reloc
= BFD_RELOC_PPC64_TPREL16_LO_DS
;
2562 case BFD_RELOC_PPC_GOT_DTPREL16
:
2563 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
2564 case BFD_RELOC_PPC_GOT_TPREL16
:
2565 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
2568 as_bad (_("unsupported relocation for DS offset field"));
2573 /* We need to generate a fixup for this expression. */
2574 if (fc
>= MAX_INSN_FIXUPS
)
2575 as_fatal (_("too many fixups"));
2576 fixups
[fc
].exp
= ex
;
2577 fixups
[fc
].opindex
= 0;
2578 fixups
[fc
].reloc
= reloc
;
2581 #endif /* OBJ_ELF */
2585 /* We need to generate a fixup for this expression. */
2586 if (fc
>= MAX_INSN_FIXUPS
)
2587 as_fatal (_("too many fixups"));
2588 fixups
[fc
].exp
= ex
;
2589 fixups
[fc
].opindex
= *opindex_ptr
;
2590 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2599 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2607 /* The call to expression should have advanced str past any
2610 && (endc
!= ',' || *str
!= '\0'))
2612 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2620 while (ISSPACE (*str
))
2624 as_bad (_("junk at end of line: `%s'"), str
);
2627 /* Do we need/want a APUinfo section? */
2628 if (ppc_cpu
& (PPC_OPCODE_SPE
2629 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
2630 | PPC_OPCODE_BRLOCK
| PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
2631 | PPC_OPCODE_RFMCI
))
2633 /* These are all version "1". */
2634 if (opcode
->flags
& PPC_OPCODE_SPE
)
2635 ppc_apuinfo_section_add (PPC_APUINFO_SPE
, 1);
2636 if (opcode
->flags
& PPC_OPCODE_ISEL
)
2637 ppc_apuinfo_section_add (PPC_APUINFO_ISEL
, 1);
2638 if (opcode
->flags
& PPC_OPCODE_EFS
)
2639 ppc_apuinfo_section_add (PPC_APUINFO_EFS
, 1);
2640 if (opcode
->flags
& PPC_OPCODE_BRLOCK
)
2641 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK
, 1);
2642 if (opcode
->flags
& PPC_OPCODE_PMR
)
2643 ppc_apuinfo_section_add (PPC_APUINFO_PMR
, 1);
2644 if (opcode
->flags
& PPC_OPCODE_CACHELCK
)
2645 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK
, 1);
2646 if (opcode
->flags
& PPC_OPCODE_RFMCI
)
2647 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI
, 1);
2651 /* Write out the instruction. */
2653 addr_mod
= frag_now_fix () & 3;
2654 if (frag_now
->has_code
&& frag_now
->insn_addr
!= addr_mod
)
2655 as_bad (_("instruction address is not a multiple of 4"));
2656 frag_now
->insn_addr
= addr_mod
;
2657 frag_now
->has_code
= 1;
2658 md_number_to_chars (f
, insn
, 4);
2661 dwarf2_emit_insn (4);
2664 /* Create any fixups. At this point we do not use a
2665 bfd_reloc_code_real_type, but instead just use the
2666 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2667 handle fixups for any operand type, although that is admittedly
2668 not a very exciting feature. We pick a BFD reloc type in
2670 for (i
= 0; i
< fc
; i
++)
2672 const struct powerpc_operand
*operand
;
2674 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2675 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2677 reloc_howto_type
*reloc_howto
;
2682 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2686 size
= bfd_get_reloc_size (reloc_howto
);
2687 offset
= target_big_endian
? (4 - size
) : 0;
2689 if (size
< 1 || size
> 4)
2692 fixP
= fix_new_exp (frag_now
,
2693 f
- frag_now
->fr_literal
+ offset
,
2696 reloc_howto
->pc_relative
,
2699 /* Turn off complaints that the addend is too large for things like
2701 switch (fixups
[i
].reloc
)
2703 case BFD_RELOC_16_GOTOFF
:
2704 case BFD_RELOC_PPC_TOC16
:
2705 case BFD_RELOC_LO16
:
2706 case BFD_RELOC_HI16
:
2707 case BFD_RELOC_HI16_S
:
2709 case BFD_RELOC_PPC64_HIGHER
:
2710 case BFD_RELOC_PPC64_HIGHER_S
:
2711 case BFD_RELOC_PPC64_HIGHEST
:
2712 case BFD_RELOC_PPC64_HIGHEST_S
:
2714 fixP
->fx_no_overflow
= 1;
2721 fix_new_exp (frag_now
,
2722 f
- frag_now
->fr_literal
,
2725 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2726 ((bfd_reloc_code_real_type
)
2727 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2731 /* Handle a macro. Gather all the operands, transform them as
2732 described by the macro, and call md_assemble recursively. All the
2733 operands are separated by commas; we don't accept parentheses
2734 around operands here. */
2737 ppc_macro (str
, macro
)
2739 const struct powerpc_macro
*macro
;
2750 /* Gather the users operands into the operands array. */
2755 if (count
>= sizeof operands
/ sizeof operands
[0])
2757 operands
[count
++] = s
;
2758 s
= strchr (s
, ',');
2759 if (s
== (char *) NULL
)
2764 if (count
!= macro
->operands
)
2766 as_bad (_("wrong number of operands"));
2770 /* Work out how large the string must be (the size is unbounded
2771 because it includes user input). */
2773 format
= macro
->format
;
2774 while (*format
!= '\0')
2783 arg
= strtol (format
+ 1, &send
, 10);
2784 know (send
!= format
&& arg
>= 0 && arg
< count
);
2785 len
+= strlen (operands
[arg
]);
2790 /* Put the string together. */
2791 complete
= s
= (char *) alloca (len
+ 1);
2792 format
= macro
->format
;
2793 while (*format
!= '\0')
2799 arg
= strtol (format
+ 1, &send
, 10);
2800 strcpy (s
, operands
[arg
]);
2807 /* Assemble the constructed instruction. */
2808 md_assemble (complete
);
2812 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2815 ppc_section_letter (letter
, ptr_msg
)
2822 *ptr_msg
= _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
2827 ppc_section_word (str
, len
)
2831 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2838 ppc_section_type (str
, len
)
2842 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2849 ppc_section_flags (flags
, attr
, type
)
2854 if (type
== SHT_ORDERED
)
2855 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2857 if (attr
& SHF_EXCLUDE
)
2858 flags
|= SEC_EXCLUDE
;
2862 #endif /* OBJ_ELF */
2865 /* Pseudo-op handling. */
2867 /* The .byte pseudo-op. This is similar to the normal .byte
2868 pseudo-op, but it can also take a single ASCII string. */
2872 int ignore ATTRIBUTE_UNUSED
;
2874 if (*input_line_pointer
!= '\"')
2880 /* Gather characters. A real double quote is doubled. Unusual
2881 characters are not permitted. */
2882 ++input_line_pointer
;
2887 c
= *input_line_pointer
++;
2891 if (*input_line_pointer
!= '\"')
2893 ++input_line_pointer
;
2896 FRAG_APPEND_1_CHAR (c
);
2899 demand_empty_rest_of_line ();
2904 /* XCOFF specific pseudo-op handling. */
2906 /* This is set if we are creating a .stabx symbol, since we don't want
2907 to handle symbol suffixes for such symbols. */
2908 static bfd_boolean ppc_stab_symbol
;
2910 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2911 symbols in the .bss segment as though they were local common
2912 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
2913 aligns .comm and .lcomm to 4 bytes. */
2919 asection
*current_seg
= now_seg
;
2920 subsegT current_subseg
= now_subseg
;
2926 symbolS
*lcomm_sym
= NULL
;
2930 name
= input_line_pointer
;
2931 endc
= get_symbol_end ();
2932 end_name
= input_line_pointer
;
2935 if (*input_line_pointer
!= ',')
2937 as_bad (_("missing size"));
2938 ignore_rest_of_line ();
2941 ++input_line_pointer
;
2943 size
= get_absolute_expression ();
2946 as_bad (_("negative size"));
2947 ignore_rest_of_line ();
2953 /* The third argument to .comm is the alignment. */
2954 if (*input_line_pointer
!= ',')
2958 ++input_line_pointer
;
2959 align
= get_absolute_expression ();
2962 as_warn (_("ignoring bad alignment"));
2977 /* The third argument to .lcomm appears to be the real local
2978 common symbol to create. References to the symbol named in
2979 the first argument are turned into references to the third
2981 if (*input_line_pointer
!= ',')
2983 as_bad (_("missing real symbol name"));
2984 ignore_rest_of_line ();
2987 ++input_line_pointer
;
2989 lcomm_name
= input_line_pointer
;
2990 lcomm_endc
= get_symbol_end ();
2992 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2994 *input_line_pointer
= lcomm_endc
;
2998 sym
= symbol_find_or_make (name
);
3001 if (S_IS_DEFINED (sym
)
3002 || S_GET_VALUE (sym
) != 0)
3004 as_bad (_("attempt to redefine symbol"));
3005 ignore_rest_of_line ();
3009 record_alignment (bss_section
, align
);
3012 || ! S_IS_DEFINED (lcomm_sym
))
3021 S_SET_EXTERNAL (sym
);
3025 symbol_get_tc (lcomm_sym
)->output
= 1;
3026 def_sym
= lcomm_sym
;
3030 subseg_set (bss_section
, 1);
3031 frag_align (align
, 0, 0);
3033 symbol_set_frag (def_sym
, frag_now
);
3034 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
3035 def_size
, (char *) NULL
);
3037 S_SET_SEGMENT (def_sym
, bss_section
);
3038 symbol_get_tc (def_sym
)->align
= align
;
3042 /* Align the size of lcomm_sym. */
3043 symbol_get_frag (lcomm_sym
)->fr_offset
=
3044 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
3045 &~ ((1 << align
) - 1));
3046 if (align
> symbol_get_tc (lcomm_sym
)->align
)
3047 symbol_get_tc (lcomm_sym
)->align
= align
;
3052 /* Make sym an offset from lcomm_sym. */
3053 S_SET_SEGMENT (sym
, bss_section
);
3054 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
3055 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
3056 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
3059 subseg_set (current_seg
, current_subseg
);
3061 demand_empty_rest_of_line ();
3064 /* The .csect pseudo-op. This switches us into a different
3065 subsegment. The first argument is a symbol whose value is the
3066 start of the .csect. In COFF, csect symbols get special aux
3067 entries defined by the x_csect field of union internal_auxent. The
3068 optional second argument is the alignment (the default is 2). */
3072 int ignore ATTRIBUTE_UNUSED
;
3079 name
= input_line_pointer
;
3080 endc
= get_symbol_end ();
3082 sym
= symbol_find_or_make (name
);
3084 *input_line_pointer
= endc
;
3086 if (S_GET_NAME (sym
)[0] == '\0')
3088 /* An unnamed csect is assumed to be [PR]. */
3089 symbol_get_tc (sym
)->class = XMC_PR
;
3093 if (*input_line_pointer
== ',')
3095 ++input_line_pointer
;
3096 align
= get_absolute_expression ();
3099 ppc_change_csect (sym
, align
);
3101 demand_empty_rest_of_line ();
3104 /* Change to a different csect. */
3107 ppc_change_csect (sym
, align
)
3111 if (S_IS_DEFINED (sym
))
3112 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
3122 /* This is a new csect. We need to look at the symbol class to
3123 figure out whether it should go in the text section or the
3127 switch (symbol_get_tc (sym
)->class)
3137 S_SET_SEGMENT (sym
, text_section
);
3138 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
3139 ++ppc_text_subsegment
;
3140 list_ptr
= &ppc_text_csects
;
3150 if (ppc_toc_csect
!= NULL
3151 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
3152 == ppc_data_subsegment
))
3154 S_SET_SEGMENT (sym
, data_section
);
3155 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
3156 ++ppc_data_subsegment
;
3157 list_ptr
= &ppc_data_csects
;
3163 /* We set the obstack chunk size to a small value before
3164 changing subsegments, so that we don't use a lot of memory
3165 space for what may be a small section. */
3166 hold_chunksize
= chunksize
;
3169 sec
= subseg_new (segment_name (S_GET_SEGMENT (sym
)),
3170 symbol_get_tc (sym
)->subseg
);
3172 chunksize
= hold_chunksize
;
3175 ppc_after_toc_frag
= frag_now
;
3177 record_alignment (sec
, align
);
3179 frag_align_code (align
, 0);
3181 frag_align (align
, 0, 0);
3183 symbol_set_frag (sym
, frag_now
);
3184 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3186 symbol_get_tc (sym
)->align
= align
;
3187 symbol_get_tc (sym
)->output
= 1;
3188 symbol_get_tc (sym
)->within
= sym
;
3190 for (list
= *list_ptr
;
3191 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3192 list
= symbol_get_tc (list
)->next
)
3194 symbol_get_tc (list
)->next
= sym
;
3196 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3197 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3201 ppc_current_csect
= sym
;
3204 /* This function handles the .text and .data pseudo-ops. These
3205 pseudo-ops aren't really used by XCOFF; we implement them for the
3206 convenience of people who aren't used to XCOFF. */
3217 else if (type
== 'd')
3222 sym
= symbol_find_or_make (name
);
3224 ppc_change_csect (sym
, 2);
3226 demand_empty_rest_of_line ();
3229 /* This function handles the .section pseudo-op. This is mostly to
3230 give an error, since XCOFF only supports .text, .data and .bss, but
3231 we do permit the user to name the text or data section. */
3234 ppc_named_section (ignore
)
3235 int ignore ATTRIBUTE_UNUSED
;
3238 const char *real_name
;
3242 user_name
= input_line_pointer
;
3243 c
= get_symbol_end ();
3245 if (strcmp (user_name
, ".text") == 0)
3246 real_name
= ".text[PR]";
3247 else if (strcmp (user_name
, ".data") == 0)
3248 real_name
= ".data[RW]";
3251 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3252 *input_line_pointer
= c
;
3253 ignore_rest_of_line ();
3257 *input_line_pointer
= c
;
3259 sym
= symbol_find_or_make (real_name
);
3261 ppc_change_csect (sym
, 2);
3263 demand_empty_rest_of_line ();
3266 /* The .extern pseudo-op. We create an undefined symbol. */
3270 int ignore ATTRIBUTE_UNUSED
;
3275 name
= input_line_pointer
;
3276 endc
= get_symbol_end ();
3278 (void) symbol_find_or_make (name
);
3280 *input_line_pointer
= endc
;
3282 demand_empty_rest_of_line ();
3285 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3289 int ignore ATTRIBUTE_UNUSED
;
3295 name
= input_line_pointer
;
3296 endc
= get_symbol_end ();
3298 sym
= symbol_find_or_make (name
);
3300 *input_line_pointer
= endc
;
3302 symbol_get_tc (sym
)->output
= 1;
3304 demand_empty_rest_of_line ();
3307 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3308 although I don't know why it bothers. */
3312 int ignore ATTRIBUTE_UNUSED
;
3319 name
= input_line_pointer
;
3320 endc
= get_symbol_end ();
3322 sym
= symbol_find_or_make (name
);
3324 *input_line_pointer
= endc
;
3326 if (*input_line_pointer
!= ',')
3328 as_bad (_("missing rename string"));
3329 ignore_rest_of_line ();
3332 ++input_line_pointer
;
3334 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
3336 demand_empty_rest_of_line ();
3339 /* The .stabx pseudo-op. This is similar to a normal .stabs
3340 pseudo-op, but slightly different. A sample is
3341 .stabx "main:F-1",.main,142,0
3342 The first argument is the symbol name to create. The second is the
3343 value, and the third is the storage class. The fourth seems to be
3344 always zero, and I am assuming it is the type. */
3348 int ignore ATTRIBUTE_UNUSED
;
3355 name
= demand_copy_C_string (&len
);
3357 if (*input_line_pointer
!= ',')
3359 as_bad (_("missing value"));
3362 ++input_line_pointer
;
3364 ppc_stab_symbol
= TRUE
;
3365 sym
= symbol_make (name
);
3366 ppc_stab_symbol
= FALSE
;
3368 symbol_get_tc (sym
)->real_name
= name
;
3370 (void) expression (&exp
);
3377 as_bad (_("illegal .stabx expression; zero assumed"));
3378 exp
.X_add_number
= 0;
3381 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
3382 symbol_set_frag (sym
, &zero_address_frag
);
3386 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
3387 symbol_set_value_expression (sym
, &exp
);
3391 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
3392 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
3397 /* The value is some complex expression. This will probably
3398 fail at some later point, but this is probably the right
3399 thing to do here. */
3400 symbol_set_value_expression (sym
, &exp
);
3404 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3405 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3407 if (*input_line_pointer
!= ',')
3409 as_bad (_("missing class"));
3412 ++input_line_pointer
;
3414 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
3416 if (*input_line_pointer
!= ',')
3418 as_bad (_("missing type"));
3421 ++input_line_pointer
;
3423 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
3425 symbol_get_tc (sym
)->output
= 1;
3427 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
3429 symbol_get_tc (sym
)->within
= ppc_current_block
;
3434 .stabx "z",arrays_,133,0
3437 .comm arrays_,13768,3
3439 resolve_symbol_value will copy the exp's "within" into sym's when the
3440 offset is 0. Since this seems to be corner case problem,
3441 only do the correction for storage class C_STSYM. A better solution
3442 would be to have the tc field updated in ppc_symbol_new_hook. */
3444 if (exp
.X_op
== O_symbol
)
3446 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
3450 if (exp
.X_op
!= O_symbol
3451 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
3452 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
3453 ppc_frob_label (sym
);
3456 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3457 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
3458 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
3459 symbol_get_tc (ppc_current_csect
)->within
= sym
;
3462 demand_empty_rest_of_line ();
3465 /* The .function pseudo-op. This takes several arguments. The first
3466 argument seems to be the external name of the symbol. The second
3467 argument seems to be the label for the start of the function. gcc
3468 uses the same name for both. I have no idea what the third and
3469 fourth arguments are meant to be. The optional fifth argument is
3470 an expression for the size of the function. In COFF this symbol
3471 gets an aux entry like that used for a csect. */
3474 ppc_function (ignore
)
3475 int ignore ATTRIBUTE_UNUSED
;
3483 name
= input_line_pointer
;
3484 endc
= get_symbol_end ();
3486 /* Ignore any [PR] suffix. */
3487 name
= ppc_canonicalize_symbol_name (name
);
3488 s
= strchr (name
, '[');
3489 if (s
!= (char *) NULL
3490 && strcmp (s
+ 1, "PR]") == 0)
3493 ext_sym
= symbol_find_or_make (name
);
3495 *input_line_pointer
= endc
;
3497 if (*input_line_pointer
!= ',')
3499 as_bad (_("missing symbol name"));
3500 ignore_rest_of_line ();
3503 ++input_line_pointer
;
3505 name
= input_line_pointer
;
3506 endc
= get_symbol_end ();
3508 lab_sym
= symbol_find_or_make (name
);
3510 *input_line_pointer
= endc
;
3512 if (ext_sym
!= lab_sym
)
3516 exp
.X_op
= O_symbol
;
3517 exp
.X_add_symbol
= lab_sym
;
3518 exp
.X_op_symbol
= NULL
;
3519 exp
.X_add_number
= 0;
3521 symbol_set_value_expression (ext_sym
, &exp
);
3524 if (symbol_get_tc (ext_sym
)->class == -1)
3525 symbol_get_tc (ext_sym
)->class = XMC_PR
;
3526 symbol_get_tc (ext_sym
)->output
= 1;
3528 if (*input_line_pointer
== ',')
3532 /* Ignore the third argument. */
3533 ++input_line_pointer
;
3534 expression (&ignore
);
3535 if (*input_line_pointer
== ',')
3537 /* Ignore the fourth argument. */
3538 ++input_line_pointer
;
3539 expression (&ignore
);
3540 if (*input_line_pointer
== ',')
3542 /* The fifth argument is the function size. */
3543 ++input_line_pointer
;
3544 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
3547 &zero_address_frag
);
3548 pseudo_set (symbol_get_tc (ext_sym
)->size
);
3553 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3554 SF_SET_FUNCTION (ext_sym
);
3555 SF_SET_PROCESS (ext_sym
);
3556 coff_add_linesym (ext_sym
);
3558 demand_empty_rest_of_line ();
3561 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3562 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3563 with the correct line number */
3565 static symbolS
*saved_bi_sym
= 0;
3569 int ignore ATTRIBUTE_UNUSED
;
3573 sym
= symbol_make (".bf");
3574 S_SET_SEGMENT (sym
, text_section
);
3575 symbol_set_frag (sym
, frag_now
);
3576 S_SET_VALUE (sym
, frag_now_fix ());
3577 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3579 coff_line_base
= get_absolute_expression ();
3581 S_SET_NUMBER_AUXILIARY (sym
, 1);
3582 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3584 /* Line number for bi. */
3587 S_SET_VALUE (saved_bi_sym
, coff_n_line_nos
);
3592 symbol_get_tc (sym
)->output
= 1;
3594 ppc_frob_label (sym
);
3596 demand_empty_rest_of_line ();
3599 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3600 ".ef", except that the line number is absolute, not relative to the
3601 most recent ".bf" symbol. */
3605 int ignore ATTRIBUTE_UNUSED
;
3609 sym
= symbol_make (".ef");
3610 S_SET_SEGMENT (sym
, text_section
);
3611 symbol_set_frag (sym
, frag_now
);
3612 S_SET_VALUE (sym
, frag_now_fix ());
3613 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3614 S_SET_NUMBER_AUXILIARY (sym
, 1);
3615 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3616 symbol_get_tc (sym
)->output
= 1;
3618 ppc_frob_label (sym
);
3620 demand_empty_rest_of_line ();
3623 /* The .bi and .ei pseudo-ops. These take a string argument and
3624 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3625 the symbol list. The value of .bi will be know when the next .bf
3632 static symbolS
*last_biei
;
3639 name
= demand_copy_C_string (&len
);
3641 /* The value of these symbols is actually file offset. Here we set
3642 the value to the index into the line number entries. In
3643 ppc_frob_symbols we set the fix_line field, which will cause BFD
3644 to do the right thing. */
3646 sym
= symbol_make (name
);
3647 /* obj-coff.c currently only handles line numbers correctly in the
3649 S_SET_SEGMENT (sym
, text_section
);
3650 S_SET_VALUE (sym
, coff_n_line_nos
);
3651 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3653 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3654 symbol_get_tc (sym
)->output
= 1;
3662 for (look
= last_biei
? last_biei
: symbol_rootP
;
3663 (look
!= (symbolS
*) NULL
3664 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3665 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3666 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3667 look
= symbol_next (look
))
3669 if (look
!= (symbolS
*) NULL
)
3671 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3672 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3676 demand_empty_rest_of_line ();
3679 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3680 There is one argument, which is a csect symbol. The value of the
3681 .bs symbol is the index of this csect symbol. */
3685 int ignore ATTRIBUTE_UNUSED
;
3692 if (ppc_current_block
!= NULL
)
3693 as_bad (_("nested .bs blocks"));
3695 name
= input_line_pointer
;
3696 endc
= get_symbol_end ();
3698 csect
= symbol_find_or_make (name
);
3700 *input_line_pointer
= endc
;
3702 sym
= symbol_make (".bs");
3703 S_SET_SEGMENT (sym
, now_seg
);
3704 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3705 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3706 symbol_get_tc (sym
)->output
= 1;
3708 symbol_get_tc (sym
)->within
= csect
;
3710 ppc_frob_label (sym
);
3712 ppc_current_block
= sym
;
3714 demand_empty_rest_of_line ();
3717 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3721 int ignore ATTRIBUTE_UNUSED
;
3725 if (ppc_current_block
== NULL
)
3726 as_bad (_(".es without preceding .bs"));
3728 sym
= symbol_make (".es");
3729 S_SET_SEGMENT (sym
, now_seg
);
3730 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3731 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3732 symbol_get_tc (sym
)->output
= 1;
3734 ppc_frob_label (sym
);
3736 ppc_current_block
= NULL
;
3738 demand_empty_rest_of_line ();
3741 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3746 int ignore ATTRIBUTE_UNUSED
;
3750 sym
= symbol_make (".bb");
3751 S_SET_SEGMENT (sym
, text_section
);
3752 symbol_set_frag (sym
, frag_now
);
3753 S_SET_VALUE (sym
, frag_now_fix ());
3754 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3756 S_SET_NUMBER_AUXILIARY (sym
, 1);
3757 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3759 symbol_get_tc (sym
)->output
= 1;
3761 SF_SET_PROCESS (sym
);
3763 ppc_frob_label (sym
);
3765 demand_empty_rest_of_line ();
3768 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3773 int ignore ATTRIBUTE_UNUSED
;
3777 sym
= symbol_make (".eb");
3778 S_SET_SEGMENT (sym
, text_section
);
3779 symbol_set_frag (sym
, frag_now
);
3780 S_SET_VALUE (sym
, frag_now_fix ());
3781 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3782 S_SET_NUMBER_AUXILIARY (sym
, 1);
3783 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3784 symbol_get_tc (sym
)->output
= 1;
3786 SF_SET_PROCESS (sym
);
3788 ppc_frob_label (sym
);
3790 demand_empty_rest_of_line ();
3793 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3798 int ignore ATTRIBUTE_UNUSED
;
3804 name
= demand_copy_C_string (&len
);
3805 sym
= symbol_make (name
);
3806 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3807 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3808 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3809 S_SET_VALUE (sym
, 0);
3810 symbol_get_tc (sym
)->output
= 1;
3812 ppc_frob_label (sym
);
3814 demand_empty_rest_of_line ();
3817 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3821 int ignore ATTRIBUTE_UNUSED
;
3825 sym
= symbol_make (".ec");
3826 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3827 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3828 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3829 S_SET_VALUE (sym
, 0);
3830 symbol_get_tc (sym
)->output
= 1;
3832 ppc_frob_label (sym
);
3834 demand_empty_rest_of_line ();
3837 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3841 int ignore ATTRIBUTE_UNUSED
;
3843 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3844 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3851 subseg
= ppc_data_subsegment
;
3852 ++ppc_data_subsegment
;
3854 subseg_new (segment_name (data_section
), subseg
);
3855 ppc_toc_frag
= frag_now
;
3857 sym
= symbol_find_or_make ("TOC[TC0]");
3858 symbol_set_frag (sym
, frag_now
);
3859 S_SET_SEGMENT (sym
, data_section
);
3860 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3861 symbol_get_tc (sym
)->subseg
= subseg
;
3862 symbol_get_tc (sym
)->output
= 1;
3863 symbol_get_tc (sym
)->within
= sym
;
3865 ppc_toc_csect
= sym
;
3867 for (list
= ppc_data_csects
;
3868 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3869 list
= symbol_get_tc (list
)->next
)
3871 symbol_get_tc (list
)->next
= sym
;
3873 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3874 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3878 ppc_current_csect
= ppc_toc_csect
;
3880 demand_empty_rest_of_line ();
3883 /* The AIX assembler automatically aligns the operands of a .long or
3884 .short pseudo-op, and we want to be compatible. */
3887 ppc_xcoff_cons (log_size
)
3890 frag_align (log_size
, 0, 0);
3891 record_alignment (now_seg
, log_size
);
3892 cons (1 << log_size
);
3897 int dummy ATTRIBUTE_UNUSED
;
3902 (void) expression (&exp
);
3904 if (exp
.X_op
!= O_constant
)
3906 as_bad (_("non-constant byte count"));
3910 byte_count
= exp
.X_add_number
;
3912 if (*input_line_pointer
!= ',')
3914 as_bad (_("missing value"));
3918 ++input_line_pointer
;
3922 #endif /* OBJ_XCOFF */
3923 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3925 /* The .tc pseudo-op. This is used when generating either XCOFF or
3926 ELF. This takes two or more arguments.
3928 When generating XCOFF output, the first argument is the name to
3929 give to this location in the toc; this will be a symbol with class
3930 TC. The rest of the arguments are N-byte values to actually put at
3931 this location in the TOC; often there is just one more argument, a
3932 relocatable symbol reference. The size of the value to store
3933 depends on target word size. A 32-bit target uses 4-byte values, a
3934 64-bit target uses 8-byte values.
3936 When not generating XCOFF output, the arguments are the same, but
3937 the first argument is simply ignored. */
3941 int ignore ATTRIBUTE_UNUSED
;
3945 /* Define the TOC symbol name. */
3951 if (ppc_toc_csect
== (symbolS
*) NULL
3952 || ppc_toc_csect
!= ppc_current_csect
)
3954 as_bad (_(".tc not in .toc section"));
3955 ignore_rest_of_line ();
3959 name
= input_line_pointer
;
3960 endc
= get_symbol_end ();
3962 sym
= symbol_find_or_make (name
);
3964 *input_line_pointer
= endc
;
3966 if (S_IS_DEFINED (sym
))
3970 label
= symbol_get_tc (ppc_current_csect
)->within
;
3971 if (symbol_get_tc (label
)->class != XMC_TC0
)
3973 as_bad (_(".tc with no label"));
3974 ignore_rest_of_line ();
3978 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3979 symbol_set_frag (label
, symbol_get_frag (sym
));
3980 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3982 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3983 ++input_line_pointer
;
3988 S_SET_SEGMENT (sym
, now_seg
);
3989 symbol_set_frag (sym
, frag_now
);
3990 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3991 symbol_get_tc (sym
)->class = XMC_TC
;
3992 symbol_get_tc (sym
)->output
= 1;
3994 ppc_frob_label (sym
);
3997 #endif /* OBJ_XCOFF */
4001 /* Skip the TOC symbol name. */
4002 while (is_part_of_name (*input_line_pointer
)
4003 || *input_line_pointer
== '['
4004 || *input_line_pointer
== ']'
4005 || *input_line_pointer
== '{'
4006 || *input_line_pointer
== '}')
4007 ++input_line_pointer
;
4009 /* Align to a four/eight byte boundary. */
4010 align
= ppc_obj64
? 3 : 2;
4011 frag_align (align
, 0, 0);
4012 record_alignment (now_seg
, align
);
4013 #endif /* OBJ_ELF */
4015 if (*input_line_pointer
!= ',')
4016 demand_empty_rest_of_line ();
4019 ++input_line_pointer
;
4020 cons (ppc_obj64
? 8 : 4);
4024 /* Pseudo-op .machine. */
4027 ppc_machine (ignore
)
4028 int ignore ATTRIBUTE_UNUSED
;
4031 #define MAX_HISTORY 100
4032 static unsigned long *cpu_history
;
4033 static int curr_hist
;
4037 if (*input_line_pointer
== '"')
4040 cpu_string
= demand_copy_C_string (&len
);
4045 cpu_string
= input_line_pointer
;
4046 c
= get_symbol_end ();
4047 cpu_string
= xstrdup (cpu_string
);
4048 *input_line_pointer
= c
;
4051 if (cpu_string
!= NULL
)
4053 unsigned long old_cpu
= ppc_cpu
;
4056 for (p
= cpu_string
; *p
!= 0; p
++)
4059 if (strcmp (cpu_string
, "push") == 0)
4061 if (cpu_history
== NULL
)
4062 cpu_history
= xmalloc (MAX_HISTORY
* sizeof (*cpu_history
));
4064 if (curr_hist
>= MAX_HISTORY
)
4065 as_bad (_(".machine stack overflow"));
4067 cpu_history
[curr_hist
++] = ppc_cpu
;
4069 else if (strcmp (cpu_string
, "pop") == 0)
4072 as_bad (_(".machine stack underflow"));
4074 ppc_cpu
= cpu_history
[--curr_hist
];
4076 else if (parse_cpu (cpu_string
))
4079 as_bad (_("invalid machine `%s'"), cpu_string
);
4081 if (ppc_cpu
!= old_cpu
)
4082 ppc_setup_opcodes ();
4085 demand_empty_rest_of_line ();
4088 /* See whether a symbol is in the TOC section. */
4091 ppc_is_toc_sym (sym
)
4095 return symbol_get_tc (sym
)->class == XMC_TC
;
4098 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
4100 return strcmp (sname
, ".toc") == 0;
4102 return strcmp (sname
, ".got") == 0;
4105 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4109 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4111 /* Set the current section. */
4113 ppc_set_current_section (new)
4116 ppc_previous_section
= ppc_current_section
;
4117 ppc_current_section
= new;
4120 /* pseudo-op: .previous
4121 behaviour: toggles the current section with the previous section.
4123 warnings: "No previous section" */
4126 ppc_previous (ignore
)
4127 int ignore ATTRIBUTE_UNUSED
;
4131 if (ppc_previous_section
== NULL
)
4133 as_warn (_("No previous section to return to. Directive ignored."));
4137 subseg_set (ppc_previous_section
, 0);
4139 ppc_set_current_section (ppc_previous_section
);
4142 /* pseudo-op: .pdata
4143 behaviour: predefined read only data section
4147 initial: .section .pdata "adr3"
4148 a - don't know -- maybe a misprint
4149 d - initialized data
4151 3 - double word aligned (that would be 4 byte boundary)
4154 Tag index tables (also known as the function table) for exception
4155 handling, debugging, etc. */
4159 int ignore ATTRIBUTE_UNUSED
;
4161 if (pdata_section
== 0)
4163 pdata_section
= subseg_new (".pdata", 0);
4165 bfd_set_section_flags (stdoutput
, pdata_section
,
4166 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4167 | SEC_READONLY
| SEC_DATA
));
4169 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
4173 pdata_section
= subseg_new (".pdata", 0);
4175 ppc_set_current_section (pdata_section
);
4178 /* pseudo-op: .ydata
4179 behaviour: predefined read only data section
4183 initial: .section .ydata "drw3"
4184 a - don't know -- maybe a misprint
4185 d - initialized data
4187 3 - double word aligned (that would be 4 byte boundary)
4189 Tag tables (also known as the scope table) for exception handling,
4194 int ignore ATTRIBUTE_UNUSED
;
4196 if (ydata_section
== 0)
4198 ydata_section
= subseg_new (".ydata", 0);
4199 bfd_set_section_flags (stdoutput
, ydata_section
,
4200 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4201 | SEC_READONLY
| SEC_DATA
));
4203 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
4207 ydata_section
= subseg_new (".ydata", 0);
4209 ppc_set_current_section (ydata_section
);
4212 /* pseudo-op: .reldata
4213 behaviour: predefined read write data section
4214 double word aligned (4-byte)
4215 FIXME: relocation is applied to it
4216 FIXME: what's the difference between this and .data?
4219 initial: .section .reldata "drw3"
4220 d - initialized data
4223 3 - double word aligned (that would be 8 byte boundary)
4226 Like .data, but intended to hold data subject to relocation, such as
4227 function descriptors, etc. */
4230 ppc_reldata (ignore
)
4231 int ignore ATTRIBUTE_UNUSED
;
4233 if (reldata_section
== 0)
4235 reldata_section
= subseg_new (".reldata", 0);
4237 bfd_set_section_flags (stdoutput
, reldata_section
,
4238 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4241 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
4245 reldata_section
= subseg_new (".reldata", 0);
4247 ppc_set_current_section (reldata_section
);
4250 /* pseudo-op: .rdata
4251 behaviour: predefined read only data section
4255 initial: .section .rdata "dr3"
4256 d - initialized data
4258 3 - double word aligned (that would be 4 byte boundary) */
4262 int ignore ATTRIBUTE_UNUSED
;
4264 if (rdata_section
== 0)
4266 rdata_section
= subseg_new (".rdata", 0);
4267 bfd_set_section_flags (stdoutput
, rdata_section
,
4268 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4269 | SEC_READONLY
| SEC_DATA
));
4271 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
4275 rdata_section
= subseg_new (".rdata", 0);
4277 ppc_set_current_section (rdata_section
);
4280 /* pseudo-op: .ualong
4281 behaviour: much like .int, with the exception that no alignment is
4283 FIXME: test the alignment statement
4289 int ignore ATTRIBUTE_UNUSED
;
4295 /* pseudo-op: .znop <symbol name>
4296 behaviour: Issue a nop instruction
4297 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4298 the supplied symbol name.
4300 warnings: Missing symbol name */
4304 int ignore ATTRIBUTE_UNUSED
;
4307 const struct powerpc_opcode
*opcode
;
4318 /* Strip out the symbol name. */
4319 symbol_name
= input_line_pointer
;
4320 c
= get_symbol_end ();
4322 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
4323 strcpy (name
, symbol_name
);
4325 sym
= symbol_find_or_make (name
);
4327 *input_line_pointer
= c
;
4331 /* Look up the opcode in the hash table. */
4332 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
4334 /* Stick in the nop. */
4335 insn
= opcode
->opcode
;
4337 /* Write out the instruction. */
4339 md_number_to_chars (f
, insn
, 4);
4341 f
- frag_now
->fr_literal
,
4346 BFD_RELOC_16_GOT_PCREL
);
4359 register char *name
;
4363 register symbolS
*symbolP
;
4366 name
= input_line_pointer
;
4367 c
= get_symbol_end ();
4369 /* just after name is now '\0'. */
4370 p
= input_line_pointer
;
4373 if (*input_line_pointer
!= ',')
4375 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4376 ignore_rest_of_line ();
4380 input_line_pointer
++; /* skip ',' */
4381 if ((temp
= get_absolute_expression ()) < 0)
4383 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
4384 ignore_rest_of_line ();
4390 /* The third argument to .comm is the alignment. */
4391 if (*input_line_pointer
!= ',')
4395 ++input_line_pointer
;
4396 align
= get_absolute_expression ();
4399 as_warn (_("ignoring bad alignment"));
4406 symbolP
= symbol_find_or_make (name
);
4409 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
4411 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4412 S_GET_NAME (symbolP
));
4413 ignore_rest_of_line ();
4417 if (S_GET_VALUE (symbolP
))
4419 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
4420 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4421 S_GET_NAME (symbolP
),
4422 (long) S_GET_VALUE (symbolP
),
4427 S_SET_VALUE (symbolP
, (valueT
) temp
);
4428 S_SET_EXTERNAL (symbolP
);
4429 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
4432 demand_empty_rest_of_line ();
4436 * implement the .section pseudo op:
4437 * .section name {, "flags"}
4439 * | +--- optional flags: 'b' for bss
4441 * +-- section name 'l' for lib
4445 * 'd' (apparently m88k for data)
4447 * But if the argument is not a quoted string, treat it as a
4448 * subsegment number.
4450 * FIXME: this is a copy of the section processing from obj-coff.c, with
4451 * additions/changes for the moto-pas assembler support. There are three
4454 * FIXME: I just noticed this. This doesn't work at all really. It it
4455 * setting bits that bfd probably neither understands or uses. The
4456 * correct approach (?) will have to incorporate extra fields attached
4457 * to the section to hold the system specific stuff. (krk)
4460 * 'a' - unknown - referred to in documentation, but no definition supplied
4461 * 'c' - section has code
4462 * 'd' - section has initialized data
4463 * 'u' - section has uninitialized data
4464 * 'i' - section contains directives (info)
4465 * 'n' - section can be discarded
4466 * 'R' - remove section at link time
4468 * Section Protection:
4469 * 'r' - section is readable
4470 * 'w' - section is writeable
4471 * 'x' - section is executable
4472 * 's' - section is sharable
4474 * Section Alignment:
4475 * '0' - align to byte boundary
4476 * '1' - align to halfword undary
4477 * '2' - align to word boundary
4478 * '3' - align to doubleword boundary
4479 * '4' - align to quadword boundary
4480 * '5' - align to 32 byte boundary
4481 * '6' - align to 64 byte boundary
4486 ppc_pe_section (ignore
)
4487 int ignore ATTRIBUTE_UNUSED
;
4489 /* Strip out the section name. */
4498 section_name
= input_line_pointer
;
4499 c
= get_symbol_end ();
4501 name
= xmalloc (input_line_pointer
- section_name
+ 1);
4502 strcpy (name
, section_name
);
4504 *input_line_pointer
= c
;
4509 flags
= SEC_NO_FLAGS
;
4511 if (strcmp (name
, ".idata$2") == 0)
4515 else if (strcmp (name
, ".idata$3") == 0)
4519 else if (strcmp (name
, ".idata$4") == 0)
4523 else if (strcmp (name
, ".idata$5") == 0)
4527 else if (strcmp (name
, ".idata$6") == 0)
4532 /* Default alignment to 16 byte boundary. */
4535 if (*input_line_pointer
== ',')
4537 ++input_line_pointer
;
4539 if (*input_line_pointer
!= '"')
4540 exp
= get_absolute_expression ();
4543 ++input_line_pointer
;
4544 while (*input_line_pointer
!= '"'
4545 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4547 switch (*input_line_pointer
)
4549 /* Section Contents */
4550 case 'a': /* unknown */
4551 as_bad (_("Unsupported section attribute -- 'a'"));
4553 case 'c': /* code section */
4556 case 'd': /* section has initialized data */
4559 case 'u': /* section has uninitialized data */
4560 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4564 case 'i': /* section contains directives (info) */
4565 /* FIXME: This is IMAGE_SCN_LNK_INFO
4567 flags
|= SEC_HAS_CONTENTS
;
4569 case 'n': /* section can be discarded */
4572 case 'R': /* Remove section at link time */
4573 flags
|= SEC_NEVER_LOAD
;
4576 /* Section Protection */
4577 case 'r': /* section is readable */
4578 flags
|= IMAGE_SCN_MEM_READ
;
4580 case 'w': /* section is writeable */
4581 flags
|= IMAGE_SCN_MEM_WRITE
;
4583 case 'x': /* section is executable */
4584 flags
|= IMAGE_SCN_MEM_EXECUTE
;
4586 case 's': /* section is sharable */
4587 flags
|= IMAGE_SCN_MEM_SHARED
;
4590 /* Section Alignment */
4591 case '0': /* align to byte boundary */
4592 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
4595 case '1': /* align to halfword boundary */
4596 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
4599 case '2': /* align to word boundary */
4600 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
4603 case '3': /* align to doubleword boundary */
4604 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
4607 case '4': /* align to quadword boundary */
4608 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
4611 case '5': /* align to 32 byte boundary */
4612 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
4615 case '6': /* align to 64 byte boundary */
4616 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
4621 as_bad (_("unknown section attribute '%c'"),
4622 *input_line_pointer
);
4625 ++input_line_pointer
;
4627 if (*input_line_pointer
== '"')
4628 ++input_line_pointer
;
4632 sec
= subseg_new (name
, (subsegT
) exp
);
4634 ppc_set_current_section (sec
);
4636 if (flags
!= SEC_NO_FLAGS
)
4638 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
4639 as_bad (_("error setting flags for \"%s\": %s"),
4640 bfd_section_name (stdoutput
, sec
),
4641 bfd_errmsg (bfd_get_error ()));
4644 bfd_set_section_alignment (stdoutput
, sec
, align
);
4649 ppc_pe_function (ignore
)
4650 int ignore ATTRIBUTE_UNUSED
;
4656 name
= input_line_pointer
;
4657 endc
= get_symbol_end ();
4659 ext_sym
= symbol_find_or_make (name
);
4661 *input_line_pointer
= endc
;
4663 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4664 SF_SET_FUNCTION (ext_sym
);
4665 SF_SET_PROCESS (ext_sym
);
4666 coff_add_linesym (ext_sym
);
4668 demand_empty_rest_of_line ();
4672 ppc_pe_tocd (ignore
)
4673 int ignore ATTRIBUTE_UNUSED
;
4675 if (tocdata_section
== 0)
4677 tocdata_section
= subseg_new (".tocd", 0);
4678 /* FIXME: section flags won't work. */
4679 bfd_set_section_flags (stdoutput
, tocdata_section
,
4680 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4681 | SEC_READONLY
| SEC_DATA
));
4683 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4687 rdata_section
= subseg_new (".tocd", 0);
4690 ppc_set_current_section (tocdata_section
);
4692 demand_empty_rest_of_line ();
4695 /* Don't adjust TOC relocs to use the section symbol. */
4698 ppc_pe_fix_adjustable (fix
)
4701 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4708 /* XCOFF specific symbol and file handling. */
4710 /* Canonicalize the symbol name. We use the to force the suffix, if
4711 any, to use square brackets, and to be in upper case. */
4714 ppc_canonicalize_symbol_name (name
)
4719 if (ppc_stab_symbol
)
4722 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4736 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4739 if (*s
== '\0' || s
[1] != '\0')
4740 as_bad (_("bad symbol suffix"));
4748 /* Set the class of a symbol based on the suffix, if any. This is
4749 called whenever a new symbol is created. */
4752 ppc_symbol_new_hook (sym
)
4755 struct ppc_tc_sy
*tc
;
4758 tc
= symbol_get_tc (sym
);
4762 tc
->real_name
= NULL
;
4768 if (ppc_stab_symbol
)
4771 s
= strchr (S_GET_NAME (sym
), '[');
4772 if (s
== (const char *) NULL
)
4774 /* There is no suffix. */
4783 if (strcmp (s
, "BS]") == 0)
4787 if (strcmp (s
, "DB]") == 0)
4789 else if (strcmp (s
, "DS]") == 0)
4793 if (strcmp (s
, "GL]") == 0)
4797 if (strcmp (s
, "PR]") == 0)
4801 if (strcmp (s
, "RO]") == 0)
4803 else if (strcmp (s
, "RW]") == 0)
4807 if (strcmp (s
, "SV]") == 0)
4811 if (strcmp (s
, "TC]") == 0)
4813 else if (strcmp (s
, "TI]") == 0)
4815 else if (strcmp (s
, "TB]") == 0)
4817 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4818 tc
->class = XMC_TC0
;
4821 if (strcmp (s
, "UA]") == 0)
4823 else if (strcmp (s
, "UC]") == 0)
4827 if (strcmp (s
, "XO]") == 0)
4832 if (tc
->class == -1)
4833 as_bad (_("Unrecognized symbol suffix"));
4836 /* Set the class of a label based on where it is defined. This
4837 handles symbols without suffixes. Also, move the symbol so that it
4838 follows the csect symbol. */
4841 ppc_frob_label (sym
)
4844 if (ppc_current_csect
!= (symbolS
*) NULL
)
4846 if (symbol_get_tc (sym
)->class == -1)
4847 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4849 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4850 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4851 &symbol_rootP
, &symbol_lastP
);
4852 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4856 dwarf2_emit_label (sym
);
4860 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4861 seen. It tells ppc_adjust_symtab whether it needs to look through
4864 static bfd_boolean ppc_saw_abs
;
4866 /* Change the name of a symbol just before writing it out. Set the
4867 real name if the .rename pseudo-op was used. Otherwise, remove any
4868 class suffix. Return 1 if the symbol should not be included in the
4872 ppc_frob_symbol (sym
)
4875 static symbolS
*ppc_last_function
;
4876 static symbolS
*set_end
;
4878 /* Discard symbols that should not be included in the output symbol
4880 if (! symbol_used_in_reloc_p (sym
)
4881 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4882 || (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
4883 && ! symbol_get_tc (sym
)->output
4884 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4887 /* This one will disappear anyway. Don't make a csect sym for it. */
4888 if (sym
== abs_section_sym
)
4891 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4892 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4898 name
= S_GET_NAME (sym
);
4899 s
= strchr (name
, '[');
4900 if (s
!= (char *) NULL
)
4906 snew
= xmalloc (len
+ 1);
4907 memcpy (snew
, name
, len
);
4910 S_SET_NAME (sym
, snew
);
4914 if (set_end
!= (symbolS
*) NULL
)
4916 SA_SET_SYM_ENDNDX (set_end
, sym
);
4920 if (SF_GET_FUNCTION (sym
))
4922 if (ppc_last_function
!= (symbolS
*) NULL
)
4923 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4924 ppc_last_function
= sym
;
4925 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4927 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4928 SA_SET_SYM_FSIZE (sym
,
4929 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4932 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4933 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4935 if (ppc_last_function
== (symbolS
*) NULL
)
4936 as_bad (_(".ef with no preceding .function"));
4939 set_end
= ppc_last_function
;
4940 ppc_last_function
= NULL
;
4942 /* We don't have a C_EFCN symbol, but we need to force the
4943 COFF backend to believe that it has seen one. */
4944 coff_last_function
= NULL
;
4948 if (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
4949 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4950 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4951 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4952 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4953 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4954 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4955 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4956 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4957 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4958 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4960 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4961 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4964 union internal_auxent
*a
;
4966 /* Create a csect aux. */
4967 i
= S_GET_NUMBER_AUXILIARY (sym
);
4968 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4969 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4970 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4972 /* This is the TOC table. */
4973 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4974 a
->x_csect
.x_scnlen
.l
= 0;
4975 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4977 else if (symbol_get_tc (sym
)->subseg
!= 0)
4979 /* This is a csect symbol. x_scnlen is the size of the
4981 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4982 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4983 S_GET_SEGMENT (sym
))
4984 - S_GET_VALUE (sym
));
4987 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4988 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4989 - S_GET_VALUE (sym
));
4991 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4993 else if (S_GET_SEGMENT (sym
) == bss_section
)
4995 /* This is a common symbol. */
4996 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4997 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4998 if (S_IS_EXTERNAL (sym
))
4999 symbol_get_tc (sym
)->class = XMC_RW
;
5001 symbol_get_tc (sym
)->class = XMC_BS
;
5003 else if (S_GET_SEGMENT (sym
) == absolute_section
)
5005 /* This is an absolute symbol. The csect will be created by
5006 ppc_adjust_symtab. */
5008 a
->x_csect
.x_smtyp
= XTY_LD
;
5009 if (symbol_get_tc (sym
)->class == -1)
5010 symbol_get_tc (sym
)->class = XMC_XO
;
5012 else if (! S_IS_DEFINED (sym
))
5014 /* This is an external symbol. */
5015 a
->x_csect
.x_scnlen
.l
= 0;
5016 a
->x_csect
.x_smtyp
= XTY_ER
;
5018 else if (symbol_get_tc (sym
)->class == XMC_TC
)
5022 /* This is a TOC definition. x_scnlen is the size of the
5024 next
= symbol_next (sym
);
5025 while (symbol_get_tc (next
)->class == XMC_TC0
)
5026 next
= symbol_next (next
);
5027 if (next
== (symbolS
*) NULL
5028 || symbol_get_tc (next
)->class != XMC_TC
)
5030 if (ppc_after_toc_frag
== (fragS
*) NULL
)
5031 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
5033 - S_GET_VALUE (sym
));
5035 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
5036 - S_GET_VALUE (sym
));
5040 resolve_symbol_value (next
);
5041 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
5042 - S_GET_VALUE (sym
));
5044 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
5050 /* This is a normal symbol definition. x_scnlen is the
5051 symbol index of the containing csect. */
5052 if (S_GET_SEGMENT (sym
) == text_section
)
5053 csect
= ppc_text_csects
;
5054 else if (S_GET_SEGMENT (sym
) == data_section
)
5055 csect
= ppc_data_csects
;
5059 /* Skip the initial dummy symbol. */
5060 csect
= symbol_get_tc (csect
)->next
;
5062 if (csect
== (symbolS
*) NULL
)
5064 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
5065 a
->x_csect
.x_scnlen
.l
= 0;
5069 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
5071 resolve_symbol_value (symbol_get_tc (csect
)->next
);
5072 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
5073 > S_GET_VALUE (sym
))
5075 csect
= symbol_get_tc (csect
)->next
;
5078 a
->x_csect
.x_scnlen
.p
=
5079 coffsymbol (symbol_get_bfdsym (csect
))->native
;
5080 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
5083 a
->x_csect
.x_smtyp
= XTY_LD
;
5086 a
->x_csect
.x_parmhash
= 0;
5087 a
->x_csect
.x_snhash
= 0;
5088 if (symbol_get_tc (sym
)->class == -1)
5089 a
->x_csect
.x_smclas
= XMC_PR
;
5091 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
5092 a
->x_csect
.x_stab
= 0;
5093 a
->x_csect
.x_snstab
= 0;
5095 /* Don't let the COFF backend resort these symbols. */
5096 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
5098 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
5100 /* We want the value to be the symbol index of the referenced
5101 csect symbol. BFD will do that for us if we set the right
5103 asymbol
*bsym
= symbol_get_bfdsym (symbol_get_tc (sym
)->within
);
5104 combined_entry_type
*c
= coffsymbol (bsym
)->native
;
5106 S_SET_VALUE (sym
, (valueT
) (size_t) c
);
5107 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
5109 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
5114 /* The value is the offset from the enclosing csect. */
5115 block
= symbol_get_tc (sym
)->within
;
5116 csect
= symbol_get_tc (block
)->within
;
5117 resolve_symbol_value (csect
);
5118 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
5120 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
5121 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
5123 /* We want the value to be a file offset into the line numbers.
5124 BFD will do that for us if we set the right flags. We have
5125 already set the value correctly. */
5126 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
5132 /* Adjust the symbol table. This creates csect symbols for all
5133 absolute symbols. */
5136 ppc_adjust_symtab ()
5143 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
5147 union internal_auxent
*a
;
5149 if (S_GET_SEGMENT (sym
) != absolute_section
)
5152 csect
= symbol_create (".abs[XO]", absolute_section
,
5153 S_GET_VALUE (sym
), &zero_address_frag
);
5154 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
5155 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
5156 i
= S_GET_NUMBER_AUXILIARY (csect
);
5157 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
5158 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
5159 a
->x_csect
.x_scnlen
.l
= 0;
5160 a
->x_csect
.x_smtyp
= XTY_SD
;
5161 a
->x_csect
.x_parmhash
= 0;
5162 a
->x_csect
.x_snhash
= 0;
5163 a
->x_csect
.x_smclas
= XMC_XO
;
5164 a
->x_csect
.x_stab
= 0;
5165 a
->x_csect
.x_snstab
= 0;
5167 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
5169 i
= S_GET_NUMBER_AUXILIARY (sym
);
5170 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
5171 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
5172 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
5175 ppc_saw_abs
= FALSE
;
5178 /* Set the VMA for a section. This is called on all the sections in
5182 ppc_frob_section (sec
)
5185 static bfd_vma vma
= 0;
5187 vma
= md_section_align (sec
, vma
);
5188 bfd_set_section_vma (stdoutput
, sec
, vma
);
5189 vma
+= bfd_section_size (stdoutput
, sec
);
5192 #endif /* OBJ_XCOFF */
5194 /* Turn a string in input_line_pointer into a floating point constant
5195 of type TYPE, and store the appropriate bytes in *LITP. The number
5196 of LITTLENUMS emitted is stored in *SIZEP. An error message is
5197 returned, or NULL on OK. */
5200 md_atof (type
, litp
, sizep
)
5206 LITTLENUM_TYPE words
[4];
5222 return _("bad call to md_atof");
5225 t
= atof_ieee (input_line_pointer
, type
, words
);
5227 input_line_pointer
= t
;
5231 if (target_big_endian
)
5233 for (i
= 0; i
< prec
; i
++)
5235 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5241 for (i
= prec
- 1; i
>= 0; i
--)
5243 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5251 /* Write a value out to the object file, using the appropriate
5255 md_number_to_chars (buf
, val
, n
)
5260 if (target_big_endian
)
5261 number_to_chars_bigendian (buf
, val
, n
);
5263 number_to_chars_littleendian (buf
, val
, n
);
5266 /* Align a section (I don't know why this is machine dependent). */
5269 md_section_align (seg
, addr
)
5273 int align
= bfd_get_section_alignment (stdoutput
, seg
);
5275 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
5278 /* We don't have any form of relaxing. */
5281 md_estimate_size_before_relax (fragp
, seg
)
5282 fragS
*fragp ATTRIBUTE_UNUSED
;
5283 asection
*seg ATTRIBUTE_UNUSED
;
5289 /* Convert a machine dependent frag. We never generate these. */
5292 md_convert_frag (abfd
, sec
, fragp
)
5293 bfd
*abfd ATTRIBUTE_UNUSED
;
5294 asection
*sec ATTRIBUTE_UNUSED
;
5295 fragS
*fragp ATTRIBUTE_UNUSED
;
5300 /* We have no need to default values of symbols. */
5303 md_undefined_symbol (name
)
5304 char *name ATTRIBUTE_UNUSED
;
5309 /* Functions concerning relocs. */
5311 /* The location from which a PC relative jump should be calculated,
5312 given a PC relative reloc. */
5315 md_pcrel_from_section (fixp
, sec
)
5317 segT sec ATTRIBUTE_UNUSED
;
5319 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5324 /* This is called to see whether a fixup should be adjusted to use a
5325 section symbol. We take the opportunity to change a fixup against
5326 a symbol in the TOC subsegment into a reloc against the
5327 corresponding .tc symbol. */
5330 ppc_fix_adjustable (fix
)
5333 valueT val
= resolve_symbol_value (fix
->fx_addsy
);
5334 segT symseg
= S_GET_SEGMENT (fix
->fx_addsy
);
5335 TC_SYMFIELD_TYPE
*tc
;
5337 if (symseg
== absolute_section
)
5340 if (ppc_toc_csect
!= (symbolS
*) NULL
5341 && fix
->fx_addsy
!= ppc_toc_csect
5342 && symseg
== data_section
5343 && val
>= ppc_toc_frag
->fr_address
5344 && (ppc_after_toc_frag
== (fragS
*) NULL
5345 || val
< ppc_after_toc_frag
->fr_address
))
5349 for (sy
= symbol_next (ppc_toc_csect
);
5350 sy
!= (symbolS
*) NULL
;
5351 sy
= symbol_next (sy
))
5353 TC_SYMFIELD_TYPE
*sy_tc
= symbol_get_tc (sy
);
5355 if (sy_tc
->class == XMC_TC0
)
5357 if (sy_tc
->class != XMC_TC
)
5359 if (val
== resolve_symbol_value (sy
))
5362 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
5367 as_bad_where (fix
->fx_file
, fix
->fx_line
,
5368 _("symbol in .toc does not match any .tc"));
5371 /* Possibly adjust the reloc to be against the csect. */
5372 tc
= symbol_get_tc (fix
->fx_addsy
);
5374 && tc
->class != XMC_TC0
5375 && tc
->class != XMC_TC
5376 && symseg
!= bss_section
5377 /* Don't adjust if this is a reloc in the toc section. */
5378 && (symseg
!= data_section
5379 || ppc_toc_csect
== NULL
5380 || val
< ppc_toc_frag
->fr_address
5381 || (ppc_after_toc_frag
!= NULL
5382 && val
>= ppc_after_toc_frag
->fr_address
)))
5385 symbolS
*next_csect
;
5387 if (symseg
== text_section
)
5388 csect
= ppc_text_csects
;
5389 else if (symseg
== data_section
)
5390 csect
= ppc_data_csects
;
5394 /* Skip the initial dummy symbol. */
5395 csect
= symbol_get_tc (csect
)->next
;
5397 if (csect
!= (symbolS
*) NULL
)
5399 while ((next_csect
= symbol_get_tc (csect
)->next
) != (symbolS
*) NULL
5400 && (symbol_get_frag (next_csect
)->fr_address
<= val
))
5402 /* If the csect address equals the symbol value, then we
5403 have to look through the full symbol table to see
5404 whether this is the csect we want. Note that we will
5405 only get here if the csect has zero length. */
5406 if (symbol_get_frag (csect
)->fr_address
== val
5407 && S_GET_VALUE (csect
) == val
)
5411 for (scan
= symbol_next (csect
);
5413 scan
= symbol_next (scan
))
5415 if (symbol_get_tc (scan
)->subseg
!= 0)
5417 if (scan
== fix
->fx_addsy
)
5421 /* If we found the symbol before the next csect
5422 symbol, then this is the csect we want. */
5423 if (scan
== fix
->fx_addsy
)
5430 fix
->fx_offset
+= val
- symbol_get_frag (csect
)->fr_address
;
5431 fix
->fx_addsy
= csect
;
5436 /* Adjust a reloc against a .lcomm symbol to be against the base
5438 if (symseg
== bss_section
5439 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
5441 symbolS
*sy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
5443 fix
->fx_offset
+= val
- resolve_symbol_value (sy
);
5450 /* A reloc from one csect to another must be kept. The assembler
5451 will, of course, keep relocs between sections, and it will keep
5452 absolute relocs, but we need to force it to keep PC relative relocs
5453 between two csects in the same section. */
5456 ppc_force_relocation (fix
)
5459 /* At this point fix->fx_addsy should already have been converted to
5460 a csect symbol. If the csect does not include the fragment, then
5461 we need to force the relocation. */
5463 && fix
->fx_addsy
!= NULL
5464 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
5465 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
5466 > fix
->fx_frag
->fr_address
)
5467 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
5468 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
5469 <= fix
->fx_frag
->fr_address
))))
5472 return generic_force_reloc (fix
);
5475 #endif /* OBJ_XCOFF */
5478 /* If this function returns non-zero, it guarantees that a relocation
5479 will be emitted for a fixup. */
5482 ppc_force_relocation (fix
)
5485 /* Branch prediction relocations must force a relocation, as must
5486 the vtable description relocs. */
5487 switch (fix
->fx_r_type
)
5489 case BFD_RELOC_PPC_B16_BRTAKEN
:
5490 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5491 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5492 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5493 case BFD_RELOC_24_PLT_PCREL
:
5494 case BFD_RELOC_PPC64_TOC
:
5500 if (fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5501 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
5504 return generic_force_reloc (fix
);
5508 ppc_fix_adjustable (fix
)
5511 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
5512 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
5513 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
5514 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
5515 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
5516 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
5517 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
5518 && !(fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5519 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
));
5523 /* Apply a fixup to the object code. This is called for all the
5524 fixups we generated by the call to fix_new_exp, above. In the call
5525 above we used a reloc code which was the largest legal reloc code
5526 plus the operand index. Here we undo that to recover the operand
5527 index. At this point all symbol values should be fully resolved,
5528 and we attempt to completely resolve the reloc. If we can not do
5529 that, we determine the correct reloc code and put it back in the
5533 md_apply_fix (fixP
, valP
, seg
)
5536 segT seg ATTRIBUTE_UNUSED
;
5538 valueT value
= * valP
;
5541 if (fixP
->fx_addsy
!= NULL
)
5543 /* Hack around bfd_install_relocation brain damage. */
5545 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5550 /* FIXME FIXME FIXME: The value we are passed in *valP includes
5551 the symbol values. If we are doing this relocation the code in
5552 write.c is going to call bfd_install_relocation, which is also
5553 going to use the symbol value. That means that if the reloc is
5554 fully resolved we want to use *valP since bfd_install_relocation is
5556 However, if the reloc is not fully resolved we do not want to use
5557 *valP, and must use fx_offset instead. However, if the reloc
5558 is PC relative, we do want to use *valP since it includes the
5559 result of md_pcrel_from. This is confusing. */
5560 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
5563 else if (fixP
->fx_pcrel
)
5567 value
= fixP
->fx_offset
;
5570 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
5572 /* We can't actually support subtracting a symbol. */
5573 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
5576 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
5579 const struct powerpc_operand
*operand
;
5583 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
5585 operand
= &powerpc_operands
[opindex
];
5588 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5589 does not generate a reloc. It uses the offset of `sym' within its
5590 csect. Other usages, such as `.long sym', generate relocs. This
5591 is the documented behaviour of non-TOC symbols. */
5592 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5593 && operand
->bits
== 16
5594 && operand
->shift
== 0
5595 && (operand
->insert
== NULL
|| ppc_obj64
)
5596 && fixP
->fx_addsy
!= NULL
5597 && symbol_get_tc (fixP
->fx_addsy
)->subseg
!= 0
5598 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC
5599 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC0
5600 && S_GET_SEGMENT (fixP
->fx_addsy
) != bss_section
)
5602 value
= fixP
->fx_offset
;
5607 /* Fetch the instruction, insert the fully resolved operand
5608 value, and stuff the instruction back again. */
5609 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5610 if (target_big_endian
)
5611 insn
= bfd_getb32 ((unsigned char *) where
);
5613 insn
= bfd_getl32 ((unsigned char *) where
);
5614 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
5615 fixP
->fx_file
, fixP
->fx_line
);
5616 if (target_big_endian
)
5617 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5619 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5622 /* Nothing else to do here. */
5625 assert (fixP
->fx_addsy
!= NULL
);
5627 /* Determine a BFD reloc value based on the operand information.
5628 We are only prepared to turn a few of the operands into
5630 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5631 && operand
->bits
== 26
5632 && operand
->shift
== 0)
5633 fixP
->fx_r_type
= BFD_RELOC_PPC_B26
;
5634 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5635 && operand
->bits
== 16
5636 && operand
->shift
== 0)
5638 fixP
->fx_r_type
= BFD_RELOC_PPC_B16
;
5641 if (target_big_endian
)
5642 fixP
->fx_where
+= 2;
5645 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5646 && operand
->bits
== 26
5647 && operand
->shift
== 0)
5648 fixP
->fx_r_type
= BFD_RELOC_PPC_BA26
;
5649 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5650 && operand
->bits
== 16
5651 && operand
->shift
== 0)
5653 fixP
->fx_r_type
= BFD_RELOC_PPC_BA16
;
5656 if (target_big_endian
)
5657 fixP
->fx_where
+= 2;
5660 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5661 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5662 && operand
->bits
== 16
5663 && operand
->shift
== 0)
5665 if (ppc_is_toc_sym (fixP
->fx_addsy
))
5667 fixP
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
5670 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5671 fixP
->fx_r_type
= BFD_RELOC_PPC64_TOC16_DS
;
5676 fixP
->fx_r_type
= BFD_RELOC_16
;
5679 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5680 fixP
->fx_r_type
= BFD_RELOC_PPC64_ADDR16_DS
;
5684 if (target_big_endian
)
5685 fixP
->fx_where
+= 2;
5687 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5693 /* Use expr_symbol_where to see if this is an expression
5695 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
5696 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5697 _("unresolved expression that must be resolved"));
5699 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5700 _("unsupported relocation against %s"),
5701 S_GET_NAME (fixP
->fx_addsy
));
5709 ppc_elf_validate_fix (fixP
, seg
);
5711 switch (fixP
->fx_r_type
)
5713 case BFD_RELOC_CTOR
:
5720 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
5724 case BFD_RELOC_32_PCREL
:
5725 case BFD_RELOC_PPC_EMB_NADDR32
:
5726 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5733 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
5736 case BFD_RELOC_64_PCREL
:
5737 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5741 case BFD_RELOC_GPREL16
:
5742 case BFD_RELOC_16_GOT_PCREL
:
5743 case BFD_RELOC_16_GOTOFF
:
5744 case BFD_RELOC_LO16_GOTOFF
:
5745 case BFD_RELOC_HI16_GOTOFF
:
5746 case BFD_RELOC_HI16_S_GOTOFF
:
5747 case BFD_RELOC_16_BASEREL
:
5748 case BFD_RELOC_LO16_BASEREL
:
5749 case BFD_RELOC_HI16_BASEREL
:
5750 case BFD_RELOC_HI16_S_BASEREL
:
5751 case BFD_RELOC_PPC_EMB_NADDR16
:
5752 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5753 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5754 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5755 case BFD_RELOC_PPC_EMB_SDAI16
:
5756 case BFD_RELOC_PPC_EMB_SDA2REL
:
5757 case BFD_RELOC_PPC_EMB_SDA2I16
:
5758 case BFD_RELOC_PPC_EMB_RELSEC16
:
5759 case BFD_RELOC_PPC_EMB_RELST_LO
:
5760 case BFD_RELOC_PPC_EMB_RELST_HI
:
5761 case BFD_RELOC_PPC_EMB_RELST_HA
:
5762 case BFD_RELOC_PPC_EMB_RELSDA
:
5763 case BFD_RELOC_PPC_TOC16
:
5765 case BFD_RELOC_PPC64_TOC16_LO
:
5766 case BFD_RELOC_PPC64_TOC16_HI
:
5767 case BFD_RELOC_PPC64_TOC16_HA
:
5771 if (fixP
->fx_addsy
!= NULL
)
5772 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5773 _("cannot emit PC relative %s relocation against %s"),
5774 bfd_get_reloc_code_name (fixP
->fx_r_type
),
5775 S_GET_NAME (fixP
->fx_addsy
));
5777 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5778 _("cannot emit PC relative %s relocation"),
5779 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5782 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5788 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
5791 case BFD_RELOC_16_PCREL
:
5792 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5796 case BFD_RELOC_LO16
:
5798 fixP
->fx_r_type
= BFD_RELOC_LO16_PCREL
;
5801 case BFD_RELOC_LO16_PCREL
:
5802 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5806 /* This case happens when you write, for example,
5808 where L1 and L2 are defined later. */
5809 case BFD_RELOC_HI16
:
5811 fixP
->fx_r_type
= BFD_RELOC_HI16_PCREL
;
5814 case BFD_RELOC_HI16_PCREL
:
5815 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5819 case BFD_RELOC_HI16_S
:
5821 fixP
->fx_r_type
= BFD_RELOC_HI16_S_PCREL
;
5824 case BFD_RELOC_HI16_S_PCREL
:
5825 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5830 case BFD_RELOC_PPC64_HIGHER
:
5833 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5834 PPC_HIGHER (value
), 2);
5837 case BFD_RELOC_PPC64_HIGHER_S
:
5840 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5841 PPC_HIGHERA (value
), 2);
5844 case BFD_RELOC_PPC64_HIGHEST
:
5847 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5848 PPC_HIGHEST (value
), 2);
5851 case BFD_RELOC_PPC64_HIGHEST_S
:
5854 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5855 PPC_HIGHESTA (value
), 2);
5858 case BFD_RELOC_PPC64_ADDR16_DS
:
5859 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
5860 case BFD_RELOC_PPC64_GOT16_DS
:
5861 case BFD_RELOC_PPC64_GOT16_LO_DS
:
5862 case BFD_RELOC_PPC64_PLT16_LO_DS
:
5863 case BFD_RELOC_PPC64_SECTOFF_DS
:
5864 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
5865 case BFD_RELOC_PPC64_TOC16_DS
:
5866 case BFD_RELOC_PPC64_TOC16_LO_DS
:
5867 case BFD_RELOC_PPC64_PLTGOT16_DS
:
5868 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
5872 char *where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5873 unsigned long val
, mask
;
5875 if (target_big_endian
)
5876 val
= bfd_getb32 (where
- 2);
5878 val
= bfd_getl32 (where
);
5880 /* lq insns reserve the four lsbs. */
5881 if ((ppc_cpu
& PPC_OPCODE_POWER4
) != 0
5882 && (val
& (0x3f << 26)) == (56u << 26))
5884 val
|= value
& mask
;
5885 if (target_big_endian
)
5886 bfd_putb16 ((bfd_vma
) val
, where
);
5888 bfd_putl16 ((bfd_vma
) val
, where
);
5892 case BFD_RELOC_PPC_B16_BRTAKEN
:
5893 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5894 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5895 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5898 case BFD_RELOC_PPC_TLS
:
5901 case BFD_RELOC_PPC_DTPMOD
:
5902 case BFD_RELOC_PPC_TPREL16
:
5903 case BFD_RELOC_PPC_TPREL16_LO
:
5904 case BFD_RELOC_PPC_TPREL16_HI
:
5905 case BFD_RELOC_PPC_TPREL16_HA
:
5906 case BFD_RELOC_PPC_TPREL
:
5907 case BFD_RELOC_PPC_DTPREL16
:
5908 case BFD_RELOC_PPC_DTPREL16_LO
:
5909 case BFD_RELOC_PPC_DTPREL16_HI
:
5910 case BFD_RELOC_PPC_DTPREL16_HA
:
5911 case BFD_RELOC_PPC_DTPREL
:
5912 case BFD_RELOC_PPC_GOT_TLSGD16
:
5913 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
5914 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
5915 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
5916 case BFD_RELOC_PPC_GOT_TLSLD16
:
5917 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
5918 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
5919 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
5920 case BFD_RELOC_PPC_GOT_TPREL16
:
5921 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
5922 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
5923 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
5924 case BFD_RELOC_PPC_GOT_DTPREL16
:
5925 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
5926 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
5927 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
5928 case BFD_RELOC_PPC64_TPREL16_DS
:
5929 case BFD_RELOC_PPC64_TPREL16_LO_DS
:
5930 case BFD_RELOC_PPC64_TPREL16_HIGHER
:
5931 case BFD_RELOC_PPC64_TPREL16_HIGHERA
:
5932 case BFD_RELOC_PPC64_TPREL16_HIGHEST
:
5933 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
:
5934 case BFD_RELOC_PPC64_DTPREL16_DS
:
5935 case BFD_RELOC_PPC64_DTPREL16_LO_DS
:
5936 case BFD_RELOC_PPC64_DTPREL16_HIGHER
:
5937 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
:
5938 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
:
5939 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
:
5940 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
5943 /* Because SDA21 modifies the register field, the size is set to 4
5944 bytes, rather than 2, so offset it here appropriately. */
5945 case BFD_RELOC_PPC_EMB_SDA21
:
5949 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
5950 + ((target_big_endian
) ? 2 : 0),
5957 /* This can occur if there is a bug in the input assembler, eg:
5958 ".byte <undefined_symbol> - ." */
5960 as_bad (_("Unable to handle reference to symbol %s"),
5961 S_GET_NAME (fixP
->fx_addsy
));
5963 as_bad (_("Unable to resolve expression"));
5967 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5971 case BFD_RELOC_24_PLT_PCREL
:
5972 case BFD_RELOC_PPC_LOCAL24PC
:
5973 if (!fixP
->fx_pcrel
&& !fixP
->fx_done
)
5981 /* Fetch the instruction, insert the fully resolved operand
5982 value, and stuff the instruction back again. */
5983 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5984 if (target_big_endian
)
5985 insn
= bfd_getb32 ((unsigned char *) where
);
5987 insn
= bfd_getl32 ((unsigned char *) where
);
5988 if ((value
& 3) != 0)
5989 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5990 _("must branch to an address a multiple of 4"));
5991 if ((offsetT
) value
< -0x40000000
5992 || (offsetT
) value
>= 0x40000000)
5993 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5994 _("@local or @plt branch destination is too far away, %ld bytes"),
5996 insn
= insn
| (value
& 0x03fffffc);
5997 if (target_big_endian
)
5998 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
6000 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
6004 case BFD_RELOC_VTABLE_INHERIT
:
6007 && !S_IS_DEFINED (fixP
->fx_addsy
)
6008 && !S_IS_WEAK (fixP
->fx_addsy
))
6009 S_SET_WEAK (fixP
->fx_addsy
);
6012 case BFD_RELOC_VTABLE_ENTRY
:
6017 /* Generated by reference to `sym@tocbase'. The sym is
6018 ignored by the linker. */
6019 case BFD_RELOC_PPC64_TOC
:
6025 _("Gas failure, reloc value %d\n"), fixP
->fx_r_type
);
6032 fixP
->fx_addnumber
= value
;
6034 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6035 from the section contents. If we are going to be emitting a reloc
6036 then the section contents are immaterial, so don't warn if they
6037 happen to overflow. Leave such warnings to ld. */
6039 fixP
->fx_no_overflow
= 1;
6041 if (fixP
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
6042 fixP
->fx_addnumber
= 0;
6046 fixP
->fx_addnumber
= 0;
6048 /* We want to use the offset within the data segment of the
6049 symbol, not the actual VMA of the symbol. */
6050 fixP
->fx_addnumber
=
6051 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixP
->fx_addsy
));
6057 /* Generate a reloc for a fixup. */
6060 tc_gen_reloc (seg
, fixp
)
6061 asection
*seg ATTRIBUTE_UNUSED
;
6066 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
6068 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
6069 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
6070 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
6071 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
6072 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
6074 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6075 _("reloc %d not supported by object file format"),
6076 (int) fixp
->fx_r_type
);
6079 reloc
->addend
= fixp
->fx_addnumber
;
6085 ppc_cfi_frame_initial_instructions ()
6087 cfi_add_CFA_def_cfa (1, 0);
6091 tc_ppc_regname_to_dw2regnum (char *regname
)
6093 unsigned int regnum
= -1;
6097 static struct { char *name
; int dw2regnum
; } regnames
[] =
6099 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6100 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6101 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6102 { "spe_acc", 111 }, { "spefscr", 112 }
6105 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
6106 if (strcmp (regnames
[i
].name
, regname
) == 0)
6107 return regnames
[i
].dw2regnum
;
6109 if (regname
[0] == 'r' || regname
[0] == 'f' || regname
[0] == 'v')
6111 p
= regname
+ 1 + (regname
[1] == '.');
6112 regnum
= strtoul (p
, &q
, 10);
6113 if (p
== q
|| *q
|| regnum
>= 32)
6115 if (regname
[0] == 'f')
6117 else if (regname
[0] == 'v')
6120 else if (regname
[0] == 'c' && regname
[1] == 'r')
6122 p
= regname
+ 2 + (regname
[2] == '.');
6123 if (p
[0] < '0' || p
[0] > '7' || p
[1])
6125 regnum
= p
[0] - '0' + 68;