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, 2007, 2008 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 3, 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 void ppc_macro (char *, const struct powerpc_macro
*);
88 static void ppc_byte (int);
90 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
91 static void ppc_tc (int);
92 static void ppc_machine (int);
96 static void ppc_comm (int);
97 static void ppc_bb (int);
98 static void ppc_bc (int);
99 static void ppc_bf (int);
100 static void ppc_biei (int);
101 static void ppc_bs (int);
102 static void ppc_eb (int);
103 static void ppc_ec (int);
104 static void ppc_ef (int);
105 static void ppc_es (int);
106 static void ppc_csect (int);
107 static void ppc_change_csect (symbolS
*, offsetT
);
108 static void ppc_function (int);
109 static void ppc_extern (int);
110 static void ppc_lglobl (int);
111 static void ppc_section (int);
112 static void ppc_named_section (int);
113 static void ppc_stabx (int);
114 static void ppc_rename (int);
115 static void ppc_toc (int);
116 static void ppc_xcoff_cons (int);
117 static void ppc_vbyte (int);
121 static void ppc_elf_cons (int);
122 static void ppc_elf_rdata (int);
123 static void ppc_elf_lcomm (int);
127 static void ppc_previous (int);
128 static void ppc_pdata (int);
129 static void ppc_ydata (int);
130 static void ppc_reldata (int);
131 static void ppc_rdata (int);
132 static void ppc_ualong (int);
133 static void ppc_znop (int);
134 static void ppc_pe_comm (int);
135 static void ppc_pe_section (int);
136 static void ppc_pe_function (int);
137 static void ppc_pe_tocd (int);
140 /* Generic assembler global variables which must be defined by all
144 /* This string holds the chars that always start a comment. If the
145 pre-processor is disabled, these aren't very useful. The macro
146 tc_comment_chars points to this. We use this, rather than the
147 usual comment_chars, so that we can switch for Solaris conventions. */
148 static const char ppc_solaris_comment_chars
[] = "#!";
149 static const char ppc_eabi_comment_chars
[] = "#";
151 #ifdef TARGET_SOLARIS_COMMENT
152 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
154 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
157 const char comment_chars
[] = "#";
160 /* Characters which start a comment at the beginning of a line. */
161 const char line_comment_chars
[] = "#";
163 /* Characters which may be used to separate multiple commands on a
165 const char line_separator_chars
[] = ";";
167 /* Characters which are used to indicate an exponent in a floating
169 const char EXP_CHARS
[] = "eE";
171 /* Characters which mean that a number is a floating point constant,
173 const char FLT_CHARS
[] = "dD";
175 /* Anything that can start an operand needs to be mentioned here,
176 to stop the input scrubber eating whitespace. */
177 const char ppc_symbol_chars
[] = "%[";
179 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
180 int ppc_cie_data_alignment
;
182 /* The type of processor we are assembling for. This is one or more
183 of the PPC_OPCODE flags defined in opcode/ppc.h. */
184 unsigned long ppc_cpu
= 0;
186 /* The target specific pseudo-ops which we support. */
188 const pseudo_typeS md_pseudo_table
[] =
190 /* Pseudo-ops which must be overridden. */
191 { "byte", ppc_byte
, 0 },
194 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
195 legitimately belong in the obj-*.c file. However, XCOFF is based
196 on COFF, and is only implemented for the RS/6000. We just use
197 obj-coff.c, and add what we need here. */
198 { "comm", ppc_comm
, 0 },
199 { "lcomm", ppc_comm
, 1 },
203 { "bi", ppc_biei
, 0 },
205 { "csect", ppc_csect
, 0 },
206 { "data", ppc_section
, 'd' },
210 { "ei", ppc_biei
, 1 },
212 { "extern", ppc_extern
, 0 },
213 { "function", ppc_function
, 0 },
214 { "lglobl", ppc_lglobl
, 0 },
215 { "rename", ppc_rename
, 0 },
216 { "section", ppc_named_section
, 0 },
217 { "stabx", ppc_stabx
, 0 },
218 { "text", ppc_section
, 't' },
219 { "toc", ppc_toc
, 0 },
220 { "long", ppc_xcoff_cons
, 2 },
221 { "llong", ppc_xcoff_cons
, 3 },
222 { "word", ppc_xcoff_cons
, 1 },
223 { "short", ppc_xcoff_cons
, 1 },
224 { "vbyte", ppc_vbyte
, 0 },
228 { "llong", ppc_elf_cons
, 8 },
229 { "quad", ppc_elf_cons
, 8 },
230 { "long", ppc_elf_cons
, 4 },
231 { "word", ppc_elf_cons
, 2 },
232 { "short", ppc_elf_cons
, 2 },
233 { "rdata", ppc_elf_rdata
, 0 },
234 { "rodata", ppc_elf_rdata
, 0 },
235 { "lcomm", ppc_elf_lcomm
, 0 },
239 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
240 { "previous", ppc_previous
, 0 },
241 { "pdata", ppc_pdata
, 0 },
242 { "ydata", ppc_ydata
, 0 },
243 { "reldata", ppc_reldata
, 0 },
244 { "rdata", ppc_rdata
, 0 },
245 { "ualong", ppc_ualong
, 0 },
246 { "znop", ppc_znop
, 0 },
247 { "comm", ppc_pe_comm
, 0 },
248 { "lcomm", ppc_pe_comm
, 1 },
249 { "section", ppc_pe_section
, 0 },
250 { "function", ppc_pe_function
,0 },
251 { "tocd", ppc_pe_tocd
, 0 },
254 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
256 { "machine", ppc_machine
, 0 },
263 /* Predefined register names if -mregnames (or default for Windows NT).
264 In general, there are lots of them, in an attempt to be compatible
265 with a number of other Windows NT assemblers. */
267 /* Structure to hold information about predefined registers. */
274 /* List of registers that are pre-defined:
276 Each general register has predefined names of the form:
277 1. r<reg_num> which has the value <reg_num>.
278 2. r.<reg_num> which has the value <reg_num>.
280 Each floating point register has predefined names of the form:
281 1. f<reg_num> which has the value <reg_num>.
282 2. f.<reg_num> which has the value <reg_num>.
284 Each vector unit register has predefined names of the form:
285 1. v<reg_num> which has the value <reg_num>.
286 2. v.<reg_num> which has the value <reg_num>.
288 Each condition register has predefined names of the form:
289 1. cr<reg_num> which has the value <reg_num>.
290 2. cr.<reg_num> which has the value <reg_num>.
292 There are individual registers as well:
293 sp or r.sp has the value 1
294 rtoc or r.toc has the value 2
295 fpscr has the value 0
301 dsisr has the value 18
303 sdr1 has the value 25
304 srr0 has the value 26
305 srr1 has the value 27
307 The table is sorted. Suitable for searching by a binary search. */
309 static const struct pd_reg pre_defined_registers
[] =
311 { "cr.0", 0 }, /* Condition Registers */
331 { "dar", 19 }, /* Data Access Register */
332 { "dec", 22 }, /* Decrementer */
333 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
335 { "f.0", 0 }, /* Floating point registers */
403 /* Quantization registers used with pair single instructions. */
421 { "lr", 8 }, /* Link Register */
425 { "r.0", 0 }, /* General Purpose Registers */
458 { "r.sp", 1 }, /* Stack Pointer */
460 { "r.toc", 2 }, /* Pointer to the table of contents */
462 { "r0", 0 }, /* More general purpose registers */
495 { "rtoc", 2 }, /* Table of contents */
497 { "sdr1", 25 }, /* Storage Description Register 1 */
501 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
502 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
504 { "v.0", 0 }, /* Vector registers */
574 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
576 /* Given NAME, find the register number associated with that name, return
577 the integer value associated with the given name or -1 on failure. */
580 reg_name_search (const struct pd_reg
*regs
, int regcount
, const char *name
)
582 int middle
, low
, high
;
590 middle
= (low
+ high
) / 2;
591 cmp
= strcasecmp (name
, regs
[middle
].name
);
597 return regs
[middle
].value
;
605 * Summary of register_name.
607 * in: Input_line_pointer points to 1st char of operand.
609 * out: A expressionS.
610 * The operand may have been a register: in this case, X_op == O_register,
611 * X_add_number is set to the register number, and truth is returned.
612 * Input_line_pointer->(next non-blank) char after operand, or is in its
617 register_name (expressionS
*expressionP
)
624 /* Find the spelling of the operand. */
625 start
= name
= input_line_pointer
;
626 if (name
[0] == '%' && ISALPHA (name
[1]))
627 name
= ++input_line_pointer
;
629 else if (!reg_names_p
|| !ISALPHA (name
[0]))
632 c
= get_symbol_end ();
633 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
635 /* Put back the delimiting char. */
636 *input_line_pointer
= c
;
638 /* Look to see if it's in the register table. */
641 expressionP
->X_op
= O_register
;
642 expressionP
->X_add_number
= reg_number
;
644 /* Make the rest nice. */
645 expressionP
->X_add_symbol
= NULL
;
646 expressionP
->X_op_symbol
= NULL
;
650 /* Reset the line as if we had not done anything. */
651 input_line_pointer
= start
;
655 /* This function is called for each symbol seen in an expression. It
656 handles the special parsing which PowerPC assemblers are supposed
657 to use for condition codes. */
659 /* Whether to do the special parsing. */
660 static bfd_boolean cr_operand
;
662 /* Names to recognize in a condition code. This table is sorted. */
663 static const struct pd_reg cr_names
[] =
680 /* Parsing function. This returns non-zero if it recognized an
684 ppc_parse_name (const char *name
, expressionS
*expr
)
693 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
698 expr
->X_op
= O_constant
;
699 expr
->X_add_number
= val
;
704 /* Local variables. */
706 /* Whether to target xcoff64/elf64. */
707 static unsigned int ppc_obj64
= BFD_DEFAULT_TARGET_SIZE
== 64;
709 /* Opcode hash table. */
710 static struct hash_control
*ppc_hash
;
712 /* Macro hash table. */
713 static struct hash_control
*ppc_macro_hash
;
716 /* What type of shared library support to use. */
717 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
719 /* Flags to set in the elf header. */
720 static flagword ppc_flags
= 0;
722 /* Whether this is Solaris or not. */
723 #ifdef TARGET_SOLARIS_COMMENT
724 #define SOLARIS_P TRUE
726 #define SOLARIS_P FALSE
729 static bfd_boolean msolaris
= SOLARIS_P
;
734 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
735 using a bunch of different sections. These assembler sections,
736 however, are all encompassed within the .text or .data sections of
737 the final output file. We handle this by using different
738 subsegments within these main segments. */
740 /* Next subsegment to allocate within the .text segment. */
741 static subsegT ppc_text_subsegment
= 2;
743 /* Linked list of csects in the text section. */
744 static symbolS
*ppc_text_csects
;
746 /* Next subsegment to allocate within the .data segment. */
747 static subsegT ppc_data_subsegment
= 2;
749 /* Linked list of csects in the data section. */
750 static symbolS
*ppc_data_csects
;
752 /* The current csect. */
753 static symbolS
*ppc_current_csect
;
755 /* The RS/6000 assembler uses a TOC which holds addresses of functions
756 and variables. Symbols are put in the TOC with the .tc pseudo-op.
757 A special relocation is used when accessing TOC entries. We handle
758 the TOC as a subsegment within the .data segment. We set it up if
759 we see a .toc pseudo-op, and save the csect symbol here. */
760 static symbolS
*ppc_toc_csect
;
762 /* The first frag in the TOC subsegment. */
763 static fragS
*ppc_toc_frag
;
765 /* The first frag in the first subsegment after the TOC in the .data
766 segment. NULL if there are no subsegments after the TOC. */
767 static fragS
*ppc_after_toc_frag
;
769 /* The current static block. */
770 static symbolS
*ppc_current_block
;
772 /* The COFF debugging section; set by md_begin. This is not the
773 .debug section, but is instead the secret BFD section which will
774 cause BFD to set the section number of a symbol to N_DEBUG. */
775 static asection
*ppc_coff_debug_section
;
777 #endif /* OBJ_XCOFF */
781 /* Various sections that we need for PE coff support. */
782 static segT ydata_section
;
783 static segT pdata_section
;
784 static segT reldata_section
;
785 static segT rdata_section
;
786 static segT tocdata_section
;
788 /* The current section and the previous section. See ppc_previous. */
789 static segT ppc_previous_section
;
790 static segT ppc_current_section
;
795 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
796 #define PPC_APUINFO_ISEL 0x40
797 #define PPC_APUINFO_PMR 0x41
798 #define PPC_APUINFO_RFMCI 0x42
799 #define PPC_APUINFO_CACHELCK 0x43
800 #define PPC_APUINFO_SPE 0x100
801 #define PPC_APUINFO_EFS 0x101
802 #define PPC_APUINFO_BRLOCK 0x102
805 * We keep a list of APUinfo
807 unsigned long *ppc_apuinfo_list
;
808 unsigned int ppc_apuinfo_num
;
809 unsigned int ppc_apuinfo_num_alloc
;
813 const char *const md_shortopts
= "b:l:usm:K:VQ:";
815 const char *const md_shortopts
= "um:";
817 const struct option md_longopts
[] = {
818 {NULL
, no_argument
, NULL
, 0}
820 const size_t md_longopts_size
= sizeof (md_longopts
);
823 /* Handle -m options that set cpu type, and .machine arg. */
826 parse_cpu (const char *arg
)
828 unsigned long altivec_or_spe
= ppc_cpu
& (PPC_OPCODE_ALTIVEC
| PPC_OPCODE_SPE
);
830 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
832 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
833 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_32
;
834 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
835 else if (strcmp (arg
, "pwr") == 0)
836 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
837 /* -m601 means to assemble for the PowerPC 601, which includes
838 instructions that are holdovers from the Power. */
839 else if (strcmp (arg
, "601") == 0)
840 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
841 | PPC_OPCODE_601
| PPC_OPCODE_32
);
842 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
844 else if (strcmp (arg
, "ppc") == 0
845 || strcmp (arg
, "ppc32") == 0
846 || strcmp (arg
, "603") == 0
847 || strcmp (arg
, "604") == 0)
848 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
849 /* Do all PPC750s have paired single ops? */
850 else if (strcmp (arg
, "750cl") == 0)
851 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_PPCPS
;
852 /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */
853 else if (strcmp (arg
, "403") == 0
854 || strcmp (arg
, "405") == 0)
855 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
856 | PPC_OPCODE_403
| PPC_OPCODE_32
);
857 else if (strcmp (arg
, "440") == 0)
858 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
859 | PPC_OPCODE_440
| PPC_OPCODE_ISEL
| PPC_OPCODE_RFMCI
);
860 else if (strcmp (arg
, "7400") == 0
861 || strcmp (arg
, "7410") == 0
862 || strcmp (arg
, "7450") == 0
863 || strcmp (arg
, "7455") == 0)
864 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
865 | PPC_OPCODE_ALTIVEC
| PPC_OPCODE_32
);
866 else if (strcmp (arg
, "e300") == 0)
867 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
869 else if (strcmp (arg
, "altivec") == 0)
872 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
;
874 altivec_or_spe
|= PPC_OPCODE_ALTIVEC
;
876 else if (strcmp (arg
, "e500") == 0 || strcmp (arg
, "e500x2") == 0)
878 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
879 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
880 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
883 else if (strcmp (arg
, "spe") == 0)
886 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_EFS
;
888 altivec_or_spe
|= PPC_OPCODE_SPE
;
890 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
892 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
894 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
896 else if (strcmp (arg
, "ppc64bridge") == 0)
898 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
899 | PPC_OPCODE_64_BRIDGE
| PPC_OPCODE_64
);
901 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
902 else if (strcmp (arg
, "booke") == 0 || strcmp (arg
, "booke32") == 0)
904 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
;
906 /* -mbooke64 means enable 64-bit BookE support. */
907 else if (strcmp (arg
, "booke64") == 0)
909 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
910 | PPC_OPCODE_BOOKE64
| PPC_OPCODE_64
);
912 else if (strcmp (arg
, "power4") == 0)
914 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
915 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
);
917 else if (strcmp (arg
, "power5") == 0)
919 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
920 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
921 | PPC_OPCODE_POWER5
);
923 else if (strcmp (arg
, "power6") == 0)
925 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
926 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
927 | PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
);
929 else if (strcmp (arg
, "cell") == 0)
931 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
932 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
935 /* -mcom means assemble for the common intersection between Power
936 and PowerPC. At present, we just allow the union, rather
937 than the intersection. */
938 else if (strcmp (arg
, "com") == 0)
939 ppc_cpu
= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
940 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
941 else if (strcmp (arg
, "any") == 0)
942 ppc_cpu
|= PPC_OPCODE_ANY
;
946 /* Make sure the the Altivec and SPE bits are not lost. */
947 ppc_cpu
|= altivec_or_spe
;
952 md_parse_option (int c
, char *arg
)
957 /* -u means that any undefined symbols should be treated as
958 external, which is the default for gas anyhow. */
963 /* Solaris as takes -le (presumably for little endian). For completeness
964 sake, recognize -be also. */
965 if (strcmp (arg
, "e") == 0)
967 target_big_endian
= 0;
968 set_target_endian
= 1;
976 if (strcmp (arg
, "e") == 0)
978 target_big_endian
= 1;
979 set_target_endian
= 1;
987 /* Recognize -K PIC. */
988 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
991 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
999 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
1001 if (strcmp (arg
, "64") == 0)
1006 as_fatal (_("%s unsupported"), "-a64");
1009 else if (strcmp (arg
, "32") == 0)
1016 if (parse_cpu (arg
))
1019 else if (strcmp (arg
, "regnames") == 0)
1022 else if (strcmp (arg
, "no-regnames") == 0)
1023 reg_names_p
= FALSE
;
1026 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1027 that require relocation. */
1028 else if (strcmp (arg
, "relocatable") == 0)
1030 shlib
= SHLIB_MRELOCATABLE
;
1031 ppc_flags
|= EF_PPC_RELOCATABLE
;
1034 else if (strcmp (arg
, "relocatable-lib") == 0)
1036 shlib
= SHLIB_MRELOCATABLE
;
1037 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
1040 /* -memb, set embedded bit. */
1041 else if (strcmp (arg
, "emb") == 0)
1042 ppc_flags
|= EF_PPC_EMB
;
1044 /* -mlittle/-mbig set the endianess. */
1045 else if (strcmp (arg
, "little") == 0
1046 || strcmp (arg
, "little-endian") == 0)
1048 target_big_endian
= 0;
1049 set_target_endian
= 1;
1052 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
1054 target_big_endian
= 1;
1055 set_target_endian
= 1;
1058 else if (strcmp (arg
, "solaris") == 0)
1061 ppc_comment_chars
= ppc_solaris_comment_chars
;
1064 else if (strcmp (arg
, "no-solaris") == 0)
1067 ppc_comment_chars
= ppc_eabi_comment_chars
;
1072 as_bad (_("invalid switch -m%s"), arg
);
1078 /* -V: SVR4 argument to print version ID. */
1080 print_version_id ();
1083 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1084 should be emitted or not. FIXME: Not implemented. */
1088 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1089 rather than .stabs.excl, which is ignored by the linker.
1090 FIXME: Not implemented. */
1106 md_show_usage (FILE *stream
)
1108 fprintf (stream
, _("\
1110 -a32 generate ELF32/XCOFF32\n\
1111 -a64 generate ELF64/XCOFF64\n\
1113 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1114 -mpwr generate code for POWER (RIOS1)\n\
1115 -m601 generate code for PowerPC 601\n\
1116 -mppc, -mppc32, -m603, -m604\n\
1117 generate code for PowerPC 603/604\n\
1118 -m403, -m405 generate code for PowerPC 403/405\n\
1119 -m440 generate code for PowerPC 440\n\
1120 -m7400, -m7410, -m7450, -m7455\n\
1121 generate code for PowerPC 7400/7410/7450/7455\n\
1122 -m750cl generate code for PowerPC 750cl\n"));
1123 fprintf (stream
, _("\
1124 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1125 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1126 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1127 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1128 -mpower4 generate code for Power4 architecture\n\
1129 -mpower5 generate code for Power5 architecture\n\
1130 -mpower6 generate code for Power6 architecture\n\
1131 -mcell generate code for Cell Broadband Engine architecture\n\
1132 -mcom generate code Power/PowerPC common instructions\n\
1133 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1134 fprintf (stream
, _("\
1135 -maltivec generate code for AltiVec\n\
1136 -me300 generate code for PowerPC e300 family\n\
1137 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1138 -mspe generate code for Motorola SPE instructions\n\
1139 -mregnames Allow symbolic names for registers\n\
1140 -mno-regnames Do not allow symbolic names for registers\n"));
1142 fprintf (stream
, _("\
1143 -mrelocatable support for GCC's -mrelocatble option\n\
1144 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1145 -memb set PPC_EMB bit in ELF flags\n\
1146 -mlittle, -mlittle-endian, -l, -le\n\
1147 generate code for a little endian machine\n\
1148 -mbig, -mbig-endian, -b, -be\n\
1149 generate code for a big endian machine\n\
1150 -msolaris generate code for Solaris\n\
1151 -mno-solaris do not generate code for Solaris\n\
1152 -V print assembler version number\n\
1153 -Qy, -Qn ignored\n"));
1157 /* Set ppc_cpu if it is not already set. */
1162 const char *default_os
= TARGET_OS
;
1163 const char *default_cpu
= TARGET_CPU
;
1165 if ((ppc_cpu
& ~PPC_OPCODE_ANY
) == 0)
1168 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
1169 else if (strncmp (default_os
, "aix", 3) == 0
1170 && default_os
[3] >= '4' && default_os
[3] <= '9')
1171 ppc_cpu
|= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
1172 else if (strncmp (default_os
, "aix3", 4) == 0)
1173 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1174 else if (strcmp (default_cpu
, "rs6000") == 0)
1175 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1176 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1177 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
1179 as_fatal (_("Unknown default cpu = %s, os = %s"),
1180 default_cpu
, default_os
);
1184 /* Figure out the BFD architecture to use. This function and ppc_mach
1185 are called well before md_begin, when the output file is opened. */
1187 enum bfd_architecture
1190 const char *default_cpu
= TARGET_CPU
;
1193 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1194 return bfd_arch_powerpc
;
1195 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1196 return bfd_arch_rs6000
;
1197 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1199 if (strcmp (default_cpu
, "rs6000") == 0)
1200 return bfd_arch_rs6000
;
1201 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1202 return bfd_arch_powerpc
;
1205 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1206 return bfd_arch_unknown
;
1213 return bfd_mach_ppc64
;
1214 else if (ppc_arch () == bfd_arch_rs6000
)
1215 return bfd_mach_rs6k
;
1217 return bfd_mach_ppc
;
1221 ppc_target_format (void)
1225 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1227 return "xcoff-powermac";
1230 return (ppc_obj64
? "aix5coff64-rs6000" : "aixcoff-rs6000");
1232 return (ppc_obj64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1238 return "elf32-powerpc-vxworks";
1240 return (target_big_endian
1241 ? (ppc_obj64
? "elf64-powerpc" : "elf32-powerpc")
1242 : (ppc_obj64
? "elf64-powerpcle" : "elf32-powerpcle"));
1247 /* Insert opcodes and macros into hash tables. Called at startup and
1251 ppc_setup_opcodes (void)
1253 const struct powerpc_opcode
*op
;
1254 const struct powerpc_opcode
*op_end
;
1255 const struct powerpc_macro
*macro
;
1256 const struct powerpc_macro
*macro_end
;
1257 bfd_boolean bad_insn
= FALSE
;
1259 if (ppc_hash
!= NULL
)
1260 hash_die (ppc_hash
);
1261 if (ppc_macro_hash
!= NULL
)
1262 hash_die (ppc_macro_hash
);
1264 /* Insert the opcodes into a hash table. */
1265 ppc_hash
= hash_new ();
1267 if (ENABLE_CHECKING
)
1271 /* Check operand masks. Code here and in the disassembler assumes
1272 all the 1's in the mask are contiguous. */
1273 for (i
= 0; i
< num_powerpc_operands
; ++i
)
1275 unsigned long mask
= powerpc_operands
[i
].bitm
;
1276 unsigned long right_bit
;
1279 right_bit
= mask
& -mask
;
1281 right_bit
= mask
& -mask
;
1282 if (mask
!= right_bit
)
1284 as_bad (_("powerpc_operands[%d].bitm invalid"), i
);
1287 for (j
= i
+ 1; j
< num_powerpc_operands
; ++j
)
1288 if (memcmp (&powerpc_operands
[i
], &powerpc_operands
[j
],
1289 sizeof (powerpc_operands
[0])) == 0)
1291 as_bad (_("powerpc_operands[%d] duplicates powerpc_operands[%d]"),
1298 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1299 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1301 if (ENABLE_CHECKING
)
1303 const unsigned char *o
;
1304 unsigned long omask
= op
->mask
;
1306 if (op
!= powerpc_opcodes
)
1308 /* The major opcodes had better be sorted. Code in the
1309 disassembler assumes the insns are sorted according to
1311 if (PPC_OP (op
[0].opcode
) < PPC_OP (op
[-1].opcode
))
1313 as_bad (_("major opcode is not sorted for %s"),
1318 /* Warn if the table isn't more strictly ordered.
1319 Unfortunately it doesn't seem possible to order the
1320 table on much more than the major opcode, which makes
1321 it difficult to implement a binary search in the
1322 disassembler. The problem is that we have multiple
1323 ways to disassemble instructions, and we usually want
1324 to choose a more specific form (with more bits set in
1325 the opcode) than a more general form. eg. all of the
1326 following are equivalent:
1327 bne label # opcode = 0x40820000, mask = 0xff830003
1328 bf 2,label # opcode = 0x40800000, mask = 0xff800003
1329 bc 4,2,label # opcode = 0x40000000, mask = 0xfc000003
1331 There are also cases where the table needs to be out
1332 of order to disassemble the correct instruction for
1333 processor variants. eg. "lhae" booke64 insn must be
1334 found before "ld" ppc64 insn. */
1337 unsigned long t1
= op
[0].opcode
;
1338 unsigned long t2
= op
[-1].opcode
;
1340 if (((t1
^ t2
) & 0xfc0007ff) == 0
1341 && (t1
& 0xfc0006df) == 0x7c000286)
1343 /* spr field is split. */
1344 t1
= ((t1
& ~0x1ff800)
1345 | ((t1
& 0xf800) << 5) | ((t1
& 0x1f0000) >> 5));
1346 t2
= ((t2
& ~0x1ff800)
1347 | ((t2
& 0xf800) << 5) | ((t2
& 0x1f0000) >> 5));
1350 as_warn (_("%s (%08lx %08lx) after %s (%08lx %08lx)"),
1351 op
[0].name
, op
[0].opcode
, op
[0].mask
,
1352 op
[-1].name
, op
[-1].opcode
, op
[-1].mask
);
1356 /* The mask had better not trim off opcode bits. */
1357 if ((op
->opcode
& omask
) != op
->opcode
)
1359 as_bad (_("mask trims opcode bits for %s"),
1364 /* The operands must not overlap the opcode or each other. */
1365 for (o
= op
->operands
; *o
; ++o
)
1366 if (*o
>= num_powerpc_operands
)
1368 as_bad (_("operand index error for %s"),
1374 const struct powerpc_operand
*operand
= &powerpc_operands
[*o
];
1375 if (operand
->shift
>= 0)
1377 unsigned long mask
= operand
->bitm
<< operand
->shift
;
1380 as_bad (_("operand %d overlap in %s"),
1381 (int) (o
- op
->operands
), op
->name
);
1389 if ((op
->flags
& ppc_cpu
& ~(PPC_OPCODE_32
| PPC_OPCODE_64
)) != 0
1390 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1391 || ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
))
1392 == (ppc_cpu
& (PPC_OPCODE_32
| PPC_OPCODE_64
)))
1393 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0)
1394 /* Certain instructions (eg: extsw) do not exist in the
1395 32-bit BookE instruction set, but they do exist in the
1396 64-bit BookE instruction set, and other PPC instruction
1397 sets. Check to see if the opcode has the BOOKE64 flag set.
1398 If it does make sure that the target CPU is not the BookE32. */
1399 && ((op
->flags
& PPC_OPCODE_BOOKE64
) == 0
1400 || (ppc_cpu
& PPC_OPCODE_BOOKE64
) == PPC_OPCODE_BOOKE64
1401 || (ppc_cpu
& PPC_OPCODE_BOOKE
) == 0)
1402 && ((op
->flags
& (PPC_OPCODE_POWER4
| PPC_OPCODE_NOPOWER4
)) == 0
1403 || ((op
->flags
& PPC_OPCODE_POWER4
)
1404 == (ppc_cpu
& PPC_OPCODE_POWER4
)))
1405 && ((op
->flags
& PPC_OPCODE_POWER5
) == 0
1406 || ((op
->flags
& PPC_OPCODE_POWER5
)
1407 == (ppc_cpu
& PPC_OPCODE_POWER5
)))
1408 && ((op
->flags
& PPC_OPCODE_POWER6
) == 0
1409 || ((op
->flags
& PPC_OPCODE_POWER6
)
1410 == (ppc_cpu
& PPC_OPCODE_POWER6
))))
1414 retval
= hash_insert (ppc_hash
, op
->name
, (void *) op
);
1417 /* Ignore Power duplicates for -m601. */
1418 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1419 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1422 as_bad (_("duplicate instruction %s"),
1429 if ((ppc_cpu
& PPC_OPCODE_ANY
) != 0)
1430 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1431 hash_insert (ppc_hash
, op
->name
, (void *) op
);
1433 /* Insert the macros into a hash table. */
1434 ppc_macro_hash
= hash_new ();
1436 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1437 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1439 if ((macro
->flags
& ppc_cpu
) != 0)
1443 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (void *) macro
);
1444 if (retval
!= (const char *) NULL
)
1446 as_bad (_("duplicate macro %s"), macro
->name
);
1456 /* This function is called when the assembler starts up. It is called
1457 after the options have been parsed and the output file has been
1465 ppc_cie_data_alignment
= ppc_obj64
? -8 : -4;
1468 /* Set the ELF flags if desired. */
1469 if (ppc_flags
&& !msolaris
)
1470 bfd_set_private_flags (stdoutput
, ppc_flags
);
1473 ppc_setup_opcodes ();
1475 /* Tell the main code what the endianness is if it is not overridden
1477 if (!set_target_endian
)
1479 set_target_endian
= 1;
1480 target_big_endian
= PPC_BIG_ENDIAN
;
1484 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1486 /* Create dummy symbols to serve as initial csects. This forces the
1487 text csects to precede the data csects. These symbols will not
1489 ppc_text_csects
= symbol_make ("dummy\001");
1490 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1491 ppc_data_csects
= symbol_make ("dummy\001");
1492 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1497 ppc_current_section
= text_section
;
1498 ppc_previous_section
= 0;
1507 if (ppc_apuinfo_list
== NULL
)
1510 /* Ok, so write the section info out. We have this layout:
1514 0 8 length of "APUinfo\0"
1515 4 (n*4) number of APU's (4 bytes each)
1518 20 APU#1 first APU's info
1519 24 APU#2 second APU's info
1524 asection
*seg
= now_seg
;
1525 subsegT subseg
= now_subseg
;
1526 asection
*apuinfo_secp
= (asection
*) NULL
;
1529 /* Create the .PPC.EMB.apuinfo section. */
1530 apuinfo_secp
= subseg_new (".PPC.EMB.apuinfo", 0);
1531 bfd_set_section_flags (stdoutput
,
1533 SEC_HAS_CONTENTS
| SEC_READONLY
);
1536 md_number_to_chars (p
, (valueT
) 8, 4);
1539 md_number_to_chars (p
, (valueT
) ppc_apuinfo_num
* 4, 4);
1542 md_number_to_chars (p
, (valueT
) 2, 4);
1545 strcpy (p
, "APUinfo");
1547 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
1550 md_number_to_chars (p
, (valueT
) ppc_apuinfo_list
[i
], 4);
1553 frag_align (2, 0, 0);
1555 /* We probably can't restore the current segment, for there likely
1558 subseg_set (seg
, subseg
);
1563 /* Insert an operand value into an instruction. */
1565 static unsigned long
1566 ppc_insert_operand (unsigned long insn
,
1567 const struct powerpc_operand
*operand
,
1569 unsigned long ppc_cpu
,
1573 long min
, max
, right
;
1575 max
= operand
->bitm
;
1579 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1581 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) == 0)
1582 max
= (max
>> 1) & -right
;
1583 min
= ~max
& -right
;
1586 if ((operand
->flags
& PPC_OPERAND_PLUS1
) != 0)
1589 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1598 /* Some people write constants with the sign extension done by
1599 hand but only up to 32 bits. This shouldn't really be valid,
1600 but, to permit this code to assemble on a 64-bit host, we
1601 sign extend the 32-bit value to 64 bits if so doing makes the
1604 && (offsetT
) (val
- 0x80000000 - 0x80000000) >= min
1605 && (offsetT
) (val
- 0x80000000 - 0x80000000) <= max
1606 && ((val
- 0x80000000 - 0x80000000) & (right
- 1)) == 0)
1607 val
= val
- 0x80000000 - 0x80000000;
1609 /* Similarly, people write expressions like ~(1<<15), and expect
1610 this to be OK for a 32-bit unsigned value. */
1612 && (offsetT
) (val
+ 0x80000000 + 0x80000000) >= min
1613 && (offsetT
) (val
+ 0x80000000 + 0x80000000) <= max
1614 && ((val
+ 0x80000000 + 0x80000000) & (right
- 1)) == 0)
1615 val
= val
+ 0x80000000 + 0x80000000;
1619 || (val
& (right
- 1)) != 0)
1620 as_bad_value_out_of_range (_("operand"), val
, min
, max
, file
, line
);
1623 if (operand
->insert
)
1628 insn
= (*operand
->insert
) (insn
, (long) val
, ppc_cpu
, &errmsg
);
1629 if (errmsg
!= (const char *) NULL
)
1630 as_bad_where (file
, line
, errmsg
);
1633 insn
|= ((long) val
& operand
->bitm
) << operand
->shift
;
1640 /* Parse @got, etc. and return the desired relocation. */
1641 static bfd_reloc_code_real_type
1642 ppc_elf_suffix (char **str_p
, expressionS
*exp_p
)
1646 unsigned int length
: 8;
1647 unsigned int valid32
: 1;
1648 unsigned int valid64
: 1;
1657 const struct map_bfd
*ptr
;
1659 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
1660 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
1661 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
1663 static const struct map_bfd mapping
[] = {
1664 MAP ("l", BFD_RELOC_LO16
),
1665 MAP ("h", BFD_RELOC_HI16
),
1666 MAP ("ha", BFD_RELOC_HI16_S
),
1667 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1668 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1669 MAP ("got", BFD_RELOC_16_GOTOFF
),
1670 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1671 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1672 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1673 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1674 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1675 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1676 MAP ("copy", BFD_RELOC_PPC_COPY
),
1677 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1678 MAP ("sectoff", BFD_RELOC_16_BASEREL
),
1679 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1680 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1681 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1682 MAP ("tls", BFD_RELOC_PPC_TLS
),
1683 MAP ("dtpmod", BFD_RELOC_PPC_DTPMOD
),
1684 MAP ("dtprel", BFD_RELOC_PPC_DTPREL
),
1685 MAP ("dtprel@l", BFD_RELOC_PPC_DTPREL16_LO
),
1686 MAP ("dtprel@h", BFD_RELOC_PPC_DTPREL16_HI
),
1687 MAP ("dtprel@ha", BFD_RELOC_PPC_DTPREL16_HA
),
1688 MAP ("tprel", BFD_RELOC_PPC_TPREL
),
1689 MAP ("tprel@l", BFD_RELOC_PPC_TPREL16_LO
),
1690 MAP ("tprel@h", BFD_RELOC_PPC_TPREL16_HI
),
1691 MAP ("tprel@ha", BFD_RELOC_PPC_TPREL16_HA
),
1692 MAP ("got@tlsgd", BFD_RELOC_PPC_GOT_TLSGD16
),
1693 MAP ("got@tlsgd@l", BFD_RELOC_PPC_GOT_TLSGD16_LO
),
1694 MAP ("got@tlsgd@h", BFD_RELOC_PPC_GOT_TLSGD16_HI
),
1695 MAP ("got@tlsgd@ha", BFD_RELOC_PPC_GOT_TLSGD16_HA
),
1696 MAP ("got@tlsld", BFD_RELOC_PPC_GOT_TLSLD16
),
1697 MAP ("got@tlsld@l", BFD_RELOC_PPC_GOT_TLSLD16_LO
),
1698 MAP ("got@tlsld@h", BFD_RELOC_PPC_GOT_TLSLD16_HI
),
1699 MAP ("got@tlsld@ha", BFD_RELOC_PPC_GOT_TLSLD16_HA
),
1700 MAP ("got@dtprel", BFD_RELOC_PPC_GOT_DTPREL16
),
1701 MAP ("got@dtprel@l", BFD_RELOC_PPC_GOT_DTPREL16_LO
),
1702 MAP ("got@dtprel@h", BFD_RELOC_PPC_GOT_DTPREL16_HI
),
1703 MAP ("got@dtprel@ha", BFD_RELOC_PPC_GOT_DTPREL16_HA
),
1704 MAP ("got@tprel", BFD_RELOC_PPC_GOT_TPREL16
),
1705 MAP ("got@tprel@l", BFD_RELOC_PPC_GOT_TPREL16_LO
),
1706 MAP ("got@tprel@h", BFD_RELOC_PPC_GOT_TPREL16_HI
),
1707 MAP ("got@tprel@ha", BFD_RELOC_PPC_GOT_TPREL16_HA
),
1708 MAP32 ("fixup", BFD_RELOC_CTOR
),
1709 MAP32 ("plt", BFD_RELOC_24_PLT_PCREL
),
1710 MAP32 ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1711 MAP32 ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1712 MAP32 ("local", BFD_RELOC_PPC_LOCAL24PC
),
1713 MAP32 ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1714 MAP32 ("sdarel", BFD_RELOC_GPREL16
),
1715 MAP32 ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1716 MAP32 ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1717 MAP32 ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1718 MAP32 ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1719 MAP32 ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1720 MAP32 ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1721 MAP32 ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1722 MAP32 ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1723 MAP32 ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1724 MAP32 ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1725 MAP32 ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1726 MAP32 ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1727 MAP32 ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1728 MAP32 ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1729 MAP32 ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1730 MAP32 ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1731 MAP32 ("xgot", BFD_RELOC_PPC_TOC16
),
1732 MAP64 ("higher", BFD_RELOC_PPC64_HIGHER
),
1733 MAP64 ("highera", BFD_RELOC_PPC64_HIGHER_S
),
1734 MAP64 ("highest", BFD_RELOC_PPC64_HIGHEST
),
1735 MAP64 ("highesta", BFD_RELOC_PPC64_HIGHEST_S
),
1736 MAP64 ("tocbase", BFD_RELOC_PPC64_TOC
),
1737 MAP64 ("toc", BFD_RELOC_PPC_TOC16
),
1738 MAP64 ("toc@l", BFD_RELOC_PPC64_TOC16_LO
),
1739 MAP64 ("toc@h", BFD_RELOC_PPC64_TOC16_HI
),
1740 MAP64 ("toc@ha", BFD_RELOC_PPC64_TOC16_HA
),
1741 MAP64 ("dtprel@higher", BFD_RELOC_PPC64_DTPREL16_HIGHER
),
1742 MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA
),
1743 MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST
),
1744 MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA
),
1745 MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER
),
1746 MAP64 ("tprel@highera", BFD_RELOC_PPC64_TPREL16_HIGHERA
),
1747 MAP64 ("tprel@highest", BFD_RELOC_PPC64_TPREL16_HIGHEST
),
1748 MAP64 ("tprel@highesta", BFD_RELOC_PPC64_TPREL16_HIGHESTA
),
1749 { (char *) 0, 0, 0, 0, BFD_RELOC_UNUSED
}
1753 return BFD_RELOC_UNUSED
;
1755 for (ch
= *str
, str2
= ident
;
1756 (str2
< ident
+ sizeof (ident
) - 1
1757 && (ISALNUM (ch
) || ch
== '@'));
1760 *str2
++ = TOLOWER (ch
);
1767 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1768 if (ch
== ptr
->string
[0]
1769 && len
== ptr
->length
1770 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0
1771 && (ppc_obj64
? ptr
->valid64
: ptr
->valid32
))
1773 int reloc
= ptr
->reloc
;
1776 if (exp_p
->X_add_number
!= 0
1777 && (reloc
== (int) BFD_RELOC_16_GOTOFF
1778 || reloc
== (int) BFD_RELOC_LO16_GOTOFF
1779 || reloc
== (int) BFD_RELOC_HI16_GOTOFF
1780 || reloc
== (int) BFD_RELOC_HI16_S_GOTOFF
))
1781 as_warn (_("identifier+constant@got means identifier@got+constant"));
1783 /* Now check for identifier@suffix+constant. */
1784 if (*str
== '-' || *str
== '+')
1786 char *orig_line
= input_line_pointer
;
1787 expressionS new_exp
;
1789 input_line_pointer
= str
;
1790 expression (&new_exp
);
1791 if (new_exp
.X_op
== O_constant
)
1793 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1794 str
= input_line_pointer
;
1797 if (&input_line_pointer
!= str_p
)
1798 input_line_pointer
= orig_line
;
1802 if (reloc
== (int) BFD_RELOC_PPC64_TOC
1803 && exp_p
->X_op
== O_symbol
1804 && strcmp (S_GET_NAME (exp_p
->X_add_symbol
), ".TOC.") == 0)
1806 /* Change the symbol so that the dummy .TOC. symbol can be
1807 omitted from the object file. */
1808 exp_p
->X_add_symbol
= &abs_symbol
;
1811 return (bfd_reloc_code_real_type
) reloc
;
1814 return BFD_RELOC_UNUSED
;
1817 /* Like normal .long/.short/.word, except support @got, etc.
1818 Clobbers input_line_pointer, checks end-of-line. */
1820 ppc_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long, 8=.llong */)
1823 bfd_reloc_code_real_type reloc
;
1825 if (is_it_end_of_statement ())
1827 demand_empty_rest_of_line ();
1834 if (exp
.X_op
== O_symbol
1835 && *input_line_pointer
== '@'
1836 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1837 &exp
)) != BFD_RELOC_UNUSED
)
1839 reloc_howto_type
*reloc_howto
;
1842 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1843 size
= bfd_get_reloc_size (reloc_howto
);
1847 as_bad (_("%s relocations do not fit in %d bytes\n"),
1848 reloc_howto
->name
, nbytes
);
1855 p
= frag_more (nbytes
);
1857 if (target_big_endian
)
1858 offset
= nbytes
- size
;
1859 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1864 emit_expr (&exp
, (unsigned int) nbytes
);
1866 while (*input_line_pointer
++ == ',');
1868 /* Put terminator back into stream. */
1869 input_line_pointer
--;
1870 demand_empty_rest_of_line ();
1873 /* Solaris pseduo op to change to the .rodata section. */
1875 ppc_elf_rdata (int xxx
)
1877 char *save_line
= input_line_pointer
;
1878 static char section
[] = ".rodata\n";
1880 /* Just pretend this is .section .rodata */
1881 input_line_pointer
= section
;
1882 obj_elf_section (xxx
);
1884 input_line_pointer
= save_line
;
1887 /* Pseudo op to make file scope bss items. */
1889 ppc_elf_lcomm (int xxx ATTRIBUTE_UNUSED
)
1902 name
= input_line_pointer
;
1903 c
= get_symbol_end ();
1905 /* just after name is now '\0'. */
1906 p
= input_line_pointer
;
1909 if (*input_line_pointer
!= ',')
1911 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1912 ignore_rest_of_line ();
1916 input_line_pointer
++; /* skip ',' */
1917 if ((size
= get_absolute_expression ()) < 0)
1919 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1920 ignore_rest_of_line ();
1924 /* The third argument to .lcomm is the alignment. */
1925 if (*input_line_pointer
!= ',')
1929 ++input_line_pointer
;
1930 align
= get_absolute_expression ();
1933 as_warn (_("ignoring bad alignment"));
1939 symbolP
= symbol_find_or_make (name
);
1942 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1944 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1945 S_GET_NAME (symbolP
));
1946 ignore_rest_of_line ();
1950 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1952 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1953 S_GET_NAME (symbolP
),
1954 (long) S_GET_VALUE (symbolP
),
1957 ignore_rest_of_line ();
1963 old_subsec
= now_subseg
;
1966 /* Convert to a power of 2 alignment. */
1967 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1970 as_bad (_("Common alignment not a power of 2"));
1971 ignore_rest_of_line ();
1978 record_alignment (bss_section
, align2
);
1979 subseg_set (bss_section
, 0);
1981 frag_align (align2
, 0, 0);
1982 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1983 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1984 symbol_set_frag (symbolP
, frag_now
);
1985 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1988 S_SET_SIZE (symbolP
, size
);
1989 S_SET_SEGMENT (symbolP
, bss_section
);
1990 subseg_set (old_sec
, old_subsec
);
1991 demand_empty_rest_of_line ();
1994 /* Validate any relocations emitted for -mrelocatable, possibly adding
1995 fixups for word relocations in writable segments, so we can adjust
1998 ppc_elf_validate_fix (fixS
*fixp
, segT seg
)
2000 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
2009 case SHLIB_MRELOCATABLE
:
2010 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
2011 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
2012 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
2013 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
2014 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
2015 && fixp
->fx_r_type
!= BFD_RELOC_16_BASEREL
2016 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
2017 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
2018 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
2019 && (seg
->flags
& SEC_LOAD
) != 0
2020 && strcmp (segment_name (seg
), ".got2") != 0
2021 && strcmp (segment_name (seg
), ".dtors") != 0
2022 && strcmp (segment_name (seg
), ".ctors") != 0
2023 && strcmp (segment_name (seg
), ".fixup") != 0
2024 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
2025 && strcmp (segment_name (seg
), ".eh_frame") != 0
2026 && strcmp (segment_name (seg
), ".ex_shared") != 0)
2028 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
2029 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
2031 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2032 _("Relocation cannot be done when using -mrelocatable"));
2039 /* Prevent elf_frob_file_before_adjust removing a weak undefined
2040 function descriptor sym if the corresponding code sym is used. */
2043 ppc_frob_file_before_adjust (void)
2051 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2058 name
= S_GET_NAME (symp
);
2062 if (! S_IS_WEAK (symp
)
2063 || S_IS_DEFINED (symp
))
2066 len
= strlen (name
) + 1;
2067 dotname
= xmalloc (len
+ 1);
2069 memcpy (dotname
+ 1, name
, len
);
2070 dotsym
= symbol_find_noref (dotname
, 1);
2072 if (dotsym
!= NULL
&& (symbol_used_p (dotsym
)
2073 || symbol_used_in_reloc_p (dotsym
)))
2074 symbol_mark_used (symp
);
2078 toc
= bfd_get_section_by_name (stdoutput
, ".toc");
2080 && bfd_section_size (stdoutput
, toc
) > 0x10000)
2081 as_warn (_("TOC section size exceeds 64k"));
2083 /* Don't emit .TOC. symbol. */
2084 symp
= symbol_find (".TOC.");
2086 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2088 #endif /* OBJ_ELF */
2093 * Summary of parse_toc_entry.
2095 * in: Input_line_pointer points to the '[' in one of:
2097 * [toc] [tocv] [toc32] [toc64]
2099 * Anything else is an error of one kind or another.
2102 * return value: success or failure
2103 * toc_kind: kind of toc reference
2104 * input_line_pointer:
2105 * success: first char after the ']'
2106 * failure: unchanged
2110 * [toc] - rv == success, toc_kind = default_toc
2111 * [tocv] - rv == success, toc_kind = data_in_toc
2112 * [toc32] - rv == success, toc_kind = must_be_32
2113 * [toc64] - rv == success, toc_kind = must_be_64
2117 enum toc_size_qualifier
2119 default_toc
, /* The toc cell constructed should be the system default size */
2120 data_in_toc
, /* This is a direct reference to a toc cell */
2121 must_be_32
, /* The toc cell constructed must be 32 bits wide */
2122 must_be_64
/* The toc cell constructed must be 64 bits wide */
2126 parse_toc_entry (enum toc_size_qualifier
*toc_kind
)
2131 enum toc_size_qualifier t
;
2133 /* Save the input_line_pointer. */
2134 start
= input_line_pointer
;
2136 /* Skip over the '[' , and whitespace. */
2137 ++input_line_pointer
;
2140 /* Find the spelling of the operand. */
2141 toc_spec
= input_line_pointer
;
2142 c
= get_symbol_end ();
2144 if (strcmp (toc_spec
, "toc") == 0)
2148 else if (strcmp (toc_spec
, "tocv") == 0)
2152 else if (strcmp (toc_spec
, "toc32") == 0)
2156 else if (strcmp (toc_spec
, "toc64") == 0)
2162 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
2163 *input_line_pointer
= c
;
2164 input_line_pointer
= start
;
2168 /* Now find the ']'. */
2169 *input_line_pointer
= c
;
2171 SKIP_WHITESPACE (); /* leading whitespace could be there. */
2172 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
2176 as_bad (_("syntax error: expected `]', found `%c'"), c
);
2177 input_line_pointer
= start
;
2188 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2190 ppc_apuinfo_section_add (unsigned int apu
, unsigned int version
)
2194 /* Check we don't already exist. */
2195 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
2196 if (ppc_apuinfo_list
[i
] == APUID (apu
, version
))
2199 if (ppc_apuinfo_num
== ppc_apuinfo_num_alloc
)
2201 if (ppc_apuinfo_num_alloc
== 0)
2203 ppc_apuinfo_num_alloc
= 4;
2204 ppc_apuinfo_list
= (unsigned long *)
2205 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2209 ppc_apuinfo_num_alloc
+= 4;
2210 ppc_apuinfo_list
= (unsigned long *) xrealloc (ppc_apuinfo_list
,
2211 sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2214 ppc_apuinfo_list
[ppc_apuinfo_num
++] = APUID (apu
, version
);
2220 /* We need to keep a list of fixups. We can't simply generate them as
2221 we go, because that would require us to first create the frag, and
2222 that would screw up references to ``.''. */
2228 bfd_reloc_code_real_type reloc
;
2231 #define MAX_INSN_FIXUPS (5)
2233 /* This routine is called for each instruction to be assembled. */
2236 md_assemble (char *str
)
2239 const struct powerpc_opcode
*opcode
;
2241 const unsigned char *opindex_ptr
;
2245 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
2251 bfd_reloc_code_real_type reloc
;
2254 /* Get the opcode. */
2255 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
2260 /* Look up the opcode in the hash table. */
2261 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
2262 if (opcode
== (const struct powerpc_opcode
*) NULL
)
2264 const struct powerpc_macro
*macro
;
2266 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
2267 if (macro
== (const struct powerpc_macro
*) NULL
)
2268 as_bad (_("Unrecognized opcode: `%s'"), str
);
2270 ppc_macro (s
, macro
);
2275 insn
= opcode
->opcode
;
2278 while (ISSPACE (*str
))
2281 /* PowerPC operands are just expressions. The only real issue is
2282 that a few operand types are optional. All cases which might use
2283 an optional operand separate the operands only with commas (in some
2284 cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2285 have optional operands). Most instructions with optional operands
2286 have only one. Those that have more than one optional operand can
2287 take either all their operands or none. So, before we start seriously
2288 parsing the operands, we check to see if we have optional operands,
2289 and if we do, we count the number of commas to see which operands
2290 have been omitted. */
2292 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2294 const struct powerpc_operand
*operand
;
2296 operand
= &powerpc_operands
[*opindex_ptr
];
2297 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
2299 unsigned int opcount
;
2300 unsigned int num_operands_expected
;
2303 /* There is an optional operand. Count the number of
2304 commas in the input line. */
2311 while ((s
= strchr (s
, ',')) != (char *) NULL
)
2318 /* Compute the number of expected operands.
2319 Do not count fake operands. */
2320 for (num_operands_expected
= 0, i
= 0; opcode
->operands
[i
]; i
++)
2321 if ((powerpc_operands
[opcode
->operands
[i
]].flags
& PPC_OPERAND_FAKE
) == 0)
2322 ++ num_operands_expected
;
2324 /* If there are fewer operands in the line then are called
2325 for by the instruction, we want to skip the optional
2327 if (opcount
< num_operands_expected
)
2334 /* Gather the operands. */
2338 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2340 const struct powerpc_operand
*operand
;
2346 if (next_opindex
== 0)
2347 operand
= &powerpc_operands
[*opindex_ptr
];
2350 operand
= &powerpc_operands
[next_opindex
];
2355 /* If this is a fake operand, then we do not expect anything
2357 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
2359 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2360 if (errmsg
!= (const char *) NULL
)
2365 /* If this is an optional operand, and we are skipping it, just
2367 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
2370 if (operand
->insert
)
2372 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2373 if (errmsg
!= (const char *) NULL
)
2376 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
2377 next_opindex
= *opindex_ptr
+ 1;
2381 /* Gather the operand. */
2382 hold
= input_line_pointer
;
2383 input_line_pointer
= str
;
2386 if (*input_line_pointer
== '[')
2388 /* We are expecting something like the second argument here:
2390 * lwz r4,[toc].GS.0.static_int(rtoc)
2391 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2392 * The argument following the `]' must be a symbol name, and the
2393 * register must be the toc register: 'rtoc' or '2'
2395 * The effect is to 0 as the displacement field
2396 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2397 * the appropriate variation) reloc against it based on the symbol.
2398 * The linker will build the toc, and insert the resolved toc offset.
2401 * o The size of the toc entry is currently assumed to be
2402 * 32 bits. This should not be assumed to be a hard coded
2404 * o In an effort to cope with a change from 32 to 64 bits,
2405 * there are also toc entries that are specified to be
2406 * either 32 or 64 bits:
2407 * lwz r4,[toc32].GS.0.static_int(rtoc)
2408 * lwz r4,[toc64].GS.0.static_int(rtoc)
2409 * These demand toc entries of the specified size, and the
2410 * instruction probably requires it.
2414 enum toc_size_qualifier toc_kind
;
2415 bfd_reloc_code_real_type toc_reloc
;
2417 /* Go parse off the [tocXX] part. */
2418 valid_toc
= parse_toc_entry (&toc_kind
);
2422 /* Note: message has already been issued.
2423 FIXME: what sort of recovery should we do?
2424 demand_rest_of_line (); return; ? */
2427 /* Now get the symbol following the ']'. */
2433 /* In this case, we may not have seen the symbol yet,
2434 since it is allowed to appear on a .extern or .globl
2435 or just be a label in the .data section. */
2436 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2439 /* 1. The symbol must be defined and either in the toc
2440 section, or a global.
2441 2. The reloc generated must have the TOCDEFN flag set
2442 in upper bit mess of the reloc type.
2443 FIXME: It's a little confusing what the tocv
2444 qualifier can be used for. At the very least, I've
2445 seen three uses, only one of which I'm sure I can
2447 if (ex
.X_op
== O_symbol
)
2449 assert (ex
.X_add_symbol
!= NULL
);
2450 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2453 as_bad (_("[tocv] symbol is not a toc symbol"));
2457 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2460 /* FIXME: these next two specifically specify 32/64 bit
2461 toc entries. We don't support them today. Is this
2462 the right way to say that? */
2463 toc_reloc
= BFD_RELOC_UNUSED
;
2464 as_bad (_("Unimplemented toc32 expression modifier"));
2467 /* FIXME: see above. */
2468 toc_reloc
= BFD_RELOC_UNUSED
;
2469 as_bad (_("Unimplemented toc64 expression modifier"));
2473 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2479 /* We need to generate a fixup for this expression. */
2480 if (fc
>= MAX_INSN_FIXUPS
)
2481 as_fatal (_("too many fixups"));
2483 fixups
[fc
].reloc
= toc_reloc
;
2484 fixups
[fc
].exp
= ex
;
2485 fixups
[fc
].opindex
= *opindex_ptr
;
2488 /* Ok. We've set up the fixup for the instruction. Now make it
2489 look like the constant 0 was found here. */
2491 ex
.X_op
= O_constant
;
2492 ex
.X_add_number
= 0;
2493 ex
.X_add_symbol
= NULL
;
2494 ex
.X_op_symbol
= NULL
;
2500 if ((reg_names_p
&& (operand
->flags
& PPC_OPERAND_CR
) != 0)
2501 || !register_name (&ex
))
2503 char save_lex
= lex_type
['%'];
2505 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
2508 lex_type
['%'] |= LEX_BEGIN_NAME
;
2512 lex_type
['%'] = save_lex
;
2516 str
= input_line_pointer
;
2517 input_line_pointer
= hold
;
2519 if (ex
.X_op
== O_illegal
)
2520 as_bad (_("illegal operand"));
2521 else if (ex
.X_op
== O_absent
)
2522 as_bad (_("missing operand"));
2523 else if (ex
.X_op
== O_register
)
2525 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2526 ppc_cpu
, (char *) NULL
, 0);
2528 else if (ex
.X_op
== O_constant
)
2531 /* Allow @HA, @L, @H on constants. */
2532 char *orig_str
= str
;
2534 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2541 case BFD_RELOC_LO16
:
2542 /* X_unsigned is the default, so if the user has done
2543 something which cleared it, we always produce a
2545 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2546 ex
.X_add_number
&= 0xffff;
2548 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2551 case BFD_RELOC_HI16
:
2552 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2553 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2555 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2558 case BFD_RELOC_HI16_S
:
2559 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2560 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2562 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2565 case BFD_RELOC_PPC64_HIGHER
:
2566 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2567 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2569 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2572 case BFD_RELOC_PPC64_HIGHER_S
:
2573 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2574 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2576 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2579 case BFD_RELOC_PPC64_HIGHEST
:
2580 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2581 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2583 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2586 case BFD_RELOC_PPC64_HIGHEST_S
:
2587 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2588 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2590 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2593 #endif /* OBJ_ELF */
2594 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2595 ppc_cpu
, (char *) NULL
, 0);
2598 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2600 /* Some TLS tweaks. */
2605 case BFD_RELOC_PPC_TLS
:
2606 insn
= ppc_insert_operand (insn
, operand
, ppc_obj64
? 13 : 2,
2607 ppc_cpu
, (char *) NULL
, 0);
2609 /* We'll only use the 32 (or 64) bit form of these relocations
2610 in constants. Instructions get the 16 bit form. */
2611 case BFD_RELOC_PPC_DTPREL
:
2612 reloc
= BFD_RELOC_PPC_DTPREL16
;
2614 case BFD_RELOC_PPC_TPREL
:
2615 reloc
= BFD_RELOC_PPC_TPREL16
;
2619 /* For the absolute forms of branches, convert the PC
2620 relative form back into the absolute. */
2621 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2625 case BFD_RELOC_PPC_B26
:
2626 reloc
= BFD_RELOC_PPC_BA26
;
2628 case BFD_RELOC_PPC_B16
:
2629 reloc
= BFD_RELOC_PPC_BA16
;
2631 case BFD_RELOC_PPC_B16_BRTAKEN
:
2632 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2634 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2635 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2643 && (operand
->flags
& (PPC_OPERAND_DS
| PPC_OPERAND_DQ
)) != 0)
2648 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
2650 case BFD_RELOC_LO16
:
2651 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
2653 case BFD_RELOC_16_GOTOFF
:
2654 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
2656 case BFD_RELOC_LO16_GOTOFF
:
2657 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
2659 case BFD_RELOC_LO16_PLTOFF
:
2660 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
2662 case BFD_RELOC_16_BASEREL
:
2663 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
2665 case BFD_RELOC_LO16_BASEREL
:
2666 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
2668 case BFD_RELOC_PPC_TOC16
:
2669 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
2671 case BFD_RELOC_PPC64_TOC16_LO
:
2672 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
2674 case BFD_RELOC_PPC64_PLTGOT16
:
2675 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
2677 case BFD_RELOC_PPC64_PLTGOT16_LO
:
2678 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
2680 case BFD_RELOC_PPC_DTPREL16
:
2681 reloc
= BFD_RELOC_PPC64_DTPREL16_DS
;
2683 case BFD_RELOC_PPC_DTPREL16_LO
:
2684 reloc
= BFD_RELOC_PPC64_DTPREL16_LO_DS
;
2686 case BFD_RELOC_PPC_TPREL16
:
2687 reloc
= BFD_RELOC_PPC64_TPREL16_DS
;
2689 case BFD_RELOC_PPC_TPREL16_LO
:
2690 reloc
= BFD_RELOC_PPC64_TPREL16_LO_DS
;
2692 case BFD_RELOC_PPC_GOT_DTPREL16
:
2693 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
2694 case BFD_RELOC_PPC_GOT_TPREL16
:
2695 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
2698 as_bad (_("unsupported relocation for DS offset field"));
2703 /* We need to generate a fixup for this expression. */
2704 if (fc
>= MAX_INSN_FIXUPS
)
2705 as_fatal (_("too many fixups"));
2706 fixups
[fc
].exp
= ex
;
2707 fixups
[fc
].opindex
= 0;
2708 fixups
[fc
].reloc
= reloc
;
2711 #endif /* OBJ_ELF */
2715 /* We need to generate a fixup for this expression. */
2716 if (fc
>= MAX_INSN_FIXUPS
)
2717 as_fatal (_("too many fixups"));
2718 fixups
[fc
].exp
= ex
;
2719 fixups
[fc
].opindex
= *opindex_ptr
;
2720 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2728 /* If expecting more operands, then we want to see "),". */
2729 if (*str
== endc
&& opindex_ptr
[1] != 0)
2733 while (ISSPACE (*str
));
2737 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2745 /* The call to expression should have advanced str past any
2748 && (endc
!= ',' || *str
!= '\0'))
2750 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2758 while (ISSPACE (*str
))
2762 as_bad (_("junk at end of line: `%s'"), str
);
2765 /* Do we need/want a APUinfo section? */
2766 if (ppc_cpu
& (PPC_OPCODE_SPE
2767 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
2768 | PPC_OPCODE_BRLOCK
| PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
2769 | PPC_OPCODE_RFMCI
))
2771 /* These are all version "1". */
2772 if (opcode
->flags
& PPC_OPCODE_SPE
)
2773 ppc_apuinfo_section_add (PPC_APUINFO_SPE
, 1);
2774 if (opcode
->flags
& PPC_OPCODE_ISEL
)
2775 ppc_apuinfo_section_add (PPC_APUINFO_ISEL
, 1);
2776 if (opcode
->flags
& PPC_OPCODE_EFS
)
2777 ppc_apuinfo_section_add (PPC_APUINFO_EFS
, 1);
2778 if (opcode
->flags
& PPC_OPCODE_BRLOCK
)
2779 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK
, 1);
2780 if (opcode
->flags
& PPC_OPCODE_PMR
)
2781 ppc_apuinfo_section_add (PPC_APUINFO_PMR
, 1);
2782 if (opcode
->flags
& PPC_OPCODE_CACHELCK
)
2783 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK
, 1);
2784 if (opcode
->flags
& PPC_OPCODE_RFMCI
)
2785 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI
, 1);
2789 /* Write out the instruction. */
2791 addr_mod
= frag_now_fix () & 3;
2792 if (frag_now
->has_code
&& frag_now
->insn_addr
!= addr_mod
)
2793 as_bad (_("instruction address is not a multiple of 4"));
2794 frag_now
->insn_addr
= addr_mod
;
2795 frag_now
->has_code
= 1;
2796 md_number_to_chars (f
, insn
, 4);
2799 dwarf2_emit_insn (4);
2802 /* Create any fixups. At this point we do not use a
2803 bfd_reloc_code_real_type, but instead just use the
2804 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2805 handle fixups for any operand type, although that is admittedly
2806 not a very exciting feature. We pick a BFD reloc type in
2808 for (i
= 0; i
< fc
; i
++)
2810 const struct powerpc_operand
*operand
;
2812 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2813 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2815 reloc_howto_type
*reloc_howto
;
2820 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2824 size
= bfd_get_reloc_size (reloc_howto
);
2825 offset
= target_big_endian
? (4 - size
) : 0;
2827 if (size
< 1 || size
> 4)
2830 fixP
= fix_new_exp (frag_now
,
2831 f
- frag_now
->fr_literal
+ offset
,
2834 reloc_howto
->pc_relative
,
2837 /* Turn off complaints that the addend is too large for things like
2839 switch (fixups
[i
].reloc
)
2841 case BFD_RELOC_16_GOTOFF
:
2842 case BFD_RELOC_PPC_TOC16
:
2843 case BFD_RELOC_LO16
:
2844 case BFD_RELOC_HI16
:
2845 case BFD_RELOC_HI16_S
:
2847 case BFD_RELOC_PPC64_HIGHER
:
2848 case BFD_RELOC_PPC64_HIGHER_S
:
2849 case BFD_RELOC_PPC64_HIGHEST
:
2850 case BFD_RELOC_PPC64_HIGHEST_S
:
2852 fixP
->fx_no_overflow
= 1;
2859 fix_new_exp (frag_now
,
2860 f
- frag_now
->fr_literal
,
2863 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2864 ((bfd_reloc_code_real_type
)
2865 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2869 /* Handle a macro. Gather all the operands, transform them as
2870 described by the macro, and call md_assemble recursively. All the
2871 operands are separated by commas; we don't accept parentheses
2872 around operands here. */
2875 ppc_macro (char *str
, const struct powerpc_macro
*macro
)
2886 /* Gather the users operands into the operands array. */
2891 if (count
>= sizeof operands
/ sizeof operands
[0])
2893 operands
[count
++] = s
;
2894 s
= strchr (s
, ',');
2895 if (s
== (char *) NULL
)
2900 if (count
!= macro
->operands
)
2902 as_bad (_("wrong number of operands"));
2906 /* Work out how large the string must be (the size is unbounded
2907 because it includes user input). */
2909 format
= macro
->format
;
2910 while (*format
!= '\0')
2919 arg
= strtol (format
+ 1, &send
, 10);
2920 know (send
!= format
&& arg
< count
);
2921 len
+= strlen (operands
[arg
]);
2926 /* Put the string together. */
2927 complete
= s
= (char *) alloca (len
+ 1);
2928 format
= macro
->format
;
2929 while (*format
!= '\0')
2935 arg
= strtol (format
+ 1, &send
, 10);
2936 strcpy (s
, operands
[arg
]);
2943 /* Assemble the constructed instruction. */
2944 md_assemble (complete
);
2948 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2951 ppc_section_letter (int letter
, char **ptr_msg
)
2956 *ptr_msg
= _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
2961 ppc_section_word (char *str
, size_t len
)
2963 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2970 ppc_section_type (char *str
, size_t len
)
2972 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2979 ppc_section_flags (int flags
, int attr
, int type
)
2981 if (type
== SHT_ORDERED
)
2982 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2984 if (attr
& SHF_EXCLUDE
)
2985 flags
|= SEC_EXCLUDE
;
2989 #endif /* OBJ_ELF */
2992 /* Pseudo-op handling. */
2994 /* The .byte pseudo-op. This is similar to the normal .byte
2995 pseudo-op, but it can also take a single ASCII string. */
2998 ppc_byte (int ignore ATTRIBUTE_UNUSED
)
3000 if (*input_line_pointer
!= '\"')
3006 /* Gather characters. A real double quote is doubled. Unusual
3007 characters are not permitted. */
3008 ++input_line_pointer
;
3013 c
= *input_line_pointer
++;
3017 if (*input_line_pointer
!= '\"')
3019 ++input_line_pointer
;
3022 FRAG_APPEND_1_CHAR (c
);
3025 demand_empty_rest_of_line ();
3030 /* XCOFF specific pseudo-op handling. */
3032 /* This is set if we are creating a .stabx symbol, since we don't want
3033 to handle symbol suffixes for such symbols. */
3034 static bfd_boolean ppc_stab_symbol
;
3036 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
3037 symbols in the .bss segment as though they were local common
3038 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
3039 aligns .comm and .lcomm to 4 bytes. */
3042 ppc_comm (int lcomm
)
3044 asection
*current_seg
= now_seg
;
3045 subsegT current_subseg
= now_subseg
;
3051 symbolS
*lcomm_sym
= NULL
;
3055 name
= input_line_pointer
;
3056 endc
= get_symbol_end ();
3057 end_name
= input_line_pointer
;
3060 if (*input_line_pointer
!= ',')
3062 as_bad (_("missing size"));
3063 ignore_rest_of_line ();
3066 ++input_line_pointer
;
3068 size
= get_absolute_expression ();
3071 as_bad (_("negative size"));
3072 ignore_rest_of_line ();
3078 /* The third argument to .comm is the alignment. */
3079 if (*input_line_pointer
!= ',')
3083 ++input_line_pointer
;
3084 align
= get_absolute_expression ();
3087 as_warn (_("ignoring bad alignment"));
3102 /* The third argument to .lcomm appears to be the real local
3103 common symbol to create. References to the symbol named in
3104 the first argument are turned into references to the third
3106 if (*input_line_pointer
!= ',')
3108 as_bad (_("missing real symbol name"));
3109 ignore_rest_of_line ();
3112 ++input_line_pointer
;
3114 lcomm_name
= input_line_pointer
;
3115 lcomm_endc
= get_symbol_end ();
3117 lcomm_sym
= symbol_find_or_make (lcomm_name
);
3119 *input_line_pointer
= lcomm_endc
;
3123 sym
= symbol_find_or_make (name
);
3126 if (S_IS_DEFINED (sym
)
3127 || S_GET_VALUE (sym
) != 0)
3129 as_bad (_("attempt to redefine symbol"));
3130 ignore_rest_of_line ();
3134 record_alignment (bss_section
, align
);
3137 || ! S_IS_DEFINED (lcomm_sym
))
3146 S_SET_EXTERNAL (sym
);
3150 symbol_get_tc (lcomm_sym
)->output
= 1;
3151 def_sym
= lcomm_sym
;
3155 subseg_set (bss_section
, 1);
3156 frag_align (align
, 0, 0);
3158 symbol_set_frag (def_sym
, frag_now
);
3159 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
3160 def_size
, (char *) NULL
);
3162 S_SET_SEGMENT (def_sym
, bss_section
);
3163 symbol_get_tc (def_sym
)->align
= align
;
3167 /* Align the size of lcomm_sym. */
3168 symbol_get_frag (lcomm_sym
)->fr_offset
=
3169 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
3170 &~ ((1 << align
) - 1));
3171 if (align
> symbol_get_tc (lcomm_sym
)->align
)
3172 symbol_get_tc (lcomm_sym
)->align
= align
;
3177 /* Make sym an offset from lcomm_sym. */
3178 S_SET_SEGMENT (sym
, bss_section
);
3179 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
3180 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
3181 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
3184 subseg_set (current_seg
, current_subseg
);
3186 demand_empty_rest_of_line ();
3189 /* The .csect pseudo-op. This switches us into a different
3190 subsegment. The first argument is a symbol whose value is the
3191 start of the .csect. In COFF, csect symbols get special aux
3192 entries defined by the x_csect field of union internal_auxent. The
3193 optional second argument is the alignment (the default is 2). */
3196 ppc_csect (int ignore ATTRIBUTE_UNUSED
)
3203 name
= input_line_pointer
;
3204 endc
= get_symbol_end ();
3206 sym
= symbol_find_or_make (name
);
3208 *input_line_pointer
= endc
;
3210 if (S_GET_NAME (sym
)[0] == '\0')
3212 /* An unnamed csect is assumed to be [PR]. */
3213 symbol_get_tc (sym
)->class = XMC_PR
;
3217 if (*input_line_pointer
== ',')
3219 ++input_line_pointer
;
3220 align
= get_absolute_expression ();
3223 ppc_change_csect (sym
, align
);
3225 demand_empty_rest_of_line ();
3228 /* Change to a different csect. */
3231 ppc_change_csect (symbolS
*sym
, offsetT align
)
3233 if (S_IS_DEFINED (sym
))
3234 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
3244 /* This is a new csect. We need to look at the symbol class to
3245 figure out whether it should go in the text section or the
3249 switch (symbol_get_tc (sym
)->class)
3259 S_SET_SEGMENT (sym
, text_section
);
3260 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
3261 ++ppc_text_subsegment
;
3262 list_ptr
= &ppc_text_csects
;
3272 if (ppc_toc_csect
!= NULL
3273 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
3274 == ppc_data_subsegment
))
3276 S_SET_SEGMENT (sym
, data_section
);
3277 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
3278 ++ppc_data_subsegment
;
3279 list_ptr
= &ppc_data_csects
;
3285 /* We set the obstack chunk size to a small value before
3286 changing subsegments, so that we don't use a lot of memory
3287 space for what may be a small section. */
3288 hold_chunksize
= chunksize
;
3291 sec
= subseg_new (segment_name (S_GET_SEGMENT (sym
)),
3292 symbol_get_tc (sym
)->subseg
);
3294 chunksize
= hold_chunksize
;
3297 ppc_after_toc_frag
= frag_now
;
3299 record_alignment (sec
, align
);
3301 frag_align_code (align
, 0);
3303 frag_align (align
, 0, 0);
3305 symbol_set_frag (sym
, frag_now
);
3306 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3308 symbol_get_tc (sym
)->align
= align
;
3309 symbol_get_tc (sym
)->output
= 1;
3310 symbol_get_tc (sym
)->within
= sym
;
3312 for (list
= *list_ptr
;
3313 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3314 list
= symbol_get_tc (list
)->next
)
3316 symbol_get_tc (list
)->next
= sym
;
3318 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3319 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3323 ppc_current_csect
= sym
;
3326 /* This function handles the .text and .data pseudo-ops. These
3327 pseudo-ops aren't really used by XCOFF; we implement them for the
3328 convenience of people who aren't used to XCOFF. */
3331 ppc_section (int type
)
3338 else if (type
== 'd')
3343 sym
= symbol_find_or_make (name
);
3345 ppc_change_csect (sym
, 2);
3347 demand_empty_rest_of_line ();
3350 /* This function handles the .section pseudo-op. This is mostly to
3351 give an error, since XCOFF only supports .text, .data and .bss, but
3352 we do permit the user to name the text or data section. */
3355 ppc_named_section (int ignore ATTRIBUTE_UNUSED
)
3358 const char *real_name
;
3362 user_name
= input_line_pointer
;
3363 c
= get_symbol_end ();
3365 if (strcmp (user_name
, ".text") == 0)
3366 real_name
= ".text[PR]";
3367 else if (strcmp (user_name
, ".data") == 0)
3368 real_name
= ".data[RW]";
3371 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3372 *input_line_pointer
= c
;
3373 ignore_rest_of_line ();
3377 *input_line_pointer
= c
;
3379 sym
= symbol_find_or_make (real_name
);
3381 ppc_change_csect (sym
, 2);
3383 demand_empty_rest_of_line ();
3386 /* The .extern pseudo-op. We create an undefined symbol. */
3389 ppc_extern (int ignore ATTRIBUTE_UNUSED
)
3394 name
= input_line_pointer
;
3395 endc
= get_symbol_end ();
3397 (void) symbol_find_or_make (name
);
3399 *input_line_pointer
= endc
;
3401 demand_empty_rest_of_line ();
3404 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3407 ppc_lglobl (int ignore ATTRIBUTE_UNUSED
)
3413 name
= input_line_pointer
;
3414 endc
= get_symbol_end ();
3416 sym
= symbol_find_or_make (name
);
3418 *input_line_pointer
= endc
;
3420 symbol_get_tc (sym
)->output
= 1;
3422 demand_empty_rest_of_line ();
3425 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3426 although I don't know why it bothers. */
3429 ppc_rename (int ignore ATTRIBUTE_UNUSED
)
3436 name
= input_line_pointer
;
3437 endc
= get_symbol_end ();
3439 sym
= symbol_find_or_make (name
);
3441 *input_line_pointer
= endc
;
3443 if (*input_line_pointer
!= ',')
3445 as_bad (_("missing rename string"));
3446 ignore_rest_of_line ();
3449 ++input_line_pointer
;
3451 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
3453 demand_empty_rest_of_line ();
3456 /* The .stabx pseudo-op. This is similar to a normal .stabs
3457 pseudo-op, but slightly different. A sample is
3458 .stabx "main:F-1",.main,142,0
3459 The first argument is the symbol name to create. The second is the
3460 value, and the third is the storage class. The fourth seems to be
3461 always zero, and I am assuming it is the type. */
3464 ppc_stabx (int ignore ATTRIBUTE_UNUSED
)
3471 name
= demand_copy_C_string (&len
);
3473 if (*input_line_pointer
!= ',')
3475 as_bad (_("missing value"));
3478 ++input_line_pointer
;
3480 ppc_stab_symbol
= TRUE
;
3481 sym
= symbol_make (name
);
3482 ppc_stab_symbol
= FALSE
;
3484 symbol_get_tc (sym
)->real_name
= name
;
3486 (void) expression (&exp
);
3493 as_bad (_("illegal .stabx expression; zero assumed"));
3494 exp
.X_add_number
= 0;
3497 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
3498 symbol_set_frag (sym
, &zero_address_frag
);
3502 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
3503 symbol_set_value_expression (sym
, &exp
);
3507 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
3508 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
3513 /* The value is some complex expression. This will probably
3514 fail at some later point, but this is probably the right
3515 thing to do here. */
3516 symbol_set_value_expression (sym
, &exp
);
3520 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3521 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3523 if (*input_line_pointer
!= ',')
3525 as_bad (_("missing class"));
3528 ++input_line_pointer
;
3530 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
3532 if (*input_line_pointer
!= ',')
3534 as_bad (_("missing type"));
3537 ++input_line_pointer
;
3539 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
3541 symbol_get_tc (sym
)->output
= 1;
3543 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
3545 symbol_get_tc (sym
)->within
= ppc_current_block
;
3550 .stabx "z",arrays_,133,0
3553 .comm arrays_,13768,3
3555 resolve_symbol_value will copy the exp's "within" into sym's when the
3556 offset is 0. Since this seems to be corner case problem,
3557 only do the correction for storage class C_STSYM. A better solution
3558 would be to have the tc field updated in ppc_symbol_new_hook. */
3560 if (exp
.X_op
== O_symbol
)
3562 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
3566 if (exp
.X_op
!= O_symbol
3567 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
3568 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
3569 ppc_frob_label (sym
);
3572 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3573 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
3574 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
3575 symbol_get_tc (ppc_current_csect
)->within
= sym
;
3578 demand_empty_rest_of_line ();
3581 /* The .function pseudo-op. This takes several arguments. The first
3582 argument seems to be the external name of the symbol. The second
3583 argument seems to be the label for the start of the function. gcc
3584 uses the same name for both. I have no idea what the third and
3585 fourth arguments are meant to be. The optional fifth argument is
3586 an expression for the size of the function. In COFF this symbol
3587 gets an aux entry like that used for a csect. */
3590 ppc_function (int ignore ATTRIBUTE_UNUSED
)
3598 name
= input_line_pointer
;
3599 endc
= get_symbol_end ();
3601 /* Ignore any [PR] suffix. */
3602 name
= ppc_canonicalize_symbol_name (name
);
3603 s
= strchr (name
, '[');
3604 if (s
!= (char *) NULL
3605 && strcmp (s
+ 1, "PR]") == 0)
3608 ext_sym
= symbol_find_or_make (name
);
3610 *input_line_pointer
= endc
;
3612 if (*input_line_pointer
!= ',')
3614 as_bad (_("missing symbol name"));
3615 ignore_rest_of_line ();
3618 ++input_line_pointer
;
3620 name
= input_line_pointer
;
3621 endc
= get_symbol_end ();
3623 lab_sym
= symbol_find_or_make (name
);
3625 *input_line_pointer
= endc
;
3627 if (ext_sym
!= lab_sym
)
3631 exp
.X_op
= O_symbol
;
3632 exp
.X_add_symbol
= lab_sym
;
3633 exp
.X_op_symbol
= NULL
;
3634 exp
.X_add_number
= 0;
3636 symbol_set_value_expression (ext_sym
, &exp
);
3639 if (symbol_get_tc (ext_sym
)->class == -1)
3640 symbol_get_tc (ext_sym
)->class = XMC_PR
;
3641 symbol_get_tc (ext_sym
)->output
= 1;
3643 if (*input_line_pointer
== ',')
3647 /* Ignore the third argument. */
3648 ++input_line_pointer
;
3649 expression (&ignore
);
3650 if (*input_line_pointer
== ',')
3652 /* Ignore the fourth argument. */
3653 ++input_line_pointer
;
3654 expression (&ignore
);
3655 if (*input_line_pointer
== ',')
3657 /* The fifth argument is the function size. */
3658 ++input_line_pointer
;
3659 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
3662 &zero_address_frag
);
3663 pseudo_set (symbol_get_tc (ext_sym
)->size
);
3668 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3669 SF_SET_FUNCTION (ext_sym
);
3670 SF_SET_PROCESS (ext_sym
);
3671 coff_add_linesym (ext_sym
);
3673 demand_empty_rest_of_line ();
3676 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3677 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3678 with the correct line number */
3680 static symbolS
*saved_bi_sym
= 0;
3683 ppc_bf (int ignore ATTRIBUTE_UNUSED
)
3687 sym
= symbol_make (".bf");
3688 S_SET_SEGMENT (sym
, text_section
);
3689 symbol_set_frag (sym
, frag_now
);
3690 S_SET_VALUE (sym
, frag_now_fix ());
3691 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3693 coff_line_base
= get_absolute_expression ();
3695 S_SET_NUMBER_AUXILIARY (sym
, 1);
3696 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3698 /* Line number for bi. */
3701 S_SET_VALUE (saved_bi_sym
, coff_n_line_nos
);
3706 symbol_get_tc (sym
)->output
= 1;
3708 ppc_frob_label (sym
);
3710 demand_empty_rest_of_line ();
3713 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3714 ".ef", except that the line number is absolute, not relative to the
3715 most recent ".bf" symbol. */
3718 ppc_ef (int ignore ATTRIBUTE_UNUSED
)
3722 sym
= symbol_make (".ef");
3723 S_SET_SEGMENT (sym
, text_section
);
3724 symbol_set_frag (sym
, frag_now
);
3725 S_SET_VALUE (sym
, frag_now_fix ());
3726 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3727 S_SET_NUMBER_AUXILIARY (sym
, 1);
3728 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3729 symbol_get_tc (sym
)->output
= 1;
3731 ppc_frob_label (sym
);
3733 demand_empty_rest_of_line ();
3736 /* The .bi and .ei pseudo-ops. These take a string argument and
3737 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3738 the symbol list. The value of .bi will be know when the next .bf
3744 static symbolS
*last_biei
;
3751 name
= demand_copy_C_string (&len
);
3753 /* The value of these symbols is actually file offset. Here we set
3754 the value to the index into the line number entries. In
3755 ppc_frob_symbols we set the fix_line field, which will cause BFD
3756 to do the right thing. */
3758 sym
= symbol_make (name
);
3759 /* obj-coff.c currently only handles line numbers correctly in the
3761 S_SET_SEGMENT (sym
, text_section
);
3762 S_SET_VALUE (sym
, coff_n_line_nos
);
3763 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3765 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3766 symbol_get_tc (sym
)->output
= 1;
3774 for (look
= last_biei
? last_biei
: symbol_rootP
;
3775 (look
!= (symbolS
*) NULL
3776 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3777 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3778 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3779 look
= symbol_next (look
))
3781 if (look
!= (symbolS
*) NULL
)
3783 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3784 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3788 demand_empty_rest_of_line ();
3791 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3792 There is one argument, which is a csect symbol. The value of the
3793 .bs symbol is the index of this csect symbol. */
3796 ppc_bs (int ignore ATTRIBUTE_UNUSED
)
3803 if (ppc_current_block
!= NULL
)
3804 as_bad (_("nested .bs blocks"));
3806 name
= input_line_pointer
;
3807 endc
= get_symbol_end ();
3809 csect
= symbol_find_or_make (name
);
3811 *input_line_pointer
= endc
;
3813 sym
= symbol_make (".bs");
3814 S_SET_SEGMENT (sym
, now_seg
);
3815 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3816 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3817 symbol_get_tc (sym
)->output
= 1;
3819 symbol_get_tc (sym
)->within
= csect
;
3821 ppc_frob_label (sym
);
3823 ppc_current_block
= sym
;
3825 demand_empty_rest_of_line ();
3828 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3831 ppc_es (int ignore ATTRIBUTE_UNUSED
)
3835 if (ppc_current_block
== NULL
)
3836 as_bad (_(".es without preceding .bs"));
3838 sym
= symbol_make (".es");
3839 S_SET_SEGMENT (sym
, now_seg
);
3840 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3841 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3842 symbol_get_tc (sym
)->output
= 1;
3844 ppc_frob_label (sym
);
3846 ppc_current_block
= NULL
;
3848 demand_empty_rest_of_line ();
3851 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3855 ppc_bb (int ignore ATTRIBUTE_UNUSED
)
3859 sym
= symbol_make (".bb");
3860 S_SET_SEGMENT (sym
, text_section
);
3861 symbol_set_frag (sym
, frag_now
);
3862 S_SET_VALUE (sym
, frag_now_fix ());
3863 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3865 S_SET_NUMBER_AUXILIARY (sym
, 1);
3866 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3868 symbol_get_tc (sym
)->output
= 1;
3870 SF_SET_PROCESS (sym
);
3872 ppc_frob_label (sym
);
3874 demand_empty_rest_of_line ();
3877 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3881 ppc_eb (int ignore ATTRIBUTE_UNUSED
)
3885 sym
= symbol_make (".eb");
3886 S_SET_SEGMENT (sym
, text_section
);
3887 symbol_set_frag (sym
, frag_now
);
3888 S_SET_VALUE (sym
, frag_now_fix ());
3889 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3890 S_SET_NUMBER_AUXILIARY (sym
, 1);
3891 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3892 symbol_get_tc (sym
)->output
= 1;
3894 SF_SET_PROCESS (sym
);
3896 ppc_frob_label (sym
);
3898 demand_empty_rest_of_line ();
3901 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3905 ppc_bc (int ignore ATTRIBUTE_UNUSED
)
3911 name
= demand_copy_C_string (&len
);
3912 sym
= symbol_make (name
);
3913 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3914 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3915 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3916 S_SET_VALUE (sym
, 0);
3917 symbol_get_tc (sym
)->output
= 1;
3919 ppc_frob_label (sym
);
3921 demand_empty_rest_of_line ();
3924 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3927 ppc_ec (int ignore ATTRIBUTE_UNUSED
)
3931 sym
= symbol_make (".ec");
3932 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3933 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3934 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3935 S_SET_VALUE (sym
, 0);
3936 symbol_get_tc (sym
)->output
= 1;
3938 ppc_frob_label (sym
);
3940 demand_empty_rest_of_line ();
3943 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3946 ppc_toc (int ignore ATTRIBUTE_UNUSED
)
3948 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3949 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3956 subseg
= ppc_data_subsegment
;
3957 ++ppc_data_subsegment
;
3959 subseg_new (segment_name (data_section
), subseg
);
3960 ppc_toc_frag
= frag_now
;
3962 sym
= symbol_find_or_make ("TOC[TC0]");
3963 symbol_set_frag (sym
, frag_now
);
3964 S_SET_SEGMENT (sym
, data_section
);
3965 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3966 symbol_get_tc (sym
)->subseg
= subseg
;
3967 symbol_get_tc (sym
)->output
= 1;
3968 symbol_get_tc (sym
)->within
= sym
;
3970 ppc_toc_csect
= sym
;
3972 for (list
= ppc_data_csects
;
3973 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3974 list
= symbol_get_tc (list
)->next
)
3976 symbol_get_tc (list
)->next
= sym
;
3978 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3979 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3983 ppc_current_csect
= ppc_toc_csect
;
3985 demand_empty_rest_of_line ();
3988 /* The AIX assembler automatically aligns the operands of a .long or
3989 .short pseudo-op, and we want to be compatible. */
3992 ppc_xcoff_cons (int log_size
)
3994 frag_align (log_size
, 0, 0);
3995 record_alignment (now_seg
, log_size
);
3996 cons (1 << log_size
);
4000 ppc_vbyte (int dummy ATTRIBUTE_UNUSED
)
4005 (void) expression (&exp
);
4007 if (exp
.X_op
!= O_constant
)
4009 as_bad (_("non-constant byte count"));
4013 byte_count
= exp
.X_add_number
;
4015 if (*input_line_pointer
!= ',')
4017 as_bad (_("missing value"));
4021 ++input_line_pointer
;
4025 #endif /* OBJ_XCOFF */
4026 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
4028 /* The .tc pseudo-op. This is used when generating either XCOFF or
4029 ELF. This takes two or more arguments.
4031 When generating XCOFF output, the first argument is the name to
4032 give to this location in the toc; this will be a symbol with class
4033 TC. The rest of the arguments are N-byte values to actually put at
4034 this location in the TOC; often there is just one more argument, a
4035 relocatable symbol reference. The size of the value to store
4036 depends on target word size. A 32-bit target uses 4-byte values, a
4037 64-bit target uses 8-byte values.
4039 When not generating XCOFF output, the arguments are the same, but
4040 the first argument is simply ignored. */
4043 ppc_tc (int ignore ATTRIBUTE_UNUSED
)
4047 /* Define the TOC symbol name. */
4053 if (ppc_toc_csect
== (symbolS
*) NULL
4054 || ppc_toc_csect
!= ppc_current_csect
)
4056 as_bad (_(".tc not in .toc section"));
4057 ignore_rest_of_line ();
4061 name
= input_line_pointer
;
4062 endc
= get_symbol_end ();
4064 sym
= symbol_find_or_make (name
);
4066 *input_line_pointer
= endc
;
4068 if (S_IS_DEFINED (sym
))
4072 label
= symbol_get_tc (ppc_current_csect
)->within
;
4073 if (symbol_get_tc (label
)->class != XMC_TC0
)
4075 as_bad (_(".tc with no label"));
4076 ignore_rest_of_line ();
4080 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
4081 symbol_set_frag (label
, symbol_get_frag (sym
));
4082 S_SET_VALUE (label
, S_GET_VALUE (sym
));
4084 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
4085 ++input_line_pointer
;
4090 S_SET_SEGMENT (sym
, now_seg
);
4091 symbol_set_frag (sym
, frag_now
);
4092 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
4093 symbol_get_tc (sym
)->class = XMC_TC
;
4094 symbol_get_tc (sym
)->output
= 1;
4096 ppc_frob_label (sym
);
4099 #endif /* OBJ_XCOFF */
4103 /* Skip the TOC symbol name. */
4104 while (is_part_of_name (*input_line_pointer
)
4105 || *input_line_pointer
== ' '
4106 || *input_line_pointer
== '['
4107 || *input_line_pointer
== ']'
4108 || *input_line_pointer
== '{'
4109 || *input_line_pointer
== '}')
4110 ++input_line_pointer
;
4112 /* Align to a four/eight byte boundary. */
4113 align
= ppc_obj64
? 3 : 2;
4114 frag_align (align
, 0, 0);
4115 record_alignment (now_seg
, align
);
4116 #endif /* OBJ_ELF */
4118 if (*input_line_pointer
!= ',')
4119 demand_empty_rest_of_line ();
4122 ++input_line_pointer
;
4123 cons (ppc_obj64
? 8 : 4);
4127 /* Pseudo-op .machine. */
4130 ppc_machine (int ignore ATTRIBUTE_UNUSED
)
4133 #define MAX_HISTORY 100
4134 static unsigned long *cpu_history
;
4135 static int curr_hist
;
4139 if (*input_line_pointer
== '"')
4142 cpu_string
= demand_copy_C_string (&len
);
4147 cpu_string
= input_line_pointer
;
4148 c
= get_symbol_end ();
4149 cpu_string
= xstrdup (cpu_string
);
4150 *input_line_pointer
= c
;
4153 if (cpu_string
!= NULL
)
4155 unsigned long old_cpu
= ppc_cpu
;
4158 for (p
= cpu_string
; *p
!= 0; p
++)
4161 if (strcmp (cpu_string
, "push") == 0)
4163 if (cpu_history
== NULL
)
4164 cpu_history
= xmalloc (MAX_HISTORY
* sizeof (*cpu_history
));
4166 if (curr_hist
>= MAX_HISTORY
)
4167 as_bad (_(".machine stack overflow"));
4169 cpu_history
[curr_hist
++] = ppc_cpu
;
4171 else if (strcmp (cpu_string
, "pop") == 0)
4174 as_bad (_(".machine stack underflow"));
4176 ppc_cpu
= cpu_history
[--curr_hist
];
4178 else if (parse_cpu (cpu_string
))
4181 as_bad (_("invalid machine `%s'"), cpu_string
);
4183 if (ppc_cpu
!= old_cpu
)
4184 ppc_setup_opcodes ();
4187 demand_empty_rest_of_line ();
4190 /* See whether a symbol is in the TOC section. */
4193 ppc_is_toc_sym (symbolS
*sym
)
4196 return symbol_get_tc (sym
)->class == XMC_TC
;
4199 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
4201 return strcmp (sname
, ".toc") == 0;
4203 return strcmp (sname
, ".got") == 0;
4206 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4210 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4212 /* Set the current section. */
4214 ppc_set_current_section (segT
new)
4216 ppc_previous_section
= ppc_current_section
;
4217 ppc_current_section
= new;
4220 /* pseudo-op: .previous
4221 behaviour: toggles the current section with the previous section.
4223 warnings: "No previous section" */
4226 ppc_previous (int ignore ATTRIBUTE_UNUSED
)
4230 if (ppc_previous_section
== NULL
)
4232 as_warn (_("No previous section to return to. Directive ignored."));
4236 subseg_set (ppc_previous_section
, 0);
4238 ppc_set_current_section (ppc_previous_section
);
4241 /* pseudo-op: .pdata
4242 behaviour: predefined read only data section
4246 initial: .section .pdata "adr3"
4247 a - don't know -- maybe a misprint
4248 d - initialized data
4250 3 - double word aligned (that would be 4 byte boundary)
4253 Tag index tables (also known as the function table) for exception
4254 handling, debugging, etc. */
4257 ppc_pdata (int ignore ATTRIBUTE_UNUSED
)
4259 if (pdata_section
== 0)
4261 pdata_section
= subseg_new (".pdata", 0);
4263 bfd_set_section_flags (stdoutput
, pdata_section
,
4264 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4265 | SEC_READONLY
| SEC_DATA
));
4267 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
4271 pdata_section
= subseg_new (".pdata", 0);
4273 ppc_set_current_section (pdata_section
);
4276 /* pseudo-op: .ydata
4277 behaviour: predefined read only data section
4281 initial: .section .ydata "drw3"
4282 a - don't know -- maybe a misprint
4283 d - initialized data
4285 3 - double word aligned (that would be 4 byte boundary)
4287 Tag tables (also known as the scope table) for exception handling,
4291 ppc_ydata (int ignore ATTRIBUTE_UNUSED
)
4293 if (ydata_section
== 0)
4295 ydata_section
= subseg_new (".ydata", 0);
4296 bfd_set_section_flags (stdoutput
, ydata_section
,
4297 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4298 | SEC_READONLY
| SEC_DATA
));
4300 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
4304 ydata_section
= subseg_new (".ydata", 0);
4306 ppc_set_current_section (ydata_section
);
4309 /* pseudo-op: .reldata
4310 behaviour: predefined read write data section
4311 double word aligned (4-byte)
4312 FIXME: relocation is applied to it
4313 FIXME: what's the difference between this and .data?
4316 initial: .section .reldata "drw3"
4317 d - initialized data
4320 3 - double word aligned (that would be 8 byte boundary)
4323 Like .data, but intended to hold data subject to relocation, such as
4324 function descriptors, etc. */
4327 ppc_reldata (int ignore ATTRIBUTE_UNUSED
)
4329 if (reldata_section
== 0)
4331 reldata_section
= subseg_new (".reldata", 0);
4333 bfd_set_section_flags (stdoutput
, reldata_section
,
4334 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4337 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
4341 reldata_section
= subseg_new (".reldata", 0);
4343 ppc_set_current_section (reldata_section
);
4346 /* pseudo-op: .rdata
4347 behaviour: predefined read only data section
4351 initial: .section .rdata "dr3"
4352 d - initialized data
4354 3 - double word aligned (that would be 4 byte boundary) */
4357 ppc_rdata (int ignore ATTRIBUTE_UNUSED
)
4359 if (rdata_section
== 0)
4361 rdata_section
= subseg_new (".rdata", 0);
4362 bfd_set_section_flags (stdoutput
, rdata_section
,
4363 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4364 | SEC_READONLY
| SEC_DATA
));
4366 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
4370 rdata_section
= subseg_new (".rdata", 0);
4372 ppc_set_current_section (rdata_section
);
4375 /* pseudo-op: .ualong
4376 behaviour: much like .int, with the exception that no alignment is
4378 FIXME: test the alignment statement
4383 ppc_ualong (int ignore ATTRIBUTE_UNUSED
)
4389 /* pseudo-op: .znop <symbol name>
4390 behaviour: Issue a nop instruction
4391 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4392 the supplied symbol name.
4394 warnings: Missing symbol name */
4397 ppc_znop (int ignore ATTRIBUTE_UNUSED
)
4400 const struct powerpc_opcode
*opcode
;
4411 /* Strip out the symbol name. */
4412 symbol_name
= input_line_pointer
;
4413 c
= get_symbol_end ();
4415 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
4416 strcpy (name
, symbol_name
);
4418 sym
= symbol_find_or_make (name
);
4420 *input_line_pointer
= c
;
4424 /* Look up the opcode in the hash table. */
4425 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
4427 /* Stick in the nop. */
4428 insn
= opcode
->opcode
;
4430 /* Write out the instruction. */
4432 md_number_to_chars (f
, insn
, 4);
4434 f
- frag_now
->fr_literal
,
4439 BFD_RELOC_16_GOT_PCREL
);
4449 ppc_pe_comm (int lcomm
)
4458 name
= input_line_pointer
;
4459 c
= get_symbol_end ();
4461 /* just after name is now '\0'. */
4462 p
= input_line_pointer
;
4465 if (*input_line_pointer
!= ',')
4467 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4468 ignore_rest_of_line ();
4472 input_line_pointer
++; /* skip ',' */
4473 if ((temp
= get_absolute_expression ()) < 0)
4475 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
4476 ignore_rest_of_line ();
4482 /* The third argument to .comm is the alignment. */
4483 if (*input_line_pointer
!= ',')
4487 ++input_line_pointer
;
4488 align
= get_absolute_expression ();
4491 as_warn (_("ignoring bad alignment"));
4498 symbolP
= symbol_find_or_make (name
);
4501 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
4503 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4504 S_GET_NAME (symbolP
));
4505 ignore_rest_of_line ();
4509 if (S_GET_VALUE (symbolP
))
4511 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
4512 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4513 S_GET_NAME (symbolP
),
4514 (long) S_GET_VALUE (symbolP
),
4519 S_SET_VALUE (symbolP
, (valueT
) temp
);
4520 S_SET_EXTERNAL (symbolP
);
4521 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
4524 demand_empty_rest_of_line ();
4528 * implement the .section pseudo op:
4529 * .section name {, "flags"}
4531 * | +--- optional flags: 'b' for bss
4533 * +-- section name 'l' for lib
4537 * 'd' (apparently m88k for data)
4539 * But if the argument is not a quoted string, treat it as a
4540 * subsegment number.
4542 * FIXME: this is a copy of the section processing from obj-coff.c, with
4543 * additions/changes for the moto-pas assembler support. There are three
4546 * FIXME: I just noticed this. This doesn't work at all really. It it
4547 * setting bits that bfd probably neither understands or uses. The
4548 * correct approach (?) will have to incorporate extra fields attached
4549 * to the section to hold the system specific stuff. (krk)
4552 * 'a' - unknown - referred to in documentation, but no definition supplied
4553 * 'c' - section has code
4554 * 'd' - section has initialized data
4555 * 'u' - section has uninitialized data
4556 * 'i' - section contains directives (info)
4557 * 'n' - section can be discarded
4558 * 'R' - remove section at link time
4560 * Section Protection:
4561 * 'r' - section is readable
4562 * 'w' - section is writeable
4563 * 'x' - section is executable
4564 * 's' - section is sharable
4566 * Section Alignment:
4567 * '0' - align to byte boundary
4568 * '1' - align to halfword undary
4569 * '2' - align to word boundary
4570 * '3' - align to doubleword boundary
4571 * '4' - align to quadword boundary
4572 * '5' - align to 32 byte boundary
4573 * '6' - align to 64 byte boundary
4578 ppc_pe_section (int ignore ATTRIBUTE_UNUSED
)
4580 /* Strip out the section name. */
4589 section_name
= input_line_pointer
;
4590 c
= get_symbol_end ();
4592 name
= xmalloc (input_line_pointer
- section_name
+ 1);
4593 strcpy (name
, section_name
);
4595 *input_line_pointer
= c
;
4600 flags
= SEC_NO_FLAGS
;
4602 if (strcmp (name
, ".idata$2") == 0)
4606 else if (strcmp (name
, ".idata$3") == 0)
4610 else if (strcmp (name
, ".idata$4") == 0)
4614 else if (strcmp (name
, ".idata$5") == 0)
4618 else if (strcmp (name
, ".idata$6") == 0)
4623 /* Default alignment to 16 byte boundary. */
4626 if (*input_line_pointer
== ',')
4628 ++input_line_pointer
;
4630 if (*input_line_pointer
!= '"')
4631 exp
= get_absolute_expression ();
4634 ++input_line_pointer
;
4635 while (*input_line_pointer
!= '"'
4636 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4638 switch (*input_line_pointer
)
4640 /* Section Contents */
4641 case 'a': /* unknown */
4642 as_bad (_("Unsupported section attribute -- 'a'"));
4644 case 'c': /* code section */
4647 case 'd': /* section has initialized data */
4650 case 'u': /* section has uninitialized data */
4651 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4655 case 'i': /* section contains directives (info) */
4656 /* FIXME: This is IMAGE_SCN_LNK_INFO
4658 flags
|= SEC_HAS_CONTENTS
;
4660 case 'n': /* section can be discarded */
4663 case 'R': /* Remove section at link time */
4664 flags
|= SEC_NEVER_LOAD
;
4666 #if IFLICT_BRAIN_DAMAGE
4667 /* Section Protection */
4668 case 'r': /* section is readable */
4669 flags
|= IMAGE_SCN_MEM_READ
;
4671 case 'w': /* section is writeable */
4672 flags
|= IMAGE_SCN_MEM_WRITE
;
4674 case 'x': /* section is executable */
4675 flags
|= IMAGE_SCN_MEM_EXECUTE
;
4677 case 's': /* section is sharable */
4678 flags
|= IMAGE_SCN_MEM_SHARED
;
4681 /* Section Alignment */
4682 case '0': /* align to byte boundary */
4683 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
4686 case '1': /* align to halfword boundary */
4687 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
4690 case '2': /* align to word boundary */
4691 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
4694 case '3': /* align to doubleword boundary */
4695 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
4698 case '4': /* align to quadword boundary */
4699 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
4702 case '5': /* align to 32 byte boundary */
4703 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
4706 case '6': /* align to 64 byte boundary */
4707 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
4712 as_bad (_("unknown section attribute '%c'"),
4713 *input_line_pointer
);
4716 ++input_line_pointer
;
4718 if (*input_line_pointer
== '"')
4719 ++input_line_pointer
;
4723 sec
= subseg_new (name
, (subsegT
) exp
);
4725 ppc_set_current_section (sec
);
4727 if (flags
!= SEC_NO_FLAGS
)
4729 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
4730 as_bad (_("error setting flags for \"%s\": %s"),
4731 bfd_section_name (stdoutput
, sec
),
4732 bfd_errmsg (bfd_get_error ()));
4735 bfd_set_section_alignment (stdoutput
, sec
, align
);
4739 ppc_pe_function (int ignore ATTRIBUTE_UNUSED
)
4745 name
= input_line_pointer
;
4746 endc
= get_symbol_end ();
4748 ext_sym
= symbol_find_or_make (name
);
4750 *input_line_pointer
= endc
;
4752 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4753 SF_SET_FUNCTION (ext_sym
);
4754 SF_SET_PROCESS (ext_sym
);
4755 coff_add_linesym (ext_sym
);
4757 demand_empty_rest_of_line ();
4761 ppc_pe_tocd (int ignore ATTRIBUTE_UNUSED
)
4763 if (tocdata_section
== 0)
4765 tocdata_section
= subseg_new (".tocd", 0);
4766 /* FIXME: section flags won't work. */
4767 bfd_set_section_flags (stdoutput
, tocdata_section
,
4768 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4769 | SEC_READONLY
| SEC_DATA
));
4771 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4775 rdata_section
= subseg_new (".tocd", 0);
4778 ppc_set_current_section (tocdata_section
);
4780 demand_empty_rest_of_line ();
4783 /* Don't adjust TOC relocs to use the section symbol. */
4786 ppc_pe_fix_adjustable (fixS
*fix
)
4788 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4795 /* XCOFF specific symbol and file handling. */
4797 /* Canonicalize the symbol name. We use the to force the suffix, if
4798 any, to use square brackets, and to be in upper case. */
4801 ppc_canonicalize_symbol_name (char *name
)
4805 if (ppc_stab_symbol
)
4808 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4822 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4825 if (*s
== '\0' || s
[1] != '\0')
4826 as_bad (_("bad symbol suffix"));
4834 /* Set the class of a symbol based on the suffix, if any. This is
4835 called whenever a new symbol is created. */
4838 ppc_symbol_new_hook (symbolS
*sym
)
4840 struct ppc_tc_sy
*tc
;
4843 tc
= symbol_get_tc (sym
);
4847 tc
->real_name
= NULL
;
4853 if (ppc_stab_symbol
)
4856 s
= strchr (S_GET_NAME (sym
), '[');
4857 if (s
== (const char *) NULL
)
4859 /* There is no suffix. */
4868 if (strcmp (s
, "BS]") == 0)
4872 if (strcmp (s
, "DB]") == 0)
4874 else if (strcmp (s
, "DS]") == 0)
4878 if (strcmp (s
, "GL]") == 0)
4882 if (strcmp (s
, "PR]") == 0)
4886 if (strcmp (s
, "RO]") == 0)
4888 else if (strcmp (s
, "RW]") == 0)
4892 if (strcmp (s
, "SV]") == 0)
4896 if (strcmp (s
, "TC]") == 0)
4898 else if (strcmp (s
, "TI]") == 0)
4900 else if (strcmp (s
, "TB]") == 0)
4902 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4903 tc
->class = XMC_TC0
;
4906 if (strcmp (s
, "UA]") == 0)
4908 else if (strcmp (s
, "UC]") == 0)
4912 if (strcmp (s
, "XO]") == 0)
4917 if (tc
->class == -1)
4918 as_bad (_("Unrecognized symbol suffix"));
4921 /* Set the class of a label based on where it is defined. This
4922 handles symbols without suffixes. Also, move the symbol so that it
4923 follows the csect symbol. */
4926 ppc_frob_label (symbolS
*sym
)
4928 if (ppc_current_csect
!= (symbolS
*) NULL
)
4930 if (symbol_get_tc (sym
)->class == -1)
4931 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4933 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4934 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4935 &symbol_rootP
, &symbol_lastP
);
4936 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4940 dwarf2_emit_label (sym
);
4944 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4945 seen. It tells ppc_adjust_symtab whether it needs to look through
4948 static bfd_boolean ppc_saw_abs
;
4950 /* Change the name of a symbol just before writing it out. Set the
4951 real name if the .rename pseudo-op was used. Otherwise, remove any
4952 class suffix. Return 1 if the symbol should not be included in the
4956 ppc_frob_symbol (symbolS
*sym
)
4958 static symbolS
*ppc_last_function
;
4959 static symbolS
*set_end
;
4961 /* Discard symbols that should not be included in the output symbol
4963 if (! symbol_used_in_reloc_p (sym
)
4964 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4965 || (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
4966 && ! symbol_get_tc (sym
)->output
4967 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4970 /* This one will disappear anyway. Don't make a csect sym for it. */
4971 if (sym
== abs_section_sym
)
4974 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4975 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4981 name
= S_GET_NAME (sym
);
4982 s
= strchr (name
, '[');
4983 if (s
!= (char *) NULL
)
4989 snew
= xmalloc (len
+ 1);
4990 memcpy (snew
, name
, len
);
4993 S_SET_NAME (sym
, snew
);
4997 if (set_end
!= (symbolS
*) NULL
)
4999 SA_SET_SYM_ENDNDX (set_end
, sym
);
5003 if (SF_GET_FUNCTION (sym
))
5005 if (ppc_last_function
!= (symbolS
*) NULL
)
5006 as_bad (_("two .function pseudo-ops with no intervening .ef"));
5007 ppc_last_function
= sym
;
5008 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
5010 resolve_symbol_value (symbol_get_tc (sym
)->size
);
5011 SA_SET_SYM_FSIZE (sym
,
5012 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
5015 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
5016 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
5018 if (ppc_last_function
== (symbolS
*) NULL
)
5019 as_bad (_(".ef with no preceding .function"));
5022 set_end
= ppc_last_function
;
5023 ppc_last_function
= NULL
;
5025 /* We don't have a C_EFCN symbol, but we need to force the
5026 COFF backend to believe that it has seen one. */
5027 coff_last_function
= NULL
;
5031 if (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
5032 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
5033 && S_GET_STORAGE_CLASS (sym
) != C_FILE
5034 && S_GET_STORAGE_CLASS (sym
) != C_FCN
5035 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
5036 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
5037 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
5038 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
5039 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
5040 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
5041 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
5043 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
5044 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
5047 union internal_auxent
*a
;
5049 /* Create a csect aux. */
5050 i
= S_GET_NUMBER_AUXILIARY (sym
);
5051 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
5052 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
5053 if (symbol_get_tc (sym
)->class == XMC_TC0
)
5055 /* This is the TOC table. */
5056 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
5057 a
->x_csect
.x_scnlen
.l
= 0;
5058 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
5060 else if (symbol_get_tc (sym
)->subseg
!= 0)
5062 /* This is a csect symbol. x_scnlen is the size of the
5064 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
5065 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
5066 S_GET_SEGMENT (sym
))
5067 - S_GET_VALUE (sym
));
5070 resolve_symbol_value (symbol_get_tc (sym
)->next
);
5071 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
5072 - S_GET_VALUE (sym
));
5074 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
5076 else if (S_GET_SEGMENT (sym
) == bss_section
)
5078 /* This is a common symbol. */
5079 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
5080 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
5081 if (S_IS_EXTERNAL (sym
))
5082 symbol_get_tc (sym
)->class = XMC_RW
;
5084 symbol_get_tc (sym
)->class = XMC_BS
;
5086 else if (S_GET_SEGMENT (sym
) == absolute_section
)
5088 /* This is an absolute symbol. The csect will be created by
5089 ppc_adjust_symtab. */
5091 a
->x_csect
.x_smtyp
= XTY_LD
;
5092 if (symbol_get_tc (sym
)->class == -1)
5093 symbol_get_tc (sym
)->class = XMC_XO
;
5095 else if (! S_IS_DEFINED (sym
))
5097 /* This is an external symbol. */
5098 a
->x_csect
.x_scnlen
.l
= 0;
5099 a
->x_csect
.x_smtyp
= XTY_ER
;
5101 else if (symbol_get_tc (sym
)->class == XMC_TC
)
5105 /* This is a TOC definition. x_scnlen is the size of the
5107 next
= symbol_next (sym
);
5108 while (symbol_get_tc (next
)->class == XMC_TC0
)
5109 next
= symbol_next (next
);
5110 if (next
== (symbolS
*) NULL
5111 || symbol_get_tc (next
)->class != XMC_TC
)
5113 if (ppc_after_toc_frag
== (fragS
*) NULL
)
5114 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
5116 - S_GET_VALUE (sym
));
5118 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
5119 - S_GET_VALUE (sym
));
5123 resolve_symbol_value (next
);
5124 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
5125 - S_GET_VALUE (sym
));
5127 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
5133 /* This is a normal symbol definition. x_scnlen is the
5134 symbol index of the containing csect. */
5135 if (S_GET_SEGMENT (sym
) == text_section
)
5136 csect
= ppc_text_csects
;
5137 else if (S_GET_SEGMENT (sym
) == data_section
)
5138 csect
= ppc_data_csects
;
5142 /* Skip the initial dummy symbol. */
5143 csect
= symbol_get_tc (csect
)->next
;
5145 if (csect
== (symbolS
*) NULL
)
5147 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
5148 a
->x_csect
.x_scnlen
.l
= 0;
5152 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
5154 resolve_symbol_value (symbol_get_tc (csect
)->next
);
5155 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
5156 > S_GET_VALUE (sym
))
5158 csect
= symbol_get_tc (csect
)->next
;
5161 a
->x_csect
.x_scnlen
.p
=
5162 coffsymbol (symbol_get_bfdsym (csect
))->native
;
5163 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
5166 a
->x_csect
.x_smtyp
= XTY_LD
;
5169 a
->x_csect
.x_parmhash
= 0;
5170 a
->x_csect
.x_snhash
= 0;
5171 if (symbol_get_tc (sym
)->class == -1)
5172 a
->x_csect
.x_smclas
= XMC_PR
;
5174 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
5175 a
->x_csect
.x_stab
= 0;
5176 a
->x_csect
.x_snstab
= 0;
5178 /* Don't let the COFF backend resort these symbols. */
5179 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
5181 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
5183 /* We want the value to be the symbol index of the referenced
5184 csect symbol. BFD will do that for us if we set the right
5186 asymbol
*bsym
= symbol_get_bfdsym (symbol_get_tc (sym
)->within
);
5187 combined_entry_type
*c
= coffsymbol (bsym
)->native
;
5189 S_SET_VALUE (sym
, (valueT
) (size_t) c
);
5190 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
5192 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
5197 /* The value is the offset from the enclosing csect. */
5198 block
= symbol_get_tc (sym
)->within
;
5199 csect
= symbol_get_tc (block
)->within
;
5200 resolve_symbol_value (csect
);
5201 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
5203 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
5204 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
5206 /* We want the value to be a file offset into the line numbers.
5207 BFD will do that for us if we set the right flags. We have
5208 already set the value correctly. */
5209 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
5215 /* Adjust the symbol table. This creates csect symbols for all
5216 absolute symbols. */
5219 ppc_adjust_symtab (void)
5226 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
5230 union internal_auxent
*a
;
5232 if (S_GET_SEGMENT (sym
) != absolute_section
)
5235 csect
= symbol_create (".abs[XO]", absolute_section
,
5236 S_GET_VALUE (sym
), &zero_address_frag
);
5237 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
5238 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
5239 i
= S_GET_NUMBER_AUXILIARY (csect
);
5240 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
5241 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
5242 a
->x_csect
.x_scnlen
.l
= 0;
5243 a
->x_csect
.x_smtyp
= XTY_SD
;
5244 a
->x_csect
.x_parmhash
= 0;
5245 a
->x_csect
.x_snhash
= 0;
5246 a
->x_csect
.x_smclas
= XMC_XO
;
5247 a
->x_csect
.x_stab
= 0;
5248 a
->x_csect
.x_snstab
= 0;
5250 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
5252 i
= S_GET_NUMBER_AUXILIARY (sym
);
5253 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
5254 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
5255 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
5258 ppc_saw_abs
= FALSE
;
5261 /* Set the VMA for a section. This is called on all the sections in
5265 ppc_frob_section (asection
*sec
)
5267 static bfd_vma vma
= 0;
5269 vma
= md_section_align (sec
, vma
);
5270 bfd_set_section_vma (stdoutput
, sec
, vma
);
5271 vma
+= bfd_section_size (stdoutput
, sec
);
5274 #endif /* OBJ_XCOFF */
5277 md_atof (int type
, char *litp
, int *sizep
)
5279 return ieee_md_atof (type
, litp
, sizep
, target_big_endian
);
5282 /* Write a value out to the object file, using the appropriate
5286 md_number_to_chars (char *buf
, valueT val
, int n
)
5288 if (target_big_endian
)
5289 number_to_chars_bigendian (buf
, val
, n
);
5291 number_to_chars_littleendian (buf
, val
, n
);
5294 /* Align a section (I don't know why this is machine dependent). */
5297 md_section_align (asection
*seg ATTRIBUTE_UNUSED
, valueT addr
)
5302 int align
= bfd_get_section_alignment (stdoutput
, seg
);
5304 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
5308 /* We don't have any form of relaxing. */
5311 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
5312 asection
*seg ATTRIBUTE_UNUSED
)
5318 /* Convert a machine dependent frag. We never generate these. */
5321 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
5322 asection
*sec ATTRIBUTE_UNUSED
,
5323 fragS
*fragp ATTRIBUTE_UNUSED
)
5328 /* We have no need to default values of symbols. */
5331 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
5336 /* Functions concerning relocs. */
5338 /* The location from which a PC relative jump should be calculated,
5339 given a PC relative reloc. */
5342 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
5344 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5349 /* This is called to see whether a fixup should be adjusted to use a
5350 section symbol. We take the opportunity to change a fixup against
5351 a symbol in the TOC subsegment into a reloc against the
5352 corresponding .tc symbol. */
5355 ppc_fix_adjustable (fixS
*fix
)
5357 valueT val
= resolve_symbol_value (fix
->fx_addsy
);
5358 segT symseg
= S_GET_SEGMENT (fix
->fx_addsy
);
5359 TC_SYMFIELD_TYPE
*tc
;
5361 if (symseg
== absolute_section
)
5364 if (ppc_toc_csect
!= (symbolS
*) NULL
5365 && fix
->fx_addsy
!= ppc_toc_csect
5366 && symseg
== data_section
5367 && val
>= ppc_toc_frag
->fr_address
5368 && (ppc_after_toc_frag
== (fragS
*) NULL
5369 || val
< ppc_after_toc_frag
->fr_address
))
5373 for (sy
= symbol_next (ppc_toc_csect
);
5374 sy
!= (symbolS
*) NULL
;
5375 sy
= symbol_next (sy
))
5377 TC_SYMFIELD_TYPE
*sy_tc
= symbol_get_tc (sy
);
5379 if (sy_tc
->class == XMC_TC0
)
5381 if (sy_tc
->class != XMC_TC
)
5383 if (val
== resolve_symbol_value (sy
))
5386 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
5391 as_bad_where (fix
->fx_file
, fix
->fx_line
,
5392 _("symbol in .toc does not match any .tc"));
5395 /* Possibly adjust the reloc to be against the csect. */
5396 tc
= symbol_get_tc (fix
->fx_addsy
);
5398 && tc
->class != XMC_TC0
5399 && tc
->class != XMC_TC
5400 && symseg
!= bss_section
5401 /* Don't adjust if this is a reloc in the toc section. */
5402 && (symseg
!= data_section
5403 || ppc_toc_csect
== NULL
5404 || val
< ppc_toc_frag
->fr_address
5405 || (ppc_after_toc_frag
!= NULL
5406 && val
>= ppc_after_toc_frag
->fr_address
)))
5409 symbolS
*next_csect
;
5411 if (symseg
== text_section
)
5412 csect
= ppc_text_csects
;
5413 else if (symseg
== data_section
)
5414 csect
= ppc_data_csects
;
5418 /* Skip the initial dummy symbol. */
5419 csect
= symbol_get_tc (csect
)->next
;
5421 if (csect
!= (symbolS
*) NULL
)
5423 while ((next_csect
= symbol_get_tc (csect
)->next
) != (symbolS
*) NULL
5424 && (symbol_get_frag (next_csect
)->fr_address
<= val
))
5426 /* If the csect address equals the symbol value, then we
5427 have to look through the full symbol table to see
5428 whether this is the csect we want. Note that we will
5429 only get here if the csect has zero length. */
5430 if (symbol_get_frag (csect
)->fr_address
== val
5431 && S_GET_VALUE (csect
) == val
)
5435 for (scan
= symbol_next (csect
);
5437 scan
= symbol_next (scan
))
5439 if (symbol_get_tc (scan
)->subseg
!= 0)
5441 if (scan
== fix
->fx_addsy
)
5445 /* If we found the symbol before the next csect
5446 symbol, then this is the csect we want. */
5447 if (scan
== fix
->fx_addsy
)
5454 fix
->fx_offset
+= val
- symbol_get_frag (csect
)->fr_address
;
5455 fix
->fx_addsy
= csect
;
5460 /* Adjust a reloc against a .lcomm symbol to be against the base
5462 if (symseg
== bss_section
5463 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
5465 symbolS
*sy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
5467 fix
->fx_offset
+= val
- resolve_symbol_value (sy
);
5474 /* A reloc from one csect to another must be kept. The assembler
5475 will, of course, keep relocs between sections, and it will keep
5476 absolute relocs, but we need to force it to keep PC relative relocs
5477 between two csects in the same section. */
5480 ppc_force_relocation (fixS
*fix
)
5482 /* At this point fix->fx_addsy should already have been converted to
5483 a csect symbol. If the csect does not include the fragment, then
5484 we need to force the relocation. */
5486 && fix
->fx_addsy
!= NULL
5487 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
5488 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
5489 > fix
->fx_frag
->fr_address
)
5490 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
5491 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
5492 <= fix
->fx_frag
->fr_address
))))
5495 return generic_force_reloc (fix
);
5498 #endif /* OBJ_XCOFF */
5501 /* If this function returns non-zero, it guarantees that a relocation
5502 will be emitted for a fixup. */
5505 ppc_force_relocation (fixS
*fix
)
5507 /* Branch prediction relocations must force a relocation, as must
5508 the vtable description relocs. */
5509 switch (fix
->fx_r_type
)
5511 case BFD_RELOC_PPC_B16_BRTAKEN
:
5512 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5513 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5514 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5515 case BFD_RELOC_24_PLT_PCREL
:
5516 case BFD_RELOC_PPC64_TOC
:
5522 if (fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5523 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
5526 return generic_force_reloc (fix
);
5530 ppc_fix_adjustable (fixS
*fix
)
5532 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
5533 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
5534 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
5535 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
5536 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
5537 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
5538 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
5539 && !(fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5540 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
));
5544 /* Implement HANDLE_ALIGN. This writes the NOP pattern into an
5545 rs_align_code frag. */
5548 ppc_handle_align (struct frag
*fragP
)
5550 valueT count
= (fragP
->fr_next
->fr_address
5551 - (fragP
->fr_address
+ fragP
->fr_fix
));
5553 if (count
!= 0 && (count
& 3) == 0)
5555 char *dest
= fragP
->fr_literal
+ fragP
->fr_fix
;
5558 md_number_to_chars (dest
, 0x60000000, 4);
5560 if ((ppc_cpu
& PPC_OPCODE_POWER6
) != 0)
5562 /* For power6, we want the last nop to be a group terminating
5563 one, "ori 1,1,0". Do this by inserting an rs_fill frag
5564 immediately after this one, with its address set to the last
5565 nop location. This will automatically reduce the number of
5566 nops in the current frag by one. */
5569 struct frag
*group_nop
= xmalloc (SIZEOF_STRUCT_FRAG
+ 4);
5571 memcpy (group_nop
, fragP
, SIZEOF_STRUCT_FRAG
);
5572 group_nop
->fr_address
= group_nop
->fr_next
->fr_address
- 4;
5573 group_nop
->fr_fix
= 0;
5574 group_nop
->fr_offset
= 1;
5575 group_nop
->fr_type
= rs_fill
;
5576 fragP
->fr_next
= group_nop
;
5577 dest
= group_nop
->fr_literal
;
5580 md_number_to_chars (dest
, 0x60210000, 4);
5585 /* Apply a fixup to the object code. This is called for all the
5586 fixups we generated by the call to fix_new_exp, above. In the call
5587 above we used a reloc code which was the largest legal reloc code
5588 plus the operand index. Here we undo that to recover the operand
5589 index. At this point all symbol values should be fully resolved,
5590 and we attempt to completely resolve the reloc. If we can not do
5591 that, we determine the correct reloc code and put it back in the
5595 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
5597 valueT value
= * valP
;
5600 if (fixP
->fx_addsy
!= NULL
)
5602 /* Hack around bfd_install_relocation brain damage. */
5604 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5609 /* FIXME FIXME FIXME: The value we are passed in *valP includes
5610 the symbol values. If we are doing this relocation the code in
5611 write.c is going to call bfd_install_relocation, which is also
5612 going to use the symbol value. That means that if the reloc is
5613 fully resolved we want to use *valP since bfd_install_relocation is
5615 However, if the reloc is not fully resolved we do not want to use
5616 *valP, and must use fx_offset instead. However, if the reloc
5617 is PC relative, we do want to use *valP since it includes the
5618 result of md_pcrel_from. This is confusing. */
5619 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
5622 else if (fixP
->fx_pcrel
)
5626 value
= fixP
->fx_offset
;
5629 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
5631 /* We can't actually support subtracting a symbol. */
5632 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
5635 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
5638 const struct powerpc_operand
*operand
;
5642 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
5644 operand
= &powerpc_operands
[opindex
];
5647 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5648 does not generate a reloc. It uses the offset of `sym' within its
5649 csect. Other usages, such as `.long sym', generate relocs. This
5650 is the documented behaviour of non-TOC symbols. */
5651 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5652 && (operand
->bitm
& 0xfff0) == 0xfff0
5653 && operand
->shift
== 0
5654 && (operand
->insert
== NULL
|| ppc_obj64
)
5655 && fixP
->fx_addsy
!= NULL
5656 && symbol_get_tc (fixP
->fx_addsy
)->subseg
!= 0
5657 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC
5658 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC0
5659 && S_GET_SEGMENT (fixP
->fx_addsy
) != bss_section
)
5661 value
= fixP
->fx_offset
;
5666 /* Fetch the instruction, insert the fully resolved operand
5667 value, and stuff the instruction back again. */
5668 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5669 if (target_big_endian
)
5670 insn
= bfd_getb32 ((unsigned char *) where
);
5672 insn
= bfd_getl32 ((unsigned char *) where
);
5673 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
5674 fixP
->tc_fix_data
.ppc_cpu
,
5675 fixP
->fx_file
, fixP
->fx_line
);
5676 if (target_big_endian
)
5677 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5679 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5682 /* Nothing else to do here. */
5685 assert (fixP
->fx_addsy
!= NULL
);
5687 /* Determine a BFD reloc value based on the operand information.
5688 We are only prepared to turn a few of the operands into
5690 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5691 && operand
->bitm
== 0x3fffffc
5692 && operand
->shift
== 0)
5693 fixP
->fx_r_type
= BFD_RELOC_PPC_B26
;
5694 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5695 && operand
->bitm
== 0xfffc
5696 && operand
->shift
== 0)
5698 fixP
->fx_r_type
= BFD_RELOC_PPC_B16
;
5701 if (target_big_endian
)
5702 fixP
->fx_where
+= 2;
5705 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5706 && operand
->bitm
== 0x3fffffc
5707 && operand
->shift
== 0)
5708 fixP
->fx_r_type
= BFD_RELOC_PPC_BA26
;
5709 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5710 && operand
->bitm
== 0xfffc
5711 && operand
->shift
== 0)
5713 fixP
->fx_r_type
= BFD_RELOC_PPC_BA16
;
5716 if (target_big_endian
)
5717 fixP
->fx_where
+= 2;
5720 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5721 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5722 && (operand
->bitm
& 0xfff0) == 0xfff0
5723 && operand
->shift
== 0)
5725 if (ppc_is_toc_sym (fixP
->fx_addsy
))
5727 fixP
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
5730 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5731 fixP
->fx_r_type
= BFD_RELOC_PPC64_TOC16_DS
;
5736 fixP
->fx_r_type
= BFD_RELOC_16
;
5739 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5740 fixP
->fx_r_type
= BFD_RELOC_PPC64_ADDR16_DS
;
5744 if (target_big_endian
)
5745 fixP
->fx_where
+= 2;
5747 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5753 /* Use expr_symbol_where to see if this is an expression
5755 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
5756 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5757 _("unresolved expression that must be resolved"));
5759 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5760 _("unsupported relocation against %s"),
5761 S_GET_NAME (fixP
->fx_addsy
));
5769 ppc_elf_validate_fix (fixP
, seg
);
5771 switch (fixP
->fx_r_type
)
5773 case BFD_RELOC_CTOR
:
5780 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
5784 case BFD_RELOC_32_PCREL
:
5785 case BFD_RELOC_PPC_EMB_NADDR32
:
5786 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5793 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
5796 case BFD_RELOC_64_PCREL
:
5797 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5801 case BFD_RELOC_GPREL16
:
5802 case BFD_RELOC_16_GOT_PCREL
:
5803 case BFD_RELOC_16_GOTOFF
:
5804 case BFD_RELOC_LO16_GOTOFF
:
5805 case BFD_RELOC_HI16_GOTOFF
:
5806 case BFD_RELOC_HI16_S_GOTOFF
:
5807 case BFD_RELOC_16_BASEREL
:
5808 case BFD_RELOC_LO16_BASEREL
:
5809 case BFD_RELOC_HI16_BASEREL
:
5810 case BFD_RELOC_HI16_S_BASEREL
:
5811 case BFD_RELOC_PPC_EMB_NADDR16
:
5812 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5813 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5814 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5815 case BFD_RELOC_PPC_EMB_SDAI16
:
5816 case BFD_RELOC_PPC_EMB_SDA2REL
:
5817 case BFD_RELOC_PPC_EMB_SDA2I16
:
5818 case BFD_RELOC_PPC_EMB_RELSEC16
:
5819 case BFD_RELOC_PPC_EMB_RELST_LO
:
5820 case BFD_RELOC_PPC_EMB_RELST_HI
:
5821 case BFD_RELOC_PPC_EMB_RELST_HA
:
5822 case BFD_RELOC_PPC_EMB_RELSDA
:
5823 case BFD_RELOC_PPC_TOC16
:
5825 case BFD_RELOC_PPC64_TOC16_LO
:
5826 case BFD_RELOC_PPC64_TOC16_HI
:
5827 case BFD_RELOC_PPC64_TOC16_HA
:
5831 if (fixP
->fx_addsy
!= NULL
)
5832 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5833 _("cannot emit PC relative %s relocation against %s"),
5834 bfd_get_reloc_code_name (fixP
->fx_r_type
),
5835 S_GET_NAME (fixP
->fx_addsy
));
5837 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5838 _("cannot emit PC relative %s relocation"),
5839 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5842 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5848 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
5851 case BFD_RELOC_16_PCREL
:
5852 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5856 case BFD_RELOC_LO16
:
5858 fixP
->fx_r_type
= BFD_RELOC_LO16_PCREL
;
5861 case BFD_RELOC_LO16_PCREL
:
5862 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5866 /* This case happens when you write, for example,
5868 where L1 and L2 are defined later. */
5869 case BFD_RELOC_HI16
:
5871 fixP
->fx_r_type
= BFD_RELOC_HI16_PCREL
;
5874 case BFD_RELOC_HI16_PCREL
:
5875 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5879 case BFD_RELOC_HI16_S
:
5881 fixP
->fx_r_type
= BFD_RELOC_HI16_S_PCREL
;
5884 case BFD_RELOC_HI16_S_PCREL
:
5885 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5890 case BFD_RELOC_PPC64_HIGHER
:
5893 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5894 PPC_HIGHER (value
), 2);
5897 case BFD_RELOC_PPC64_HIGHER_S
:
5900 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5901 PPC_HIGHERA (value
), 2);
5904 case BFD_RELOC_PPC64_HIGHEST
:
5907 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5908 PPC_HIGHEST (value
), 2);
5911 case BFD_RELOC_PPC64_HIGHEST_S
:
5914 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5915 PPC_HIGHESTA (value
), 2);
5918 case BFD_RELOC_PPC64_ADDR16_DS
:
5919 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
5920 case BFD_RELOC_PPC64_GOT16_DS
:
5921 case BFD_RELOC_PPC64_GOT16_LO_DS
:
5922 case BFD_RELOC_PPC64_PLT16_LO_DS
:
5923 case BFD_RELOC_PPC64_SECTOFF_DS
:
5924 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
5925 case BFD_RELOC_PPC64_TOC16_DS
:
5926 case BFD_RELOC_PPC64_TOC16_LO_DS
:
5927 case BFD_RELOC_PPC64_PLTGOT16_DS
:
5928 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
5932 char *where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5933 unsigned long val
, mask
;
5935 if (target_big_endian
)
5936 val
= bfd_getb32 (where
- 2);
5938 val
= bfd_getl32 (where
);
5940 /* lq insns reserve the four lsbs. */
5941 if ((ppc_cpu
& PPC_OPCODE_POWER4
) != 0
5942 && (val
& (0x3f << 26)) == (56u << 26))
5944 val
|= value
& mask
;
5945 if (target_big_endian
)
5946 bfd_putb16 ((bfd_vma
) val
, where
);
5948 bfd_putl16 ((bfd_vma
) val
, where
);
5952 case BFD_RELOC_PPC_B16_BRTAKEN
:
5953 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5954 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5955 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5958 case BFD_RELOC_PPC_TLS
:
5961 case BFD_RELOC_PPC_DTPMOD
:
5962 case BFD_RELOC_PPC_TPREL16
:
5963 case BFD_RELOC_PPC_TPREL16_LO
:
5964 case BFD_RELOC_PPC_TPREL16_HI
:
5965 case BFD_RELOC_PPC_TPREL16_HA
:
5966 case BFD_RELOC_PPC_TPREL
:
5967 case BFD_RELOC_PPC_DTPREL16
:
5968 case BFD_RELOC_PPC_DTPREL16_LO
:
5969 case BFD_RELOC_PPC_DTPREL16_HI
:
5970 case BFD_RELOC_PPC_DTPREL16_HA
:
5971 case BFD_RELOC_PPC_DTPREL
:
5972 case BFD_RELOC_PPC_GOT_TLSGD16
:
5973 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
5974 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
5975 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
5976 case BFD_RELOC_PPC_GOT_TLSLD16
:
5977 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
5978 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
5979 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
5980 case BFD_RELOC_PPC_GOT_TPREL16
:
5981 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
5982 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
5983 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
5984 case BFD_RELOC_PPC_GOT_DTPREL16
:
5985 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
5986 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
5987 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
5988 case BFD_RELOC_PPC64_TPREL16_DS
:
5989 case BFD_RELOC_PPC64_TPREL16_LO_DS
:
5990 case BFD_RELOC_PPC64_TPREL16_HIGHER
:
5991 case BFD_RELOC_PPC64_TPREL16_HIGHERA
:
5992 case BFD_RELOC_PPC64_TPREL16_HIGHEST
:
5993 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
:
5994 case BFD_RELOC_PPC64_DTPREL16_DS
:
5995 case BFD_RELOC_PPC64_DTPREL16_LO_DS
:
5996 case BFD_RELOC_PPC64_DTPREL16_HIGHER
:
5997 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
:
5998 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
:
5999 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
:
6000 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
6003 /* Because SDA21 modifies the register field, the size is set to 4
6004 bytes, rather than 2, so offset it here appropriately. */
6005 case BFD_RELOC_PPC_EMB_SDA21
:
6009 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
6010 + ((target_big_endian
) ? 2 : 0),
6017 /* This can occur if there is a bug in the input assembler, eg:
6018 ".byte <undefined_symbol> - ." */
6020 as_bad (_("Unable to handle reference to symbol %s"),
6021 S_GET_NAME (fixP
->fx_addsy
));
6023 as_bad (_("Unable to resolve expression"));
6027 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6031 case BFD_RELOC_24_PLT_PCREL
:
6032 case BFD_RELOC_PPC_LOCAL24PC
:
6033 if (!fixP
->fx_pcrel
&& !fixP
->fx_done
)
6041 /* Fetch the instruction, insert the fully resolved operand
6042 value, and stuff the instruction back again. */
6043 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
6044 if (target_big_endian
)
6045 insn
= bfd_getb32 ((unsigned char *) where
);
6047 insn
= bfd_getl32 ((unsigned char *) where
);
6048 if ((value
& 3) != 0)
6049 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6050 _("must branch to an address a multiple of 4"));
6051 if ((offsetT
) value
< -0x40000000
6052 || (offsetT
) value
>= 0x40000000)
6053 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6054 _("@local or @plt branch destination is too far away, %ld bytes"),
6056 insn
= insn
| (value
& 0x03fffffc);
6057 if (target_big_endian
)
6058 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
6060 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
6064 case BFD_RELOC_VTABLE_INHERIT
:
6067 && !S_IS_DEFINED (fixP
->fx_addsy
)
6068 && !S_IS_WEAK (fixP
->fx_addsy
))
6069 S_SET_WEAK (fixP
->fx_addsy
);
6072 case BFD_RELOC_VTABLE_ENTRY
:
6077 /* Generated by reference to `sym@tocbase'. The sym is
6078 ignored by the linker. */
6079 case BFD_RELOC_PPC64_TOC
:
6085 _("Gas failure, reloc value %d\n"), fixP
->fx_r_type
);
6092 fixP
->fx_addnumber
= value
;
6094 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6095 from the section contents. If we are going to be emitting a reloc
6096 then the section contents are immaterial, so don't warn if they
6097 happen to overflow. Leave such warnings to ld. */
6099 fixP
->fx_no_overflow
= 1;
6101 if (fixP
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
6102 fixP
->fx_addnumber
= 0;
6106 fixP
->fx_addnumber
= 0;
6108 /* We want to use the offset within the toc, not the actual VMA
6110 fixP
->fx_addnumber
=
6111 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixP
->fx_addsy
))
6112 - S_GET_VALUE (ppc_toc_csect
);
6118 /* Generate a reloc for a fixup. */
6121 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
6125 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
6127 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
6128 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
6129 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
6130 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
6131 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
6133 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6134 _("reloc %d not supported by object file format"),
6135 (int) fixp
->fx_r_type
);
6138 reloc
->addend
= fixp
->fx_addnumber
;
6144 ppc_cfi_frame_initial_instructions (void)
6146 cfi_add_CFA_def_cfa (1, 0);
6150 tc_ppc_regname_to_dw2regnum (char *regname
)
6152 unsigned int regnum
= -1;
6156 static struct { char *name
; int dw2regnum
; } regnames
[] =
6158 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6159 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6160 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6161 { "spe_acc", 111 }, { "spefscr", 112 }
6164 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
6165 if (strcmp (regnames
[i
].name
, regname
) == 0)
6166 return regnames
[i
].dw2regnum
;
6168 if (regname
[0] == 'r' || regname
[0] == 'f' || regname
[0] == 'v')
6170 p
= regname
+ 1 + (regname
[1] == '.');
6171 regnum
= strtoul (p
, &q
, 10);
6172 if (p
== q
|| *q
|| regnum
>= 32)
6174 if (regname
[0] == 'f')
6176 else if (regname
[0] == 'v')
6179 else if (regname
[0] == 'c' && regname
[1] == 'r')
6181 p
= regname
+ 2 + (regname
[2] == '.');
6182 if (p
[0] < '0' || p
[0] > '7' || p
[1])
6184 regnum
= p
[0] - '0' + 68;