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
24 #include "safe-ctype.h"
26 #include "dw2gencfi.h"
27 #include "opcode/ppc.h"
31 #include "dwarf2dbg.h"
38 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
40 /* Tell the main code what the endianness is. */
41 extern int target_big_endian
;
43 /* Whether or not, we've set target_big_endian. */
44 static int set_target_endian
= 0;
46 /* Whether to use user friendly register names. */
47 #ifndef TARGET_REG_NAMES_P
49 #define TARGET_REG_NAMES_P TRUE
51 #define TARGET_REG_NAMES_P FALSE
55 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
58 /* #lo(value) denotes the least significant 16 bits of the indicated. */
59 #define PPC_LO(v) ((v) & 0xffff)
61 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
62 #define PPC_HI(v) (((v) >> 16) & 0xffff)
64 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
65 the indicated value, compensating for #lo() being treated as a
67 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
69 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
70 #define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
72 /* #highera(value) denotes bits 32 through 47 of the indicated value,
73 compensating for #lo() being treated as a signed number. */
74 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
76 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
77 #define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
79 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
80 compensating for #lo being treated as a signed number. */
81 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
83 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
85 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
87 static bfd_boolean register_name
PARAMS ((expressionS
*));
88 static void ppc_set_cpu
PARAMS ((void));
89 static unsigned long ppc_insert_operand
90 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
91 offsetT val
, char *file
, unsigned int line
));
92 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
93 static void ppc_byte
PARAMS ((int));
95 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
96 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
97 static void ppc_tc
PARAMS ((int));
98 static void ppc_machine
PARAMS ((int));
102 static void ppc_comm
PARAMS ((int));
103 static void ppc_bb
PARAMS ((int));
104 static void ppc_bc
PARAMS ((int));
105 static void ppc_bf
PARAMS ((int));
106 static void ppc_biei
PARAMS ((int));
107 static void ppc_bs
PARAMS ((int));
108 static void ppc_eb
PARAMS ((int));
109 static void ppc_ec
PARAMS ((int));
110 static void ppc_ef
PARAMS ((int));
111 static void ppc_es
PARAMS ((int));
112 static void ppc_csect
PARAMS ((int));
113 static void ppc_change_csect
PARAMS ((symbolS
*, offsetT
));
114 static void ppc_function
PARAMS ((int));
115 static void ppc_extern
PARAMS ((int));
116 static void ppc_lglobl
PARAMS ((int));
117 static void ppc_section
PARAMS ((int));
118 static void ppc_named_section
PARAMS ((int));
119 static void ppc_stabx
PARAMS ((int));
120 static void ppc_rename
PARAMS ((int));
121 static void ppc_toc
PARAMS ((int));
122 static void ppc_xcoff_cons
PARAMS ((int));
123 static void ppc_vbyte
PARAMS ((int));
127 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
128 static void ppc_elf_cons
PARAMS ((int));
129 static void ppc_elf_rdata
PARAMS ((int));
130 static void ppc_elf_lcomm
PARAMS ((int));
131 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
132 static void ppc_apuinfo_section_add
PARAMS ((unsigned int apu
, unsigned int version
));
136 static void ppc_set_current_section
PARAMS ((segT
));
137 static void ppc_previous
PARAMS ((int));
138 static void ppc_pdata
PARAMS ((int));
139 static void ppc_ydata
PARAMS ((int));
140 static void ppc_reldata
PARAMS ((int));
141 static void ppc_rdata
PARAMS ((int));
142 static void ppc_ualong
PARAMS ((int));
143 static void ppc_znop
PARAMS ((int));
144 static void ppc_pe_comm
PARAMS ((int));
145 static void ppc_pe_section
PARAMS ((int));
146 static void ppc_pe_function
PARAMS ((int));
147 static void ppc_pe_tocd
PARAMS ((int));
150 /* Generic assembler global variables which must be defined by all
154 /* This string holds the chars that always start a comment. If the
155 pre-processor is disabled, these aren't very useful. The macro
156 tc_comment_chars points to this. We use this, rather than the
157 usual comment_chars, so that we can switch for Solaris conventions. */
158 static const char ppc_solaris_comment_chars
[] = "#!";
159 static const char ppc_eabi_comment_chars
[] = "#";
161 #ifdef TARGET_SOLARIS_COMMENT
162 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
164 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
167 const char comment_chars
[] = "#";
170 /* Characters which start a comment at the beginning of a line. */
171 const char line_comment_chars
[] = "#";
173 /* Characters which may be used to separate multiple commands on a
175 const char line_separator_chars
[] = ";";
177 /* Characters which are used to indicate an exponent in a floating
179 const char EXP_CHARS
[] = "eE";
181 /* Characters which mean that a number is a floating point constant,
183 const char FLT_CHARS
[] = "dD";
185 /* Anything that can start an operand needs to be mentioned here,
186 to stop the input scrubber eating whitespace. */
187 const char ppc_symbol_chars
[] = "%[";
189 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
190 int ppc_cie_data_alignment
;
192 /* The target specific pseudo-ops which we support. */
194 const pseudo_typeS md_pseudo_table
[] =
196 /* Pseudo-ops which must be overridden. */
197 { "byte", ppc_byte
, 0 },
200 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
201 legitimately belong in the obj-*.c file. However, XCOFF is based
202 on COFF, and is only implemented for the RS/6000. We just use
203 obj-coff.c, and add what we need here. */
204 { "comm", ppc_comm
, 0 },
205 { "lcomm", ppc_comm
, 1 },
209 { "bi", ppc_biei
, 0 },
211 { "csect", ppc_csect
, 0 },
212 { "data", ppc_section
, 'd' },
216 { "ei", ppc_biei
, 1 },
218 { "extern", ppc_extern
, 0 },
219 { "function", ppc_function
, 0 },
220 { "lglobl", ppc_lglobl
, 0 },
221 { "rename", ppc_rename
, 0 },
222 { "section", ppc_named_section
, 0 },
223 { "stabx", ppc_stabx
, 0 },
224 { "text", ppc_section
, 't' },
225 { "toc", ppc_toc
, 0 },
226 { "long", ppc_xcoff_cons
, 2 },
227 { "llong", ppc_xcoff_cons
, 3 },
228 { "word", ppc_xcoff_cons
, 1 },
229 { "short", ppc_xcoff_cons
, 1 },
230 { "vbyte", ppc_vbyte
, 0 },
234 { "llong", ppc_elf_cons
, 8 },
235 { "quad", ppc_elf_cons
, 8 },
236 { "long", ppc_elf_cons
, 4 },
237 { "word", ppc_elf_cons
, 2 },
238 { "short", ppc_elf_cons
, 2 },
239 { "rdata", ppc_elf_rdata
, 0 },
240 { "rodata", ppc_elf_rdata
, 0 },
241 { "lcomm", ppc_elf_lcomm
, 0 },
245 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
246 { "previous", ppc_previous
, 0 },
247 { "pdata", ppc_pdata
, 0 },
248 { "ydata", ppc_ydata
, 0 },
249 { "reldata", ppc_reldata
, 0 },
250 { "rdata", ppc_rdata
, 0 },
251 { "ualong", ppc_ualong
, 0 },
252 { "znop", ppc_znop
, 0 },
253 { "comm", ppc_pe_comm
, 0 },
254 { "lcomm", ppc_pe_comm
, 1 },
255 { "section", ppc_pe_section
, 0 },
256 { "function", ppc_pe_function
,0 },
257 { "tocd", ppc_pe_tocd
, 0 },
260 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
262 { "machine", ppc_machine
, 0 },
269 /* Predefined register names if -mregnames (or default for Windows NT).
270 In general, there are lots of them, in an attempt to be compatible
271 with a number of other Windows NT assemblers. */
273 /* Structure to hold information about predefined registers. */
280 /* List of registers that are pre-defined:
282 Each general register has predefined names of the form:
283 1. r<reg_num> which has the value <reg_num>.
284 2. r.<reg_num> which has the value <reg_num>.
286 Each floating point register has predefined names of the form:
287 1. f<reg_num> which has the value <reg_num>.
288 2. f.<reg_num> which has the value <reg_num>.
290 Each vector unit register has predefined names of the form:
291 1. v<reg_num> which has the value <reg_num>.
292 2. v.<reg_num> which has the value <reg_num>.
294 Each condition register has predefined names of the form:
295 1. cr<reg_num> which has the value <reg_num>.
296 2. cr.<reg_num> which has the value <reg_num>.
298 There are individual registers as well:
299 sp or r.sp has the value 1
300 rtoc or r.toc has the value 2
301 fpscr has the value 0
307 dsisr has the value 18
309 sdr1 has the value 25
310 srr0 has the value 26
311 srr1 has the value 27
313 The table is sorted. Suitable for searching by a binary search. */
315 static const struct pd_reg pre_defined_registers
[] =
317 { "cr.0", 0 }, /* Condition Registers */
337 { "dar", 19 }, /* Data Access Register */
338 { "dec", 22 }, /* Decrementer */
339 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
341 { "f.0", 0 }, /* Floating point registers */
409 { "lr", 8 }, /* Link Register */
413 { "r.0", 0 }, /* General Purpose Registers */
446 { "r.sp", 1 }, /* Stack Pointer */
448 { "r.toc", 2 }, /* Pointer to the table of contents */
450 { "r0", 0 }, /* More general purpose registers */
483 { "rtoc", 2 }, /* Table of contents */
485 { "sdr1", 25 }, /* Storage Description Register 1 */
489 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
490 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
492 { "v.0", 0 }, /* Vector registers */
562 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
564 /* Given NAME, find the register number associated with that name, return
565 the integer value associated with the given name or -1 on failure. */
567 static int reg_name_search
568 PARAMS ((const struct pd_reg
*, int, const char * name
));
571 reg_name_search (regs
, regcount
, name
)
572 const struct pd_reg
*regs
;
576 int middle
, low
, high
;
584 middle
= (low
+ high
) / 2;
585 cmp
= strcasecmp (name
, regs
[middle
].name
);
591 return regs
[middle
].value
;
599 * Summary of register_name.
601 * in: Input_line_pointer points to 1st char of operand.
603 * out: A expressionS.
604 * The operand may have been a register: in this case, X_op == O_register,
605 * X_add_number is set to the register number, and truth is returned.
606 * Input_line_pointer->(next non-blank) char after operand, or is in its
611 register_name (expressionP
)
612 expressionS
*expressionP
;
619 /* Find the spelling of the operand. */
620 start
= name
= input_line_pointer
;
621 if (name
[0] == '%' && ISALPHA (name
[1]))
622 name
= ++input_line_pointer
;
624 else if (!reg_names_p
|| !ISALPHA (name
[0]))
627 c
= get_symbol_end ();
628 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
630 /* Put back the delimiting char. */
631 *input_line_pointer
= c
;
633 /* Look to see if it's in the register table. */
636 expressionP
->X_op
= O_register
;
637 expressionP
->X_add_number
= reg_number
;
639 /* Make the rest nice. */
640 expressionP
->X_add_symbol
= NULL
;
641 expressionP
->X_op_symbol
= NULL
;
645 /* Reset the line as if we had not done anything. */
646 input_line_pointer
= start
;
650 /* This function is called for each symbol seen in an expression. It
651 handles the special parsing which PowerPC assemblers are supposed
652 to use for condition codes. */
654 /* Whether to do the special parsing. */
655 static bfd_boolean cr_operand
;
657 /* Names to recognize in a condition code. This table is sorted. */
658 static const struct pd_reg cr_names
[] =
675 /* Parsing function. This returns non-zero if it recognized an
679 ppc_parse_name (name
, expr
)
688 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
693 expr
->X_op
= O_constant
;
694 expr
->X_add_number
= val
;
699 /* Local variables. */
701 /* The type of processor we are assembling for. This is one or more
702 of the PPC_OPCODE flags defined in opcode/ppc.h. */
703 static unsigned long ppc_cpu
= 0;
705 /* Whether to target xcoff64/elf64. */
706 static unsigned int ppc_obj64
= BFD_DEFAULT_TARGET_SIZE
== 64;
708 /* Opcode hash table. */
709 static struct hash_control
*ppc_hash
;
711 /* Macro hash table. */
712 static struct hash_control
*ppc_macro_hash
;
715 /* What type of shared library support to use. */
716 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
718 /* Flags to set in the elf header. */
719 static flagword ppc_flags
= 0;
721 /* Whether this is Solaris or not. */
722 #ifdef TARGET_SOLARIS_COMMENT
723 #define SOLARIS_P TRUE
725 #define SOLARIS_P FALSE
728 static bfd_boolean msolaris
= SOLARIS_P
;
733 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
734 using a bunch of different sections. These assembler sections,
735 however, are all encompassed within the .text or .data sections of
736 the final output file. We handle this by using different
737 subsegments within these main segments. */
739 /* Next subsegment to allocate within the .text segment. */
740 static subsegT ppc_text_subsegment
= 2;
742 /* Linked list of csects in the text section. */
743 static symbolS
*ppc_text_csects
;
745 /* Next subsegment to allocate within the .data segment. */
746 static subsegT ppc_data_subsegment
= 2;
748 /* Linked list of csects in the data section. */
749 static symbolS
*ppc_data_csects
;
751 /* The current csect. */
752 static symbolS
*ppc_current_csect
;
754 /* The RS/6000 assembler uses a TOC which holds addresses of functions
755 and variables. Symbols are put in the TOC with the .tc pseudo-op.
756 A special relocation is used when accessing TOC entries. We handle
757 the TOC as a subsegment within the .data segment. We set it up if
758 we see a .toc pseudo-op, and save the csect symbol here. */
759 static symbolS
*ppc_toc_csect
;
761 /* The first frag in the TOC subsegment. */
762 static fragS
*ppc_toc_frag
;
764 /* The first frag in the first subsegment after the TOC in the .data
765 segment. NULL if there are no subsegments after the TOC. */
766 static fragS
*ppc_after_toc_frag
;
768 /* The current static block. */
769 static symbolS
*ppc_current_block
;
771 /* The COFF debugging section; set by md_begin. This is not the
772 .debug section, but is instead the secret BFD section which will
773 cause BFD to set the section number of a symbol to N_DEBUG. */
774 static asection
*ppc_coff_debug_section
;
776 #endif /* OBJ_XCOFF */
780 /* Various sections that we need for PE coff support. */
781 static segT ydata_section
;
782 static segT pdata_section
;
783 static segT reldata_section
;
784 static segT rdata_section
;
785 static segT tocdata_section
;
787 /* The current section and the previous section. See ppc_previous. */
788 static segT ppc_previous_section
;
789 static segT ppc_current_section
;
794 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
795 #define PPC_APUINFO_ISEL 0x40
796 #define PPC_APUINFO_PMR 0x41
797 #define PPC_APUINFO_RFMCI 0x42
798 #define PPC_APUINFO_CACHELCK 0x43
799 #define PPC_APUINFO_SPE 0x100
800 #define PPC_APUINFO_EFS 0x101
801 #define PPC_APUINFO_BRLOCK 0x102
804 * We keep a list of APUinfo
806 unsigned long *ppc_apuinfo_list
;
807 unsigned int ppc_apuinfo_num
;
808 unsigned int ppc_apuinfo_num_alloc
;
812 const char *const md_shortopts
= "b:l:usm:K:VQ:";
814 const char *const md_shortopts
= "um:";
816 const struct option md_longopts
[] = {
817 {NULL
, no_argument
, NULL
, 0}
819 const size_t md_longopts_size
= sizeof (md_longopts
);
822 /* Handle -m options that set cpu type, and .machine arg. */
825 parse_cpu (const char *arg
)
827 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
829 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
830 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_32
;
831 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
832 else if (strcmp (arg
, "pwr") == 0)
833 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
834 /* -m601 means to assemble for the PowerPC 601, which includes
835 instructions that are holdovers from the Power. */
836 else if (strcmp (arg
, "601") == 0)
837 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
838 | PPC_OPCODE_601
| PPC_OPCODE_32
);
839 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
841 else if (strcmp (arg
, "ppc") == 0
842 || strcmp (arg
, "ppc32") == 0
843 || strcmp (arg
, "603") == 0
844 || strcmp (arg
, "604") == 0)
845 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
846 /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */
847 else if (strcmp (arg
, "403") == 0
848 || strcmp (arg
, "405") == 0)
849 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
850 | PPC_OPCODE_403
| PPC_OPCODE_32
);
851 else if (strcmp (arg
, "440") == 0)
852 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
853 | PPC_OPCODE_440
| PPC_OPCODE_ISEL
| PPC_OPCODE_RFMCI
);
854 else if (strcmp (arg
, "7400") == 0
855 || strcmp (arg
, "7410") == 0
856 || strcmp (arg
, "7450") == 0
857 || strcmp (arg
, "7455") == 0)
858 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
859 | PPC_OPCODE_ALTIVEC
| PPC_OPCODE_32
);
860 else if (strcmp (arg
, "e300") == 0)
861 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
863 else if (strcmp (arg
, "altivec") == 0)
866 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_ALTIVEC
;
868 ppc_cpu
|= PPC_OPCODE_ALTIVEC
;
870 else if (strcmp (arg
, "e500") == 0 || strcmp (arg
, "e500x2") == 0)
872 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
873 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
874 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
877 else if (strcmp (arg
, "spe") == 0)
880 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_SPE
| PPC_OPCODE_EFS
;
882 ppc_cpu
|= PPC_OPCODE_SPE
;
884 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
886 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
888 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
890 else if (strcmp (arg
, "ppc64bridge") == 0)
892 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
893 | PPC_OPCODE_64_BRIDGE
| PPC_OPCODE_64
);
895 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
896 else if (strcmp (arg
, "booke") == 0 || strcmp (arg
, "booke32") == 0)
898 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
;
900 /* -mbooke64 means enable 64-bit BookE support. */
901 else if (strcmp (arg
, "booke64") == 0)
903 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
904 | PPC_OPCODE_BOOKE64
| PPC_OPCODE_64
);
906 else if (strcmp (arg
, "power4") == 0)
908 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
909 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
);
911 else if (strcmp (arg
, "power5") == 0)
913 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
914 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
915 | PPC_OPCODE_POWER5
);
917 else if (strcmp (arg
, "power6") == 0)
919 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
920 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
921 | PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
);
923 else if (strcmp (arg
, "cell") == 0)
925 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
926 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
929 /* -mcom means assemble for the common intersection between Power
930 and PowerPC. At present, we just allow the union, rather
931 than the intersection. */
932 else if (strcmp (arg
, "com") == 0)
933 ppc_cpu
= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
934 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
935 else if (strcmp (arg
, "any") == 0)
936 ppc_cpu
|= PPC_OPCODE_ANY
;
944 md_parse_option (c
, arg
)
951 /* -u means that any undefined symbols should be treated as
952 external, which is the default for gas anyhow. */
957 /* Solaris as takes -le (presumably for little endian). For completeness
958 sake, recognize -be also. */
959 if (strcmp (arg
, "e") == 0)
961 target_big_endian
= 0;
962 set_target_endian
= 1;
970 if (strcmp (arg
, "e") == 0)
972 target_big_endian
= 1;
973 set_target_endian
= 1;
981 /* Recognize -K PIC. */
982 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
985 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
993 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
995 if (strcmp (arg
, "64") == 0)
1000 as_fatal (_("%s unsupported"), "-a64");
1003 else if (strcmp (arg
, "32") == 0)
1010 if (parse_cpu (arg
))
1013 else if (strcmp (arg
, "regnames") == 0)
1016 else if (strcmp (arg
, "no-regnames") == 0)
1017 reg_names_p
= FALSE
;
1020 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1021 that require relocation. */
1022 else if (strcmp (arg
, "relocatable") == 0)
1024 shlib
= SHLIB_MRELOCATABLE
;
1025 ppc_flags
|= EF_PPC_RELOCATABLE
;
1028 else if (strcmp (arg
, "relocatable-lib") == 0)
1030 shlib
= SHLIB_MRELOCATABLE
;
1031 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
1034 /* -memb, set embedded bit. */
1035 else if (strcmp (arg
, "emb") == 0)
1036 ppc_flags
|= EF_PPC_EMB
;
1038 /* -mlittle/-mbig set the endianess. */
1039 else if (strcmp (arg
, "little") == 0
1040 || strcmp (arg
, "little-endian") == 0)
1042 target_big_endian
= 0;
1043 set_target_endian
= 1;
1046 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
1048 target_big_endian
= 1;
1049 set_target_endian
= 1;
1052 else if (strcmp (arg
, "solaris") == 0)
1055 ppc_comment_chars
= ppc_solaris_comment_chars
;
1058 else if (strcmp (arg
, "no-solaris") == 0)
1061 ppc_comment_chars
= ppc_eabi_comment_chars
;
1066 as_bad (_("invalid switch -m%s"), arg
);
1072 /* -V: SVR4 argument to print version ID. */
1074 print_version_id ();
1077 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1078 should be emitted or not. FIXME: Not implemented. */
1082 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1083 rather than .stabs.excl, which is ignored by the linker.
1084 FIXME: Not implemented. */
1100 md_show_usage (stream
)
1103 fprintf (stream
, _("\
1105 -a32 generate ELF32/XCOFF32\n\
1106 -a64 generate ELF64/XCOFF64\n\
1108 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1109 -mpwr generate code for POWER (RIOS1)\n\
1110 -m601 generate code for PowerPC 601\n\
1111 -mppc, -mppc32, -m603, -m604\n\
1112 generate code for PowerPC 603/604\n\
1113 -m403, -m405 generate code for PowerPC 403/405\n\
1114 -m440 generate code for PowerPC 440\n\
1115 -m7400, -m7410, -m7450, -m7455\n\
1116 generate code For PowerPC 7400/7410/7450/7455\n"));
1117 fprintf (stream
, _("\
1118 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1119 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1120 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1121 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1122 -mpower4 generate code for Power4 architecture\n\
1123 -mpower5 generate code for Power5 architecture\n\
1124 -mpower6 generate code for Power6 architecture\n\
1125 -mcell generate code for Cell Broadband Engine architecture\n\
1126 -mcom generate code Power/PowerPC common instructions\n\
1127 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1128 fprintf (stream
, _("\
1129 -maltivec generate code for AltiVec\n\
1130 -me300 generate code for PowerPC e300 family\n\
1131 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1132 -mspe generate code for Motorola SPE instructions\n\
1133 -mregnames Allow symbolic names for registers\n\
1134 -mno-regnames Do not allow symbolic names for registers\n"));
1136 fprintf (stream
, _("\
1137 -mrelocatable support for GCC's -mrelocatble option\n\
1138 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1139 -memb set PPC_EMB bit in ELF flags\n\
1140 -mlittle, -mlittle-endian, -l, -le\n\
1141 generate code for a little endian machine\n\
1142 -mbig, -mbig-endian, -b, -be\n\
1143 generate code for a big endian machine\n\
1144 -msolaris generate code for Solaris\n\
1145 -mno-solaris do not generate code for Solaris\n\
1146 -V print assembler version number\n\
1147 -Qy, -Qn ignored\n"));
1151 /* Set ppc_cpu if it is not already set. */
1156 const char *default_os
= TARGET_OS
;
1157 const char *default_cpu
= TARGET_CPU
;
1159 if ((ppc_cpu
& ~PPC_OPCODE_ANY
) == 0)
1162 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
1163 else if (strncmp (default_os
, "aix", 3) == 0
1164 && default_os
[3] >= '4' && default_os
[3] <= '9')
1165 ppc_cpu
|= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
1166 else if (strncmp (default_os
, "aix3", 4) == 0)
1167 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1168 else if (strcmp (default_cpu
, "rs6000") == 0)
1169 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1170 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1171 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
1173 as_fatal (_("Unknown default cpu = %s, os = %s"),
1174 default_cpu
, default_os
);
1178 /* Figure out the BFD architecture to use. This function and ppc_mach
1179 are called well before md_begin, when the output file is opened. */
1181 enum bfd_architecture
1184 const char *default_cpu
= TARGET_CPU
;
1187 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1188 return bfd_arch_powerpc
;
1189 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1190 return bfd_arch_rs6000
;
1191 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1193 if (strcmp (default_cpu
, "rs6000") == 0)
1194 return bfd_arch_rs6000
;
1195 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1196 return bfd_arch_powerpc
;
1199 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1200 return bfd_arch_unknown
;
1207 return bfd_mach_ppc64
;
1208 else if (ppc_arch () == bfd_arch_rs6000
)
1209 return bfd_mach_rs6k
;
1211 return bfd_mach_ppc
;
1215 ppc_target_format ()
1219 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1221 return "xcoff-powermac";
1224 return (ppc_obj64
? "aix5coff64-rs6000" : "aixcoff-rs6000");
1226 return (ppc_obj64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1232 return "elf32-powerpc-vxworks";
1234 return (target_big_endian
1235 ? (ppc_obj64
? "elf64-powerpc" : "elf32-powerpc")
1236 : (ppc_obj64
? "elf64-powerpcle" : "elf32-powerpcle"));
1241 /* Insert opcodes and macros into hash tables. Called at startup and
1245 ppc_setup_opcodes (void)
1247 register const struct powerpc_opcode
*op
;
1248 const struct powerpc_opcode
*op_end
;
1249 const struct powerpc_macro
*macro
;
1250 const struct powerpc_macro
*macro_end
;
1251 bfd_boolean dup_insn
= FALSE
;
1253 if (ppc_hash
!= NULL
)
1254 hash_die (ppc_hash
);
1255 if (ppc_macro_hash
!= NULL
)
1256 hash_die (ppc_macro_hash
);
1258 /* Insert the opcodes into a hash table. */
1259 ppc_hash
= hash_new ();
1261 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1262 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1264 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1266 if ((op
->flags
& ppc_cpu
& ~(PPC_OPCODE_32
| PPC_OPCODE_64
)) != 0
1267 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1268 || ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
))
1269 == (ppc_cpu
& (PPC_OPCODE_32
| PPC_OPCODE_64
)))
1270 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0)
1271 /* Certain instructions (eg: extsw) do not exist in the
1272 32-bit BookE instruction set, but they do exist in the
1273 64-bit BookE instruction set, and other PPC instruction
1274 sets. Check to see if the opcode has the BOOKE64 flag set.
1275 If it does make sure that the target CPU is not the BookE32. */
1276 && ((op
->flags
& PPC_OPCODE_BOOKE64
) == 0
1277 || (ppc_cpu
& PPC_OPCODE_BOOKE64
) == PPC_OPCODE_BOOKE64
1278 || (ppc_cpu
& PPC_OPCODE_BOOKE
) == 0)
1279 && ((op
->flags
& (PPC_OPCODE_POWER4
| PPC_OPCODE_NOPOWER4
)) == 0
1280 || ((op
->flags
& PPC_OPCODE_POWER4
)
1281 == (ppc_cpu
& PPC_OPCODE_POWER4
)))
1282 && ((op
->flags
& PPC_OPCODE_POWER5
) == 0
1283 || ((op
->flags
& PPC_OPCODE_POWER5
)
1284 == (ppc_cpu
& PPC_OPCODE_POWER5
)))
1285 && ((op
->flags
& PPC_OPCODE_POWER6
) == 0
1286 || ((op
->flags
& PPC_OPCODE_POWER6
)
1287 == (ppc_cpu
& PPC_OPCODE_POWER6
))))
1291 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1294 /* Ignore Power duplicates for -m601. */
1295 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1296 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1299 as_bad (_("Internal assembler error for instruction %s"),
1306 if ((ppc_cpu
& PPC_OPCODE_ANY
) != 0)
1307 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1308 hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1310 /* Insert the macros into a hash table. */
1311 ppc_macro_hash
= hash_new ();
1313 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1314 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1316 if ((macro
->flags
& ppc_cpu
) != 0)
1320 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1321 if (retval
!= (const char *) NULL
)
1323 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1333 /* This function is called when the assembler starts up. It is called
1334 after the options have been parsed and the output file has been
1342 ppc_cie_data_alignment
= ppc_obj64
? -8 : -4;
1345 /* Set the ELF flags if desired. */
1346 if (ppc_flags
&& !msolaris
)
1347 bfd_set_private_flags (stdoutput
, ppc_flags
);
1350 ppc_setup_opcodes ();
1352 /* Tell the main code what the endianness is if it is not overridden
1354 if (!set_target_endian
)
1356 set_target_endian
= 1;
1357 target_big_endian
= PPC_BIG_ENDIAN
;
1361 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1363 /* Create dummy symbols to serve as initial csects. This forces the
1364 text csects to precede the data csects. These symbols will not
1366 ppc_text_csects
= symbol_make ("dummy\001");
1367 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1368 ppc_data_csects
= symbol_make ("dummy\001");
1369 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1374 ppc_current_section
= text_section
;
1375 ppc_previous_section
= 0;
1384 if (ppc_apuinfo_list
== NULL
)
1387 /* Ok, so write the section info out. We have this layout:
1391 0 8 length of "APUinfo\0"
1392 4 (n*4) number of APU's (4 bytes each)
1395 20 APU#1 first APU's info
1396 24 APU#2 second APU's info
1401 asection
*seg
= now_seg
;
1402 subsegT subseg
= now_subseg
;
1403 asection
*apuinfo_secp
= (asection
*) NULL
;
1406 /* Create the .PPC.EMB.apuinfo section. */
1407 apuinfo_secp
= subseg_new (".PPC.EMB.apuinfo", 0);
1408 bfd_set_section_flags (stdoutput
,
1410 SEC_HAS_CONTENTS
| SEC_READONLY
);
1413 md_number_to_chars (p
, (valueT
) 8, 4);
1416 md_number_to_chars (p
, (valueT
) ppc_apuinfo_num
* 4, 4);
1419 md_number_to_chars (p
, (valueT
) 2, 4);
1422 strcpy (p
, "APUinfo");
1424 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
1427 md_number_to_chars (p
, (valueT
) ppc_apuinfo_list
[i
], 4);
1430 frag_align (2, 0, 0);
1432 /* We probably can't restore the current segment, for there likely
1435 subseg_set (seg
, subseg
);
1440 /* Insert an operand value into an instruction. */
1442 static unsigned long
1443 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1445 const struct powerpc_operand
*operand
;
1450 if (operand
->bits
!= 32)
1455 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1457 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1458 max
= (1 << operand
->bits
) - 1;
1460 max
= (1 << (operand
->bits
- 1)) - 1;
1461 min
= - (1 << (operand
->bits
- 1));
1465 /* Some people write 32 bit hex constants with the sign
1466 extension done by hand. This shouldn't really be
1467 valid, but, to permit this code to assemble on a 64
1468 bit host, we sign extend the 32 bit value. */
1470 && (val
& (offsetT
) 0x80000000) != 0
1471 && (val
& (offsetT
) 0xffffffff) == val
)
1480 max
= (1 << operand
->bits
) - 1;
1484 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1489 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1490 as_bad_value_out_of_range (_("operand"), test
, (offsetT
) min
, (offsetT
) max
, file
, line
);
1493 if (operand
->insert
)
1498 insn
= (*operand
->insert
) (insn
, (long) val
, ppc_cpu
, &errmsg
);
1499 if (errmsg
!= (const char *) NULL
)
1500 as_bad_where (file
, line
, errmsg
);
1503 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1511 /* Parse @got, etc. and return the desired relocation. */
1512 static bfd_reloc_code_real_type
1513 ppc_elf_suffix (str_p
, exp_p
)
1519 unsigned int length
: 8;
1520 unsigned int valid32
: 1;
1521 unsigned int valid64
: 1;
1530 const struct map_bfd
*ptr
;
1532 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
1533 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
1534 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
1536 static const struct map_bfd mapping
[] = {
1537 MAP ("l", BFD_RELOC_LO16
),
1538 MAP ("h", BFD_RELOC_HI16
),
1539 MAP ("ha", BFD_RELOC_HI16_S
),
1540 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1541 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1542 MAP ("got", BFD_RELOC_16_GOTOFF
),
1543 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1544 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1545 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1546 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1547 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1548 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1549 MAP ("copy", BFD_RELOC_PPC_COPY
),
1550 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1551 MAP ("sectoff", BFD_RELOC_16_BASEREL
),
1552 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1553 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1554 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1555 MAP ("tls", BFD_RELOC_PPC_TLS
),
1556 MAP ("dtpmod", BFD_RELOC_PPC_DTPMOD
),
1557 MAP ("dtprel", BFD_RELOC_PPC_DTPREL
),
1558 MAP ("dtprel@l", BFD_RELOC_PPC_DTPREL16_LO
),
1559 MAP ("dtprel@h", BFD_RELOC_PPC_DTPREL16_HI
),
1560 MAP ("dtprel@ha", BFD_RELOC_PPC_DTPREL16_HA
),
1561 MAP ("tprel", BFD_RELOC_PPC_TPREL
),
1562 MAP ("tprel@l", BFD_RELOC_PPC_TPREL16_LO
),
1563 MAP ("tprel@h", BFD_RELOC_PPC_TPREL16_HI
),
1564 MAP ("tprel@ha", BFD_RELOC_PPC_TPREL16_HA
),
1565 MAP ("got@tlsgd", BFD_RELOC_PPC_GOT_TLSGD16
),
1566 MAP ("got@tlsgd@l", BFD_RELOC_PPC_GOT_TLSGD16_LO
),
1567 MAP ("got@tlsgd@h", BFD_RELOC_PPC_GOT_TLSGD16_HI
),
1568 MAP ("got@tlsgd@ha", BFD_RELOC_PPC_GOT_TLSGD16_HA
),
1569 MAP ("got@tlsld", BFD_RELOC_PPC_GOT_TLSLD16
),
1570 MAP ("got@tlsld@l", BFD_RELOC_PPC_GOT_TLSLD16_LO
),
1571 MAP ("got@tlsld@h", BFD_RELOC_PPC_GOT_TLSLD16_HI
),
1572 MAP ("got@tlsld@ha", BFD_RELOC_PPC_GOT_TLSLD16_HA
),
1573 MAP ("got@dtprel", BFD_RELOC_PPC_GOT_DTPREL16
),
1574 MAP ("got@dtprel@l", BFD_RELOC_PPC_GOT_DTPREL16_LO
),
1575 MAP ("got@dtprel@h", BFD_RELOC_PPC_GOT_DTPREL16_HI
),
1576 MAP ("got@dtprel@ha", BFD_RELOC_PPC_GOT_DTPREL16_HA
),
1577 MAP ("got@tprel", BFD_RELOC_PPC_GOT_TPREL16
),
1578 MAP ("got@tprel@l", BFD_RELOC_PPC_GOT_TPREL16_LO
),
1579 MAP ("got@tprel@h", BFD_RELOC_PPC_GOT_TPREL16_HI
),
1580 MAP ("got@tprel@ha", BFD_RELOC_PPC_GOT_TPREL16_HA
),
1581 MAP32 ("fixup", BFD_RELOC_CTOR
),
1582 MAP32 ("plt", BFD_RELOC_24_PLT_PCREL
),
1583 MAP32 ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1584 MAP32 ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1585 MAP32 ("local", BFD_RELOC_PPC_LOCAL24PC
),
1586 MAP32 ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1587 MAP32 ("sdarel", BFD_RELOC_GPREL16
),
1588 MAP32 ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1589 MAP32 ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1590 MAP32 ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1591 MAP32 ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1592 MAP32 ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1593 MAP32 ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1594 MAP32 ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1595 MAP32 ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1596 MAP32 ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1597 MAP32 ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1598 MAP32 ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1599 MAP32 ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1600 MAP32 ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1601 MAP32 ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1602 MAP32 ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1603 MAP32 ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1604 MAP32 ("xgot", BFD_RELOC_PPC_TOC16
),
1605 MAP64 ("higher", BFD_RELOC_PPC64_HIGHER
),
1606 MAP64 ("highera", BFD_RELOC_PPC64_HIGHER_S
),
1607 MAP64 ("highest", BFD_RELOC_PPC64_HIGHEST
),
1608 MAP64 ("highesta", BFD_RELOC_PPC64_HIGHEST_S
),
1609 MAP64 ("tocbase", BFD_RELOC_PPC64_TOC
),
1610 MAP64 ("toc", BFD_RELOC_PPC_TOC16
),
1611 MAP64 ("toc@l", BFD_RELOC_PPC64_TOC16_LO
),
1612 MAP64 ("toc@h", BFD_RELOC_PPC64_TOC16_HI
),
1613 MAP64 ("toc@ha", BFD_RELOC_PPC64_TOC16_HA
),
1614 MAP64 ("dtprel@higher", BFD_RELOC_PPC64_DTPREL16_HIGHER
),
1615 MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA
),
1616 MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST
),
1617 MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA
),
1618 MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER
),
1619 MAP64 ("tprel@highera", BFD_RELOC_PPC64_TPREL16_HIGHERA
),
1620 MAP64 ("tprel@highest", BFD_RELOC_PPC64_TPREL16_HIGHEST
),
1621 MAP64 ("tprel@highesta", BFD_RELOC_PPC64_TPREL16_HIGHESTA
),
1622 { (char *) 0, 0, 0, 0, BFD_RELOC_UNUSED
}
1626 return BFD_RELOC_UNUSED
;
1628 for (ch
= *str
, str2
= ident
;
1629 (str2
< ident
+ sizeof (ident
) - 1
1630 && (ISALNUM (ch
) || ch
== '@'));
1633 *str2
++ = TOLOWER (ch
);
1640 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1641 if (ch
== ptr
->string
[0]
1642 && len
== ptr
->length
1643 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0
1644 && (ppc_obj64
? ptr
->valid64
: ptr
->valid32
))
1646 int reloc
= ptr
->reloc
;
1649 if (exp_p
->X_add_number
!= 0
1650 && (reloc
== (int) BFD_RELOC_16_GOTOFF
1651 || reloc
== (int) BFD_RELOC_LO16_GOTOFF
1652 || reloc
== (int) BFD_RELOC_HI16_GOTOFF
1653 || reloc
== (int) BFD_RELOC_HI16_S_GOTOFF
))
1654 as_warn (_("identifier+constant@got means identifier@got+constant"));
1656 /* Now check for identifier@suffix+constant. */
1657 if (*str
== '-' || *str
== '+')
1659 char *orig_line
= input_line_pointer
;
1660 expressionS new_exp
;
1662 input_line_pointer
= str
;
1663 expression (&new_exp
);
1664 if (new_exp
.X_op
== O_constant
)
1666 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1667 str
= input_line_pointer
;
1670 if (&input_line_pointer
!= str_p
)
1671 input_line_pointer
= orig_line
;
1675 if (reloc
== (int) BFD_RELOC_PPC64_TOC
1676 && exp_p
->X_op
== O_symbol
1677 && strcmp (S_GET_NAME (exp_p
->X_add_symbol
), ".TOC.") == 0)
1679 /* Change the symbol so that the dummy .TOC. symbol can be
1680 omitted from the object file. */
1681 exp_p
->X_add_symbol
= &abs_symbol
;
1684 return (bfd_reloc_code_real_type
) reloc
;
1687 return BFD_RELOC_UNUSED
;
1690 /* Like normal .long/.short/.word, except support @got, etc.
1691 Clobbers input_line_pointer, checks end-of-line. */
1693 ppc_elf_cons (nbytes
)
1694 register int nbytes
; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1697 bfd_reloc_code_real_type reloc
;
1699 if (is_it_end_of_statement ())
1701 demand_empty_rest_of_line ();
1708 if (exp
.X_op
== O_symbol
1709 && *input_line_pointer
== '@'
1710 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1711 &exp
)) != BFD_RELOC_UNUSED
)
1713 reloc_howto_type
*reloc_howto
;
1716 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1717 size
= bfd_get_reloc_size (reloc_howto
);
1721 as_bad (_("%s relocations do not fit in %d bytes\n"),
1722 reloc_howto
->name
, nbytes
);
1729 p
= frag_more (nbytes
);
1731 if (target_big_endian
)
1732 offset
= nbytes
- size
;
1733 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1738 emit_expr (&exp
, (unsigned int) nbytes
);
1740 while (*input_line_pointer
++ == ',');
1742 /* Put terminator back into stream. */
1743 input_line_pointer
--;
1744 demand_empty_rest_of_line ();
1747 /* Solaris pseduo op to change to the .rodata section. */
1752 char *save_line
= input_line_pointer
;
1753 static char section
[] = ".rodata\n";
1755 /* Just pretend this is .section .rodata */
1756 input_line_pointer
= section
;
1757 obj_elf_section (xxx
);
1759 input_line_pointer
= save_line
;
1762 /* Pseudo op to make file scope bss items. */
1765 int xxx ATTRIBUTE_UNUSED
;
1767 register char *name
;
1771 register symbolS
*symbolP
;
1778 name
= input_line_pointer
;
1779 c
= get_symbol_end ();
1781 /* just after name is now '\0'. */
1782 p
= input_line_pointer
;
1785 if (*input_line_pointer
!= ',')
1787 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1788 ignore_rest_of_line ();
1792 input_line_pointer
++; /* skip ',' */
1793 if ((size
= get_absolute_expression ()) < 0)
1795 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1796 ignore_rest_of_line ();
1800 /* The third argument to .lcomm is the alignment. */
1801 if (*input_line_pointer
!= ',')
1805 ++input_line_pointer
;
1806 align
= get_absolute_expression ();
1809 as_warn (_("ignoring bad alignment"));
1815 symbolP
= symbol_find_or_make (name
);
1818 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1820 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1821 S_GET_NAME (symbolP
));
1822 ignore_rest_of_line ();
1826 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1828 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1829 S_GET_NAME (symbolP
),
1830 (long) S_GET_VALUE (symbolP
),
1833 ignore_rest_of_line ();
1839 old_subsec
= now_subseg
;
1842 /* Convert to a power of 2 alignment. */
1843 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1846 as_bad (_("Common alignment not a power of 2"));
1847 ignore_rest_of_line ();
1854 record_alignment (bss_section
, align2
);
1855 subseg_set (bss_section
, 0);
1857 frag_align (align2
, 0, 0);
1858 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1859 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1860 symbol_set_frag (symbolP
, frag_now
);
1861 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1864 S_SET_SIZE (symbolP
, size
);
1865 S_SET_SEGMENT (symbolP
, bss_section
);
1866 subseg_set (old_sec
, old_subsec
);
1867 demand_empty_rest_of_line ();
1870 /* Validate any relocations emitted for -mrelocatable, possibly adding
1871 fixups for word relocations in writable segments, so we can adjust
1874 ppc_elf_validate_fix (fixp
, seg
)
1878 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1887 case SHLIB_MRELOCATABLE
:
1888 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1889 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1890 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1891 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1892 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1893 && fixp
->fx_r_type
!= BFD_RELOC_16_BASEREL
1894 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1895 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1896 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1897 && (seg
->flags
& SEC_LOAD
) != 0
1898 && strcmp (segment_name (seg
), ".got2") != 0
1899 && strcmp (segment_name (seg
), ".dtors") != 0
1900 && strcmp (segment_name (seg
), ".ctors") != 0
1901 && strcmp (segment_name (seg
), ".fixup") != 0
1902 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1903 && strcmp (segment_name (seg
), ".eh_frame") != 0
1904 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1906 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1907 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1909 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1910 _("Relocation cannot be done when using -mrelocatable"));
1917 /* Prevent elf_frob_file_before_adjust removing a weak undefined
1918 function descriptor sym if the corresponding code sym is used. */
1921 ppc_frob_file_before_adjust ()
1929 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1936 name
= S_GET_NAME (symp
);
1940 if (! S_IS_WEAK (symp
)
1941 || S_IS_DEFINED (symp
))
1944 len
= strlen (name
) + 1;
1945 dotname
= xmalloc (len
+ 1);
1947 memcpy (dotname
+ 1, name
, len
);
1948 dotsym
= symbol_find_noref (dotname
, 1);
1950 if (dotsym
!= NULL
&& (symbol_used_p (dotsym
)
1951 || symbol_used_in_reloc_p (dotsym
)))
1952 symbol_mark_used (symp
);
1956 toc
= bfd_get_section_by_name (stdoutput
, ".toc");
1958 && bfd_section_size (stdoutput
, toc
) > 0x10000)
1959 as_warn (_("TOC section size exceeds 64k"));
1961 /* Don't emit .TOC. symbol. */
1962 symp
= symbol_find (".TOC.");
1964 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1966 #endif /* OBJ_ELF */
1971 * Summary of parse_toc_entry.
1973 * in: Input_line_pointer points to the '[' in one of:
1975 * [toc] [tocv] [toc32] [toc64]
1977 * Anything else is an error of one kind or another.
1980 * return value: success or failure
1981 * toc_kind: kind of toc reference
1982 * input_line_pointer:
1983 * success: first char after the ']'
1984 * failure: unchanged
1988 * [toc] - rv == success, toc_kind = default_toc
1989 * [tocv] - rv == success, toc_kind = data_in_toc
1990 * [toc32] - rv == success, toc_kind = must_be_32
1991 * [toc64] - rv == success, toc_kind = must_be_64
1995 enum toc_size_qualifier
1997 default_toc
, /* The toc cell constructed should be the system default size */
1998 data_in_toc
, /* This is a direct reference to a toc cell */
1999 must_be_32
, /* The toc cell constructed must be 32 bits wide */
2000 must_be_64
/* The toc cell constructed must be 64 bits wide */
2004 parse_toc_entry (toc_kind
)
2005 enum toc_size_qualifier
*toc_kind
;
2010 enum toc_size_qualifier t
;
2012 /* Save the input_line_pointer. */
2013 start
= input_line_pointer
;
2015 /* Skip over the '[' , and whitespace. */
2016 ++input_line_pointer
;
2019 /* Find the spelling of the operand. */
2020 toc_spec
= input_line_pointer
;
2021 c
= get_symbol_end ();
2023 if (strcmp (toc_spec
, "toc") == 0)
2027 else if (strcmp (toc_spec
, "tocv") == 0)
2031 else if (strcmp (toc_spec
, "toc32") == 0)
2035 else if (strcmp (toc_spec
, "toc64") == 0)
2041 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
2042 *input_line_pointer
= c
;
2043 input_line_pointer
= start
;
2047 /* Now find the ']'. */
2048 *input_line_pointer
= c
;
2050 SKIP_WHITESPACE (); /* leading whitespace could be there. */
2051 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
2055 as_bad (_("syntax error: expected `]', found `%c'"), c
);
2056 input_line_pointer
= start
;
2067 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2069 ppc_apuinfo_section_add (apu
, version
)
2070 unsigned int apu
, version
;
2074 /* Check we don't already exist. */
2075 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
2076 if (ppc_apuinfo_list
[i
] == APUID (apu
, version
))
2079 if (ppc_apuinfo_num
== ppc_apuinfo_num_alloc
)
2081 if (ppc_apuinfo_num_alloc
== 0)
2083 ppc_apuinfo_num_alloc
= 4;
2084 ppc_apuinfo_list
= (unsigned long *)
2085 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2089 ppc_apuinfo_num_alloc
+= 4;
2090 ppc_apuinfo_list
= (unsigned long *) xrealloc (ppc_apuinfo_list
,
2091 sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2094 ppc_apuinfo_list
[ppc_apuinfo_num
++] = APUID (apu
, version
);
2100 /* We need to keep a list of fixups. We can't simply generate them as
2101 we go, because that would require us to first create the frag, and
2102 that would screw up references to ``.''. */
2108 bfd_reloc_code_real_type reloc
;
2111 #define MAX_INSN_FIXUPS (5)
2113 /* This routine is called for each instruction to be assembled. */
2120 const struct powerpc_opcode
*opcode
;
2122 const unsigned char *opindex_ptr
;
2126 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
2132 bfd_reloc_code_real_type reloc
;
2135 /* Get the opcode. */
2136 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
2141 /* Look up the opcode in the hash table. */
2142 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
2143 if (opcode
== (const struct powerpc_opcode
*) NULL
)
2145 const struct powerpc_macro
*macro
;
2147 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
2148 if (macro
== (const struct powerpc_macro
*) NULL
)
2149 as_bad (_("Unrecognized opcode: `%s'"), str
);
2151 ppc_macro (s
, macro
);
2156 insn
= opcode
->opcode
;
2159 while (ISSPACE (*str
))
2162 /* PowerPC operands are just expressions. The only real issue is
2163 that a few operand types are optional. All cases which might use
2164 an optional operand separate the operands only with commas (in some
2165 cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2166 have optional operands). Most instructions with optional operands
2167 have only one. Those that have more than one optional operand can
2168 take either all their operands or none. So, before we start seriously
2169 parsing the operands, we check to see if we have optional operands,
2170 and if we do, we count the number of commas to see which operands
2171 have been omitted. */
2173 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2175 const struct powerpc_operand
*operand
;
2177 operand
= &powerpc_operands
[*opindex_ptr
];
2178 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
2180 unsigned int opcount
;
2181 unsigned int num_operands_expected
;
2184 /* There is an optional operand. Count the number of
2185 commas in the input line. */
2192 while ((s
= strchr (s
, ',')) != (char *) NULL
)
2199 /* Compute the number of expected operands.
2200 Do not count fake operands. */
2201 for (num_operands_expected
= 0, i
= 0; opcode
->operands
[i
]; i
++)
2202 if ((powerpc_operands
[opcode
->operands
[i
]].flags
& PPC_OPERAND_FAKE
) == 0)
2203 ++ num_operands_expected
;
2205 /* If there are fewer operands in the line then are called
2206 for by the instruction, we want to skip the optional
2208 if (opcount
< num_operands_expected
)
2215 /* Gather the operands. */
2219 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2221 const struct powerpc_operand
*operand
;
2227 if (next_opindex
== 0)
2228 operand
= &powerpc_operands
[*opindex_ptr
];
2231 operand
= &powerpc_operands
[next_opindex
];
2236 /* If this is a fake operand, then we do not expect anything
2238 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
2240 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2241 if (errmsg
!= (const char *) NULL
)
2246 /* If this is an optional operand, and we are skipping it, just
2248 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
2251 if (operand
->insert
)
2253 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2254 if (errmsg
!= (const char *) NULL
)
2257 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
2258 next_opindex
= *opindex_ptr
+ 1;
2262 /* Gather the operand. */
2263 hold
= input_line_pointer
;
2264 input_line_pointer
= str
;
2267 if (*input_line_pointer
== '[')
2269 /* We are expecting something like the second argument here:
2271 * lwz r4,[toc].GS.0.static_int(rtoc)
2272 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2273 * The argument following the `]' must be a symbol name, and the
2274 * register must be the toc register: 'rtoc' or '2'
2276 * The effect is to 0 as the displacement field
2277 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2278 * the appropriate variation) reloc against it based on the symbol.
2279 * The linker will build the toc, and insert the resolved toc offset.
2282 * o The size of the toc entry is currently assumed to be
2283 * 32 bits. This should not be assumed to be a hard coded
2285 * o In an effort to cope with a change from 32 to 64 bits,
2286 * there are also toc entries that are specified to be
2287 * either 32 or 64 bits:
2288 * lwz r4,[toc32].GS.0.static_int(rtoc)
2289 * lwz r4,[toc64].GS.0.static_int(rtoc)
2290 * These demand toc entries of the specified size, and the
2291 * instruction probably requires it.
2295 enum toc_size_qualifier toc_kind
;
2296 bfd_reloc_code_real_type toc_reloc
;
2298 /* Go parse off the [tocXX] part. */
2299 valid_toc
= parse_toc_entry (&toc_kind
);
2303 /* Note: message has already been issued.
2304 FIXME: what sort of recovery should we do?
2305 demand_rest_of_line (); return; ? */
2308 /* Now get the symbol following the ']'. */
2314 /* In this case, we may not have seen the symbol yet,
2315 since it is allowed to appear on a .extern or .globl
2316 or just be a label in the .data section. */
2317 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2320 /* 1. The symbol must be defined and either in the toc
2321 section, or a global.
2322 2. The reloc generated must have the TOCDEFN flag set
2323 in upper bit mess of the reloc type.
2324 FIXME: It's a little confusing what the tocv
2325 qualifier can be used for. At the very least, I've
2326 seen three uses, only one of which I'm sure I can
2328 if (ex
.X_op
== O_symbol
)
2330 assert (ex
.X_add_symbol
!= NULL
);
2331 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2334 as_bad (_("[tocv] symbol is not a toc symbol"));
2338 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2341 /* FIXME: these next two specifically specify 32/64 bit
2342 toc entries. We don't support them today. Is this
2343 the right way to say that? */
2344 toc_reloc
= BFD_RELOC_UNUSED
;
2345 as_bad (_("Unimplemented toc32 expression modifier"));
2348 /* FIXME: see above. */
2349 toc_reloc
= BFD_RELOC_UNUSED
;
2350 as_bad (_("Unimplemented toc64 expression modifier"));
2354 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2360 /* We need to generate a fixup for this expression. */
2361 if (fc
>= MAX_INSN_FIXUPS
)
2362 as_fatal (_("too many fixups"));
2364 fixups
[fc
].reloc
= toc_reloc
;
2365 fixups
[fc
].exp
= ex
;
2366 fixups
[fc
].opindex
= *opindex_ptr
;
2369 /* Ok. We've set up the fixup for the instruction. Now make it
2370 look like the constant 0 was found here. */
2372 ex
.X_op
= O_constant
;
2373 ex
.X_add_number
= 0;
2374 ex
.X_add_symbol
= NULL
;
2375 ex
.X_op_symbol
= NULL
;
2381 if (! register_name (&ex
))
2383 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
2390 str
= input_line_pointer
;
2391 input_line_pointer
= hold
;
2393 if (ex
.X_op
== O_illegal
)
2394 as_bad (_("illegal operand"));
2395 else if (ex
.X_op
== O_absent
)
2396 as_bad (_("missing operand"));
2397 else if (ex
.X_op
== O_register
)
2399 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2402 else if (ex
.X_op
== O_constant
)
2405 /* Allow @HA, @L, @H on constants. */
2406 char *orig_str
= str
;
2408 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2415 case BFD_RELOC_LO16
:
2416 /* X_unsigned is the default, so if the user has done
2417 something which cleared it, we always produce a
2419 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2420 ex
.X_add_number
&= 0xffff;
2422 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2425 case BFD_RELOC_HI16
:
2426 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2427 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2429 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2432 case BFD_RELOC_HI16_S
:
2433 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2434 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2436 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2439 case BFD_RELOC_PPC64_HIGHER
:
2440 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2441 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2443 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2446 case BFD_RELOC_PPC64_HIGHER_S
:
2447 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2448 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2450 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2453 case BFD_RELOC_PPC64_HIGHEST
:
2454 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2455 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2457 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2460 case BFD_RELOC_PPC64_HIGHEST_S
:
2461 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2462 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2464 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2467 #endif /* OBJ_ELF */
2468 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2472 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2474 /* Some TLS tweaks. */
2479 case BFD_RELOC_PPC_TLS
:
2480 insn
= ppc_insert_operand (insn
, operand
, ppc_obj64
? 13 : 2,
2483 /* We'll only use the 32 (or 64) bit form of these relocations
2484 in constants. Instructions get the 16 bit form. */
2485 case BFD_RELOC_PPC_DTPREL
:
2486 reloc
= BFD_RELOC_PPC_DTPREL16
;
2488 case BFD_RELOC_PPC_TPREL
:
2489 reloc
= BFD_RELOC_PPC_TPREL16
;
2493 /* For the absolute forms of branches, convert the PC
2494 relative form back into the absolute. */
2495 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2499 case BFD_RELOC_PPC_B26
:
2500 reloc
= BFD_RELOC_PPC_BA26
;
2502 case BFD_RELOC_PPC_B16
:
2503 reloc
= BFD_RELOC_PPC_BA16
;
2505 case BFD_RELOC_PPC_B16_BRTAKEN
:
2506 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2508 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2509 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2517 && (operand
->flags
& (PPC_OPERAND_DS
| PPC_OPERAND_DQ
)) != 0)
2522 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
2524 case BFD_RELOC_LO16
:
2525 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
2527 case BFD_RELOC_16_GOTOFF
:
2528 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
2530 case BFD_RELOC_LO16_GOTOFF
:
2531 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
2533 case BFD_RELOC_LO16_PLTOFF
:
2534 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
2536 case BFD_RELOC_16_BASEREL
:
2537 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
2539 case BFD_RELOC_LO16_BASEREL
:
2540 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
2542 case BFD_RELOC_PPC_TOC16
:
2543 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
2545 case BFD_RELOC_PPC64_TOC16_LO
:
2546 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
2548 case BFD_RELOC_PPC64_PLTGOT16
:
2549 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
2551 case BFD_RELOC_PPC64_PLTGOT16_LO
:
2552 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
2554 case BFD_RELOC_PPC_DTPREL16
:
2555 reloc
= BFD_RELOC_PPC64_DTPREL16_DS
;
2557 case BFD_RELOC_PPC_DTPREL16_LO
:
2558 reloc
= BFD_RELOC_PPC64_DTPREL16_LO_DS
;
2560 case BFD_RELOC_PPC_TPREL16
:
2561 reloc
= BFD_RELOC_PPC64_TPREL16_DS
;
2563 case BFD_RELOC_PPC_TPREL16_LO
:
2564 reloc
= BFD_RELOC_PPC64_TPREL16_LO_DS
;
2566 case BFD_RELOC_PPC_GOT_DTPREL16
:
2567 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
2568 case BFD_RELOC_PPC_GOT_TPREL16
:
2569 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
2572 as_bad (_("unsupported relocation for DS offset field"));
2577 /* We need to generate a fixup for this expression. */
2578 if (fc
>= MAX_INSN_FIXUPS
)
2579 as_fatal (_("too many fixups"));
2580 fixups
[fc
].exp
= ex
;
2581 fixups
[fc
].opindex
= 0;
2582 fixups
[fc
].reloc
= reloc
;
2585 #endif /* OBJ_ELF */
2589 /* We need to generate a fixup for this expression. */
2590 if (fc
>= MAX_INSN_FIXUPS
)
2591 as_fatal (_("too many fixups"));
2592 fixups
[fc
].exp
= ex
;
2593 fixups
[fc
].opindex
= *opindex_ptr
;
2594 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2603 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2611 /* The call to expression should have advanced str past any
2614 && (endc
!= ',' || *str
!= '\0'))
2616 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2624 while (ISSPACE (*str
))
2628 as_bad (_("junk at end of line: `%s'"), str
);
2631 /* Do we need/want a APUinfo section? */
2632 if (ppc_cpu
& (PPC_OPCODE_SPE
2633 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
2634 | PPC_OPCODE_BRLOCK
| PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
2635 | PPC_OPCODE_RFMCI
))
2637 /* These are all version "1". */
2638 if (opcode
->flags
& PPC_OPCODE_SPE
)
2639 ppc_apuinfo_section_add (PPC_APUINFO_SPE
, 1);
2640 if (opcode
->flags
& PPC_OPCODE_ISEL
)
2641 ppc_apuinfo_section_add (PPC_APUINFO_ISEL
, 1);
2642 if (opcode
->flags
& PPC_OPCODE_EFS
)
2643 ppc_apuinfo_section_add (PPC_APUINFO_EFS
, 1);
2644 if (opcode
->flags
& PPC_OPCODE_BRLOCK
)
2645 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK
, 1);
2646 if (opcode
->flags
& PPC_OPCODE_PMR
)
2647 ppc_apuinfo_section_add (PPC_APUINFO_PMR
, 1);
2648 if (opcode
->flags
& PPC_OPCODE_CACHELCK
)
2649 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK
, 1);
2650 if (opcode
->flags
& PPC_OPCODE_RFMCI
)
2651 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI
, 1);
2655 /* Write out the instruction. */
2657 addr_mod
= frag_now_fix () & 3;
2658 if (frag_now
->has_code
&& frag_now
->insn_addr
!= addr_mod
)
2659 as_bad (_("instruction address is not a multiple of 4"));
2660 frag_now
->insn_addr
= addr_mod
;
2661 frag_now
->has_code
= 1;
2662 md_number_to_chars (f
, insn
, 4);
2665 dwarf2_emit_insn (4);
2668 /* Create any fixups. At this point we do not use a
2669 bfd_reloc_code_real_type, but instead just use the
2670 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2671 handle fixups for any operand type, although that is admittedly
2672 not a very exciting feature. We pick a BFD reloc type in
2674 for (i
= 0; i
< fc
; i
++)
2676 const struct powerpc_operand
*operand
;
2678 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2679 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2681 reloc_howto_type
*reloc_howto
;
2686 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2690 size
= bfd_get_reloc_size (reloc_howto
);
2691 offset
= target_big_endian
? (4 - size
) : 0;
2693 if (size
< 1 || size
> 4)
2696 fixP
= fix_new_exp (frag_now
,
2697 f
- frag_now
->fr_literal
+ offset
,
2700 reloc_howto
->pc_relative
,
2703 /* Turn off complaints that the addend is too large for things like
2705 switch (fixups
[i
].reloc
)
2707 case BFD_RELOC_16_GOTOFF
:
2708 case BFD_RELOC_PPC_TOC16
:
2709 case BFD_RELOC_LO16
:
2710 case BFD_RELOC_HI16
:
2711 case BFD_RELOC_HI16_S
:
2713 case BFD_RELOC_PPC64_HIGHER
:
2714 case BFD_RELOC_PPC64_HIGHER_S
:
2715 case BFD_RELOC_PPC64_HIGHEST
:
2716 case BFD_RELOC_PPC64_HIGHEST_S
:
2718 fixP
->fx_no_overflow
= 1;
2725 fix_new_exp (frag_now
,
2726 f
- frag_now
->fr_literal
,
2729 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2730 ((bfd_reloc_code_real_type
)
2731 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2735 /* Handle a macro. Gather all the operands, transform them as
2736 described by the macro, and call md_assemble recursively. All the
2737 operands are separated by commas; we don't accept parentheses
2738 around operands here. */
2741 ppc_macro (str
, macro
)
2743 const struct powerpc_macro
*macro
;
2754 /* Gather the users operands into the operands array. */
2759 if (count
>= sizeof operands
/ sizeof operands
[0])
2761 operands
[count
++] = s
;
2762 s
= strchr (s
, ',');
2763 if (s
== (char *) NULL
)
2768 if (count
!= macro
->operands
)
2770 as_bad (_("wrong number of operands"));
2774 /* Work out how large the string must be (the size is unbounded
2775 because it includes user input). */
2777 format
= macro
->format
;
2778 while (*format
!= '\0')
2787 arg
= strtol (format
+ 1, &send
, 10);
2788 know (send
!= format
&& arg
>= 0 && arg
< count
);
2789 len
+= strlen (operands
[arg
]);
2794 /* Put the string together. */
2795 complete
= s
= (char *) alloca (len
+ 1);
2796 format
= macro
->format
;
2797 while (*format
!= '\0')
2803 arg
= strtol (format
+ 1, &send
, 10);
2804 strcpy (s
, operands
[arg
]);
2811 /* Assemble the constructed instruction. */
2812 md_assemble (complete
);
2816 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2819 ppc_section_letter (letter
, ptr_msg
)
2826 *ptr_msg
= _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
2831 ppc_section_word (str
, len
)
2835 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2842 ppc_section_type (str
, len
)
2846 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2853 ppc_section_flags (flags
, attr
, type
)
2858 if (type
== SHT_ORDERED
)
2859 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2861 if (attr
& SHF_EXCLUDE
)
2862 flags
|= SEC_EXCLUDE
;
2866 #endif /* OBJ_ELF */
2869 /* Pseudo-op handling. */
2871 /* The .byte pseudo-op. This is similar to the normal .byte
2872 pseudo-op, but it can also take a single ASCII string. */
2876 int ignore ATTRIBUTE_UNUSED
;
2878 if (*input_line_pointer
!= '\"')
2884 /* Gather characters. A real double quote is doubled. Unusual
2885 characters are not permitted. */
2886 ++input_line_pointer
;
2891 c
= *input_line_pointer
++;
2895 if (*input_line_pointer
!= '\"')
2897 ++input_line_pointer
;
2900 FRAG_APPEND_1_CHAR (c
);
2903 demand_empty_rest_of_line ();
2908 /* XCOFF specific pseudo-op handling. */
2910 /* This is set if we are creating a .stabx symbol, since we don't want
2911 to handle symbol suffixes for such symbols. */
2912 static bfd_boolean ppc_stab_symbol
;
2914 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2915 symbols in the .bss segment as though they were local common
2916 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
2917 aligns .comm and .lcomm to 4 bytes. */
2923 asection
*current_seg
= now_seg
;
2924 subsegT current_subseg
= now_subseg
;
2930 symbolS
*lcomm_sym
= NULL
;
2934 name
= input_line_pointer
;
2935 endc
= get_symbol_end ();
2936 end_name
= input_line_pointer
;
2939 if (*input_line_pointer
!= ',')
2941 as_bad (_("missing size"));
2942 ignore_rest_of_line ();
2945 ++input_line_pointer
;
2947 size
= get_absolute_expression ();
2950 as_bad (_("negative size"));
2951 ignore_rest_of_line ();
2957 /* The third argument to .comm is the alignment. */
2958 if (*input_line_pointer
!= ',')
2962 ++input_line_pointer
;
2963 align
= get_absolute_expression ();
2966 as_warn (_("ignoring bad alignment"));
2981 /* The third argument to .lcomm appears to be the real local
2982 common symbol to create. References to the symbol named in
2983 the first argument are turned into references to the third
2985 if (*input_line_pointer
!= ',')
2987 as_bad (_("missing real symbol name"));
2988 ignore_rest_of_line ();
2991 ++input_line_pointer
;
2993 lcomm_name
= input_line_pointer
;
2994 lcomm_endc
= get_symbol_end ();
2996 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2998 *input_line_pointer
= lcomm_endc
;
3002 sym
= symbol_find_or_make (name
);
3005 if (S_IS_DEFINED (sym
)
3006 || S_GET_VALUE (sym
) != 0)
3008 as_bad (_("attempt to redefine symbol"));
3009 ignore_rest_of_line ();
3013 record_alignment (bss_section
, align
);
3016 || ! S_IS_DEFINED (lcomm_sym
))
3025 S_SET_EXTERNAL (sym
);
3029 symbol_get_tc (lcomm_sym
)->output
= 1;
3030 def_sym
= lcomm_sym
;
3034 subseg_set (bss_section
, 1);
3035 frag_align (align
, 0, 0);
3037 symbol_set_frag (def_sym
, frag_now
);
3038 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
3039 def_size
, (char *) NULL
);
3041 S_SET_SEGMENT (def_sym
, bss_section
);
3042 symbol_get_tc (def_sym
)->align
= align
;
3046 /* Align the size of lcomm_sym. */
3047 symbol_get_frag (lcomm_sym
)->fr_offset
=
3048 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
3049 &~ ((1 << align
) - 1));
3050 if (align
> symbol_get_tc (lcomm_sym
)->align
)
3051 symbol_get_tc (lcomm_sym
)->align
= align
;
3056 /* Make sym an offset from lcomm_sym. */
3057 S_SET_SEGMENT (sym
, bss_section
);
3058 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
3059 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
3060 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
3063 subseg_set (current_seg
, current_subseg
);
3065 demand_empty_rest_of_line ();
3068 /* The .csect pseudo-op. This switches us into a different
3069 subsegment. The first argument is a symbol whose value is the
3070 start of the .csect. In COFF, csect symbols get special aux
3071 entries defined by the x_csect field of union internal_auxent. The
3072 optional second argument is the alignment (the default is 2). */
3076 int ignore ATTRIBUTE_UNUSED
;
3083 name
= input_line_pointer
;
3084 endc
= get_symbol_end ();
3086 sym
= symbol_find_or_make (name
);
3088 *input_line_pointer
= endc
;
3090 if (S_GET_NAME (sym
)[0] == '\0')
3092 /* An unnamed csect is assumed to be [PR]. */
3093 symbol_get_tc (sym
)->class = XMC_PR
;
3097 if (*input_line_pointer
== ',')
3099 ++input_line_pointer
;
3100 align
= get_absolute_expression ();
3103 ppc_change_csect (sym
, align
);
3105 demand_empty_rest_of_line ();
3108 /* Change to a different csect. */
3111 ppc_change_csect (sym
, align
)
3115 if (S_IS_DEFINED (sym
))
3116 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
3126 /* This is a new csect. We need to look at the symbol class to
3127 figure out whether it should go in the text section or the
3131 switch (symbol_get_tc (sym
)->class)
3141 S_SET_SEGMENT (sym
, text_section
);
3142 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
3143 ++ppc_text_subsegment
;
3144 list_ptr
= &ppc_text_csects
;
3154 if (ppc_toc_csect
!= NULL
3155 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
3156 == ppc_data_subsegment
))
3158 S_SET_SEGMENT (sym
, data_section
);
3159 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
3160 ++ppc_data_subsegment
;
3161 list_ptr
= &ppc_data_csects
;
3167 /* We set the obstack chunk size to a small value before
3168 changing subsegments, so that we don't use a lot of memory
3169 space for what may be a small section. */
3170 hold_chunksize
= chunksize
;
3173 sec
= subseg_new (segment_name (S_GET_SEGMENT (sym
)),
3174 symbol_get_tc (sym
)->subseg
);
3176 chunksize
= hold_chunksize
;
3179 ppc_after_toc_frag
= frag_now
;
3181 record_alignment (sec
, align
);
3183 frag_align_code (align
, 0);
3185 frag_align (align
, 0, 0);
3187 symbol_set_frag (sym
, frag_now
);
3188 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3190 symbol_get_tc (sym
)->align
= align
;
3191 symbol_get_tc (sym
)->output
= 1;
3192 symbol_get_tc (sym
)->within
= sym
;
3194 for (list
= *list_ptr
;
3195 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3196 list
= symbol_get_tc (list
)->next
)
3198 symbol_get_tc (list
)->next
= sym
;
3200 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3201 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3205 ppc_current_csect
= sym
;
3208 /* This function handles the .text and .data pseudo-ops. These
3209 pseudo-ops aren't really used by XCOFF; we implement them for the
3210 convenience of people who aren't used to XCOFF. */
3221 else if (type
== 'd')
3226 sym
= symbol_find_or_make (name
);
3228 ppc_change_csect (sym
, 2);
3230 demand_empty_rest_of_line ();
3233 /* This function handles the .section pseudo-op. This is mostly to
3234 give an error, since XCOFF only supports .text, .data and .bss, but
3235 we do permit the user to name the text or data section. */
3238 ppc_named_section (ignore
)
3239 int ignore ATTRIBUTE_UNUSED
;
3242 const char *real_name
;
3246 user_name
= input_line_pointer
;
3247 c
= get_symbol_end ();
3249 if (strcmp (user_name
, ".text") == 0)
3250 real_name
= ".text[PR]";
3251 else if (strcmp (user_name
, ".data") == 0)
3252 real_name
= ".data[RW]";
3255 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3256 *input_line_pointer
= c
;
3257 ignore_rest_of_line ();
3261 *input_line_pointer
= c
;
3263 sym
= symbol_find_or_make (real_name
);
3265 ppc_change_csect (sym
, 2);
3267 demand_empty_rest_of_line ();
3270 /* The .extern pseudo-op. We create an undefined symbol. */
3274 int ignore ATTRIBUTE_UNUSED
;
3279 name
= input_line_pointer
;
3280 endc
= get_symbol_end ();
3282 (void) symbol_find_or_make (name
);
3284 *input_line_pointer
= endc
;
3286 demand_empty_rest_of_line ();
3289 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3293 int ignore ATTRIBUTE_UNUSED
;
3299 name
= input_line_pointer
;
3300 endc
= get_symbol_end ();
3302 sym
= symbol_find_or_make (name
);
3304 *input_line_pointer
= endc
;
3306 symbol_get_tc (sym
)->output
= 1;
3308 demand_empty_rest_of_line ();
3311 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3312 although I don't know why it bothers. */
3316 int ignore ATTRIBUTE_UNUSED
;
3323 name
= input_line_pointer
;
3324 endc
= get_symbol_end ();
3326 sym
= symbol_find_or_make (name
);
3328 *input_line_pointer
= endc
;
3330 if (*input_line_pointer
!= ',')
3332 as_bad (_("missing rename string"));
3333 ignore_rest_of_line ();
3336 ++input_line_pointer
;
3338 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
3340 demand_empty_rest_of_line ();
3343 /* The .stabx pseudo-op. This is similar to a normal .stabs
3344 pseudo-op, but slightly different. A sample is
3345 .stabx "main:F-1",.main,142,0
3346 The first argument is the symbol name to create. The second is the
3347 value, and the third is the storage class. The fourth seems to be
3348 always zero, and I am assuming it is the type. */
3352 int ignore ATTRIBUTE_UNUSED
;
3359 name
= demand_copy_C_string (&len
);
3361 if (*input_line_pointer
!= ',')
3363 as_bad (_("missing value"));
3366 ++input_line_pointer
;
3368 ppc_stab_symbol
= TRUE
;
3369 sym
= symbol_make (name
);
3370 ppc_stab_symbol
= FALSE
;
3372 symbol_get_tc (sym
)->real_name
= name
;
3374 (void) expression (&exp
);
3381 as_bad (_("illegal .stabx expression; zero assumed"));
3382 exp
.X_add_number
= 0;
3385 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
3386 symbol_set_frag (sym
, &zero_address_frag
);
3390 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
3391 symbol_set_value_expression (sym
, &exp
);
3395 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
3396 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
3401 /* The value is some complex expression. This will probably
3402 fail at some later point, but this is probably the right
3403 thing to do here. */
3404 symbol_set_value_expression (sym
, &exp
);
3408 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3409 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3411 if (*input_line_pointer
!= ',')
3413 as_bad (_("missing class"));
3416 ++input_line_pointer
;
3418 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
3420 if (*input_line_pointer
!= ',')
3422 as_bad (_("missing type"));
3425 ++input_line_pointer
;
3427 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
3429 symbol_get_tc (sym
)->output
= 1;
3431 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
3433 symbol_get_tc (sym
)->within
= ppc_current_block
;
3438 .stabx "z",arrays_,133,0
3441 .comm arrays_,13768,3
3443 resolve_symbol_value will copy the exp's "within" into sym's when the
3444 offset is 0. Since this seems to be corner case problem,
3445 only do the correction for storage class C_STSYM. A better solution
3446 would be to have the tc field updated in ppc_symbol_new_hook. */
3448 if (exp
.X_op
== O_symbol
)
3450 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
3454 if (exp
.X_op
!= O_symbol
3455 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
3456 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
3457 ppc_frob_label (sym
);
3460 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3461 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
3462 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
3463 symbol_get_tc (ppc_current_csect
)->within
= sym
;
3466 demand_empty_rest_of_line ();
3469 /* The .function pseudo-op. This takes several arguments. The first
3470 argument seems to be the external name of the symbol. The second
3471 argument seems to be the label for the start of the function. gcc
3472 uses the same name for both. I have no idea what the third and
3473 fourth arguments are meant to be. The optional fifth argument is
3474 an expression for the size of the function. In COFF this symbol
3475 gets an aux entry like that used for a csect. */
3478 ppc_function (ignore
)
3479 int ignore ATTRIBUTE_UNUSED
;
3487 name
= input_line_pointer
;
3488 endc
= get_symbol_end ();
3490 /* Ignore any [PR] suffix. */
3491 name
= ppc_canonicalize_symbol_name (name
);
3492 s
= strchr (name
, '[');
3493 if (s
!= (char *) NULL
3494 && strcmp (s
+ 1, "PR]") == 0)
3497 ext_sym
= symbol_find_or_make (name
);
3499 *input_line_pointer
= endc
;
3501 if (*input_line_pointer
!= ',')
3503 as_bad (_("missing symbol name"));
3504 ignore_rest_of_line ();
3507 ++input_line_pointer
;
3509 name
= input_line_pointer
;
3510 endc
= get_symbol_end ();
3512 lab_sym
= symbol_find_or_make (name
);
3514 *input_line_pointer
= endc
;
3516 if (ext_sym
!= lab_sym
)
3520 exp
.X_op
= O_symbol
;
3521 exp
.X_add_symbol
= lab_sym
;
3522 exp
.X_op_symbol
= NULL
;
3523 exp
.X_add_number
= 0;
3525 symbol_set_value_expression (ext_sym
, &exp
);
3528 if (symbol_get_tc (ext_sym
)->class == -1)
3529 symbol_get_tc (ext_sym
)->class = XMC_PR
;
3530 symbol_get_tc (ext_sym
)->output
= 1;
3532 if (*input_line_pointer
== ',')
3536 /* Ignore the third argument. */
3537 ++input_line_pointer
;
3538 expression (&ignore
);
3539 if (*input_line_pointer
== ',')
3541 /* Ignore the fourth argument. */
3542 ++input_line_pointer
;
3543 expression (&ignore
);
3544 if (*input_line_pointer
== ',')
3546 /* The fifth argument is the function size. */
3547 ++input_line_pointer
;
3548 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
3551 &zero_address_frag
);
3552 pseudo_set (symbol_get_tc (ext_sym
)->size
);
3557 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3558 SF_SET_FUNCTION (ext_sym
);
3559 SF_SET_PROCESS (ext_sym
);
3560 coff_add_linesym (ext_sym
);
3562 demand_empty_rest_of_line ();
3565 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3566 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3567 with the correct line number */
3569 static symbolS
*saved_bi_sym
= 0;
3573 int ignore ATTRIBUTE_UNUSED
;
3577 sym
= symbol_make (".bf");
3578 S_SET_SEGMENT (sym
, text_section
);
3579 symbol_set_frag (sym
, frag_now
);
3580 S_SET_VALUE (sym
, frag_now_fix ());
3581 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3583 coff_line_base
= get_absolute_expression ();
3585 S_SET_NUMBER_AUXILIARY (sym
, 1);
3586 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3588 /* Line number for bi. */
3591 S_SET_VALUE (saved_bi_sym
, coff_n_line_nos
);
3596 symbol_get_tc (sym
)->output
= 1;
3598 ppc_frob_label (sym
);
3600 demand_empty_rest_of_line ();
3603 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3604 ".ef", except that the line number is absolute, not relative to the
3605 most recent ".bf" symbol. */
3609 int ignore ATTRIBUTE_UNUSED
;
3613 sym
= symbol_make (".ef");
3614 S_SET_SEGMENT (sym
, text_section
);
3615 symbol_set_frag (sym
, frag_now
);
3616 S_SET_VALUE (sym
, frag_now_fix ());
3617 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3618 S_SET_NUMBER_AUXILIARY (sym
, 1);
3619 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3620 symbol_get_tc (sym
)->output
= 1;
3622 ppc_frob_label (sym
);
3624 demand_empty_rest_of_line ();
3627 /* The .bi and .ei pseudo-ops. These take a string argument and
3628 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3629 the symbol list. The value of .bi will be know when the next .bf
3636 static symbolS
*last_biei
;
3643 name
= demand_copy_C_string (&len
);
3645 /* The value of these symbols is actually file offset. Here we set
3646 the value to the index into the line number entries. In
3647 ppc_frob_symbols we set the fix_line field, which will cause BFD
3648 to do the right thing. */
3650 sym
= symbol_make (name
);
3651 /* obj-coff.c currently only handles line numbers correctly in the
3653 S_SET_SEGMENT (sym
, text_section
);
3654 S_SET_VALUE (sym
, coff_n_line_nos
);
3655 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3657 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3658 symbol_get_tc (sym
)->output
= 1;
3666 for (look
= last_biei
? last_biei
: symbol_rootP
;
3667 (look
!= (symbolS
*) NULL
3668 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3669 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3670 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3671 look
= symbol_next (look
))
3673 if (look
!= (symbolS
*) NULL
)
3675 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3676 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3680 demand_empty_rest_of_line ();
3683 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3684 There is one argument, which is a csect symbol. The value of the
3685 .bs symbol is the index of this csect symbol. */
3689 int ignore ATTRIBUTE_UNUSED
;
3696 if (ppc_current_block
!= NULL
)
3697 as_bad (_("nested .bs blocks"));
3699 name
= input_line_pointer
;
3700 endc
= get_symbol_end ();
3702 csect
= symbol_find_or_make (name
);
3704 *input_line_pointer
= endc
;
3706 sym
= symbol_make (".bs");
3707 S_SET_SEGMENT (sym
, now_seg
);
3708 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3709 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3710 symbol_get_tc (sym
)->output
= 1;
3712 symbol_get_tc (sym
)->within
= csect
;
3714 ppc_frob_label (sym
);
3716 ppc_current_block
= sym
;
3718 demand_empty_rest_of_line ();
3721 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3725 int ignore ATTRIBUTE_UNUSED
;
3729 if (ppc_current_block
== NULL
)
3730 as_bad (_(".es without preceding .bs"));
3732 sym
= symbol_make (".es");
3733 S_SET_SEGMENT (sym
, now_seg
);
3734 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3735 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3736 symbol_get_tc (sym
)->output
= 1;
3738 ppc_frob_label (sym
);
3740 ppc_current_block
= NULL
;
3742 demand_empty_rest_of_line ();
3745 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3750 int ignore ATTRIBUTE_UNUSED
;
3754 sym
= symbol_make (".bb");
3755 S_SET_SEGMENT (sym
, text_section
);
3756 symbol_set_frag (sym
, frag_now
);
3757 S_SET_VALUE (sym
, frag_now_fix ());
3758 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3760 S_SET_NUMBER_AUXILIARY (sym
, 1);
3761 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3763 symbol_get_tc (sym
)->output
= 1;
3765 SF_SET_PROCESS (sym
);
3767 ppc_frob_label (sym
);
3769 demand_empty_rest_of_line ();
3772 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3777 int ignore ATTRIBUTE_UNUSED
;
3781 sym
= symbol_make (".eb");
3782 S_SET_SEGMENT (sym
, text_section
);
3783 symbol_set_frag (sym
, frag_now
);
3784 S_SET_VALUE (sym
, frag_now_fix ());
3785 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3786 S_SET_NUMBER_AUXILIARY (sym
, 1);
3787 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3788 symbol_get_tc (sym
)->output
= 1;
3790 SF_SET_PROCESS (sym
);
3792 ppc_frob_label (sym
);
3794 demand_empty_rest_of_line ();
3797 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3802 int ignore ATTRIBUTE_UNUSED
;
3808 name
= demand_copy_C_string (&len
);
3809 sym
= symbol_make (name
);
3810 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3811 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3812 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3813 S_SET_VALUE (sym
, 0);
3814 symbol_get_tc (sym
)->output
= 1;
3816 ppc_frob_label (sym
);
3818 demand_empty_rest_of_line ();
3821 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3825 int ignore ATTRIBUTE_UNUSED
;
3829 sym
= symbol_make (".ec");
3830 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3831 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3832 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3833 S_SET_VALUE (sym
, 0);
3834 symbol_get_tc (sym
)->output
= 1;
3836 ppc_frob_label (sym
);
3838 demand_empty_rest_of_line ();
3841 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3845 int ignore ATTRIBUTE_UNUSED
;
3847 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3848 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3855 subseg
= ppc_data_subsegment
;
3856 ++ppc_data_subsegment
;
3858 subseg_new (segment_name (data_section
), subseg
);
3859 ppc_toc_frag
= frag_now
;
3861 sym
= symbol_find_or_make ("TOC[TC0]");
3862 symbol_set_frag (sym
, frag_now
);
3863 S_SET_SEGMENT (sym
, data_section
);
3864 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3865 symbol_get_tc (sym
)->subseg
= subseg
;
3866 symbol_get_tc (sym
)->output
= 1;
3867 symbol_get_tc (sym
)->within
= sym
;
3869 ppc_toc_csect
= sym
;
3871 for (list
= ppc_data_csects
;
3872 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3873 list
= symbol_get_tc (list
)->next
)
3875 symbol_get_tc (list
)->next
= sym
;
3877 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3878 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3882 ppc_current_csect
= ppc_toc_csect
;
3884 demand_empty_rest_of_line ();
3887 /* The AIX assembler automatically aligns the operands of a .long or
3888 .short pseudo-op, and we want to be compatible. */
3891 ppc_xcoff_cons (log_size
)
3894 frag_align (log_size
, 0, 0);
3895 record_alignment (now_seg
, log_size
);
3896 cons (1 << log_size
);
3901 int dummy ATTRIBUTE_UNUSED
;
3906 (void) expression (&exp
);
3908 if (exp
.X_op
!= O_constant
)
3910 as_bad (_("non-constant byte count"));
3914 byte_count
= exp
.X_add_number
;
3916 if (*input_line_pointer
!= ',')
3918 as_bad (_("missing value"));
3922 ++input_line_pointer
;
3926 #endif /* OBJ_XCOFF */
3927 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3929 /* The .tc pseudo-op. This is used when generating either XCOFF or
3930 ELF. This takes two or more arguments.
3932 When generating XCOFF output, the first argument is the name to
3933 give to this location in the toc; this will be a symbol with class
3934 TC. The rest of the arguments are N-byte values to actually put at
3935 this location in the TOC; often there is just one more argument, a
3936 relocatable symbol reference. The size of the value to store
3937 depends on target word size. A 32-bit target uses 4-byte values, a
3938 64-bit target uses 8-byte values.
3940 When not generating XCOFF output, the arguments are the same, but
3941 the first argument is simply ignored. */
3945 int ignore ATTRIBUTE_UNUSED
;
3949 /* Define the TOC symbol name. */
3955 if (ppc_toc_csect
== (symbolS
*) NULL
3956 || ppc_toc_csect
!= ppc_current_csect
)
3958 as_bad (_(".tc not in .toc section"));
3959 ignore_rest_of_line ();
3963 name
= input_line_pointer
;
3964 endc
= get_symbol_end ();
3966 sym
= symbol_find_or_make (name
);
3968 *input_line_pointer
= endc
;
3970 if (S_IS_DEFINED (sym
))
3974 label
= symbol_get_tc (ppc_current_csect
)->within
;
3975 if (symbol_get_tc (label
)->class != XMC_TC0
)
3977 as_bad (_(".tc with no label"));
3978 ignore_rest_of_line ();
3982 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3983 symbol_set_frag (label
, symbol_get_frag (sym
));
3984 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3986 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3987 ++input_line_pointer
;
3992 S_SET_SEGMENT (sym
, now_seg
);
3993 symbol_set_frag (sym
, frag_now
);
3994 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3995 symbol_get_tc (sym
)->class = XMC_TC
;
3996 symbol_get_tc (sym
)->output
= 1;
3998 ppc_frob_label (sym
);
4001 #endif /* OBJ_XCOFF */
4005 /* Skip the TOC symbol name. */
4006 while (is_part_of_name (*input_line_pointer
)
4007 || *input_line_pointer
== '['
4008 || *input_line_pointer
== ']'
4009 || *input_line_pointer
== '{'
4010 || *input_line_pointer
== '}')
4011 ++input_line_pointer
;
4013 /* Align to a four/eight byte boundary. */
4014 align
= ppc_obj64
? 3 : 2;
4015 frag_align (align
, 0, 0);
4016 record_alignment (now_seg
, align
);
4017 #endif /* OBJ_ELF */
4019 if (*input_line_pointer
!= ',')
4020 demand_empty_rest_of_line ();
4023 ++input_line_pointer
;
4024 cons (ppc_obj64
? 8 : 4);
4028 /* Pseudo-op .machine. */
4031 ppc_machine (ignore
)
4032 int ignore ATTRIBUTE_UNUSED
;
4035 #define MAX_HISTORY 100
4036 static unsigned long *cpu_history
;
4037 static int curr_hist
;
4041 if (*input_line_pointer
== '"')
4044 cpu_string
= demand_copy_C_string (&len
);
4049 cpu_string
= input_line_pointer
;
4050 c
= get_symbol_end ();
4051 cpu_string
= xstrdup (cpu_string
);
4052 *input_line_pointer
= c
;
4055 if (cpu_string
!= NULL
)
4057 unsigned long old_cpu
= ppc_cpu
;
4060 for (p
= cpu_string
; *p
!= 0; p
++)
4063 if (strcmp (cpu_string
, "push") == 0)
4065 if (cpu_history
== NULL
)
4066 cpu_history
= xmalloc (MAX_HISTORY
* sizeof (*cpu_history
));
4068 if (curr_hist
>= MAX_HISTORY
)
4069 as_bad (_(".machine stack overflow"));
4071 cpu_history
[curr_hist
++] = ppc_cpu
;
4073 else if (strcmp (cpu_string
, "pop") == 0)
4076 as_bad (_(".machine stack underflow"));
4078 ppc_cpu
= cpu_history
[--curr_hist
];
4080 else if (parse_cpu (cpu_string
))
4083 as_bad (_("invalid machine `%s'"), cpu_string
);
4085 if (ppc_cpu
!= old_cpu
)
4086 ppc_setup_opcodes ();
4089 demand_empty_rest_of_line ();
4092 /* See whether a symbol is in the TOC section. */
4095 ppc_is_toc_sym (sym
)
4099 return symbol_get_tc (sym
)->class == XMC_TC
;
4102 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
4104 return strcmp (sname
, ".toc") == 0;
4106 return strcmp (sname
, ".got") == 0;
4109 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4113 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4115 /* Set the current section. */
4117 ppc_set_current_section (new)
4120 ppc_previous_section
= ppc_current_section
;
4121 ppc_current_section
= new;
4124 /* pseudo-op: .previous
4125 behaviour: toggles the current section with the previous section.
4127 warnings: "No previous section" */
4130 ppc_previous (ignore
)
4131 int ignore ATTRIBUTE_UNUSED
;
4135 if (ppc_previous_section
== NULL
)
4137 as_warn (_("No previous section to return to. Directive ignored."));
4141 subseg_set (ppc_previous_section
, 0);
4143 ppc_set_current_section (ppc_previous_section
);
4146 /* pseudo-op: .pdata
4147 behaviour: predefined read only data section
4151 initial: .section .pdata "adr3"
4152 a - don't know -- maybe a misprint
4153 d - initialized data
4155 3 - double word aligned (that would be 4 byte boundary)
4158 Tag index tables (also known as the function table) for exception
4159 handling, debugging, etc. */
4163 int ignore ATTRIBUTE_UNUSED
;
4165 if (pdata_section
== 0)
4167 pdata_section
= subseg_new (".pdata", 0);
4169 bfd_set_section_flags (stdoutput
, pdata_section
,
4170 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4171 | SEC_READONLY
| SEC_DATA
));
4173 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
4177 pdata_section
= subseg_new (".pdata", 0);
4179 ppc_set_current_section (pdata_section
);
4182 /* pseudo-op: .ydata
4183 behaviour: predefined read only data section
4187 initial: .section .ydata "drw3"
4188 a - don't know -- maybe a misprint
4189 d - initialized data
4191 3 - double word aligned (that would be 4 byte boundary)
4193 Tag tables (also known as the scope table) for exception handling,
4198 int ignore ATTRIBUTE_UNUSED
;
4200 if (ydata_section
== 0)
4202 ydata_section
= subseg_new (".ydata", 0);
4203 bfd_set_section_flags (stdoutput
, ydata_section
,
4204 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4205 | SEC_READONLY
| SEC_DATA
));
4207 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
4211 ydata_section
= subseg_new (".ydata", 0);
4213 ppc_set_current_section (ydata_section
);
4216 /* pseudo-op: .reldata
4217 behaviour: predefined read write data section
4218 double word aligned (4-byte)
4219 FIXME: relocation is applied to it
4220 FIXME: what's the difference between this and .data?
4223 initial: .section .reldata "drw3"
4224 d - initialized data
4227 3 - double word aligned (that would be 8 byte boundary)
4230 Like .data, but intended to hold data subject to relocation, such as
4231 function descriptors, etc. */
4234 ppc_reldata (ignore
)
4235 int ignore ATTRIBUTE_UNUSED
;
4237 if (reldata_section
== 0)
4239 reldata_section
= subseg_new (".reldata", 0);
4241 bfd_set_section_flags (stdoutput
, reldata_section
,
4242 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4245 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
4249 reldata_section
= subseg_new (".reldata", 0);
4251 ppc_set_current_section (reldata_section
);
4254 /* pseudo-op: .rdata
4255 behaviour: predefined read only data section
4259 initial: .section .rdata "dr3"
4260 d - initialized data
4262 3 - double word aligned (that would be 4 byte boundary) */
4266 int ignore ATTRIBUTE_UNUSED
;
4268 if (rdata_section
== 0)
4270 rdata_section
= subseg_new (".rdata", 0);
4271 bfd_set_section_flags (stdoutput
, rdata_section
,
4272 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4273 | SEC_READONLY
| SEC_DATA
));
4275 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
4279 rdata_section
= subseg_new (".rdata", 0);
4281 ppc_set_current_section (rdata_section
);
4284 /* pseudo-op: .ualong
4285 behaviour: much like .int, with the exception that no alignment is
4287 FIXME: test the alignment statement
4293 int ignore ATTRIBUTE_UNUSED
;
4299 /* pseudo-op: .znop <symbol name>
4300 behaviour: Issue a nop instruction
4301 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4302 the supplied symbol name.
4304 warnings: Missing symbol name */
4308 int ignore ATTRIBUTE_UNUSED
;
4311 const struct powerpc_opcode
*opcode
;
4322 /* Strip out the symbol name. */
4323 symbol_name
= input_line_pointer
;
4324 c
= get_symbol_end ();
4326 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
4327 strcpy (name
, symbol_name
);
4329 sym
= symbol_find_or_make (name
);
4331 *input_line_pointer
= c
;
4335 /* Look up the opcode in the hash table. */
4336 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
4338 /* Stick in the nop. */
4339 insn
= opcode
->opcode
;
4341 /* Write out the instruction. */
4343 md_number_to_chars (f
, insn
, 4);
4345 f
- frag_now
->fr_literal
,
4350 BFD_RELOC_16_GOT_PCREL
);
4363 register char *name
;
4367 register symbolS
*symbolP
;
4370 name
= input_line_pointer
;
4371 c
= get_symbol_end ();
4373 /* just after name is now '\0'. */
4374 p
= input_line_pointer
;
4377 if (*input_line_pointer
!= ',')
4379 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4380 ignore_rest_of_line ();
4384 input_line_pointer
++; /* skip ',' */
4385 if ((temp
= get_absolute_expression ()) < 0)
4387 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
4388 ignore_rest_of_line ();
4394 /* The third argument to .comm is the alignment. */
4395 if (*input_line_pointer
!= ',')
4399 ++input_line_pointer
;
4400 align
= get_absolute_expression ();
4403 as_warn (_("ignoring bad alignment"));
4410 symbolP
= symbol_find_or_make (name
);
4413 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
4415 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4416 S_GET_NAME (symbolP
));
4417 ignore_rest_of_line ();
4421 if (S_GET_VALUE (symbolP
))
4423 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
4424 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4425 S_GET_NAME (symbolP
),
4426 (long) S_GET_VALUE (symbolP
),
4431 S_SET_VALUE (symbolP
, (valueT
) temp
);
4432 S_SET_EXTERNAL (symbolP
);
4433 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
4436 demand_empty_rest_of_line ();
4440 * implement the .section pseudo op:
4441 * .section name {, "flags"}
4443 * | +--- optional flags: 'b' for bss
4445 * +-- section name 'l' for lib
4449 * 'd' (apparently m88k for data)
4451 * But if the argument is not a quoted string, treat it as a
4452 * subsegment number.
4454 * FIXME: this is a copy of the section processing from obj-coff.c, with
4455 * additions/changes for the moto-pas assembler support. There are three
4458 * FIXME: I just noticed this. This doesn't work at all really. It it
4459 * setting bits that bfd probably neither understands or uses. The
4460 * correct approach (?) will have to incorporate extra fields attached
4461 * to the section to hold the system specific stuff. (krk)
4464 * 'a' - unknown - referred to in documentation, but no definition supplied
4465 * 'c' - section has code
4466 * 'd' - section has initialized data
4467 * 'u' - section has uninitialized data
4468 * 'i' - section contains directives (info)
4469 * 'n' - section can be discarded
4470 * 'R' - remove section at link time
4472 * Section Protection:
4473 * 'r' - section is readable
4474 * 'w' - section is writeable
4475 * 'x' - section is executable
4476 * 's' - section is sharable
4478 * Section Alignment:
4479 * '0' - align to byte boundary
4480 * '1' - align to halfword undary
4481 * '2' - align to word boundary
4482 * '3' - align to doubleword boundary
4483 * '4' - align to quadword boundary
4484 * '5' - align to 32 byte boundary
4485 * '6' - align to 64 byte boundary
4490 ppc_pe_section (ignore
)
4491 int ignore ATTRIBUTE_UNUSED
;
4493 /* Strip out the section name. */
4502 section_name
= input_line_pointer
;
4503 c
= get_symbol_end ();
4505 name
= xmalloc (input_line_pointer
- section_name
+ 1);
4506 strcpy (name
, section_name
);
4508 *input_line_pointer
= c
;
4513 flags
= SEC_NO_FLAGS
;
4515 if (strcmp (name
, ".idata$2") == 0)
4519 else if (strcmp (name
, ".idata$3") == 0)
4523 else if (strcmp (name
, ".idata$4") == 0)
4527 else if (strcmp (name
, ".idata$5") == 0)
4531 else if (strcmp (name
, ".idata$6") == 0)
4536 /* Default alignment to 16 byte boundary. */
4539 if (*input_line_pointer
== ',')
4541 ++input_line_pointer
;
4543 if (*input_line_pointer
!= '"')
4544 exp
= get_absolute_expression ();
4547 ++input_line_pointer
;
4548 while (*input_line_pointer
!= '"'
4549 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4551 switch (*input_line_pointer
)
4553 /* Section Contents */
4554 case 'a': /* unknown */
4555 as_bad (_("Unsupported section attribute -- 'a'"));
4557 case 'c': /* code section */
4560 case 'd': /* section has initialized data */
4563 case 'u': /* section has uninitialized data */
4564 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4568 case 'i': /* section contains directives (info) */
4569 /* FIXME: This is IMAGE_SCN_LNK_INFO
4571 flags
|= SEC_HAS_CONTENTS
;
4573 case 'n': /* section can be discarded */
4576 case 'R': /* Remove section at link time */
4577 flags
|= SEC_NEVER_LOAD
;
4580 /* Section Protection */
4581 case 'r': /* section is readable */
4582 flags
|= IMAGE_SCN_MEM_READ
;
4584 case 'w': /* section is writeable */
4585 flags
|= IMAGE_SCN_MEM_WRITE
;
4587 case 'x': /* section is executable */
4588 flags
|= IMAGE_SCN_MEM_EXECUTE
;
4590 case 's': /* section is sharable */
4591 flags
|= IMAGE_SCN_MEM_SHARED
;
4594 /* Section Alignment */
4595 case '0': /* align to byte boundary */
4596 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
4599 case '1': /* align to halfword boundary */
4600 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
4603 case '2': /* align to word boundary */
4604 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
4607 case '3': /* align to doubleword boundary */
4608 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
4611 case '4': /* align to quadword boundary */
4612 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
4615 case '5': /* align to 32 byte boundary */
4616 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
4619 case '6': /* align to 64 byte boundary */
4620 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
4625 as_bad (_("unknown section attribute '%c'"),
4626 *input_line_pointer
);
4629 ++input_line_pointer
;
4631 if (*input_line_pointer
== '"')
4632 ++input_line_pointer
;
4636 sec
= subseg_new (name
, (subsegT
) exp
);
4638 ppc_set_current_section (sec
);
4640 if (flags
!= SEC_NO_FLAGS
)
4642 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
4643 as_bad (_("error setting flags for \"%s\": %s"),
4644 bfd_section_name (stdoutput
, sec
),
4645 bfd_errmsg (bfd_get_error ()));
4648 bfd_set_section_alignment (stdoutput
, sec
, align
);
4653 ppc_pe_function (ignore
)
4654 int ignore ATTRIBUTE_UNUSED
;
4660 name
= input_line_pointer
;
4661 endc
= get_symbol_end ();
4663 ext_sym
= symbol_find_or_make (name
);
4665 *input_line_pointer
= endc
;
4667 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4668 SF_SET_FUNCTION (ext_sym
);
4669 SF_SET_PROCESS (ext_sym
);
4670 coff_add_linesym (ext_sym
);
4672 demand_empty_rest_of_line ();
4676 ppc_pe_tocd (ignore
)
4677 int ignore ATTRIBUTE_UNUSED
;
4679 if (tocdata_section
== 0)
4681 tocdata_section
= subseg_new (".tocd", 0);
4682 /* FIXME: section flags won't work. */
4683 bfd_set_section_flags (stdoutput
, tocdata_section
,
4684 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4685 | SEC_READONLY
| SEC_DATA
));
4687 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4691 rdata_section
= subseg_new (".tocd", 0);
4694 ppc_set_current_section (tocdata_section
);
4696 demand_empty_rest_of_line ();
4699 /* Don't adjust TOC relocs to use the section symbol. */
4702 ppc_pe_fix_adjustable (fix
)
4705 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4712 /* XCOFF specific symbol and file handling. */
4714 /* Canonicalize the symbol name. We use the to force the suffix, if
4715 any, to use square brackets, and to be in upper case. */
4718 ppc_canonicalize_symbol_name (name
)
4723 if (ppc_stab_symbol
)
4726 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4740 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4743 if (*s
== '\0' || s
[1] != '\0')
4744 as_bad (_("bad symbol suffix"));
4752 /* Set the class of a symbol based on the suffix, if any. This is
4753 called whenever a new symbol is created. */
4756 ppc_symbol_new_hook (sym
)
4759 struct ppc_tc_sy
*tc
;
4762 tc
= symbol_get_tc (sym
);
4766 tc
->real_name
= NULL
;
4772 if (ppc_stab_symbol
)
4775 s
= strchr (S_GET_NAME (sym
), '[');
4776 if (s
== (const char *) NULL
)
4778 /* There is no suffix. */
4787 if (strcmp (s
, "BS]") == 0)
4791 if (strcmp (s
, "DB]") == 0)
4793 else if (strcmp (s
, "DS]") == 0)
4797 if (strcmp (s
, "GL]") == 0)
4801 if (strcmp (s
, "PR]") == 0)
4805 if (strcmp (s
, "RO]") == 0)
4807 else if (strcmp (s
, "RW]") == 0)
4811 if (strcmp (s
, "SV]") == 0)
4815 if (strcmp (s
, "TC]") == 0)
4817 else if (strcmp (s
, "TI]") == 0)
4819 else if (strcmp (s
, "TB]") == 0)
4821 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4822 tc
->class = XMC_TC0
;
4825 if (strcmp (s
, "UA]") == 0)
4827 else if (strcmp (s
, "UC]") == 0)
4831 if (strcmp (s
, "XO]") == 0)
4836 if (tc
->class == -1)
4837 as_bad (_("Unrecognized symbol suffix"));
4840 /* Set the class of a label based on where it is defined. This
4841 handles symbols without suffixes. Also, move the symbol so that it
4842 follows the csect symbol. */
4845 ppc_frob_label (sym
)
4848 if (ppc_current_csect
!= (symbolS
*) NULL
)
4850 if (symbol_get_tc (sym
)->class == -1)
4851 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4853 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4854 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4855 &symbol_rootP
, &symbol_lastP
);
4856 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4860 dwarf2_emit_label (sym
);
4864 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4865 seen. It tells ppc_adjust_symtab whether it needs to look through
4868 static bfd_boolean ppc_saw_abs
;
4870 /* Change the name of a symbol just before writing it out. Set the
4871 real name if the .rename pseudo-op was used. Otherwise, remove any
4872 class suffix. Return 1 if the symbol should not be included in the
4876 ppc_frob_symbol (sym
)
4879 static symbolS
*ppc_last_function
;
4880 static symbolS
*set_end
;
4882 /* Discard symbols that should not be included in the output symbol
4884 if (! symbol_used_in_reloc_p (sym
)
4885 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4886 || (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
4887 && ! symbol_get_tc (sym
)->output
4888 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4891 /* This one will disappear anyway. Don't make a csect sym for it. */
4892 if (sym
== abs_section_sym
)
4895 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4896 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4902 name
= S_GET_NAME (sym
);
4903 s
= strchr (name
, '[');
4904 if (s
!= (char *) NULL
)
4910 snew
= xmalloc (len
+ 1);
4911 memcpy (snew
, name
, len
);
4914 S_SET_NAME (sym
, snew
);
4918 if (set_end
!= (symbolS
*) NULL
)
4920 SA_SET_SYM_ENDNDX (set_end
, sym
);
4924 if (SF_GET_FUNCTION (sym
))
4926 if (ppc_last_function
!= (symbolS
*) NULL
)
4927 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4928 ppc_last_function
= sym
;
4929 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4931 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4932 SA_SET_SYM_FSIZE (sym
,
4933 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4936 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4937 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4939 if (ppc_last_function
== (symbolS
*) NULL
)
4940 as_bad (_(".ef with no preceding .function"));
4943 set_end
= ppc_last_function
;
4944 ppc_last_function
= NULL
;
4946 /* We don't have a C_EFCN symbol, but we need to force the
4947 COFF backend to believe that it has seen one. */
4948 coff_last_function
= NULL
;
4952 if (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
4953 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4954 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4955 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4956 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4957 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4958 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4959 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4960 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4961 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4962 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4964 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4965 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4968 union internal_auxent
*a
;
4970 /* Create a csect aux. */
4971 i
= S_GET_NUMBER_AUXILIARY (sym
);
4972 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4973 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4974 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4976 /* This is the TOC table. */
4977 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4978 a
->x_csect
.x_scnlen
.l
= 0;
4979 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4981 else if (symbol_get_tc (sym
)->subseg
!= 0)
4983 /* This is a csect symbol. x_scnlen is the size of the
4985 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4986 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4987 S_GET_SEGMENT (sym
))
4988 - S_GET_VALUE (sym
));
4991 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4992 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4993 - S_GET_VALUE (sym
));
4995 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4997 else if (S_GET_SEGMENT (sym
) == bss_section
)
4999 /* This is a common symbol. */
5000 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
5001 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
5002 if (S_IS_EXTERNAL (sym
))
5003 symbol_get_tc (sym
)->class = XMC_RW
;
5005 symbol_get_tc (sym
)->class = XMC_BS
;
5007 else if (S_GET_SEGMENT (sym
) == absolute_section
)
5009 /* This is an absolute symbol. The csect will be created by
5010 ppc_adjust_symtab. */
5012 a
->x_csect
.x_smtyp
= XTY_LD
;
5013 if (symbol_get_tc (sym
)->class == -1)
5014 symbol_get_tc (sym
)->class = XMC_XO
;
5016 else if (! S_IS_DEFINED (sym
))
5018 /* This is an external symbol. */
5019 a
->x_csect
.x_scnlen
.l
= 0;
5020 a
->x_csect
.x_smtyp
= XTY_ER
;
5022 else if (symbol_get_tc (sym
)->class == XMC_TC
)
5026 /* This is a TOC definition. x_scnlen is the size of the
5028 next
= symbol_next (sym
);
5029 while (symbol_get_tc (next
)->class == XMC_TC0
)
5030 next
= symbol_next (next
);
5031 if (next
== (symbolS
*) NULL
5032 || symbol_get_tc (next
)->class != XMC_TC
)
5034 if (ppc_after_toc_frag
== (fragS
*) NULL
)
5035 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
5037 - S_GET_VALUE (sym
));
5039 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
5040 - S_GET_VALUE (sym
));
5044 resolve_symbol_value (next
);
5045 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
5046 - S_GET_VALUE (sym
));
5048 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
5054 /* This is a normal symbol definition. x_scnlen is the
5055 symbol index of the containing csect. */
5056 if (S_GET_SEGMENT (sym
) == text_section
)
5057 csect
= ppc_text_csects
;
5058 else if (S_GET_SEGMENT (sym
) == data_section
)
5059 csect
= ppc_data_csects
;
5063 /* Skip the initial dummy symbol. */
5064 csect
= symbol_get_tc (csect
)->next
;
5066 if (csect
== (symbolS
*) NULL
)
5068 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
5069 a
->x_csect
.x_scnlen
.l
= 0;
5073 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
5075 resolve_symbol_value (symbol_get_tc (csect
)->next
);
5076 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
5077 > S_GET_VALUE (sym
))
5079 csect
= symbol_get_tc (csect
)->next
;
5082 a
->x_csect
.x_scnlen
.p
=
5083 coffsymbol (symbol_get_bfdsym (csect
))->native
;
5084 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
5087 a
->x_csect
.x_smtyp
= XTY_LD
;
5090 a
->x_csect
.x_parmhash
= 0;
5091 a
->x_csect
.x_snhash
= 0;
5092 if (symbol_get_tc (sym
)->class == -1)
5093 a
->x_csect
.x_smclas
= XMC_PR
;
5095 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
5096 a
->x_csect
.x_stab
= 0;
5097 a
->x_csect
.x_snstab
= 0;
5099 /* Don't let the COFF backend resort these symbols. */
5100 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
5102 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
5104 /* We want the value to be the symbol index of the referenced
5105 csect symbol. BFD will do that for us if we set the right
5107 asymbol
*bsym
= symbol_get_bfdsym (symbol_get_tc (sym
)->within
);
5108 combined_entry_type
*c
= coffsymbol (bsym
)->native
;
5110 S_SET_VALUE (sym
, (valueT
) (size_t) c
);
5111 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
5113 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
5118 /* The value is the offset from the enclosing csect. */
5119 block
= symbol_get_tc (sym
)->within
;
5120 csect
= symbol_get_tc (block
)->within
;
5121 resolve_symbol_value (csect
);
5122 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
5124 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
5125 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
5127 /* We want the value to be a file offset into the line numbers.
5128 BFD will do that for us if we set the right flags. We have
5129 already set the value correctly. */
5130 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
5136 /* Adjust the symbol table. This creates csect symbols for all
5137 absolute symbols. */
5140 ppc_adjust_symtab ()
5147 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
5151 union internal_auxent
*a
;
5153 if (S_GET_SEGMENT (sym
) != absolute_section
)
5156 csect
= symbol_create (".abs[XO]", absolute_section
,
5157 S_GET_VALUE (sym
), &zero_address_frag
);
5158 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
5159 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
5160 i
= S_GET_NUMBER_AUXILIARY (csect
);
5161 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
5162 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
5163 a
->x_csect
.x_scnlen
.l
= 0;
5164 a
->x_csect
.x_smtyp
= XTY_SD
;
5165 a
->x_csect
.x_parmhash
= 0;
5166 a
->x_csect
.x_snhash
= 0;
5167 a
->x_csect
.x_smclas
= XMC_XO
;
5168 a
->x_csect
.x_stab
= 0;
5169 a
->x_csect
.x_snstab
= 0;
5171 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
5173 i
= S_GET_NUMBER_AUXILIARY (sym
);
5174 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
5175 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
5176 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
5179 ppc_saw_abs
= FALSE
;
5182 /* Set the VMA for a section. This is called on all the sections in
5186 ppc_frob_section (sec
)
5189 static bfd_vma vma
= 0;
5191 vma
= md_section_align (sec
, vma
);
5192 bfd_set_section_vma (stdoutput
, sec
, vma
);
5193 vma
+= bfd_section_size (stdoutput
, sec
);
5196 #endif /* OBJ_XCOFF */
5198 /* Turn a string in input_line_pointer into a floating point constant
5199 of type TYPE, and store the appropriate bytes in *LITP. The number
5200 of LITTLENUMS emitted is stored in *SIZEP. An error message is
5201 returned, or NULL on OK. */
5204 md_atof (type
, litp
, sizep
)
5210 LITTLENUM_TYPE words
[4];
5226 return _("bad call to md_atof");
5229 t
= atof_ieee (input_line_pointer
, type
, words
);
5231 input_line_pointer
= t
;
5235 if (target_big_endian
)
5237 for (i
= 0; i
< prec
; i
++)
5239 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5245 for (i
= prec
- 1; i
>= 0; i
--)
5247 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5255 /* Write a value out to the object file, using the appropriate
5259 md_number_to_chars (buf
, val
, n
)
5264 if (target_big_endian
)
5265 number_to_chars_bigendian (buf
, val
, n
);
5267 number_to_chars_littleendian (buf
, val
, n
);
5270 /* Align a section (I don't know why this is machine dependent). */
5273 md_section_align (asection
*seg ATTRIBUTE_UNUSED
, valueT addr
)
5278 int align
= bfd_get_section_alignment (stdoutput
, seg
);
5280 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
5284 /* We don't have any form of relaxing. */
5287 md_estimate_size_before_relax (fragp
, seg
)
5288 fragS
*fragp ATTRIBUTE_UNUSED
;
5289 asection
*seg ATTRIBUTE_UNUSED
;
5295 /* Convert a machine dependent frag. We never generate these. */
5298 md_convert_frag (abfd
, sec
, fragp
)
5299 bfd
*abfd ATTRIBUTE_UNUSED
;
5300 asection
*sec ATTRIBUTE_UNUSED
;
5301 fragS
*fragp ATTRIBUTE_UNUSED
;
5306 /* We have no need to default values of symbols. */
5309 md_undefined_symbol (name
)
5310 char *name ATTRIBUTE_UNUSED
;
5315 /* Functions concerning relocs. */
5317 /* The location from which a PC relative jump should be calculated,
5318 given a PC relative reloc. */
5321 md_pcrel_from_section (fixp
, sec
)
5323 segT sec ATTRIBUTE_UNUSED
;
5325 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5330 /* This is called to see whether a fixup should be adjusted to use a
5331 section symbol. We take the opportunity to change a fixup against
5332 a symbol in the TOC subsegment into a reloc against the
5333 corresponding .tc symbol. */
5336 ppc_fix_adjustable (fix
)
5339 valueT val
= resolve_symbol_value (fix
->fx_addsy
);
5340 segT symseg
= S_GET_SEGMENT (fix
->fx_addsy
);
5341 TC_SYMFIELD_TYPE
*tc
;
5343 if (symseg
== absolute_section
)
5346 if (ppc_toc_csect
!= (symbolS
*) NULL
5347 && fix
->fx_addsy
!= ppc_toc_csect
5348 && symseg
== data_section
5349 && val
>= ppc_toc_frag
->fr_address
5350 && (ppc_after_toc_frag
== (fragS
*) NULL
5351 || val
< ppc_after_toc_frag
->fr_address
))
5355 for (sy
= symbol_next (ppc_toc_csect
);
5356 sy
!= (symbolS
*) NULL
;
5357 sy
= symbol_next (sy
))
5359 TC_SYMFIELD_TYPE
*sy_tc
= symbol_get_tc (sy
);
5361 if (sy_tc
->class == XMC_TC0
)
5363 if (sy_tc
->class != XMC_TC
)
5365 if (val
== resolve_symbol_value (sy
))
5368 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
5373 as_bad_where (fix
->fx_file
, fix
->fx_line
,
5374 _("symbol in .toc does not match any .tc"));
5377 /* Possibly adjust the reloc to be against the csect. */
5378 tc
= symbol_get_tc (fix
->fx_addsy
);
5380 && tc
->class != XMC_TC0
5381 && tc
->class != XMC_TC
5382 && symseg
!= bss_section
5383 /* Don't adjust if this is a reloc in the toc section. */
5384 && (symseg
!= data_section
5385 || ppc_toc_csect
== NULL
5386 || val
< ppc_toc_frag
->fr_address
5387 || (ppc_after_toc_frag
!= NULL
5388 && val
>= ppc_after_toc_frag
->fr_address
)))
5391 symbolS
*next_csect
;
5393 if (symseg
== text_section
)
5394 csect
= ppc_text_csects
;
5395 else if (symseg
== data_section
)
5396 csect
= ppc_data_csects
;
5400 /* Skip the initial dummy symbol. */
5401 csect
= symbol_get_tc (csect
)->next
;
5403 if (csect
!= (symbolS
*) NULL
)
5405 while ((next_csect
= symbol_get_tc (csect
)->next
) != (symbolS
*) NULL
5406 && (symbol_get_frag (next_csect
)->fr_address
<= val
))
5408 /* If the csect address equals the symbol value, then we
5409 have to look through the full symbol table to see
5410 whether this is the csect we want. Note that we will
5411 only get here if the csect has zero length. */
5412 if (symbol_get_frag (csect
)->fr_address
== val
5413 && S_GET_VALUE (csect
) == val
)
5417 for (scan
= symbol_next (csect
);
5419 scan
= symbol_next (scan
))
5421 if (symbol_get_tc (scan
)->subseg
!= 0)
5423 if (scan
== fix
->fx_addsy
)
5427 /* If we found the symbol before the next csect
5428 symbol, then this is the csect we want. */
5429 if (scan
== fix
->fx_addsy
)
5436 fix
->fx_offset
+= val
- symbol_get_frag (csect
)->fr_address
;
5437 fix
->fx_addsy
= csect
;
5442 /* Adjust a reloc against a .lcomm symbol to be against the base
5444 if (symseg
== bss_section
5445 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
5447 symbolS
*sy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
5449 fix
->fx_offset
+= val
- resolve_symbol_value (sy
);
5456 /* A reloc from one csect to another must be kept. The assembler
5457 will, of course, keep relocs between sections, and it will keep
5458 absolute relocs, but we need to force it to keep PC relative relocs
5459 between two csects in the same section. */
5462 ppc_force_relocation (fix
)
5465 /* At this point fix->fx_addsy should already have been converted to
5466 a csect symbol. If the csect does not include the fragment, then
5467 we need to force the relocation. */
5469 && fix
->fx_addsy
!= NULL
5470 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
5471 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
5472 > fix
->fx_frag
->fr_address
)
5473 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
5474 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
5475 <= fix
->fx_frag
->fr_address
))))
5478 return generic_force_reloc (fix
);
5481 #endif /* OBJ_XCOFF */
5484 /* If this function returns non-zero, it guarantees that a relocation
5485 will be emitted for a fixup. */
5488 ppc_force_relocation (fix
)
5491 /* Branch prediction relocations must force a relocation, as must
5492 the vtable description relocs. */
5493 switch (fix
->fx_r_type
)
5495 case BFD_RELOC_PPC_B16_BRTAKEN
:
5496 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5497 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5498 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5499 case BFD_RELOC_24_PLT_PCREL
:
5500 case BFD_RELOC_PPC64_TOC
:
5506 if (fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5507 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
5510 return generic_force_reloc (fix
);
5514 ppc_fix_adjustable (fix
)
5517 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
5518 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
5519 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
5520 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
5521 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
5522 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
5523 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
5524 && !(fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5525 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
));
5529 /* Implement HANDLE_ALIGN. This writes the NOP pattern into an
5530 rs_align_code frag. */
5533 ppc_handle_align (struct frag
*fragP
)
5535 valueT count
= (fragP
->fr_next
->fr_address
5536 - (fragP
->fr_address
+ fragP
->fr_fix
));
5538 if (count
!= 0 && (count
& 3) == 0)
5540 char *dest
= fragP
->fr_literal
+ fragP
->fr_fix
;
5543 md_number_to_chars (dest
, 0x60000000, 4);
5545 if ((ppc_cpu
& PPC_OPCODE_POWER6
) != 0)
5547 /* For power6, we want the last nop to be a group terminating
5548 one, "ori 1,1,0". Do this by inserting an rs_fill frag
5549 immediately after this one, with its address set to the last
5550 nop location. This will automatically reduce the number of
5551 nops in the current frag by one. */
5554 struct frag
*group_nop
= xmalloc (SIZEOF_STRUCT_FRAG
+ 4);
5556 memcpy (group_nop
, fragP
, SIZEOF_STRUCT_FRAG
);
5557 group_nop
->fr_address
= group_nop
->fr_next
->fr_address
- 4;
5558 group_nop
->fr_fix
= 0;
5559 group_nop
->fr_offset
= 1;
5560 group_nop
->fr_type
= rs_fill
;
5561 fragP
->fr_next
= group_nop
;
5562 dest
= group_nop
->fr_literal
;
5565 md_number_to_chars (dest
, 0x60210000, 4);
5570 /* Apply a fixup to the object code. This is called for all the
5571 fixups we generated by the call to fix_new_exp, above. In the call
5572 above we used a reloc code which was the largest legal reloc code
5573 plus the operand index. Here we undo that to recover the operand
5574 index. At this point all symbol values should be fully resolved,
5575 and we attempt to completely resolve the reloc. If we can not do
5576 that, we determine the correct reloc code and put it back in the
5580 md_apply_fix (fixP
, valP
, seg
)
5583 segT seg ATTRIBUTE_UNUSED
;
5585 valueT value
= * valP
;
5588 if (fixP
->fx_addsy
!= NULL
)
5590 /* Hack around bfd_install_relocation brain damage. */
5592 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5597 /* FIXME FIXME FIXME: The value we are passed in *valP includes
5598 the symbol values. If we are doing this relocation the code in
5599 write.c is going to call bfd_install_relocation, which is also
5600 going to use the symbol value. That means that if the reloc is
5601 fully resolved we want to use *valP since bfd_install_relocation is
5603 However, if the reloc is not fully resolved we do not want to use
5604 *valP, and must use fx_offset instead. However, if the reloc
5605 is PC relative, we do want to use *valP since it includes the
5606 result of md_pcrel_from. This is confusing. */
5607 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
5610 else if (fixP
->fx_pcrel
)
5614 value
= fixP
->fx_offset
;
5617 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
5619 /* We can't actually support subtracting a symbol. */
5620 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
5623 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
5626 const struct powerpc_operand
*operand
;
5630 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
5632 operand
= &powerpc_operands
[opindex
];
5635 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5636 does not generate a reloc. It uses the offset of `sym' within its
5637 csect. Other usages, such as `.long sym', generate relocs. This
5638 is the documented behaviour of non-TOC symbols. */
5639 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5640 && operand
->bits
== 16
5641 && operand
->shift
== 0
5642 && (operand
->insert
== NULL
|| ppc_obj64
)
5643 && fixP
->fx_addsy
!= NULL
5644 && symbol_get_tc (fixP
->fx_addsy
)->subseg
!= 0
5645 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC
5646 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC0
5647 && S_GET_SEGMENT (fixP
->fx_addsy
) != bss_section
)
5649 value
= fixP
->fx_offset
;
5654 /* Fetch the instruction, insert the fully resolved operand
5655 value, and stuff the instruction back again. */
5656 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5657 if (target_big_endian
)
5658 insn
= bfd_getb32 ((unsigned char *) where
);
5660 insn
= bfd_getl32 ((unsigned char *) where
);
5661 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
5662 fixP
->fx_file
, fixP
->fx_line
);
5663 if (target_big_endian
)
5664 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5666 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5669 /* Nothing else to do here. */
5672 assert (fixP
->fx_addsy
!= NULL
);
5674 /* Determine a BFD reloc value based on the operand information.
5675 We are only prepared to turn a few of the operands into
5677 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5678 && operand
->bits
== 26
5679 && operand
->shift
== 0)
5680 fixP
->fx_r_type
= BFD_RELOC_PPC_B26
;
5681 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5682 && operand
->bits
== 16
5683 && operand
->shift
== 0)
5685 fixP
->fx_r_type
= BFD_RELOC_PPC_B16
;
5688 if (target_big_endian
)
5689 fixP
->fx_where
+= 2;
5692 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5693 && operand
->bits
== 26
5694 && operand
->shift
== 0)
5695 fixP
->fx_r_type
= BFD_RELOC_PPC_BA26
;
5696 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5697 && operand
->bits
== 16
5698 && operand
->shift
== 0)
5700 fixP
->fx_r_type
= BFD_RELOC_PPC_BA16
;
5703 if (target_big_endian
)
5704 fixP
->fx_where
+= 2;
5707 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5708 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5709 && operand
->bits
== 16
5710 && operand
->shift
== 0)
5712 if (ppc_is_toc_sym (fixP
->fx_addsy
))
5714 fixP
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
5717 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5718 fixP
->fx_r_type
= BFD_RELOC_PPC64_TOC16_DS
;
5723 fixP
->fx_r_type
= BFD_RELOC_16
;
5726 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5727 fixP
->fx_r_type
= BFD_RELOC_PPC64_ADDR16_DS
;
5731 if (target_big_endian
)
5732 fixP
->fx_where
+= 2;
5734 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5740 /* Use expr_symbol_where to see if this is an expression
5742 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
5743 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5744 _("unresolved expression that must be resolved"));
5746 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5747 _("unsupported relocation against %s"),
5748 S_GET_NAME (fixP
->fx_addsy
));
5756 ppc_elf_validate_fix (fixP
, seg
);
5758 switch (fixP
->fx_r_type
)
5760 case BFD_RELOC_CTOR
:
5767 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
5771 case BFD_RELOC_32_PCREL
:
5772 case BFD_RELOC_PPC_EMB_NADDR32
:
5773 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5780 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
5783 case BFD_RELOC_64_PCREL
:
5784 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5788 case BFD_RELOC_GPREL16
:
5789 case BFD_RELOC_16_GOT_PCREL
:
5790 case BFD_RELOC_16_GOTOFF
:
5791 case BFD_RELOC_LO16_GOTOFF
:
5792 case BFD_RELOC_HI16_GOTOFF
:
5793 case BFD_RELOC_HI16_S_GOTOFF
:
5794 case BFD_RELOC_16_BASEREL
:
5795 case BFD_RELOC_LO16_BASEREL
:
5796 case BFD_RELOC_HI16_BASEREL
:
5797 case BFD_RELOC_HI16_S_BASEREL
:
5798 case BFD_RELOC_PPC_EMB_NADDR16
:
5799 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5800 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5801 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5802 case BFD_RELOC_PPC_EMB_SDAI16
:
5803 case BFD_RELOC_PPC_EMB_SDA2REL
:
5804 case BFD_RELOC_PPC_EMB_SDA2I16
:
5805 case BFD_RELOC_PPC_EMB_RELSEC16
:
5806 case BFD_RELOC_PPC_EMB_RELST_LO
:
5807 case BFD_RELOC_PPC_EMB_RELST_HI
:
5808 case BFD_RELOC_PPC_EMB_RELST_HA
:
5809 case BFD_RELOC_PPC_EMB_RELSDA
:
5810 case BFD_RELOC_PPC_TOC16
:
5812 case BFD_RELOC_PPC64_TOC16_LO
:
5813 case BFD_RELOC_PPC64_TOC16_HI
:
5814 case BFD_RELOC_PPC64_TOC16_HA
:
5818 if (fixP
->fx_addsy
!= NULL
)
5819 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5820 _("cannot emit PC relative %s relocation against %s"),
5821 bfd_get_reloc_code_name (fixP
->fx_r_type
),
5822 S_GET_NAME (fixP
->fx_addsy
));
5824 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5825 _("cannot emit PC relative %s relocation"),
5826 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5829 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5835 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
5838 case BFD_RELOC_16_PCREL
:
5839 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5843 case BFD_RELOC_LO16
:
5845 fixP
->fx_r_type
= BFD_RELOC_LO16_PCREL
;
5848 case BFD_RELOC_LO16_PCREL
:
5849 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5853 /* This case happens when you write, for example,
5855 where L1 and L2 are defined later. */
5856 case BFD_RELOC_HI16
:
5858 fixP
->fx_r_type
= BFD_RELOC_HI16_PCREL
;
5861 case BFD_RELOC_HI16_PCREL
:
5862 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5866 case BFD_RELOC_HI16_S
:
5868 fixP
->fx_r_type
= BFD_RELOC_HI16_S_PCREL
;
5871 case BFD_RELOC_HI16_S_PCREL
:
5872 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5877 case BFD_RELOC_PPC64_HIGHER
:
5880 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5881 PPC_HIGHER (value
), 2);
5884 case BFD_RELOC_PPC64_HIGHER_S
:
5887 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5888 PPC_HIGHERA (value
), 2);
5891 case BFD_RELOC_PPC64_HIGHEST
:
5894 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5895 PPC_HIGHEST (value
), 2);
5898 case BFD_RELOC_PPC64_HIGHEST_S
:
5901 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5902 PPC_HIGHESTA (value
), 2);
5905 case BFD_RELOC_PPC64_ADDR16_DS
:
5906 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
5907 case BFD_RELOC_PPC64_GOT16_DS
:
5908 case BFD_RELOC_PPC64_GOT16_LO_DS
:
5909 case BFD_RELOC_PPC64_PLT16_LO_DS
:
5910 case BFD_RELOC_PPC64_SECTOFF_DS
:
5911 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
5912 case BFD_RELOC_PPC64_TOC16_DS
:
5913 case BFD_RELOC_PPC64_TOC16_LO_DS
:
5914 case BFD_RELOC_PPC64_PLTGOT16_DS
:
5915 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
5919 char *where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5920 unsigned long val
, mask
;
5922 if (target_big_endian
)
5923 val
= bfd_getb32 (where
- 2);
5925 val
= bfd_getl32 (where
);
5927 /* lq insns reserve the four lsbs. */
5928 if ((ppc_cpu
& PPC_OPCODE_POWER4
) != 0
5929 && (val
& (0x3f << 26)) == (56u << 26))
5931 val
|= value
& mask
;
5932 if (target_big_endian
)
5933 bfd_putb16 ((bfd_vma
) val
, where
);
5935 bfd_putl16 ((bfd_vma
) val
, where
);
5939 case BFD_RELOC_PPC_B16_BRTAKEN
:
5940 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5941 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5942 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5945 case BFD_RELOC_PPC_TLS
:
5948 case BFD_RELOC_PPC_DTPMOD
:
5949 case BFD_RELOC_PPC_TPREL16
:
5950 case BFD_RELOC_PPC_TPREL16_LO
:
5951 case BFD_RELOC_PPC_TPREL16_HI
:
5952 case BFD_RELOC_PPC_TPREL16_HA
:
5953 case BFD_RELOC_PPC_TPREL
:
5954 case BFD_RELOC_PPC_DTPREL16
:
5955 case BFD_RELOC_PPC_DTPREL16_LO
:
5956 case BFD_RELOC_PPC_DTPREL16_HI
:
5957 case BFD_RELOC_PPC_DTPREL16_HA
:
5958 case BFD_RELOC_PPC_DTPREL
:
5959 case BFD_RELOC_PPC_GOT_TLSGD16
:
5960 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
5961 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
5962 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
5963 case BFD_RELOC_PPC_GOT_TLSLD16
:
5964 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
5965 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
5966 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
5967 case BFD_RELOC_PPC_GOT_TPREL16
:
5968 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
5969 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
5970 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
5971 case BFD_RELOC_PPC_GOT_DTPREL16
:
5972 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
5973 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
5974 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
5975 case BFD_RELOC_PPC64_TPREL16_DS
:
5976 case BFD_RELOC_PPC64_TPREL16_LO_DS
:
5977 case BFD_RELOC_PPC64_TPREL16_HIGHER
:
5978 case BFD_RELOC_PPC64_TPREL16_HIGHERA
:
5979 case BFD_RELOC_PPC64_TPREL16_HIGHEST
:
5980 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
:
5981 case BFD_RELOC_PPC64_DTPREL16_DS
:
5982 case BFD_RELOC_PPC64_DTPREL16_LO_DS
:
5983 case BFD_RELOC_PPC64_DTPREL16_HIGHER
:
5984 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
:
5985 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
:
5986 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
:
5987 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
5990 /* Because SDA21 modifies the register field, the size is set to 4
5991 bytes, rather than 2, so offset it here appropriately. */
5992 case BFD_RELOC_PPC_EMB_SDA21
:
5996 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
5997 + ((target_big_endian
) ? 2 : 0),
6004 /* This can occur if there is a bug in the input assembler, eg:
6005 ".byte <undefined_symbol> - ." */
6007 as_bad (_("Unable to handle reference to symbol %s"),
6008 S_GET_NAME (fixP
->fx_addsy
));
6010 as_bad (_("Unable to resolve expression"));
6014 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6018 case BFD_RELOC_24_PLT_PCREL
:
6019 case BFD_RELOC_PPC_LOCAL24PC
:
6020 if (!fixP
->fx_pcrel
&& !fixP
->fx_done
)
6028 /* Fetch the instruction, insert the fully resolved operand
6029 value, and stuff the instruction back again. */
6030 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
6031 if (target_big_endian
)
6032 insn
= bfd_getb32 ((unsigned char *) where
);
6034 insn
= bfd_getl32 ((unsigned char *) where
);
6035 if ((value
& 3) != 0)
6036 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6037 _("must branch to an address a multiple of 4"));
6038 if ((offsetT
) value
< -0x40000000
6039 || (offsetT
) value
>= 0x40000000)
6040 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6041 _("@local or @plt branch destination is too far away, %ld bytes"),
6043 insn
= insn
| (value
& 0x03fffffc);
6044 if (target_big_endian
)
6045 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
6047 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
6051 case BFD_RELOC_VTABLE_INHERIT
:
6054 && !S_IS_DEFINED (fixP
->fx_addsy
)
6055 && !S_IS_WEAK (fixP
->fx_addsy
))
6056 S_SET_WEAK (fixP
->fx_addsy
);
6059 case BFD_RELOC_VTABLE_ENTRY
:
6064 /* Generated by reference to `sym@tocbase'. The sym is
6065 ignored by the linker. */
6066 case BFD_RELOC_PPC64_TOC
:
6072 _("Gas failure, reloc value %d\n"), fixP
->fx_r_type
);
6079 fixP
->fx_addnumber
= value
;
6081 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6082 from the section contents. If we are going to be emitting a reloc
6083 then the section contents are immaterial, so don't warn if they
6084 happen to overflow. Leave such warnings to ld. */
6086 fixP
->fx_no_overflow
= 1;
6088 if (fixP
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
6089 fixP
->fx_addnumber
= 0;
6093 fixP
->fx_addnumber
= 0;
6095 /* We want to use the offset within the data segment of the
6096 symbol, not the actual VMA of the symbol. */
6097 fixP
->fx_addnumber
=
6098 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixP
->fx_addsy
));
6104 /* Generate a reloc for a fixup. */
6107 tc_gen_reloc (seg
, fixp
)
6108 asection
*seg ATTRIBUTE_UNUSED
;
6113 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
6115 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
6116 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
6117 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
6118 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
6119 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
6121 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6122 _("reloc %d not supported by object file format"),
6123 (int) fixp
->fx_r_type
);
6126 reloc
->addend
= fixp
->fx_addnumber
;
6132 ppc_cfi_frame_initial_instructions ()
6134 cfi_add_CFA_def_cfa (1, 0);
6138 tc_ppc_regname_to_dw2regnum (char *regname
)
6140 unsigned int regnum
= -1;
6144 static struct { char *name
; int dw2regnum
; } regnames
[] =
6146 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6147 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6148 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6149 { "spe_acc", 111 }, { "spefscr", 112 }
6152 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
6153 if (strcmp (regnames
[i
].name
, regname
) == 0)
6154 return regnames
[i
].dw2regnum
;
6156 if (regname
[0] == 'r' || regname
[0] == 'f' || regname
[0] == 'v')
6158 p
= regname
+ 1 + (regname
[1] == '.');
6159 regnum
= strtoul (p
, &q
, 10);
6160 if (p
== q
|| *q
|| regnum
>= 32)
6162 if (regname
[0] == 'f')
6164 else if (regname
[0] == 'v')
6167 else if (regname
[0] == 'c' && regname
[1] == 'r')
6169 p
= regname
+ 2 + (regname
[2] == '.');
6170 if (p
[0] < '0' || p
[0] > '7' || p
[1])
6172 regnum
= p
[0] - '0' + 68;