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 /* -mcom means assemble for the common intersection between Power
924 and PowerPC. At present, we just allow the union, rather
925 than the intersection. */
926 else if (strcmp (arg
, "com") == 0)
927 ppc_cpu
= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
928 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
929 else if (strcmp (arg
, "any") == 0)
930 ppc_cpu
|= PPC_OPCODE_ANY
;
938 md_parse_option (c
, arg
)
945 /* -u means that any undefined symbols should be treated as
946 external, which is the default for gas anyhow. */
951 /* Solaris as takes -le (presumably for little endian). For completeness
952 sake, recognize -be also. */
953 if (strcmp (arg
, "e") == 0)
955 target_big_endian
= 0;
956 set_target_endian
= 1;
964 if (strcmp (arg
, "e") == 0)
966 target_big_endian
= 1;
967 set_target_endian
= 1;
975 /* Recognize -K PIC. */
976 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
979 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
987 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
989 if (strcmp (arg
, "64") == 0)
994 as_fatal (_("%s unsupported"), "-a64");
997 else if (strcmp (arg
, "32") == 0)
1004 if (parse_cpu (arg
))
1007 else if (strcmp (arg
, "regnames") == 0)
1010 else if (strcmp (arg
, "no-regnames") == 0)
1011 reg_names_p
= FALSE
;
1014 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1015 that require relocation. */
1016 else if (strcmp (arg
, "relocatable") == 0)
1018 shlib
= SHLIB_MRELOCATABLE
;
1019 ppc_flags
|= EF_PPC_RELOCATABLE
;
1022 else if (strcmp (arg
, "relocatable-lib") == 0)
1024 shlib
= SHLIB_MRELOCATABLE
;
1025 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
1028 /* -memb, set embedded bit. */
1029 else if (strcmp (arg
, "emb") == 0)
1030 ppc_flags
|= EF_PPC_EMB
;
1032 /* -mlittle/-mbig set the endianess. */
1033 else if (strcmp (arg
, "little") == 0
1034 || strcmp (arg
, "little-endian") == 0)
1036 target_big_endian
= 0;
1037 set_target_endian
= 1;
1040 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
1042 target_big_endian
= 1;
1043 set_target_endian
= 1;
1046 else if (strcmp (arg
, "solaris") == 0)
1049 ppc_comment_chars
= ppc_solaris_comment_chars
;
1052 else if (strcmp (arg
, "no-solaris") == 0)
1055 ppc_comment_chars
= ppc_eabi_comment_chars
;
1060 as_bad (_("invalid switch -m%s"), arg
);
1066 /* -V: SVR4 argument to print version ID. */
1068 print_version_id ();
1071 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1072 should be emitted or not. FIXME: Not implemented. */
1076 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1077 rather than .stabs.excl, which is ignored by the linker.
1078 FIXME: Not implemented. */
1094 md_show_usage (stream
)
1097 fprintf (stream
, _("\
1099 -a32 generate ELF32/XCOFF32\n\
1100 -a64 generate ELF64/XCOFF64\n\
1102 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1103 -mpwr generate code for POWER (RIOS1)\n\
1104 -m601 generate code for PowerPC 601\n\
1105 -mppc, -mppc32, -m603, -m604\n\
1106 generate code for PowerPC 603/604\n\
1107 -m403, -m405 generate code for PowerPC 403/405\n\
1108 -m440 generate code for PowerPC 440\n\
1109 -m7400, -m7410, -m7450, -m7455\n\
1110 generate code For PowerPC 7400/7410/7450/7455\n"));
1111 fprintf (stream
, _("\
1112 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1113 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1114 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1115 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1116 -mpower4 generate code for Power4 architecture\n\
1117 -mpower5 generate code for Power5 architecture\n\
1118 -mpower6 generate code for Power6 architecture\n\
1119 -mcom generate code Power/PowerPC common instructions\n\
1120 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1121 fprintf (stream
, _("\
1122 -maltivec generate code for AltiVec\n\
1123 -me300 generate code for PowerPC e300 family\n\
1124 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1125 -mspe generate code for Motorola SPE instructions\n\
1126 -mregnames Allow symbolic names for registers\n\
1127 -mno-regnames Do not allow symbolic names for registers\n"));
1129 fprintf (stream
, _("\
1130 -mrelocatable support for GCC's -mrelocatble option\n\
1131 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1132 -memb set PPC_EMB bit in ELF flags\n\
1133 -mlittle, -mlittle-endian, -l, -le\n\
1134 generate code for a little endian machine\n\
1135 -mbig, -mbig-endian, -b, -be\n\
1136 generate code for a big endian machine\n\
1137 -msolaris generate code for Solaris\n\
1138 -mno-solaris do not generate code for Solaris\n\
1139 -V print assembler version number\n\
1140 -Qy, -Qn ignored\n"));
1144 /* Set ppc_cpu if it is not already set. */
1149 const char *default_os
= TARGET_OS
;
1150 const char *default_cpu
= TARGET_CPU
;
1152 if ((ppc_cpu
& ~PPC_OPCODE_ANY
) == 0)
1155 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
1156 else if (strncmp (default_os
, "aix", 3) == 0
1157 && default_os
[3] >= '4' && default_os
[3] <= '9')
1158 ppc_cpu
|= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
1159 else if (strncmp (default_os
, "aix3", 4) == 0)
1160 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1161 else if (strcmp (default_cpu
, "rs6000") == 0)
1162 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1163 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1164 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
1166 as_fatal (_("Unknown default cpu = %s, os = %s"),
1167 default_cpu
, default_os
);
1171 /* Figure out the BFD architecture to use. This function and ppc_mach
1172 are called well before md_begin, when the output file is opened. */
1174 enum bfd_architecture
1177 const char *default_cpu
= TARGET_CPU
;
1180 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1181 return bfd_arch_powerpc
;
1182 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1183 return bfd_arch_rs6000
;
1184 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1186 if (strcmp (default_cpu
, "rs6000") == 0)
1187 return bfd_arch_rs6000
;
1188 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1189 return bfd_arch_powerpc
;
1192 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1193 return bfd_arch_unknown
;
1200 return bfd_mach_ppc64
;
1201 else if (ppc_arch () == bfd_arch_rs6000
)
1202 return bfd_mach_rs6k
;
1204 return bfd_mach_ppc
;
1208 ppc_target_format ()
1212 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1214 return "xcoff-powermac";
1217 return (ppc_obj64
? "aix5coff64-rs6000" : "aixcoff-rs6000");
1219 return (ppc_obj64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1225 return "elf32-powerpc-vxworks";
1227 return (target_big_endian
1228 ? (ppc_obj64
? "elf64-powerpc" : "elf32-powerpc")
1229 : (ppc_obj64
? "elf64-powerpcle" : "elf32-powerpcle"));
1234 /* Insert opcodes and macros into hash tables. Called at startup and
1238 ppc_setup_opcodes (void)
1240 register const struct powerpc_opcode
*op
;
1241 const struct powerpc_opcode
*op_end
;
1242 const struct powerpc_macro
*macro
;
1243 const struct powerpc_macro
*macro_end
;
1244 bfd_boolean dup_insn
= FALSE
;
1246 if (ppc_hash
!= NULL
)
1247 hash_die (ppc_hash
);
1248 if (ppc_macro_hash
!= NULL
)
1249 hash_die (ppc_macro_hash
);
1251 /* Insert the opcodes into a hash table. */
1252 ppc_hash
= hash_new ();
1254 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1255 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1257 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1259 if ((op
->flags
& ppc_cpu
& ~(PPC_OPCODE_32
| PPC_OPCODE_64
)) != 0
1260 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1261 || ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
))
1262 == (ppc_cpu
& (PPC_OPCODE_32
| PPC_OPCODE_64
)))
1263 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0)
1264 /* Certain instructions (eg: extsw) do not exist in the
1265 32-bit BookE instruction set, but they do exist in the
1266 64-bit BookE instruction set, and other PPC instruction
1267 sets. Check to see if the opcode has the BOOKE64 flag set.
1268 If it does make sure that the target CPU is not the BookE32. */
1269 && ((op
->flags
& PPC_OPCODE_BOOKE64
) == 0
1270 || (ppc_cpu
& PPC_OPCODE_BOOKE64
) == PPC_OPCODE_BOOKE64
1271 || (ppc_cpu
& PPC_OPCODE_BOOKE
) == 0)
1272 && ((op
->flags
& (PPC_OPCODE_POWER4
| PPC_OPCODE_NOPOWER4
)) == 0
1273 || ((op
->flags
& PPC_OPCODE_POWER4
)
1274 == (ppc_cpu
& PPC_OPCODE_POWER4
)))
1275 && ((op
->flags
& PPC_OPCODE_POWER5
) == 0
1276 || ((op
->flags
& PPC_OPCODE_POWER5
)
1277 == (ppc_cpu
& PPC_OPCODE_POWER5
)))
1278 && ((op
->flags
& PPC_OPCODE_POWER6
) == 0
1279 || ((op
->flags
& PPC_OPCODE_POWER6
)
1280 == (ppc_cpu
& PPC_OPCODE_POWER6
))))
1284 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1287 /* Ignore Power duplicates for -m601. */
1288 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1289 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1292 as_bad (_("Internal assembler error for instruction %s"),
1299 if ((ppc_cpu
& PPC_OPCODE_ANY
) != 0)
1300 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1301 hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1303 /* Insert the macros into a hash table. */
1304 ppc_macro_hash
= hash_new ();
1306 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1307 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1309 if ((macro
->flags
& ppc_cpu
) != 0)
1313 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1314 if (retval
!= (const char *) NULL
)
1316 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1326 /* This function is called when the assembler starts up. It is called
1327 after the options have been parsed and the output file has been
1335 ppc_cie_data_alignment
= ppc_obj64
? -8 : -4;
1338 /* Set the ELF flags if desired. */
1339 if (ppc_flags
&& !msolaris
)
1340 bfd_set_private_flags (stdoutput
, ppc_flags
);
1343 ppc_setup_opcodes ();
1345 /* Tell the main code what the endianness is if it is not overridden
1347 if (!set_target_endian
)
1349 set_target_endian
= 1;
1350 target_big_endian
= PPC_BIG_ENDIAN
;
1354 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1356 /* Create dummy symbols to serve as initial csects. This forces the
1357 text csects to precede the data csects. These symbols will not
1359 ppc_text_csects
= symbol_make ("dummy\001");
1360 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1361 ppc_data_csects
= symbol_make ("dummy\001");
1362 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1367 ppc_current_section
= text_section
;
1368 ppc_previous_section
= 0;
1377 if (ppc_apuinfo_list
== NULL
)
1380 /* Ok, so write the section info out. We have this layout:
1384 0 8 length of "APUinfo\0"
1385 4 (n*4) number of APU's (4 bytes each)
1388 20 APU#1 first APU's info
1389 24 APU#2 second APU's info
1394 asection
*seg
= now_seg
;
1395 subsegT subseg
= now_subseg
;
1396 asection
*apuinfo_secp
= (asection
*) NULL
;
1399 /* Create the .PPC.EMB.apuinfo section. */
1400 apuinfo_secp
= subseg_new (".PPC.EMB.apuinfo", 0);
1401 bfd_set_section_flags (stdoutput
,
1403 SEC_HAS_CONTENTS
| SEC_READONLY
);
1406 md_number_to_chars (p
, (valueT
) 8, 4);
1409 md_number_to_chars (p
, (valueT
) ppc_apuinfo_num
* 4, 4);
1412 md_number_to_chars (p
, (valueT
) 2, 4);
1415 strcpy (p
, "APUinfo");
1417 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
1420 md_number_to_chars (p
, (valueT
) ppc_apuinfo_list
[i
], 4);
1423 frag_align (2, 0, 0);
1425 /* We probably can't restore the current segment, for there likely
1428 subseg_set (seg
, subseg
);
1433 /* Insert an operand value into an instruction. */
1435 static unsigned long
1436 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1438 const struct powerpc_operand
*operand
;
1443 if (operand
->bits
!= 32)
1448 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1450 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1451 max
= (1 << operand
->bits
) - 1;
1453 max
= (1 << (operand
->bits
- 1)) - 1;
1454 min
= - (1 << (operand
->bits
- 1));
1458 /* Some people write 32 bit hex constants with the sign
1459 extension done by hand. This shouldn't really be
1460 valid, but, to permit this code to assemble on a 64
1461 bit host, we sign extend the 32 bit value. */
1463 && (val
& (offsetT
) 0x80000000) != 0
1464 && (val
& (offsetT
) 0xffffffff) == val
)
1473 max
= (1 << operand
->bits
) - 1;
1477 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1482 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1483 as_bad_value_out_of_range (_("operand"), test
, (offsetT
) min
, (offsetT
) max
, file
, line
);
1486 if (operand
->insert
)
1491 insn
= (*operand
->insert
) (insn
, (long) val
, ppc_cpu
, &errmsg
);
1492 if (errmsg
!= (const char *) NULL
)
1493 as_bad_where (file
, line
, errmsg
);
1496 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1504 /* Parse @got, etc. and return the desired relocation. */
1505 static bfd_reloc_code_real_type
1506 ppc_elf_suffix (str_p
, exp_p
)
1512 unsigned int length
: 8;
1513 unsigned int valid32
: 1;
1514 unsigned int valid64
: 1;
1523 const struct map_bfd
*ptr
;
1525 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
1526 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
1527 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
1529 static const struct map_bfd mapping
[] = {
1530 MAP ("l", BFD_RELOC_LO16
),
1531 MAP ("h", BFD_RELOC_HI16
),
1532 MAP ("ha", BFD_RELOC_HI16_S
),
1533 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1534 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1535 MAP ("got", BFD_RELOC_16_GOTOFF
),
1536 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1537 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1538 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1539 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1540 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1541 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1542 MAP ("copy", BFD_RELOC_PPC_COPY
),
1543 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1544 MAP ("sectoff", BFD_RELOC_16_BASEREL
),
1545 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1546 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1547 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1548 MAP ("tls", BFD_RELOC_PPC_TLS
),
1549 MAP ("dtpmod", BFD_RELOC_PPC_DTPMOD
),
1550 MAP ("dtprel", BFD_RELOC_PPC_DTPREL
),
1551 MAP ("dtprel@l", BFD_RELOC_PPC_DTPREL16_LO
),
1552 MAP ("dtprel@h", BFD_RELOC_PPC_DTPREL16_HI
),
1553 MAP ("dtprel@ha", BFD_RELOC_PPC_DTPREL16_HA
),
1554 MAP ("tprel", BFD_RELOC_PPC_TPREL
),
1555 MAP ("tprel@l", BFD_RELOC_PPC_TPREL16_LO
),
1556 MAP ("tprel@h", BFD_RELOC_PPC_TPREL16_HI
),
1557 MAP ("tprel@ha", BFD_RELOC_PPC_TPREL16_HA
),
1558 MAP ("got@tlsgd", BFD_RELOC_PPC_GOT_TLSGD16
),
1559 MAP ("got@tlsgd@l", BFD_RELOC_PPC_GOT_TLSGD16_LO
),
1560 MAP ("got@tlsgd@h", BFD_RELOC_PPC_GOT_TLSGD16_HI
),
1561 MAP ("got@tlsgd@ha", BFD_RELOC_PPC_GOT_TLSGD16_HA
),
1562 MAP ("got@tlsld", BFD_RELOC_PPC_GOT_TLSLD16
),
1563 MAP ("got@tlsld@l", BFD_RELOC_PPC_GOT_TLSLD16_LO
),
1564 MAP ("got@tlsld@h", BFD_RELOC_PPC_GOT_TLSLD16_HI
),
1565 MAP ("got@tlsld@ha", BFD_RELOC_PPC_GOT_TLSLD16_HA
),
1566 MAP ("got@dtprel", BFD_RELOC_PPC_GOT_DTPREL16
),
1567 MAP ("got@dtprel@l", BFD_RELOC_PPC_GOT_DTPREL16_LO
),
1568 MAP ("got@dtprel@h", BFD_RELOC_PPC_GOT_DTPREL16_HI
),
1569 MAP ("got@dtprel@ha", BFD_RELOC_PPC_GOT_DTPREL16_HA
),
1570 MAP ("got@tprel", BFD_RELOC_PPC_GOT_TPREL16
),
1571 MAP ("got@tprel@l", BFD_RELOC_PPC_GOT_TPREL16_LO
),
1572 MAP ("got@tprel@h", BFD_RELOC_PPC_GOT_TPREL16_HI
),
1573 MAP ("got@tprel@ha", BFD_RELOC_PPC_GOT_TPREL16_HA
),
1574 MAP32 ("fixup", BFD_RELOC_CTOR
),
1575 MAP32 ("plt", BFD_RELOC_24_PLT_PCREL
),
1576 MAP32 ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1577 MAP32 ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1578 MAP32 ("local", BFD_RELOC_PPC_LOCAL24PC
),
1579 MAP32 ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1580 MAP32 ("sdarel", BFD_RELOC_GPREL16
),
1581 MAP32 ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1582 MAP32 ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1583 MAP32 ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1584 MAP32 ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1585 MAP32 ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1586 MAP32 ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1587 MAP32 ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1588 MAP32 ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1589 MAP32 ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1590 MAP32 ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1591 MAP32 ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1592 MAP32 ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1593 MAP32 ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1594 MAP32 ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1595 MAP32 ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1596 MAP32 ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1597 MAP32 ("xgot", BFD_RELOC_PPC_TOC16
),
1598 MAP64 ("higher", BFD_RELOC_PPC64_HIGHER
),
1599 MAP64 ("highera", BFD_RELOC_PPC64_HIGHER_S
),
1600 MAP64 ("highest", BFD_RELOC_PPC64_HIGHEST
),
1601 MAP64 ("highesta", BFD_RELOC_PPC64_HIGHEST_S
),
1602 MAP64 ("tocbase", BFD_RELOC_PPC64_TOC
),
1603 MAP64 ("toc", BFD_RELOC_PPC_TOC16
),
1604 MAP64 ("toc@l", BFD_RELOC_PPC64_TOC16_LO
),
1605 MAP64 ("toc@h", BFD_RELOC_PPC64_TOC16_HI
),
1606 MAP64 ("toc@ha", BFD_RELOC_PPC64_TOC16_HA
),
1607 MAP64 ("dtprel@higher", BFD_RELOC_PPC64_DTPREL16_HIGHER
),
1608 MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA
),
1609 MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST
),
1610 MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA
),
1611 MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER
),
1612 MAP64 ("tprel@highera", BFD_RELOC_PPC64_TPREL16_HIGHERA
),
1613 MAP64 ("tprel@highest", BFD_RELOC_PPC64_TPREL16_HIGHEST
),
1614 MAP64 ("tprel@highesta", BFD_RELOC_PPC64_TPREL16_HIGHESTA
),
1615 { (char *) 0, 0, 0, 0, BFD_RELOC_UNUSED
}
1619 return BFD_RELOC_UNUSED
;
1621 for (ch
= *str
, str2
= ident
;
1622 (str2
< ident
+ sizeof (ident
) - 1
1623 && (ISALNUM (ch
) || ch
== '@'));
1626 *str2
++ = TOLOWER (ch
);
1633 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1634 if (ch
== ptr
->string
[0]
1635 && len
== ptr
->length
1636 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0
1637 && (ppc_obj64
? ptr
->valid64
: ptr
->valid32
))
1639 int reloc
= ptr
->reloc
;
1642 if (exp_p
->X_add_number
!= 0
1643 && (reloc
== (int) BFD_RELOC_16_GOTOFF
1644 || reloc
== (int) BFD_RELOC_LO16_GOTOFF
1645 || reloc
== (int) BFD_RELOC_HI16_GOTOFF
1646 || reloc
== (int) BFD_RELOC_HI16_S_GOTOFF
))
1647 as_warn (_("identifier+constant@got means identifier@got+constant"));
1649 /* Now check for identifier@suffix+constant. */
1650 if (*str
== '-' || *str
== '+')
1652 char *orig_line
= input_line_pointer
;
1653 expressionS new_exp
;
1655 input_line_pointer
= str
;
1656 expression (&new_exp
);
1657 if (new_exp
.X_op
== O_constant
)
1659 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1660 str
= input_line_pointer
;
1663 if (&input_line_pointer
!= str_p
)
1664 input_line_pointer
= orig_line
;
1668 if (reloc
== (int) BFD_RELOC_PPC64_TOC
1669 && exp_p
->X_op
== O_symbol
1670 && strcmp (S_GET_NAME (exp_p
->X_add_symbol
), ".TOC.") == 0)
1672 /* Change the symbol so that the dummy .TOC. symbol can be
1673 omitted from the object file. */
1674 exp_p
->X_add_symbol
= &abs_symbol
;
1677 return (bfd_reloc_code_real_type
) reloc
;
1680 return BFD_RELOC_UNUSED
;
1683 /* Like normal .long/.short/.word, except support @got, etc.
1684 Clobbers input_line_pointer, checks end-of-line. */
1686 ppc_elf_cons (nbytes
)
1687 register int nbytes
; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1690 bfd_reloc_code_real_type reloc
;
1692 if (is_it_end_of_statement ())
1694 demand_empty_rest_of_line ();
1701 if (exp
.X_op
== O_symbol
1702 && *input_line_pointer
== '@'
1703 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1704 &exp
)) != BFD_RELOC_UNUSED
)
1706 reloc_howto_type
*reloc_howto
;
1709 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1710 size
= bfd_get_reloc_size (reloc_howto
);
1714 as_bad (_("%s relocations do not fit in %d bytes\n"),
1715 reloc_howto
->name
, nbytes
);
1722 p
= frag_more (nbytes
);
1724 if (target_big_endian
)
1725 offset
= nbytes
- size
;
1726 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1731 emit_expr (&exp
, (unsigned int) nbytes
);
1733 while (*input_line_pointer
++ == ',');
1735 /* Put terminator back into stream. */
1736 input_line_pointer
--;
1737 demand_empty_rest_of_line ();
1740 /* Solaris pseduo op to change to the .rodata section. */
1745 char *save_line
= input_line_pointer
;
1746 static char section
[] = ".rodata\n";
1748 /* Just pretend this is .section .rodata */
1749 input_line_pointer
= section
;
1750 obj_elf_section (xxx
);
1752 input_line_pointer
= save_line
;
1755 /* Pseudo op to make file scope bss items. */
1758 int xxx ATTRIBUTE_UNUSED
;
1760 register char *name
;
1764 register symbolS
*symbolP
;
1771 name
= input_line_pointer
;
1772 c
= get_symbol_end ();
1774 /* just after name is now '\0'. */
1775 p
= input_line_pointer
;
1778 if (*input_line_pointer
!= ',')
1780 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1781 ignore_rest_of_line ();
1785 input_line_pointer
++; /* skip ',' */
1786 if ((size
= get_absolute_expression ()) < 0)
1788 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1789 ignore_rest_of_line ();
1793 /* The third argument to .lcomm is the alignment. */
1794 if (*input_line_pointer
!= ',')
1798 ++input_line_pointer
;
1799 align
= get_absolute_expression ();
1802 as_warn (_("ignoring bad alignment"));
1808 symbolP
= symbol_find_or_make (name
);
1811 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1813 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1814 S_GET_NAME (symbolP
));
1815 ignore_rest_of_line ();
1819 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1821 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1822 S_GET_NAME (symbolP
),
1823 (long) S_GET_VALUE (symbolP
),
1826 ignore_rest_of_line ();
1832 old_subsec
= now_subseg
;
1835 /* Convert to a power of 2 alignment. */
1836 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1839 as_bad (_("Common alignment not a power of 2"));
1840 ignore_rest_of_line ();
1847 record_alignment (bss_section
, align2
);
1848 subseg_set (bss_section
, 0);
1850 frag_align (align2
, 0, 0);
1851 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1852 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1853 symbol_set_frag (symbolP
, frag_now
);
1854 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1857 S_SET_SIZE (symbolP
, size
);
1858 S_SET_SEGMENT (symbolP
, bss_section
);
1859 subseg_set (old_sec
, old_subsec
);
1860 demand_empty_rest_of_line ();
1863 /* Validate any relocations emitted for -mrelocatable, possibly adding
1864 fixups for word relocations in writable segments, so we can adjust
1867 ppc_elf_validate_fix (fixp
, seg
)
1871 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1880 case SHLIB_MRELOCATABLE
:
1881 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1882 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1883 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1884 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1885 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1886 && fixp
->fx_r_type
!= BFD_RELOC_16_BASEREL
1887 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1888 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1889 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1890 && (seg
->flags
& SEC_LOAD
) != 0
1891 && strcmp (segment_name (seg
), ".got2") != 0
1892 && strcmp (segment_name (seg
), ".dtors") != 0
1893 && strcmp (segment_name (seg
), ".ctors") != 0
1894 && strcmp (segment_name (seg
), ".fixup") != 0
1895 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1896 && strcmp (segment_name (seg
), ".eh_frame") != 0
1897 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1899 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1900 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1902 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1903 _("Relocation cannot be done when using -mrelocatable"));
1910 /* Prevent elf_frob_file_before_adjust removing a weak undefined
1911 function descriptor sym if the corresponding code sym is used. */
1914 ppc_frob_file_before_adjust ()
1922 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1929 name
= S_GET_NAME (symp
);
1933 if (! S_IS_WEAK (symp
)
1934 || S_IS_DEFINED (symp
))
1937 len
= strlen (name
) + 1;
1938 dotname
= xmalloc (len
+ 1);
1940 memcpy (dotname
+ 1, name
, len
);
1941 dotsym
= symbol_find_noref (dotname
, 1);
1943 if (dotsym
!= NULL
&& (symbol_used_p (dotsym
)
1944 || symbol_used_in_reloc_p (dotsym
)))
1945 symbol_mark_used (symp
);
1949 toc
= bfd_get_section_by_name (stdoutput
, ".toc");
1951 && bfd_section_size (stdoutput
, toc
) > 0x10000)
1952 as_warn (_("TOC section size exceeds 64k"));
1954 /* Don't emit .TOC. symbol. */
1955 symp
= symbol_find (".TOC.");
1957 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1959 #endif /* OBJ_ELF */
1964 * Summary of parse_toc_entry.
1966 * in: Input_line_pointer points to the '[' in one of:
1968 * [toc] [tocv] [toc32] [toc64]
1970 * Anything else is an error of one kind or another.
1973 * return value: success or failure
1974 * toc_kind: kind of toc reference
1975 * input_line_pointer:
1976 * success: first char after the ']'
1977 * failure: unchanged
1981 * [toc] - rv == success, toc_kind = default_toc
1982 * [tocv] - rv == success, toc_kind = data_in_toc
1983 * [toc32] - rv == success, toc_kind = must_be_32
1984 * [toc64] - rv == success, toc_kind = must_be_64
1988 enum toc_size_qualifier
1990 default_toc
, /* The toc cell constructed should be the system default size */
1991 data_in_toc
, /* This is a direct reference to a toc cell */
1992 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1993 must_be_64
/* The toc cell constructed must be 64 bits wide */
1997 parse_toc_entry (toc_kind
)
1998 enum toc_size_qualifier
*toc_kind
;
2003 enum toc_size_qualifier t
;
2005 /* Save the input_line_pointer. */
2006 start
= input_line_pointer
;
2008 /* Skip over the '[' , and whitespace. */
2009 ++input_line_pointer
;
2012 /* Find the spelling of the operand. */
2013 toc_spec
= input_line_pointer
;
2014 c
= get_symbol_end ();
2016 if (strcmp (toc_spec
, "toc") == 0)
2020 else if (strcmp (toc_spec
, "tocv") == 0)
2024 else if (strcmp (toc_spec
, "toc32") == 0)
2028 else if (strcmp (toc_spec
, "toc64") == 0)
2034 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
2035 *input_line_pointer
= c
;
2036 input_line_pointer
= start
;
2040 /* Now find the ']'. */
2041 *input_line_pointer
= c
;
2043 SKIP_WHITESPACE (); /* leading whitespace could be there. */
2044 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
2048 as_bad (_("syntax error: expected `]', found `%c'"), c
);
2049 input_line_pointer
= start
;
2060 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2062 ppc_apuinfo_section_add (apu
, version
)
2063 unsigned int apu
, version
;
2067 /* Check we don't already exist. */
2068 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
2069 if (ppc_apuinfo_list
[i
] == APUID (apu
, version
))
2072 if (ppc_apuinfo_num
== ppc_apuinfo_num_alloc
)
2074 if (ppc_apuinfo_num_alloc
== 0)
2076 ppc_apuinfo_num_alloc
= 4;
2077 ppc_apuinfo_list
= (unsigned long *)
2078 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2082 ppc_apuinfo_num_alloc
+= 4;
2083 ppc_apuinfo_list
= (unsigned long *) xrealloc (ppc_apuinfo_list
,
2084 sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2087 ppc_apuinfo_list
[ppc_apuinfo_num
++] = APUID (apu
, version
);
2093 /* We need to keep a list of fixups. We can't simply generate them as
2094 we go, because that would require us to first create the frag, and
2095 that would screw up references to ``.''. */
2101 bfd_reloc_code_real_type reloc
;
2104 #define MAX_INSN_FIXUPS (5)
2106 /* This routine is called for each instruction to be assembled. */
2113 const struct powerpc_opcode
*opcode
;
2115 const unsigned char *opindex_ptr
;
2119 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
2125 bfd_reloc_code_real_type reloc
;
2128 /* Get the opcode. */
2129 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
2134 /* Look up the opcode in the hash table. */
2135 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
2136 if (opcode
== (const struct powerpc_opcode
*) NULL
)
2138 const struct powerpc_macro
*macro
;
2140 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
2141 if (macro
== (const struct powerpc_macro
*) NULL
)
2142 as_bad (_("Unrecognized opcode: `%s'"), str
);
2144 ppc_macro (s
, macro
);
2149 insn
= opcode
->opcode
;
2152 while (ISSPACE (*str
))
2155 /* PowerPC operands are just expressions. The only real issue is
2156 that a few operand types are optional. All cases which might use
2157 an optional operand separate the operands only with commas (in some
2158 cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2159 have optional operands). Most instructions with optional operands
2160 have only one. Those that have more than one optional operand can
2161 take either all their operands or none. So, before we start seriously
2162 parsing the operands, we check to see if we have optional operands,
2163 and if we do, we count the number of commas to see which operands
2164 have been omitted. */
2166 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2168 const struct powerpc_operand
*operand
;
2170 operand
= &powerpc_operands
[*opindex_ptr
];
2171 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
2173 unsigned int opcount
;
2174 unsigned int num_operands_expected
;
2177 /* There is an optional operand. Count the number of
2178 commas in the input line. */
2185 while ((s
= strchr (s
, ',')) != (char *) NULL
)
2192 /* Compute the number of expected operands.
2193 Do not count fake operands. */
2194 for (num_operands_expected
= 0, i
= 0; opcode
->operands
[i
]; i
++)
2195 if ((powerpc_operands
[opcode
->operands
[i
]].flags
& PPC_OPERAND_FAKE
) == 0)
2196 ++ num_operands_expected
;
2198 /* If there are fewer operands in the line then are called
2199 for by the instruction, we want to skip the optional
2201 if (opcount
< num_operands_expected
)
2208 /* Gather the operands. */
2212 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2214 const struct powerpc_operand
*operand
;
2220 if (next_opindex
== 0)
2221 operand
= &powerpc_operands
[*opindex_ptr
];
2224 operand
= &powerpc_operands
[next_opindex
];
2229 /* If this is a fake operand, then we do not expect anything
2231 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
2233 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2234 if (errmsg
!= (const char *) NULL
)
2239 /* If this is an optional operand, and we are skipping it, just
2241 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
2244 if (operand
->insert
)
2246 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2247 if (errmsg
!= (const char *) NULL
)
2250 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
2251 next_opindex
= *opindex_ptr
+ 1;
2255 /* Gather the operand. */
2256 hold
= input_line_pointer
;
2257 input_line_pointer
= str
;
2260 if (*input_line_pointer
== '[')
2262 /* We are expecting something like the second argument here:
2264 * lwz r4,[toc].GS.0.static_int(rtoc)
2265 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2266 * The argument following the `]' must be a symbol name, and the
2267 * register must be the toc register: 'rtoc' or '2'
2269 * The effect is to 0 as the displacement field
2270 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2271 * the appropriate variation) reloc against it based on the symbol.
2272 * The linker will build the toc, and insert the resolved toc offset.
2275 * o The size of the toc entry is currently assumed to be
2276 * 32 bits. This should not be assumed to be a hard coded
2278 * o In an effort to cope with a change from 32 to 64 bits,
2279 * there are also toc entries that are specified to be
2280 * either 32 or 64 bits:
2281 * lwz r4,[toc32].GS.0.static_int(rtoc)
2282 * lwz r4,[toc64].GS.0.static_int(rtoc)
2283 * These demand toc entries of the specified size, and the
2284 * instruction probably requires it.
2288 enum toc_size_qualifier toc_kind
;
2289 bfd_reloc_code_real_type toc_reloc
;
2291 /* Go parse off the [tocXX] part. */
2292 valid_toc
= parse_toc_entry (&toc_kind
);
2296 /* Note: message has already been issued.
2297 FIXME: what sort of recovery should we do?
2298 demand_rest_of_line (); return; ? */
2301 /* Now get the symbol following the ']'. */
2307 /* In this case, we may not have seen the symbol yet,
2308 since it is allowed to appear on a .extern or .globl
2309 or just be a label in the .data section. */
2310 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2313 /* 1. The symbol must be defined and either in the toc
2314 section, or a global.
2315 2. The reloc generated must have the TOCDEFN flag set
2316 in upper bit mess of the reloc type.
2317 FIXME: It's a little confusing what the tocv
2318 qualifier can be used for. At the very least, I've
2319 seen three uses, only one of which I'm sure I can
2321 if (ex
.X_op
== O_symbol
)
2323 assert (ex
.X_add_symbol
!= NULL
);
2324 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2327 as_bad (_("[tocv] symbol is not a toc symbol"));
2331 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2334 /* FIXME: these next two specifically specify 32/64 bit
2335 toc entries. We don't support them today. Is this
2336 the right way to say that? */
2337 toc_reloc
= BFD_RELOC_UNUSED
;
2338 as_bad (_("Unimplemented toc32 expression modifier"));
2341 /* FIXME: see above. */
2342 toc_reloc
= BFD_RELOC_UNUSED
;
2343 as_bad (_("Unimplemented toc64 expression modifier"));
2347 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2353 /* We need to generate a fixup for this expression. */
2354 if (fc
>= MAX_INSN_FIXUPS
)
2355 as_fatal (_("too many fixups"));
2357 fixups
[fc
].reloc
= toc_reloc
;
2358 fixups
[fc
].exp
= ex
;
2359 fixups
[fc
].opindex
= *opindex_ptr
;
2362 /* Ok. We've set up the fixup for the instruction. Now make it
2363 look like the constant 0 was found here. */
2365 ex
.X_op
= O_constant
;
2366 ex
.X_add_number
= 0;
2367 ex
.X_add_symbol
= NULL
;
2368 ex
.X_op_symbol
= NULL
;
2374 if (! register_name (&ex
))
2376 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
2383 str
= input_line_pointer
;
2384 input_line_pointer
= hold
;
2386 if (ex
.X_op
== O_illegal
)
2387 as_bad (_("illegal operand"));
2388 else if (ex
.X_op
== O_absent
)
2389 as_bad (_("missing operand"));
2390 else if (ex
.X_op
== O_register
)
2392 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2395 else if (ex
.X_op
== O_constant
)
2398 /* Allow @HA, @L, @H on constants. */
2399 char *orig_str
= str
;
2401 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2408 case BFD_RELOC_LO16
:
2409 /* X_unsigned is the default, so if the user has done
2410 something which cleared it, we always produce a
2412 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2413 ex
.X_add_number
&= 0xffff;
2415 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2418 case BFD_RELOC_HI16
:
2419 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2420 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2422 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2425 case BFD_RELOC_HI16_S
:
2426 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2427 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2429 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2432 case BFD_RELOC_PPC64_HIGHER
:
2433 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2434 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2436 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2439 case BFD_RELOC_PPC64_HIGHER_S
:
2440 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2441 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2443 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2446 case BFD_RELOC_PPC64_HIGHEST
:
2447 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2448 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2450 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2453 case BFD_RELOC_PPC64_HIGHEST_S
:
2454 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2455 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2457 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2460 #endif /* OBJ_ELF */
2461 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2465 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2467 /* Some TLS tweaks. */
2472 case BFD_RELOC_PPC_TLS
:
2473 insn
= ppc_insert_operand (insn
, operand
, ppc_obj64
? 13 : 2,
2476 /* We'll only use the 32 (or 64) bit form of these relocations
2477 in constants. Instructions get the 16 bit form. */
2478 case BFD_RELOC_PPC_DTPREL
:
2479 reloc
= BFD_RELOC_PPC_DTPREL16
;
2481 case BFD_RELOC_PPC_TPREL
:
2482 reloc
= BFD_RELOC_PPC_TPREL16
;
2486 /* For the absolute forms of branches, convert the PC
2487 relative form back into the absolute. */
2488 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2492 case BFD_RELOC_PPC_B26
:
2493 reloc
= BFD_RELOC_PPC_BA26
;
2495 case BFD_RELOC_PPC_B16
:
2496 reloc
= BFD_RELOC_PPC_BA16
;
2498 case BFD_RELOC_PPC_B16_BRTAKEN
:
2499 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2501 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2502 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2510 && (operand
->flags
& (PPC_OPERAND_DS
| PPC_OPERAND_DQ
)) != 0)
2515 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
2517 case BFD_RELOC_LO16
:
2518 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
2520 case BFD_RELOC_16_GOTOFF
:
2521 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
2523 case BFD_RELOC_LO16_GOTOFF
:
2524 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
2526 case BFD_RELOC_LO16_PLTOFF
:
2527 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
2529 case BFD_RELOC_16_BASEREL
:
2530 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
2532 case BFD_RELOC_LO16_BASEREL
:
2533 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
2535 case BFD_RELOC_PPC_TOC16
:
2536 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
2538 case BFD_RELOC_PPC64_TOC16_LO
:
2539 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
2541 case BFD_RELOC_PPC64_PLTGOT16
:
2542 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
2544 case BFD_RELOC_PPC64_PLTGOT16_LO
:
2545 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
2547 case BFD_RELOC_PPC_DTPREL16
:
2548 reloc
= BFD_RELOC_PPC64_DTPREL16_DS
;
2550 case BFD_RELOC_PPC_DTPREL16_LO
:
2551 reloc
= BFD_RELOC_PPC64_DTPREL16_LO_DS
;
2553 case BFD_RELOC_PPC_TPREL16
:
2554 reloc
= BFD_RELOC_PPC64_TPREL16_DS
;
2556 case BFD_RELOC_PPC_TPREL16_LO
:
2557 reloc
= BFD_RELOC_PPC64_TPREL16_LO_DS
;
2559 case BFD_RELOC_PPC_GOT_DTPREL16
:
2560 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
2561 case BFD_RELOC_PPC_GOT_TPREL16
:
2562 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
2565 as_bad (_("unsupported relocation for DS offset field"));
2570 /* We need to generate a fixup for this expression. */
2571 if (fc
>= MAX_INSN_FIXUPS
)
2572 as_fatal (_("too many fixups"));
2573 fixups
[fc
].exp
= ex
;
2574 fixups
[fc
].opindex
= 0;
2575 fixups
[fc
].reloc
= reloc
;
2578 #endif /* OBJ_ELF */
2582 /* We need to generate a fixup for this expression. */
2583 if (fc
>= MAX_INSN_FIXUPS
)
2584 as_fatal (_("too many fixups"));
2585 fixups
[fc
].exp
= ex
;
2586 fixups
[fc
].opindex
= *opindex_ptr
;
2587 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2596 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2604 /* The call to expression should have advanced str past any
2607 && (endc
!= ',' || *str
!= '\0'))
2609 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2617 while (ISSPACE (*str
))
2621 as_bad (_("junk at end of line: `%s'"), str
);
2624 /* Do we need/want a APUinfo section? */
2625 if (ppc_cpu
& (PPC_OPCODE_SPE
2626 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
2627 | PPC_OPCODE_BRLOCK
| PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
2628 | PPC_OPCODE_RFMCI
))
2630 /* These are all version "1". */
2631 if (opcode
->flags
& PPC_OPCODE_SPE
)
2632 ppc_apuinfo_section_add (PPC_APUINFO_SPE
, 1);
2633 if (opcode
->flags
& PPC_OPCODE_ISEL
)
2634 ppc_apuinfo_section_add (PPC_APUINFO_ISEL
, 1);
2635 if (opcode
->flags
& PPC_OPCODE_EFS
)
2636 ppc_apuinfo_section_add (PPC_APUINFO_EFS
, 1);
2637 if (opcode
->flags
& PPC_OPCODE_BRLOCK
)
2638 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK
, 1);
2639 if (opcode
->flags
& PPC_OPCODE_PMR
)
2640 ppc_apuinfo_section_add (PPC_APUINFO_PMR
, 1);
2641 if (opcode
->flags
& PPC_OPCODE_CACHELCK
)
2642 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK
, 1);
2643 if (opcode
->flags
& PPC_OPCODE_RFMCI
)
2644 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI
, 1);
2648 /* Write out the instruction. */
2650 addr_mod
= frag_now_fix () & 3;
2651 if (frag_now
->has_code
&& frag_now
->insn_addr
!= addr_mod
)
2652 as_bad (_("instruction address is not a multiple of 4"));
2653 frag_now
->insn_addr
= addr_mod
;
2654 frag_now
->has_code
= 1;
2655 md_number_to_chars (f
, insn
, 4);
2658 dwarf2_emit_insn (4);
2661 /* Create any fixups. At this point we do not use a
2662 bfd_reloc_code_real_type, but instead just use the
2663 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2664 handle fixups for any operand type, although that is admittedly
2665 not a very exciting feature. We pick a BFD reloc type in
2667 for (i
= 0; i
< fc
; i
++)
2669 const struct powerpc_operand
*operand
;
2671 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2672 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2674 reloc_howto_type
*reloc_howto
;
2679 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2683 size
= bfd_get_reloc_size (reloc_howto
);
2684 offset
= target_big_endian
? (4 - size
) : 0;
2686 if (size
< 1 || size
> 4)
2689 fixP
= fix_new_exp (frag_now
,
2690 f
- frag_now
->fr_literal
+ offset
,
2693 reloc_howto
->pc_relative
,
2696 /* Turn off complaints that the addend is too large for things like
2698 switch (fixups
[i
].reloc
)
2700 case BFD_RELOC_16_GOTOFF
:
2701 case BFD_RELOC_PPC_TOC16
:
2702 case BFD_RELOC_LO16
:
2703 case BFD_RELOC_HI16
:
2704 case BFD_RELOC_HI16_S
:
2706 case BFD_RELOC_PPC64_HIGHER
:
2707 case BFD_RELOC_PPC64_HIGHER_S
:
2708 case BFD_RELOC_PPC64_HIGHEST
:
2709 case BFD_RELOC_PPC64_HIGHEST_S
:
2711 fixP
->fx_no_overflow
= 1;
2718 fix_new_exp (frag_now
,
2719 f
- frag_now
->fr_literal
,
2722 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2723 ((bfd_reloc_code_real_type
)
2724 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2728 /* Handle a macro. Gather all the operands, transform them as
2729 described by the macro, and call md_assemble recursively. All the
2730 operands are separated by commas; we don't accept parentheses
2731 around operands here. */
2734 ppc_macro (str
, macro
)
2736 const struct powerpc_macro
*macro
;
2747 /* Gather the users operands into the operands array. */
2752 if (count
>= sizeof operands
/ sizeof operands
[0])
2754 operands
[count
++] = s
;
2755 s
= strchr (s
, ',');
2756 if (s
== (char *) NULL
)
2761 if (count
!= macro
->operands
)
2763 as_bad (_("wrong number of operands"));
2767 /* Work out how large the string must be (the size is unbounded
2768 because it includes user input). */
2770 format
= macro
->format
;
2771 while (*format
!= '\0')
2780 arg
= strtol (format
+ 1, &send
, 10);
2781 know (send
!= format
&& arg
>= 0 && arg
< count
);
2782 len
+= strlen (operands
[arg
]);
2787 /* Put the string together. */
2788 complete
= s
= (char *) alloca (len
+ 1);
2789 format
= macro
->format
;
2790 while (*format
!= '\0')
2796 arg
= strtol (format
+ 1, &send
, 10);
2797 strcpy (s
, operands
[arg
]);
2804 /* Assemble the constructed instruction. */
2805 md_assemble (complete
);
2809 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2812 ppc_section_letter (letter
, ptr_msg
)
2819 *ptr_msg
= _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
2824 ppc_section_word (str
, len
)
2828 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2835 ppc_section_type (str
, len
)
2839 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2846 ppc_section_flags (flags
, attr
, type
)
2851 if (type
== SHT_ORDERED
)
2852 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2854 if (attr
& SHF_EXCLUDE
)
2855 flags
|= SEC_EXCLUDE
;
2859 #endif /* OBJ_ELF */
2862 /* Pseudo-op handling. */
2864 /* The .byte pseudo-op. This is similar to the normal .byte
2865 pseudo-op, but it can also take a single ASCII string. */
2869 int ignore ATTRIBUTE_UNUSED
;
2871 if (*input_line_pointer
!= '\"')
2877 /* Gather characters. A real double quote is doubled. Unusual
2878 characters are not permitted. */
2879 ++input_line_pointer
;
2884 c
= *input_line_pointer
++;
2888 if (*input_line_pointer
!= '\"')
2890 ++input_line_pointer
;
2893 FRAG_APPEND_1_CHAR (c
);
2896 demand_empty_rest_of_line ();
2901 /* XCOFF specific pseudo-op handling. */
2903 /* This is set if we are creating a .stabx symbol, since we don't want
2904 to handle symbol suffixes for such symbols. */
2905 static bfd_boolean ppc_stab_symbol
;
2907 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2908 symbols in the .bss segment as though they were local common
2909 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
2910 aligns .comm and .lcomm to 4 bytes. */
2916 asection
*current_seg
= now_seg
;
2917 subsegT current_subseg
= now_subseg
;
2923 symbolS
*lcomm_sym
= NULL
;
2927 name
= input_line_pointer
;
2928 endc
= get_symbol_end ();
2929 end_name
= input_line_pointer
;
2932 if (*input_line_pointer
!= ',')
2934 as_bad (_("missing size"));
2935 ignore_rest_of_line ();
2938 ++input_line_pointer
;
2940 size
= get_absolute_expression ();
2943 as_bad (_("negative size"));
2944 ignore_rest_of_line ();
2950 /* The third argument to .comm is the alignment. */
2951 if (*input_line_pointer
!= ',')
2955 ++input_line_pointer
;
2956 align
= get_absolute_expression ();
2959 as_warn (_("ignoring bad alignment"));
2974 /* The third argument to .lcomm appears to be the real local
2975 common symbol to create. References to the symbol named in
2976 the first argument are turned into references to the third
2978 if (*input_line_pointer
!= ',')
2980 as_bad (_("missing real symbol name"));
2981 ignore_rest_of_line ();
2984 ++input_line_pointer
;
2986 lcomm_name
= input_line_pointer
;
2987 lcomm_endc
= get_symbol_end ();
2989 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2991 *input_line_pointer
= lcomm_endc
;
2995 sym
= symbol_find_or_make (name
);
2998 if (S_IS_DEFINED (sym
)
2999 || S_GET_VALUE (sym
) != 0)
3001 as_bad (_("attempt to redefine symbol"));
3002 ignore_rest_of_line ();
3006 record_alignment (bss_section
, align
);
3009 || ! S_IS_DEFINED (lcomm_sym
))
3018 S_SET_EXTERNAL (sym
);
3022 symbol_get_tc (lcomm_sym
)->output
= 1;
3023 def_sym
= lcomm_sym
;
3027 subseg_set (bss_section
, 1);
3028 frag_align (align
, 0, 0);
3030 symbol_set_frag (def_sym
, frag_now
);
3031 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
3032 def_size
, (char *) NULL
);
3034 S_SET_SEGMENT (def_sym
, bss_section
);
3035 symbol_get_tc (def_sym
)->align
= align
;
3039 /* Align the size of lcomm_sym. */
3040 symbol_get_frag (lcomm_sym
)->fr_offset
=
3041 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
3042 &~ ((1 << align
) - 1));
3043 if (align
> symbol_get_tc (lcomm_sym
)->align
)
3044 symbol_get_tc (lcomm_sym
)->align
= align
;
3049 /* Make sym an offset from lcomm_sym. */
3050 S_SET_SEGMENT (sym
, bss_section
);
3051 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
3052 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
3053 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
3056 subseg_set (current_seg
, current_subseg
);
3058 demand_empty_rest_of_line ();
3061 /* The .csect pseudo-op. This switches us into a different
3062 subsegment. The first argument is a symbol whose value is the
3063 start of the .csect. In COFF, csect symbols get special aux
3064 entries defined by the x_csect field of union internal_auxent. The
3065 optional second argument is the alignment (the default is 2). */
3069 int ignore ATTRIBUTE_UNUSED
;
3076 name
= input_line_pointer
;
3077 endc
= get_symbol_end ();
3079 sym
= symbol_find_or_make (name
);
3081 *input_line_pointer
= endc
;
3083 if (S_GET_NAME (sym
)[0] == '\0')
3085 /* An unnamed csect is assumed to be [PR]. */
3086 symbol_get_tc (sym
)->class = XMC_PR
;
3090 if (*input_line_pointer
== ',')
3092 ++input_line_pointer
;
3093 align
= get_absolute_expression ();
3096 ppc_change_csect (sym
, align
);
3098 demand_empty_rest_of_line ();
3101 /* Change to a different csect. */
3104 ppc_change_csect (sym
, align
)
3108 if (S_IS_DEFINED (sym
))
3109 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
3119 /* This is a new csect. We need to look at the symbol class to
3120 figure out whether it should go in the text section or the
3124 switch (symbol_get_tc (sym
)->class)
3134 S_SET_SEGMENT (sym
, text_section
);
3135 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
3136 ++ppc_text_subsegment
;
3137 list_ptr
= &ppc_text_csects
;
3147 if (ppc_toc_csect
!= NULL
3148 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
3149 == ppc_data_subsegment
))
3151 S_SET_SEGMENT (sym
, data_section
);
3152 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
3153 ++ppc_data_subsegment
;
3154 list_ptr
= &ppc_data_csects
;
3160 /* We set the obstack chunk size to a small value before
3161 changing subsegments, so that we don't use a lot of memory
3162 space for what may be a small section. */
3163 hold_chunksize
= chunksize
;
3166 sec
= subseg_new (segment_name (S_GET_SEGMENT (sym
)),
3167 symbol_get_tc (sym
)->subseg
);
3169 chunksize
= hold_chunksize
;
3172 ppc_after_toc_frag
= frag_now
;
3174 record_alignment (sec
, align
);
3176 frag_align_code (align
, 0);
3178 frag_align (align
, 0, 0);
3180 symbol_set_frag (sym
, frag_now
);
3181 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3183 symbol_get_tc (sym
)->align
= align
;
3184 symbol_get_tc (sym
)->output
= 1;
3185 symbol_get_tc (sym
)->within
= sym
;
3187 for (list
= *list_ptr
;
3188 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3189 list
= symbol_get_tc (list
)->next
)
3191 symbol_get_tc (list
)->next
= sym
;
3193 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3194 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3198 ppc_current_csect
= sym
;
3201 /* This function handles the .text and .data pseudo-ops. These
3202 pseudo-ops aren't really used by XCOFF; we implement them for the
3203 convenience of people who aren't used to XCOFF. */
3214 else if (type
== 'd')
3219 sym
= symbol_find_or_make (name
);
3221 ppc_change_csect (sym
, 2);
3223 demand_empty_rest_of_line ();
3226 /* This function handles the .section pseudo-op. This is mostly to
3227 give an error, since XCOFF only supports .text, .data and .bss, but
3228 we do permit the user to name the text or data section. */
3231 ppc_named_section (ignore
)
3232 int ignore ATTRIBUTE_UNUSED
;
3235 const char *real_name
;
3239 user_name
= input_line_pointer
;
3240 c
= get_symbol_end ();
3242 if (strcmp (user_name
, ".text") == 0)
3243 real_name
= ".text[PR]";
3244 else if (strcmp (user_name
, ".data") == 0)
3245 real_name
= ".data[RW]";
3248 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3249 *input_line_pointer
= c
;
3250 ignore_rest_of_line ();
3254 *input_line_pointer
= c
;
3256 sym
= symbol_find_or_make (real_name
);
3258 ppc_change_csect (sym
, 2);
3260 demand_empty_rest_of_line ();
3263 /* The .extern pseudo-op. We create an undefined symbol. */
3267 int ignore ATTRIBUTE_UNUSED
;
3272 name
= input_line_pointer
;
3273 endc
= get_symbol_end ();
3275 (void) symbol_find_or_make (name
);
3277 *input_line_pointer
= endc
;
3279 demand_empty_rest_of_line ();
3282 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3286 int ignore ATTRIBUTE_UNUSED
;
3292 name
= input_line_pointer
;
3293 endc
= get_symbol_end ();
3295 sym
= symbol_find_or_make (name
);
3297 *input_line_pointer
= endc
;
3299 symbol_get_tc (sym
)->output
= 1;
3301 demand_empty_rest_of_line ();
3304 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3305 although I don't know why it bothers. */
3309 int ignore ATTRIBUTE_UNUSED
;
3316 name
= input_line_pointer
;
3317 endc
= get_symbol_end ();
3319 sym
= symbol_find_or_make (name
);
3321 *input_line_pointer
= endc
;
3323 if (*input_line_pointer
!= ',')
3325 as_bad (_("missing rename string"));
3326 ignore_rest_of_line ();
3329 ++input_line_pointer
;
3331 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
3333 demand_empty_rest_of_line ();
3336 /* The .stabx pseudo-op. This is similar to a normal .stabs
3337 pseudo-op, but slightly different. A sample is
3338 .stabx "main:F-1",.main,142,0
3339 The first argument is the symbol name to create. The second is the
3340 value, and the third is the storage class. The fourth seems to be
3341 always zero, and I am assuming it is the type. */
3345 int ignore ATTRIBUTE_UNUSED
;
3352 name
= demand_copy_C_string (&len
);
3354 if (*input_line_pointer
!= ',')
3356 as_bad (_("missing value"));
3359 ++input_line_pointer
;
3361 ppc_stab_symbol
= TRUE
;
3362 sym
= symbol_make (name
);
3363 ppc_stab_symbol
= FALSE
;
3365 symbol_get_tc (sym
)->real_name
= name
;
3367 (void) expression (&exp
);
3374 as_bad (_("illegal .stabx expression; zero assumed"));
3375 exp
.X_add_number
= 0;
3378 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
3379 symbol_set_frag (sym
, &zero_address_frag
);
3383 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
3384 symbol_set_value_expression (sym
, &exp
);
3388 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
3389 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
3394 /* The value is some complex expression. This will probably
3395 fail at some later point, but this is probably the right
3396 thing to do here. */
3397 symbol_set_value_expression (sym
, &exp
);
3401 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3402 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3404 if (*input_line_pointer
!= ',')
3406 as_bad (_("missing class"));
3409 ++input_line_pointer
;
3411 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
3413 if (*input_line_pointer
!= ',')
3415 as_bad (_("missing type"));
3418 ++input_line_pointer
;
3420 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
3422 symbol_get_tc (sym
)->output
= 1;
3424 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
3426 symbol_get_tc (sym
)->within
= ppc_current_block
;
3431 .stabx "z",arrays_,133,0
3434 .comm arrays_,13768,3
3436 resolve_symbol_value will copy the exp's "within" into sym's when the
3437 offset is 0. Since this seems to be corner case problem,
3438 only do the correction for storage class C_STSYM. A better solution
3439 would be to have the tc field updated in ppc_symbol_new_hook. */
3441 if (exp
.X_op
== O_symbol
)
3443 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
3447 if (exp
.X_op
!= O_symbol
3448 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
3449 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
3450 ppc_frob_label (sym
);
3453 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3454 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
3455 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
3456 symbol_get_tc (ppc_current_csect
)->within
= sym
;
3459 demand_empty_rest_of_line ();
3462 /* The .function pseudo-op. This takes several arguments. The first
3463 argument seems to be the external name of the symbol. The second
3464 argument seems to be the label for the start of the function. gcc
3465 uses the same name for both. I have no idea what the third and
3466 fourth arguments are meant to be. The optional fifth argument is
3467 an expression for the size of the function. In COFF this symbol
3468 gets an aux entry like that used for a csect. */
3471 ppc_function (ignore
)
3472 int ignore ATTRIBUTE_UNUSED
;
3480 name
= input_line_pointer
;
3481 endc
= get_symbol_end ();
3483 /* Ignore any [PR] suffix. */
3484 name
= ppc_canonicalize_symbol_name (name
);
3485 s
= strchr (name
, '[');
3486 if (s
!= (char *) NULL
3487 && strcmp (s
+ 1, "PR]") == 0)
3490 ext_sym
= symbol_find_or_make (name
);
3492 *input_line_pointer
= endc
;
3494 if (*input_line_pointer
!= ',')
3496 as_bad (_("missing symbol name"));
3497 ignore_rest_of_line ();
3500 ++input_line_pointer
;
3502 name
= input_line_pointer
;
3503 endc
= get_symbol_end ();
3505 lab_sym
= symbol_find_or_make (name
);
3507 *input_line_pointer
= endc
;
3509 if (ext_sym
!= lab_sym
)
3513 exp
.X_op
= O_symbol
;
3514 exp
.X_add_symbol
= lab_sym
;
3515 exp
.X_op_symbol
= NULL
;
3516 exp
.X_add_number
= 0;
3518 symbol_set_value_expression (ext_sym
, &exp
);
3521 if (symbol_get_tc (ext_sym
)->class == -1)
3522 symbol_get_tc (ext_sym
)->class = XMC_PR
;
3523 symbol_get_tc (ext_sym
)->output
= 1;
3525 if (*input_line_pointer
== ',')
3529 /* Ignore the third argument. */
3530 ++input_line_pointer
;
3531 expression (&ignore
);
3532 if (*input_line_pointer
== ',')
3534 /* Ignore the fourth argument. */
3535 ++input_line_pointer
;
3536 expression (&ignore
);
3537 if (*input_line_pointer
== ',')
3539 /* The fifth argument is the function size. */
3540 ++input_line_pointer
;
3541 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
3544 &zero_address_frag
);
3545 pseudo_set (symbol_get_tc (ext_sym
)->size
);
3550 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3551 SF_SET_FUNCTION (ext_sym
);
3552 SF_SET_PROCESS (ext_sym
);
3553 coff_add_linesym (ext_sym
);
3555 demand_empty_rest_of_line ();
3558 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3559 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3560 with the correct line number */
3562 static symbolS
*saved_bi_sym
= 0;
3566 int ignore ATTRIBUTE_UNUSED
;
3570 sym
= symbol_make (".bf");
3571 S_SET_SEGMENT (sym
, text_section
);
3572 symbol_set_frag (sym
, frag_now
);
3573 S_SET_VALUE (sym
, frag_now_fix ());
3574 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3576 coff_line_base
= get_absolute_expression ();
3578 S_SET_NUMBER_AUXILIARY (sym
, 1);
3579 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3581 /* Line number for bi. */
3584 S_SET_VALUE (saved_bi_sym
, coff_n_line_nos
);
3589 symbol_get_tc (sym
)->output
= 1;
3591 ppc_frob_label (sym
);
3593 demand_empty_rest_of_line ();
3596 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3597 ".ef", except that the line number is absolute, not relative to the
3598 most recent ".bf" symbol. */
3602 int ignore ATTRIBUTE_UNUSED
;
3606 sym
= symbol_make (".ef");
3607 S_SET_SEGMENT (sym
, text_section
);
3608 symbol_set_frag (sym
, frag_now
);
3609 S_SET_VALUE (sym
, frag_now_fix ());
3610 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3611 S_SET_NUMBER_AUXILIARY (sym
, 1);
3612 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3613 symbol_get_tc (sym
)->output
= 1;
3615 ppc_frob_label (sym
);
3617 demand_empty_rest_of_line ();
3620 /* The .bi and .ei pseudo-ops. These take a string argument and
3621 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3622 the symbol list. The value of .bi will be know when the next .bf
3629 static symbolS
*last_biei
;
3636 name
= demand_copy_C_string (&len
);
3638 /* The value of these symbols is actually file offset. Here we set
3639 the value to the index into the line number entries. In
3640 ppc_frob_symbols we set the fix_line field, which will cause BFD
3641 to do the right thing. */
3643 sym
= symbol_make (name
);
3644 /* obj-coff.c currently only handles line numbers correctly in the
3646 S_SET_SEGMENT (sym
, text_section
);
3647 S_SET_VALUE (sym
, coff_n_line_nos
);
3648 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3650 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3651 symbol_get_tc (sym
)->output
= 1;
3659 for (look
= last_biei
? last_biei
: symbol_rootP
;
3660 (look
!= (symbolS
*) NULL
3661 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3662 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3663 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3664 look
= symbol_next (look
))
3666 if (look
!= (symbolS
*) NULL
)
3668 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3669 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3673 demand_empty_rest_of_line ();
3676 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3677 There is one argument, which is a csect symbol. The value of the
3678 .bs symbol is the index of this csect symbol. */
3682 int ignore ATTRIBUTE_UNUSED
;
3689 if (ppc_current_block
!= NULL
)
3690 as_bad (_("nested .bs blocks"));
3692 name
= input_line_pointer
;
3693 endc
= get_symbol_end ();
3695 csect
= symbol_find_or_make (name
);
3697 *input_line_pointer
= endc
;
3699 sym
= symbol_make (".bs");
3700 S_SET_SEGMENT (sym
, now_seg
);
3701 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3702 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3703 symbol_get_tc (sym
)->output
= 1;
3705 symbol_get_tc (sym
)->within
= csect
;
3707 ppc_frob_label (sym
);
3709 ppc_current_block
= sym
;
3711 demand_empty_rest_of_line ();
3714 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3718 int ignore ATTRIBUTE_UNUSED
;
3722 if (ppc_current_block
== NULL
)
3723 as_bad (_(".es without preceding .bs"));
3725 sym
= symbol_make (".es");
3726 S_SET_SEGMENT (sym
, now_seg
);
3727 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3728 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3729 symbol_get_tc (sym
)->output
= 1;
3731 ppc_frob_label (sym
);
3733 ppc_current_block
= NULL
;
3735 demand_empty_rest_of_line ();
3738 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3743 int ignore ATTRIBUTE_UNUSED
;
3747 sym
= symbol_make (".bb");
3748 S_SET_SEGMENT (sym
, text_section
);
3749 symbol_set_frag (sym
, frag_now
);
3750 S_SET_VALUE (sym
, frag_now_fix ());
3751 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3753 S_SET_NUMBER_AUXILIARY (sym
, 1);
3754 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3756 symbol_get_tc (sym
)->output
= 1;
3758 SF_SET_PROCESS (sym
);
3760 ppc_frob_label (sym
);
3762 demand_empty_rest_of_line ();
3765 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3770 int ignore ATTRIBUTE_UNUSED
;
3774 sym
= symbol_make (".eb");
3775 S_SET_SEGMENT (sym
, text_section
);
3776 symbol_set_frag (sym
, frag_now
);
3777 S_SET_VALUE (sym
, frag_now_fix ());
3778 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3779 S_SET_NUMBER_AUXILIARY (sym
, 1);
3780 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3781 symbol_get_tc (sym
)->output
= 1;
3783 SF_SET_PROCESS (sym
);
3785 ppc_frob_label (sym
);
3787 demand_empty_rest_of_line ();
3790 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3795 int ignore ATTRIBUTE_UNUSED
;
3801 name
= demand_copy_C_string (&len
);
3802 sym
= symbol_make (name
);
3803 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3804 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3805 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3806 S_SET_VALUE (sym
, 0);
3807 symbol_get_tc (sym
)->output
= 1;
3809 ppc_frob_label (sym
);
3811 demand_empty_rest_of_line ();
3814 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3818 int ignore ATTRIBUTE_UNUSED
;
3822 sym
= symbol_make (".ec");
3823 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3824 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3825 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3826 S_SET_VALUE (sym
, 0);
3827 symbol_get_tc (sym
)->output
= 1;
3829 ppc_frob_label (sym
);
3831 demand_empty_rest_of_line ();
3834 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3838 int ignore ATTRIBUTE_UNUSED
;
3840 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3841 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3848 subseg
= ppc_data_subsegment
;
3849 ++ppc_data_subsegment
;
3851 subseg_new (segment_name (data_section
), subseg
);
3852 ppc_toc_frag
= frag_now
;
3854 sym
= symbol_find_or_make ("TOC[TC0]");
3855 symbol_set_frag (sym
, frag_now
);
3856 S_SET_SEGMENT (sym
, data_section
);
3857 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3858 symbol_get_tc (sym
)->subseg
= subseg
;
3859 symbol_get_tc (sym
)->output
= 1;
3860 symbol_get_tc (sym
)->within
= sym
;
3862 ppc_toc_csect
= sym
;
3864 for (list
= ppc_data_csects
;
3865 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3866 list
= symbol_get_tc (list
)->next
)
3868 symbol_get_tc (list
)->next
= sym
;
3870 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3871 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3875 ppc_current_csect
= ppc_toc_csect
;
3877 demand_empty_rest_of_line ();
3880 /* The AIX assembler automatically aligns the operands of a .long or
3881 .short pseudo-op, and we want to be compatible. */
3884 ppc_xcoff_cons (log_size
)
3887 frag_align (log_size
, 0, 0);
3888 record_alignment (now_seg
, log_size
);
3889 cons (1 << log_size
);
3894 int dummy ATTRIBUTE_UNUSED
;
3899 (void) expression (&exp
);
3901 if (exp
.X_op
!= O_constant
)
3903 as_bad (_("non-constant byte count"));
3907 byte_count
= exp
.X_add_number
;
3909 if (*input_line_pointer
!= ',')
3911 as_bad (_("missing value"));
3915 ++input_line_pointer
;
3919 #endif /* OBJ_XCOFF */
3920 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3922 /* The .tc pseudo-op. This is used when generating either XCOFF or
3923 ELF. This takes two or more arguments.
3925 When generating XCOFF output, the first argument is the name to
3926 give to this location in the toc; this will be a symbol with class
3927 TC. The rest of the arguments are N-byte values to actually put at
3928 this location in the TOC; often there is just one more argument, a
3929 relocatable symbol reference. The size of the value to store
3930 depends on target word size. A 32-bit target uses 4-byte values, a
3931 64-bit target uses 8-byte values.
3933 When not generating XCOFF output, the arguments are the same, but
3934 the first argument is simply ignored. */
3938 int ignore ATTRIBUTE_UNUSED
;
3942 /* Define the TOC symbol name. */
3948 if (ppc_toc_csect
== (symbolS
*) NULL
3949 || ppc_toc_csect
!= ppc_current_csect
)
3951 as_bad (_(".tc not in .toc section"));
3952 ignore_rest_of_line ();
3956 name
= input_line_pointer
;
3957 endc
= get_symbol_end ();
3959 sym
= symbol_find_or_make (name
);
3961 *input_line_pointer
= endc
;
3963 if (S_IS_DEFINED (sym
))
3967 label
= symbol_get_tc (ppc_current_csect
)->within
;
3968 if (symbol_get_tc (label
)->class != XMC_TC0
)
3970 as_bad (_(".tc with no label"));
3971 ignore_rest_of_line ();
3975 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3976 symbol_set_frag (label
, symbol_get_frag (sym
));
3977 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3979 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3980 ++input_line_pointer
;
3985 S_SET_SEGMENT (sym
, now_seg
);
3986 symbol_set_frag (sym
, frag_now
);
3987 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3988 symbol_get_tc (sym
)->class = XMC_TC
;
3989 symbol_get_tc (sym
)->output
= 1;
3991 ppc_frob_label (sym
);
3994 #endif /* OBJ_XCOFF */
3998 /* Skip the TOC symbol name. */
3999 while (is_part_of_name (*input_line_pointer
)
4000 || *input_line_pointer
== '['
4001 || *input_line_pointer
== ']'
4002 || *input_line_pointer
== '{'
4003 || *input_line_pointer
== '}')
4004 ++input_line_pointer
;
4006 /* Align to a four/eight byte boundary. */
4007 align
= ppc_obj64
? 3 : 2;
4008 frag_align (align
, 0, 0);
4009 record_alignment (now_seg
, align
);
4010 #endif /* OBJ_ELF */
4012 if (*input_line_pointer
!= ',')
4013 demand_empty_rest_of_line ();
4016 ++input_line_pointer
;
4017 cons (ppc_obj64
? 8 : 4);
4021 /* Pseudo-op .machine. */
4024 ppc_machine (ignore
)
4025 int ignore ATTRIBUTE_UNUSED
;
4028 #define MAX_HISTORY 100
4029 static unsigned long *cpu_history
;
4030 static int curr_hist
;
4034 if (*input_line_pointer
== '"')
4037 cpu_string
= demand_copy_C_string (&len
);
4042 cpu_string
= input_line_pointer
;
4043 c
= get_symbol_end ();
4044 cpu_string
= xstrdup (cpu_string
);
4045 *input_line_pointer
= c
;
4048 if (cpu_string
!= NULL
)
4050 unsigned long old_cpu
= ppc_cpu
;
4053 for (p
= cpu_string
; *p
!= 0; p
++)
4056 if (strcmp (cpu_string
, "push") == 0)
4058 if (cpu_history
== NULL
)
4059 cpu_history
= xmalloc (MAX_HISTORY
* sizeof (*cpu_history
));
4061 if (curr_hist
>= MAX_HISTORY
)
4062 as_bad (_(".machine stack overflow"));
4064 cpu_history
[curr_hist
++] = ppc_cpu
;
4066 else if (strcmp (cpu_string
, "pop") == 0)
4069 as_bad (_(".machine stack underflow"));
4071 ppc_cpu
= cpu_history
[--curr_hist
];
4073 else if (parse_cpu (cpu_string
))
4076 as_bad (_("invalid machine `%s'"), cpu_string
);
4078 if (ppc_cpu
!= old_cpu
)
4079 ppc_setup_opcodes ();
4082 demand_empty_rest_of_line ();
4085 /* See whether a symbol is in the TOC section. */
4088 ppc_is_toc_sym (sym
)
4092 return symbol_get_tc (sym
)->class == XMC_TC
;
4095 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
4097 return strcmp (sname
, ".toc") == 0;
4099 return strcmp (sname
, ".got") == 0;
4102 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4106 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4108 /* Set the current section. */
4110 ppc_set_current_section (new)
4113 ppc_previous_section
= ppc_current_section
;
4114 ppc_current_section
= new;
4117 /* pseudo-op: .previous
4118 behaviour: toggles the current section with the previous section.
4120 warnings: "No previous section" */
4123 ppc_previous (ignore
)
4124 int ignore ATTRIBUTE_UNUSED
;
4128 if (ppc_previous_section
== NULL
)
4130 as_warn (_("No previous section to return to. Directive ignored."));
4134 subseg_set (ppc_previous_section
, 0);
4136 ppc_set_current_section (ppc_previous_section
);
4139 /* pseudo-op: .pdata
4140 behaviour: predefined read only data section
4144 initial: .section .pdata "adr3"
4145 a - don't know -- maybe a misprint
4146 d - initialized data
4148 3 - double word aligned (that would be 4 byte boundary)
4151 Tag index tables (also known as the function table) for exception
4152 handling, debugging, etc. */
4156 int ignore ATTRIBUTE_UNUSED
;
4158 if (pdata_section
== 0)
4160 pdata_section
= subseg_new (".pdata", 0);
4162 bfd_set_section_flags (stdoutput
, pdata_section
,
4163 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4164 | SEC_READONLY
| SEC_DATA
));
4166 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
4170 pdata_section
= subseg_new (".pdata", 0);
4172 ppc_set_current_section (pdata_section
);
4175 /* pseudo-op: .ydata
4176 behaviour: predefined read only data section
4180 initial: .section .ydata "drw3"
4181 a - don't know -- maybe a misprint
4182 d - initialized data
4184 3 - double word aligned (that would be 4 byte boundary)
4186 Tag tables (also known as the scope table) for exception handling,
4191 int ignore ATTRIBUTE_UNUSED
;
4193 if (ydata_section
== 0)
4195 ydata_section
= subseg_new (".ydata", 0);
4196 bfd_set_section_flags (stdoutput
, ydata_section
,
4197 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4198 | SEC_READONLY
| SEC_DATA
));
4200 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
4204 ydata_section
= subseg_new (".ydata", 0);
4206 ppc_set_current_section (ydata_section
);
4209 /* pseudo-op: .reldata
4210 behaviour: predefined read write data section
4211 double word aligned (4-byte)
4212 FIXME: relocation is applied to it
4213 FIXME: what's the difference between this and .data?
4216 initial: .section .reldata "drw3"
4217 d - initialized data
4220 3 - double word aligned (that would be 8 byte boundary)
4223 Like .data, but intended to hold data subject to relocation, such as
4224 function descriptors, etc. */
4227 ppc_reldata (ignore
)
4228 int ignore ATTRIBUTE_UNUSED
;
4230 if (reldata_section
== 0)
4232 reldata_section
= subseg_new (".reldata", 0);
4234 bfd_set_section_flags (stdoutput
, reldata_section
,
4235 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4238 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
4242 reldata_section
= subseg_new (".reldata", 0);
4244 ppc_set_current_section (reldata_section
);
4247 /* pseudo-op: .rdata
4248 behaviour: predefined read only data section
4252 initial: .section .rdata "dr3"
4253 d - initialized data
4255 3 - double word aligned (that would be 4 byte boundary) */
4259 int ignore ATTRIBUTE_UNUSED
;
4261 if (rdata_section
== 0)
4263 rdata_section
= subseg_new (".rdata", 0);
4264 bfd_set_section_flags (stdoutput
, rdata_section
,
4265 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4266 | SEC_READONLY
| SEC_DATA
));
4268 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
4272 rdata_section
= subseg_new (".rdata", 0);
4274 ppc_set_current_section (rdata_section
);
4277 /* pseudo-op: .ualong
4278 behaviour: much like .int, with the exception that no alignment is
4280 FIXME: test the alignment statement
4286 int ignore ATTRIBUTE_UNUSED
;
4292 /* pseudo-op: .znop <symbol name>
4293 behaviour: Issue a nop instruction
4294 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4295 the supplied symbol name.
4297 warnings: Missing symbol name */
4301 int ignore ATTRIBUTE_UNUSED
;
4304 const struct powerpc_opcode
*opcode
;
4315 /* Strip out the symbol name. */
4316 symbol_name
= input_line_pointer
;
4317 c
= get_symbol_end ();
4319 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
4320 strcpy (name
, symbol_name
);
4322 sym
= symbol_find_or_make (name
);
4324 *input_line_pointer
= c
;
4328 /* Look up the opcode in the hash table. */
4329 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
4331 /* Stick in the nop. */
4332 insn
= opcode
->opcode
;
4334 /* Write out the instruction. */
4336 md_number_to_chars (f
, insn
, 4);
4338 f
- frag_now
->fr_literal
,
4343 BFD_RELOC_16_GOT_PCREL
);
4356 register char *name
;
4360 register symbolS
*symbolP
;
4363 name
= input_line_pointer
;
4364 c
= get_symbol_end ();
4366 /* just after name is now '\0'. */
4367 p
= input_line_pointer
;
4370 if (*input_line_pointer
!= ',')
4372 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4373 ignore_rest_of_line ();
4377 input_line_pointer
++; /* skip ',' */
4378 if ((temp
= get_absolute_expression ()) < 0)
4380 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
4381 ignore_rest_of_line ();
4387 /* The third argument to .comm is the alignment. */
4388 if (*input_line_pointer
!= ',')
4392 ++input_line_pointer
;
4393 align
= get_absolute_expression ();
4396 as_warn (_("ignoring bad alignment"));
4403 symbolP
= symbol_find_or_make (name
);
4406 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
4408 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4409 S_GET_NAME (symbolP
));
4410 ignore_rest_of_line ();
4414 if (S_GET_VALUE (symbolP
))
4416 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
4417 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4418 S_GET_NAME (symbolP
),
4419 (long) S_GET_VALUE (symbolP
),
4424 S_SET_VALUE (symbolP
, (valueT
) temp
);
4425 S_SET_EXTERNAL (symbolP
);
4426 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
4429 demand_empty_rest_of_line ();
4433 * implement the .section pseudo op:
4434 * .section name {, "flags"}
4436 * | +--- optional flags: 'b' for bss
4438 * +-- section name 'l' for lib
4442 * 'd' (apparently m88k for data)
4444 * But if the argument is not a quoted string, treat it as a
4445 * subsegment number.
4447 * FIXME: this is a copy of the section processing from obj-coff.c, with
4448 * additions/changes for the moto-pas assembler support. There are three
4451 * FIXME: I just noticed this. This doesn't work at all really. It it
4452 * setting bits that bfd probably neither understands or uses. The
4453 * correct approach (?) will have to incorporate extra fields attached
4454 * to the section to hold the system specific stuff. (krk)
4457 * 'a' - unknown - referred to in documentation, but no definition supplied
4458 * 'c' - section has code
4459 * 'd' - section has initialized data
4460 * 'u' - section has uninitialized data
4461 * 'i' - section contains directives (info)
4462 * 'n' - section can be discarded
4463 * 'R' - remove section at link time
4465 * Section Protection:
4466 * 'r' - section is readable
4467 * 'w' - section is writeable
4468 * 'x' - section is executable
4469 * 's' - section is sharable
4471 * Section Alignment:
4472 * '0' - align to byte boundary
4473 * '1' - align to halfword undary
4474 * '2' - align to word boundary
4475 * '3' - align to doubleword boundary
4476 * '4' - align to quadword boundary
4477 * '5' - align to 32 byte boundary
4478 * '6' - align to 64 byte boundary
4483 ppc_pe_section (ignore
)
4484 int ignore ATTRIBUTE_UNUSED
;
4486 /* Strip out the section name. */
4495 section_name
= input_line_pointer
;
4496 c
= get_symbol_end ();
4498 name
= xmalloc (input_line_pointer
- section_name
+ 1);
4499 strcpy (name
, section_name
);
4501 *input_line_pointer
= c
;
4506 flags
= SEC_NO_FLAGS
;
4508 if (strcmp (name
, ".idata$2") == 0)
4512 else if (strcmp (name
, ".idata$3") == 0)
4516 else if (strcmp (name
, ".idata$4") == 0)
4520 else if (strcmp (name
, ".idata$5") == 0)
4524 else if (strcmp (name
, ".idata$6") == 0)
4529 /* Default alignment to 16 byte boundary. */
4532 if (*input_line_pointer
== ',')
4534 ++input_line_pointer
;
4536 if (*input_line_pointer
!= '"')
4537 exp
= get_absolute_expression ();
4540 ++input_line_pointer
;
4541 while (*input_line_pointer
!= '"'
4542 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4544 switch (*input_line_pointer
)
4546 /* Section Contents */
4547 case 'a': /* unknown */
4548 as_bad (_("Unsupported section attribute -- 'a'"));
4550 case 'c': /* code section */
4553 case 'd': /* section has initialized data */
4556 case 'u': /* section has uninitialized data */
4557 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4561 case 'i': /* section contains directives (info) */
4562 /* FIXME: This is IMAGE_SCN_LNK_INFO
4564 flags
|= SEC_HAS_CONTENTS
;
4566 case 'n': /* section can be discarded */
4569 case 'R': /* Remove section at link time */
4570 flags
|= SEC_NEVER_LOAD
;
4573 /* Section Protection */
4574 case 'r': /* section is readable */
4575 flags
|= IMAGE_SCN_MEM_READ
;
4577 case 'w': /* section is writeable */
4578 flags
|= IMAGE_SCN_MEM_WRITE
;
4580 case 'x': /* section is executable */
4581 flags
|= IMAGE_SCN_MEM_EXECUTE
;
4583 case 's': /* section is sharable */
4584 flags
|= IMAGE_SCN_MEM_SHARED
;
4587 /* Section Alignment */
4588 case '0': /* align to byte boundary */
4589 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
4592 case '1': /* align to halfword boundary */
4593 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
4596 case '2': /* align to word boundary */
4597 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
4600 case '3': /* align to doubleword boundary */
4601 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
4604 case '4': /* align to quadword boundary */
4605 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
4608 case '5': /* align to 32 byte boundary */
4609 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
4612 case '6': /* align to 64 byte boundary */
4613 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
4618 as_bad (_("unknown section attribute '%c'"),
4619 *input_line_pointer
);
4622 ++input_line_pointer
;
4624 if (*input_line_pointer
== '"')
4625 ++input_line_pointer
;
4629 sec
= subseg_new (name
, (subsegT
) exp
);
4631 ppc_set_current_section (sec
);
4633 if (flags
!= SEC_NO_FLAGS
)
4635 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
4636 as_bad (_("error setting flags for \"%s\": %s"),
4637 bfd_section_name (stdoutput
, sec
),
4638 bfd_errmsg (bfd_get_error ()));
4641 bfd_set_section_alignment (stdoutput
, sec
, align
);
4646 ppc_pe_function (ignore
)
4647 int ignore ATTRIBUTE_UNUSED
;
4653 name
= input_line_pointer
;
4654 endc
= get_symbol_end ();
4656 ext_sym
= symbol_find_or_make (name
);
4658 *input_line_pointer
= endc
;
4660 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4661 SF_SET_FUNCTION (ext_sym
);
4662 SF_SET_PROCESS (ext_sym
);
4663 coff_add_linesym (ext_sym
);
4665 demand_empty_rest_of_line ();
4669 ppc_pe_tocd (ignore
)
4670 int ignore ATTRIBUTE_UNUSED
;
4672 if (tocdata_section
== 0)
4674 tocdata_section
= subseg_new (".tocd", 0);
4675 /* FIXME: section flags won't work. */
4676 bfd_set_section_flags (stdoutput
, tocdata_section
,
4677 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4678 | SEC_READONLY
| SEC_DATA
));
4680 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4684 rdata_section
= subseg_new (".tocd", 0);
4687 ppc_set_current_section (tocdata_section
);
4689 demand_empty_rest_of_line ();
4692 /* Don't adjust TOC relocs to use the section symbol. */
4695 ppc_pe_fix_adjustable (fix
)
4698 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4705 /* XCOFF specific symbol and file handling. */
4707 /* Canonicalize the symbol name. We use the to force the suffix, if
4708 any, to use square brackets, and to be in upper case. */
4711 ppc_canonicalize_symbol_name (name
)
4716 if (ppc_stab_symbol
)
4719 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4733 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4736 if (*s
== '\0' || s
[1] != '\0')
4737 as_bad (_("bad symbol suffix"));
4745 /* Set the class of a symbol based on the suffix, if any. This is
4746 called whenever a new symbol is created. */
4749 ppc_symbol_new_hook (sym
)
4752 struct ppc_tc_sy
*tc
;
4755 tc
= symbol_get_tc (sym
);
4759 tc
->real_name
= NULL
;
4765 if (ppc_stab_symbol
)
4768 s
= strchr (S_GET_NAME (sym
), '[');
4769 if (s
== (const char *) NULL
)
4771 /* There is no suffix. */
4780 if (strcmp (s
, "BS]") == 0)
4784 if (strcmp (s
, "DB]") == 0)
4786 else if (strcmp (s
, "DS]") == 0)
4790 if (strcmp (s
, "GL]") == 0)
4794 if (strcmp (s
, "PR]") == 0)
4798 if (strcmp (s
, "RO]") == 0)
4800 else if (strcmp (s
, "RW]") == 0)
4804 if (strcmp (s
, "SV]") == 0)
4808 if (strcmp (s
, "TC]") == 0)
4810 else if (strcmp (s
, "TI]") == 0)
4812 else if (strcmp (s
, "TB]") == 0)
4814 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4815 tc
->class = XMC_TC0
;
4818 if (strcmp (s
, "UA]") == 0)
4820 else if (strcmp (s
, "UC]") == 0)
4824 if (strcmp (s
, "XO]") == 0)
4829 if (tc
->class == -1)
4830 as_bad (_("Unrecognized symbol suffix"));
4833 /* Set the class of a label based on where it is defined. This
4834 handles symbols without suffixes. Also, move the symbol so that it
4835 follows the csect symbol. */
4838 ppc_frob_label (sym
)
4841 if (ppc_current_csect
!= (symbolS
*) NULL
)
4843 if (symbol_get_tc (sym
)->class == -1)
4844 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4846 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4847 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4848 &symbol_rootP
, &symbol_lastP
);
4849 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4853 dwarf2_emit_label (sym
);
4857 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4858 seen. It tells ppc_adjust_symtab whether it needs to look through
4861 static bfd_boolean ppc_saw_abs
;
4863 /* Change the name of a symbol just before writing it out. Set the
4864 real name if the .rename pseudo-op was used. Otherwise, remove any
4865 class suffix. Return 1 if the symbol should not be included in the
4869 ppc_frob_symbol (sym
)
4872 static symbolS
*ppc_last_function
;
4873 static symbolS
*set_end
;
4875 /* Discard symbols that should not be included in the output symbol
4877 if (! symbol_used_in_reloc_p (sym
)
4878 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4879 || (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
4880 && ! symbol_get_tc (sym
)->output
4881 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4884 /* This one will disappear anyway. Don't make a csect sym for it. */
4885 if (sym
== abs_section_sym
)
4888 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4889 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4895 name
= S_GET_NAME (sym
);
4896 s
= strchr (name
, '[');
4897 if (s
!= (char *) NULL
)
4903 snew
= xmalloc (len
+ 1);
4904 memcpy (snew
, name
, len
);
4907 S_SET_NAME (sym
, snew
);
4911 if (set_end
!= (symbolS
*) NULL
)
4913 SA_SET_SYM_ENDNDX (set_end
, sym
);
4917 if (SF_GET_FUNCTION (sym
))
4919 if (ppc_last_function
!= (symbolS
*) NULL
)
4920 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4921 ppc_last_function
= sym
;
4922 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4924 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4925 SA_SET_SYM_FSIZE (sym
,
4926 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4929 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4930 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4932 if (ppc_last_function
== (symbolS
*) NULL
)
4933 as_bad (_(".ef with no preceding .function"));
4936 set_end
= ppc_last_function
;
4937 ppc_last_function
= NULL
;
4939 /* We don't have a C_EFCN symbol, but we need to force the
4940 COFF backend to believe that it has seen one. */
4941 coff_last_function
= NULL
;
4945 if (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
4946 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4947 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4948 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4949 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4950 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4951 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4952 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4953 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4954 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4955 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4957 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4958 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4961 union internal_auxent
*a
;
4963 /* Create a csect aux. */
4964 i
= S_GET_NUMBER_AUXILIARY (sym
);
4965 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4966 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4967 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4969 /* This is the TOC table. */
4970 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4971 a
->x_csect
.x_scnlen
.l
= 0;
4972 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4974 else if (symbol_get_tc (sym
)->subseg
!= 0)
4976 /* This is a csect symbol. x_scnlen is the size of the
4978 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4979 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4980 S_GET_SEGMENT (sym
))
4981 - S_GET_VALUE (sym
));
4984 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4985 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4986 - S_GET_VALUE (sym
));
4988 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4990 else if (S_GET_SEGMENT (sym
) == bss_section
)
4992 /* This is a common symbol. */
4993 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4994 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4995 if (S_IS_EXTERNAL (sym
))
4996 symbol_get_tc (sym
)->class = XMC_RW
;
4998 symbol_get_tc (sym
)->class = XMC_BS
;
5000 else if (S_GET_SEGMENT (sym
) == absolute_section
)
5002 /* This is an absolute symbol. The csect will be created by
5003 ppc_adjust_symtab. */
5005 a
->x_csect
.x_smtyp
= XTY_LD
;
5006 if (symbol_get_tc (sym
)->class == -1)
5007 symbol_get_tc (sym
)->class = XMC_XO
;
5009 else if (! S_IS_DEFINED (sym
))
5011 /* This is an external symbol. */
5012 a
->x_csect
.x_scnlen
.l
= 0;
5013 a
->x_csect
.x_smtyp
= XTY_ER
;
5015 else if (symbol_get_tc (sym
)->class == XMC_TC
)
5019 /* This is a TOC definition. x_scnlen is the size of the
5021 next
= symbol_next (sym
);
5022 while (symbol_get_tc (next
)->class == XMC_TC0
)
5023 next
= symbol_next (next
);
5024 if (next
== (symbolS
*) NULL
5025 || symbol_get_tc (next
)->class != XMC_TC
)
5027 if (ppc_after_toc_frag
== (fragS
*) NULL
)
5028 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
5030 - S_GET_VALUE (sym
));
5032 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
5033 - S_GET_VALUE (sym
));
5037 resolve_symbol_value (next
);
5038 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
5039 - S_GET_VALUE (sym
));
5041 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
5047 /* This is a normal symbol definition. x_scnlen is the
5048 symbol index of the containing csect. */
5049 if (S_GET_SEGMENT (sym
) == text_section
)
5050 csect
= ppc_text_csects
;
5051 else if (S_GET_SEGMENT (sym
) == data_section
)
5052 csect
= ppc_data_csects
;
5056 /* Skip the initial dummy symbol. */
5057 csect
= symbol_get_tc (csect
)->next
;
5059 if (csect
== (symbolS
*) NULL
)
5061 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
5062 a
->x_csect
.x_scnlen
.l
= 0;
5066 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
5068 resolve_symbol_value (symbol_get_tc (csect
)->next
);
5069 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
5070 > S_GET_VALUE (sym
))
5072 csect
= symbol_get_tc (csect
)->next
;
5075 a
->x_csect
.x_scnlen
.p
=
5076 coffsymbol (symbol_get_bfdsym (csect
))->native
;
5077 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
5080 a
->x_csect
.x_smtyp
= XTY_LD
;
5083 a
->x_csect
.x_parmhash
= 0;
5084 a
->x_csect
.x_snhash
= 0;
5085 if (symbol_get_tc (sym
)->class == -1)
5086 a
->x_csect
.x_smclas
= XMC_PR
;
5088 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
5089 a
->x_csect
.x_stab
= 0;
5090 a
->x_csect
.x_snstab
= 0;
5092 /* Don't let the COFF backend resort these symbols. */
5093 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
5095 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
5097 /* We want the value to be the symbol index of the referenced
5098 csect symbol. BFD will do that for us if we set the right
5100 asymbol
*bsym
= symbol_get_bfdsym (symbol_get_tc (sym
)->within
);
5101 combined_entry_type
*c
= coffsymbol (bsym
)->native
;
5103 S_SET_VALUE (sym
, (valueT
) (size_t) c
);
5104 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
5106 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
5111 /* The value is the offset from the enclosing csect. */
5112 block
= symbol_get_tc (sym
)->within
;
5113 csect
= symbol_get_tc (block
)->within
;
5114 resolve_symbol_value (csect
);
5115 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
5117 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
5118 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
5120 /* We want the value to be a file offset into the line numbers.
5121 BFD will do that for us if we set the right flags. We have
5122 already set the value correctly. */
5123 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
5129 /* Adjust the symbol table. This creates csect symbols for all
5130 absolute symbols. */
5133 ppc_adjust_symtab ()
5140 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
5144 union internal_auxent
*a
;
5146 if (S_GET_SEGMENT (sym
) != absolute_section
)
5149 csect
= symbol_create (".abs[XO]", absolute_section
,
5150 S_GET_VALUE (sym
), &zero_address_frag
);
5151 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
5152 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
5153 i
= S_GET_NUMBER_AUXILIARY (csect
);
5154 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
5155 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
5156 a
->x_csect
.x_scnlen
.l
= 0;
5157 a
->x_csect
.x_smtyp
= XTY_SD
;
5158 a
->x_csect
.x_parmhash
= 0;
5159 a
->x_csect
.x_snhash
= 0;
5160 a
->x_csect
.x_smclas
= XMC_XO
;
5161 a
->x_csect
.x_stab
= 0;
5162 a
->x_csect
.x_snstab
= 0;
5164 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
5166 i
= S_GET_NUMBER_AUXILIARY (sym
);
5167 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
5168 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
5169 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
5172 ppc_saw_abs
= FALSE
;
5175 /* Set the VMA for a section. This is called on all the sections in
5179 ppc_frob_section (sec
)
5182 static bfd_vma vma
= 0;
5184 vma
= md_section_align (sec
, vma
);
5185 bfd_set_section_vma (stdoutput
, sec
, vma
);
5186 vma
+= bfd_section_size (stdoutput
, sec
);
5189 #endif /* OBJ_XCOFF */
5191 /* Turn a string in input_line_pointer into a floating point constant
5192 of type TYPE, and store the appropriate bytes in *LITP. The number
5193 of LITTLENUMS emitted is stored in *SIZEP. An error message is
5194 returned, or NULL on OK. */
5197 md_atof (type
, litp
, sizep
)
5203 LITTLENUM_TYPE words
[4];
5219 return _("bad call to md_atof");
5222 t
= atof_ieee (input_line_pointer
, type
, words
);
5224 input_line_pointer
= t
;
5228 if (target_big_endian
)
5230 for (i
= 0; i
< prec
; i
++)
5232 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5238 for (i
= prec
- 1; i
>= 0; i
--)
5240 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5248 /* Write a value out to the object file, using the appropriate
5252 md_number_to_chars (buf
, val
, n
)
5257 if (target_big_endian
)
5258 number_to_chars_bigendian (buf
, val
, n
);
5260 number_to_chars_littleendian (buf
, val
, n
);
5263 /* Align a section (I don't know why this is machine dependent). */
5266 md_section_align (asection
*seg ATTRIBUTE_UNUSED
, valueT addr
)
5271 int align
= bfd_get_section_alignment (stdoutput
, seg
);
5273 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
5277 /* We don't have any form of relaxing. */
5280 md_estimate_size_before_relax (fragp
, seg
)
5281 fragS
*fragp ATTRIBUTE_UNUSED
;
5282 asection
*seg ATTRIBUTE_UNUSED
;
5288 /* Convert a machine dependent frag. We never generate these. */
5291 md_convert_frag (abfd
, sec
, fragp
)
5292 bfd
*abfd ATTRIBUTE_UNUSED
;
5293 asection
*sec ATTRIBUTE_UNUSED
;
5294 fragS
*fragp ATTRIBUTE_UNUSED
;
5299 /* We have no need to default values of symbols. */
5302 md_undefined_symbol (name
)
5303 char *name ATTRIBUTE_UNUSED
;
5308 /* Functions concerning relocs. */
5310 /* The location from which a PC relative jump should be calculated,
5311 given a PC relative reloc. */
5314 md_pcrel_from_section (fixp
, sec
)
5316 segT sec ATTRIBUTE_UNUSED
;
5318 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5323 /* This is called to see whether a fixup should be adjusted to use a
5324 section symbol. We take the opportunity to change a fixup against
5325 a symbol in the TOC subsegment into a reloc against the
5326 corresponding .tc symbol. */
5329 ppc_fix_adjustable (fix
)
5332 valueT val
= resolve_symbol_value (fix
->fx_addsy
);
5333 segT symseg
= S_GET_SEGMENT (fix
->fx_addsy
);
5334 TC_SYMFIELD_TYPE
*tc
;
5336 if (symseg
== absolute_section
)
5339 if (ppc_toc_csect
!= (symbolS
*) NULL
5340 && fix
->fx_addsy
!= ppc_toc_csect
5341 && symseg
== data_section
5342 && val
>= ppc_toc_frag
->fr_address
5343 && (ppc_after_toc_frag
== (fragS
*) NULL
5344 || val
< ppc_after_toc_frag
->fr_address
))
5348 for (sy
= symbol_next (ppc_toc_csect
);
5349 sy
!= (symbolS
*) NULL
;
5350 sy
= symbol_next (sy
))
5352 TC_SYMFIELD_TYPE
*sy_tc
= symbol_get_tc (sy
);
5354 if (sy_tc
->class == XMC_TC0
)
5356 if (sy_tc
->class != XMC_TC
)
5358 if (val
== resolve_symbol_value (sy
))
5361 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
5366 as_bad_where (fix
->fx_file
, fix
->fx_line
,
5367 _("symbol in .toc does not match any .tc"));
5370 /* Possibly adjust the reloc to be against the csect. */
5371 tc
= symbol_get_tc (fix
->fx_addsy
);
5373 && tc
->class != XMC_TC0
5374 && tc
->class != XMC_TC
5375 && symseg
!= bss_section
5376 /* Don't adjust if this is a reloc in the toc section. */
5377 && (symseg
!= data_section
5378 || ppc_toc_csect
== NULL
5379 || val
< ppc_toc_frag
->fr_address
5380 || (ppc_after_toc_frag
!= NULL
5381 && val
>= ppc_after_toc_frag
->fr_address
)))
5384 symbolS
*next_csect
;
5386 if (symseg
== text_section
)
5387 csect
= ppc_text_csects
;
5388 else if (symseg
== data_section
)
5389 csect
= ppc_data_csects
;
5393 /* Skip the initial dummy symbol. */
5394 csect
= symbol_get_tc (csect
)->next
;
5396 if (csect
!= (symbolS
*) NULL
)
5398 while ((next_csect
= symbol_get_tc (csect
)->next
) != (symbolS
*) NULL
5399 && (symbol_get_frag (next_csect
)->fr_address
<= val
))
5401 /* If the csect address equals the symbol value, then we
5402 have to look through the full symbol table to see
5403 whether this is the csect we want. Note that we will
5404 only get here if the csect has zero length. */
5405 if (symbol_get_frag (csect
)->fr_address
== val
5406 && S_GET_VALUE (csect
) == val
)
5410 for (scan
= symbol_next (csect
);
5412 scan
= symbol_next (scan
))
5414 if (symbol_get_tc (scan
)->subseg
!= 0)
5416 if (scan
== fix
->fx_addsy
)
5420 /* If we found the symbol before the next csect
5421 symbol, then this is the csect we want. */
5422 if (scan
== fix
->fx_addsy
)
5429 fix
->fx_offset
+= val
- symbol_get_frag (csect
)->fr_address
;
5430 fix
->fx_addsy
= csect
;
5435 /* Adjust a reloc against a .lcomm symbol to be against the base
5437 if (symseg
== bss_section
5438 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
5440 symbolS
*sy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
5442 fix
->fx_offset
+= val
- resolve_symbol_value (sy
);
5449 /* A reloc from one csect to another must be kept. The assembler
5450 will, of course, keep relocs between sections, and it will keep
5451 absolute relocs, but we need to force it to keep PC relative relocs
5452 between two csects in the same section. */
5455 ppc_force_relocation (fix
)
5458 /* At this point fix->fx_addsy should already have been converted to
5459 a csect symbol. If the csect does not include the fragment, then
5460 we need to force the relocation. */
5462 && fix
->fx_addsy
!= NULL
5463 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
5464 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
5465 > fix
->fx_frag
->fr_address
)
5466 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
5467 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
5468 <= fix
->fx_frag
->fr_address
))))
5471 return generic_force_reloc (fix
);
5474 #endif /* OBJ_XCOFF */
5477 /* If this function returns non-zero, it guarantees that a relocation
5478 will be emitted for a fixup. */
5481 ppc_force_relocation (fix
)
5484 /* Branch prediction relocations must force a relocation, as must
5485 the vtable description relocs. */
5486 switch (fix
->fx_r_type
)
5488 case BFD_RELOC_PPC_B16_BRTAKEN
:
5489 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5490 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5491 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5492 case BFD_RELOC_24_PLT_PCREL
:
5493 case BFD_RELOC_PPC64_TOC
:
5499 if (fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5500 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
5503 return generic_force_reloc (fix
);
5507 ppc_fix_adjustable (fix
)
5510 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
5511 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
5512 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
5513 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
5514 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
5515 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
5516 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
5517 && !(fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5518 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
));
5522 /* Implement HANDLE_ALIGN. This writes the NOP pattern into an
5523 rs_align_code frag. */
5526 ppc_handle_align (struct frag
*fragP
)
5528 valueT count
= (fragP
->fr_next
->fr_address
5529 - (fragP
->fr_address
+ fragP
->fr_fix
));
5531 if (count
!= 0 && (count
& 3) == 0)
5533 char *dest
= fragP
->fr_literal
+ fragP
->fr_fix
;
5536 md_number_to_chars (dest
, 0x60000000, 4);
5538 if ((ppc_cpu
& PPC_OPCODE_POWER6
) != 0)
5540 /* For power6, we want the last nop to be a group terminating
5541 one, "ori 1,1,0". Do this by inserting an rs_fill frag
5542 immediately after this one, with its address set to the last
5543 nop location. This will automatically reduce the number of
5544 nops in the current frag by one. */
5547 struct frag
*group_nop
= xmalloc (SIZEOF_STRUCT_FRAG
+ 4);
5549 memcpy (group_nop
, fragP
, SIZEOF_STRUCT_FRAG
);
5550 group_nop
->fr_address
= group_nop
->fr_next
->fr_address
- 4;
5551 group_nop
->fr_fix
= 0;
5552 group_nop
->fr_offset
= 1;
5553 group_nop
->fr_type
= rs_fill
;
5554 fragP
->fr_next
= group_nop
;
5555 dest
= group_nop
->fr_literal
;
5558 md_number_to_chars (dest
, 0x60210000, 4);
5563 /* Apply a fixup to the object code. This is called for all the
5564 fixups we generated by the call to fix_new_exp, above. In the call
5565 above we used a reloc code which was the largest legal reloc code
5566 plus the operand index. Here we undo that to recover the operand
5567 index. At this point all symbol values should be fully resolved,
5568 and we attempt to completely resolve the reloc. If we can not do
5569 that, we determine the correct reloc code and put it back in the
5573 md_apply_fix (fixP
, valP
, seg
)
5576 segT seg ATTRIBUTE_UNUSED
;
5578 valueT value
= * valP
;
5581 if (fixP
->fx_addsy
!= NULL
)
5583 /* Hack around bfd_install_relocation brain damage. */
5585 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5590 /* FIXME FIXME FIXME: The value we are passed in *valP includes
5591 the symbol values. If we are doing this relocation the code in
5592 write.c is going to call bfd_install_relocation, which is also
5593 going to use the symbol value. That means that if the reloc is
5594 fully resolved we want to use *valP since bfd_install_relocation is
5596 However, if the reloc is not fully resolved we do not want to use
5597 *valP, and must use fx_offset instead. However, if the reloc
5598 is PC relative, we do want to use *valP since it includes the
5599 result of md_pcrel_from. This is confusing. */
5600 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
5603 else if (fixP
->fx_pcrel
)
5607 value
= fixP
->fx_offset
;
5610 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
5612 /* We can't actually support subtracting a symbol. */
5613 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
5616 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
5619 const struct powerpc_operand
*operand
;
5623 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
5625 operand
= &powerpc_operands
[opindex
];
5628 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5629 does not generate a reloc. It uses the offset of `sym' within its
5630 csect. Other usages, such as `.long sym', generate relocs. This
5631 is the documented behaviour of non-TOC symbols. */
5632 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5633 && operand
->bits
== 16
5634 && operand
->shift
== 0
5635 && (operand
->insert
== NULL
|| ppc_obj64
)
5636 && fixP
->fx_addsy
!= NULL
5637 && symbol_get_tc (fixP
->fx_addsy
)->subseg
!= 0
5638 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC
5639 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC0
5640 && S_GET_SEGMENT (fixP
->fx_addsy
) != bss_section
)
5642 value
= fixP
->fx_offset
;
5647 /* Fetch the instruction, insert the fully resolved operand
5648 value, and stuff the instruction back again. */
5649 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5650 if (target_big_endian
)
5651 insn
= bfd_getb32 ((unsigned char *) where
);
5653 insn
= bfd_getl32 ((unsigned char *) where
);
5654 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
5655 fixP
->fx_file
, fixP
->fx_line
);
5656 if (target_big_endian
)
5657 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5659 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5662 /* Nothing else to do here. */
5665 assert (fixP
->fx_addsy
!= NULL
);
5667 /* Determine a BFD reloc value based on the operand information.
5668 We are only prepared to turn a few of the operands into
5670 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5671 && operand
->bits
== 26
5672 && operand
->shift
== 0)
5673 fixP
->fx_r_type
= BFD_RELOC_PPC_B26
;
5674 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5675 && operand
->bits
== 16
5676 && operand
->shift
== 0)
5678 fixP
->fx_r_type
= BFD_RELOC_PPC_B16
;
5681 if (target_big_endian
)
5682 fixP
->fx_where
+= 2;
5685 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5686 && operand
->bits
== 26
5687 && operand
->shift
== 0)
5688 fixP
->fx_r_type
= BFD_RELOC_PPC_BA26
;
5689 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5690 && operand
->bits
== 16
5691 && operand
->shift
== 0)
5693 fixP
->fx_r_type
= BFD_RELOC_PPC_BA16
;
5696 if (target_big_endian
)
5697 fixP
->fx_where
+= 2;
5700 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5701 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5702 && operand
->bits
== 16
5703 && operand
->shift
== 0)
5705 if (ppc_is_toc_sym (fixP
->fx_addsy
))
5707 fixP
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
5710 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5711 fixP
->fx_r_type
= BFD_RELOC_PPC64_TOC16_DS
;
5716 fixP
->fx_r_type
= BFD_RELOC_16
;
5719 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5720 fixP
->fx_r_type
= BFD_RELOC_PPC64_ADDR16_DS
;
5724 if (target_big_endian
)
5725 fixP
->fx_where
+= 2;
5727 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5733 /* Use expr_symbol_where to see if this is an expression
5735 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
5736 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5737 _("unresolved expression that must be resolved"));
5739 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5740 _("unsupported relocation against %s"),
5741 S_GET_NAME (fixP
->fx_addsy
));
5749 ppc_elf_validate_fix (fixP
, seg
);
5751 switch (fixP
->fx_r_type
)
5753 case BFD_RELOC_CTOR
:
5760 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
5764 case BFD_RELOC_32_PCREL
:
5765 case BFD_RELOC_PPC_EMB_NADDR32
:
5766 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5773 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
5776 case BFD_RELOC_64_PCREL
:
5777 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5781 case BFD_RELOC_GPREL16
:
5782 case BFD_RELOC_16_GOT_PCREL
:
5783 case BFD_RELOC_16_GOTOFF
:
5784 case BFD_RELOC_LO16_GOTOFF
:
5785 case BFD_RELOC_HI16_GOTOFF
:
5786 case BFD_RELOC_HI16_S_GOTOFF
:
5787 case BFD_RELOC_16_BASEREL
:
5788 case BFD_RELOC_LO16_BASEREL
:
5789 case BFD_RELOC_HI16_BASEREL
:
5790 case BFD_RELOC_HI16_S_BASEREL
:
5791 case BFD_RELOC_PPC_EMB_NADDR16
:
5792 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5793 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5794 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5795 case BFD_RELOC_PPC_EMB_SDAI16
:
5796 case BFD_RELOC_PPC_EMB_SDA2REL
:
5797 case BFD_RELOC_PPC_EMB_SDA2I16
:
5798 case BFD_RELOC_PPC_EMB_RELSEC16
:
5799 case BFD_RELOC_PPC_EMB_RELST_LO
:
5800 case BFD_RELOC_PPC_EMB_RELST_HI
:
5801 case BFD_RELOC_PPC_EMB_RELST_HA
:
5802 case BFD_RELOC_PPC_EMB_RELSDA
:
5803 case BFD_RELOC_PPC_TOC16
:
5805 case BFD_RELOC_PPC64_TOC16_LO
:
5806 case BFD_RELOC_PPC64_TOC16_HI
:
5807 case BFD_RELOC_PPC64_TOC16_HA
:
5811 if (fixP
->fx_addsy
!= NULL
)
5812 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5813 _("cannot emit PC relative %s relocation against %s"),
5814 bfd_get_reloc_code_name (fixP
->fx_r_type
),
5815 S_GET_NAME (fixP
->fx_addsy
));
5817 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5818 _("cannot emit PC relative %s relocation"),
5819 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5822 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5828 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
5831 case BFD_RELOC_16_PCREL
:
5832 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5836 case BFD_RELOC_LO16
:
5838 fixP
->fx_r_type
= BFD_RELOC_LO16_PCREL
;
5841 case BFD_RELOC_LO16_PCREL
:
5842 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5846 /* This case happens when you write, for example,
5848 where L1 and L2 are defined later. */
5849 case BFD_RELOC_HI16
:
5851 fixP
->fx_r_type
= BFD_RELOC_HI16_PCREL
;
5854 case BFD_RELOC_HI16_PCREL
:
5855 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5859 case BFD_RELOC_HI16_S
:
5861 fixP
->fx_r_type
= BFD_RELOC_HI16_S_PCREL
;
5864 case BFD_RELOC_HI16_S_PCREL
:
5865 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5870 case BFD_RELOC_PPC64_HIGHER
:
5873 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5874 PPC_HIGHER (value
), 2);
5877 case BFD_RELOC_PPC64_HIGHER_S
:
5880 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5881 PPC_HIGHERA (value
), 2);
5884 case BFD_RELOC_PPC64_HIGHEST
:
5887 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5888 PPC_HIGHEST (value
), 2);
5891 case BFD_RELOC_PPC64_HIGHEST_S
:
5894 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5895 PPC_HIGHESTA (value
), 2);
5898 case BFD_RELOC_PPC64_ADDR16_DS
:
5899 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
5900 case BFD_RELOC_PPC64_GOT16_DS
:
5901 case BFD_RELOC_PPC64_GOT16_LO_DS
:
5902 case BFD_RELOC_PPC64_PLT16_LO_DS
:
5903 case BFD_RELOC_PPC64_SECTOFF_DS
:
5904 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
5905 case BFD_RELOC_PPC64_TOC16_DS
:
5906 case BFD_RELOC_PPC64_TOC16_LO_DS
:
5907 case BFD_RELOC_PPC64_PLTGOT16_DS
:
5908 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
5912 char *where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5913 unsigned long val
, mask
;
5915 if (target_big_endian
)
5916 val
= bfd_getb32 (where
- 2);
5918 val
= bfd_getl32 (where
);
5920 /* lq insns reserve the four lsbs. */
5921 if ((ppc_cpu
& PPC_OPCODE_POWER4
) != 0
5922 && (val
& (0x3f << 26)) == (56u << 26))
5924 val
|= value
& mask
;
5925 if (target_big_endian
)
5926 bfd_putb16 ((bfd_vma
) val
, where
);
5928 bfd_putl16 ((bfd_vma
) val
, where
);
5932 case BFD_RELOC_PPC_B16_BRTAKEN
:
5933 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5934 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5935 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5938 case BFD_RELOC_PPC_TLS
:
5941 case BFD_RELOC_PPC_DTPMOD
:
5942 case BFD_RELOC_PPC_TPREL16
:
5943 case BFD_RELOC_PPC_TPREL16_LO
:
5944 case BFD_RELOC_PPC_TPREL16_HI
:
5945 case BFD_RELOC_PPC_TPREL16_HA
:
5946 case BFD_RELOC_PPC_TPREL
:
5947 case BFD_RELOC_PPC_DTPREL16
:
5948 case BFD_RELOC_PPC_DTPREL16_LO
:
5949 case BFD_RELOC_PPC_DTPREL16_HI
:
5950 case BFD_RELOC_PPC_DTPREL16_HA
:
5951 case BFD_RELOC_PPC_DTPREL
:
5952 case BFD_RELOC_PPC_GOT_TLSGD16
:
5953 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
5954 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
5955 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
5956 case BFD_RELOC_PPC_GOT_TLSLD16
:
5957 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
5958 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
5959 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
5960 case BFD_RELOC_PPC_GOT_TPREL16
:
5961 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
5962 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
5963 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
5964 case BFD_RELOC_PPC_GOT_DTPREL16
:
5965 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
5966 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
5967 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
5968 case BFD_RELOC_PPC64_TPREL16_DS
:
5969 case BFD_RELOC_PPC64_TPREL16_LO_DS
:
5970 case BFD_RELOC_PPC64_TPREL16_HIGHER
:
5971 case BFD_RELOC_PPC64_TPREL16_HIGHERA
:
5972 case BFD_RELOC_PPC64_TPREL16_HIGHEST
:
5973 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
:
5974 case BFD_RELOC_PPC64_DTPREL16_DS
:
5975 case BFD_RELOC_PPC64_DTPREL16_LO_DS
:
5976 case BFD_RELOC_PPC64_DTPREL16_HIGHER
:
5977 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
:
5978 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
:
5979 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
:
5980 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
5983 /* Because SDA21 modifies the register field, the size is set to 4
5984 bytes, rather than 2, so offset it here appropriately. */
5985 case BFD_RELOC_PPC_EMB_SDA21
:
5989 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
5990 + ((target_big_endian
) ? 2 : 0),
5997 /* This can occur if there is a bug in the input assembler, eg:
5998 ".byte <undefined_symbol> - ." */
6000 as_bad (_("Unable to handle reference to symbol %s"),
6001 S_GET_NAME (fixP
->fx_addsy
));
6003 as_bad (_("Unable to resolve expression"));
6007 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6011 case BFD_RELOC_24_PLT_PCREL
:
6012 case BFD_RELOC_PPC_LOCAL24PC
:
6013 if (!fixP
->fx_pcrel
&& !fixP
->fx_done
)
6021 /* Fetch the instruction, insert the fully resolved operand
6022 value, and stuff the instruction back again. */
6023 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
6024 if (target_big_endian
)
6025 insn
= bfd_getb32 ((unsigned char *) where
);
6027 insn
= bfd_getl32 ((unsigned char *) where
);
6028 if ((value
& 3) != 0)
6029 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6030 _("must branch to an address a multiple of 4"));
6031 if ((offsetT
) value
< -0x40000000
6032 || (offsetT
) value
>= 0x40000000)
6033 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6034 _("@local or @plt branch destination is too far away, %ld bytes"),
6036 insn
= insn
| (value
& 0x03fffffc);
6037 if (target_big_endian
)
6038 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
6040 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
6044 case BFD_RELOC_VTABLE_INHERIT
:
6047 && !S_IS_DEFINED (fixP
->fx_addsy
)
6048 && !S_IS_WEAK (fixP
->fx_addsy
))
6049 S_SET_WEAK (fixP
->fx_addsy
);
6052 case BFD_RELOC_VTABLE_ENTRY
:
6057 /* Generated by reference to `sym@tocbase'. The sym is
6058 ignored by the linker. */
6059 case BFD_RELOC_PPC64_TOC
:
6065 _("Gas failure, reloc value %d\n"), fixP
->fx_r_type
);
6072 fixP
->fx_addnumber
= value
;
6074 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6075 from the section contents. If we are going to be emitting a reloc
6076 then the section contents are immaterial, so don't warn if they
6077 happen to overflow. Leave such warnings to ld. */
6079 fixP
->fx_no_overflow
= 1;
6081 if (fixP
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
6082 fixP
->fx_addnumber
= 0;
6086 fixP
->fx_addnumber
= 0;
6088 /* We want to use the offset within the data segment of the
6089 symbol, not the actual VMA of the symbol. */
6090 fixP
->fx_addnumber
=
6091 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixP
->fx_addsy
));
6097 /* Generate a reloc for a fixup. */
6100 tc_gen_reloc (seg
, fixp
)
6101 asection
*seg ATTRIBUTE_UNUSED
;
6106 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
6108 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
6109 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
6110 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
6111 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
6112 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
6114 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6115 _("reloc %d not supported by object file format"),
6116 (int) fixp
->fx_r_type
);
6119 reloc
->addend
= fixp
->fx_addnumber
;
6125 ppc_cfi_frame_initial_instructions ()
6127 cfi_add_CFA_def_cfa (1, 0);
6131 tc_ppc_regname_to_dw2regnum (char *regname
)
6133 unsigned int regnum
= -1;
6137 static struct { char *name
; int dw2regnum
; } regnames
[] =
6139 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6140 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6141 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6142 { "spe_acc", 111 }, { "spefscr", 112 }
6145 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
6146 if (strcmp (regnames
[i
].name
, regname
) == 0)
6147 return regnames
[i
].dw2regnum
;
6149 if (regname
[0] == 'r' || regname
[0] == 'f' || regname
[0] == 'v')
6151 p
= regname
+ 1 + (regname
[1] == '.');
6152 regnum
= strtoul (p
, &q
, 10);
6153 if (p
== q
|| *q
|| regnum
>= 32)
6155 if (regname
[0] == 'f')
6157 else if (regname
[0] == 'v')
6160 else if (regname
[0] == 'c' && regname
[1] == 'r')
6162 p
= regname
+ 2 + (regname
[2] == '.');
6163 if (p
[0] < '0' || p
[0] > '7' || p
[1])
6165 regnum
= p
[0] - '0' + 68;