1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "safe-ctype.h"
28 #include "opcode/ppc.h"
32 #include "dwarf2dbg.h"
39 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
41 /* Tell the main code what the endianness is. */
42 extern int target_big_endian
;
44 /* Whether or not, we've set target_big_endian. */
45 static int set_target_endian
= 0;
47 /* Whether to use user friendly register names. */
48 #ifndef TARGET_REG_NAMES_P
50 #define TARGET_REG_NAMES_P true
52 #define TARGET_REG_NAMES_P false
56 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
59 /* #lo(value) denotes the least significant 16 bits of the indicated. */
60 #define PPC_LO(v) ((v) & 0xffff)
62 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
63 #define PPC_HI(v) (((v) >> 16) & 0xffff)
65 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
66 the indicated value, compensating for #lo() being treated as a
68 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
70 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
71 #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
73 /* #highera(value) denotes bits 32 through 47 of the indicated value,
74 compensating for #lo() being treated as a signed number. */
75 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
77 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
78 #define PPC_HIGHEST(v) (((v) >> 48) & 0xffff)
80 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
81 compensating for #lo being treated as a signed number. */
82 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
84 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
86 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
88 static boolean register_name
PARAMS ((expressionS
*));
89 static void ppc_set_cpu
PARAMS ((void));
90 static unsigned long ppc_insert_operand
91 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
92 offsetT val
, char *file
, unsigned int line
));
93 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
94 static void ppc_byte
PARAMS ((int));
96 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
97 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
98 static void ppc_tc
PARAMS ((int));
99 static void ppc_machine
PARAMS ((int));
103 static void ppc_comm
PARAMS ((int));
104 static void ppc_bb
PARAMS ((int));
105 static void ppc_bc
PARAMS ((int));
106 static void ppc_bf
PARAMS ((int));
107 static void ppc_biei
PARAMS ((int));
108 static void ppc_bs
PARAMS ((int));
109 static void ppc_eb
PARAMS ((int));
110 static void ppc_ec
PARAMS ((int));
111 static void ppc_ef
PARAMS ((int));
112 static void ppc_es
PARAMS ((int));
113 static void ppc_csect
PARAMS ((int));
114 static void ppc_change_csect
PARAMS ((symbolS
*));
115 static void ppc_function
PARAMS ((int));
116 static void ppc_extern
PARAMS ((int));
117 static void ppc_lglobl
PARAMS ((int));
118 static void ppc_section
PARAMS ((int));
119 static void ppc_named_section
PARAMS ((int));
120 static void ppc_stabx
PARAMS ((int));
121 static void ppc_rename
PARAMS ((int));
122 static void ppc_toc
PARAMS ((int));
123 static void ppc_xcoff_cons
PARAMS ((int));
124 static void ppc_vbyte
PARAMS ((int));
128 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
129 static void ppc_elf_cons
PARAMS ((int));
130 static void ppc_elf_rdata
PARAMS ((int));
131 static void ppc_elf_lcomm
PARAMS ((int));
132 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
136 static void ppc_set_current_section
PARAMS ((segT
));
137 static void ppc_previous
PARAMS ((int));
138 static void ppc_pdata
PARAMS ((int));
139 static void ppc_ydata
PARAMS ((int));
140 static void ppc_reldata
PARAMS ((int));
141 static void ppc_rdata
PARAMS ((int));
142 static void ppc_ualong
PARAMS ((int));
143 static void ppc_znop
PARAMS ((int));
144 static void ppc_pe_comm
PARAMS ((int));
145 static void ppc_pe_section
PARAMS ((int));
146 static void ppc_pe_function
PARAMS ((int));
147 static void ppc_pe_tocd
PARAMS ((int));
150 /* Generic assembler global variables which must be defined by all
154 /* This string holds the chars that always start a comment. If the
155 pre-processor is disabled, these aren't very useful. The macro
156 tc_comment_chars points to this. We use this, rather than the
157 usual comment_chars, so that we can switch for Solaris conventions. */
158 static const char ppc_solaris_comment_chars
[] = "#!";
159 static const char ppc_eabi_comment_chars
[] = "#";
161 #ifdef TARGET_SOLARIS_COMMENT
162 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
164 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
167 const char comment_chars
[] = "#";
170 /* Characters which start a comment at the beginning of a line. */
171 const char line_comment_chars
[] = "#";
173 /* Characters which may be used to separate multiple commands on a
175 const char line_separator_chars
[] = ";";
177 /* Characters which are used to indicate an exponent in a floating
179 const char EXP_CHARS
[] = "eE";
181 /* Characters which mean that a number is a floating point constant,
183 const char FLT_CHARS
[] = "dD";
185 /* The target specific pseudo-ops which we support. */
187 const pseudo_typeS md_pseudo_table
[] =
189 /* Pseudo-ops which must be overridden. */
190 { "byte", ppc_byte
, 0 },
193 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
194 legitimately belong in the obj-*.c file. However, XCOFF is based
195 on COFF, and is only implemented for the RS/6000. We just use
196 obj-coff.c, and add what we need here. */
197 { "comm", ppc_comm
, 0 },
198 { "lcomm", ppc_comm
, 1 },
202 { "bi", ppc_biei
, 0 },
204 { "csect", ppc_csect
, 0 },
205 { "data", ppc_section
, 'd' },
209 { "ei", ppc_biei
, 1 },
211 { "extern", ppc_extern
, 0 },
212 { "function", ppc_function
, 0 },
213 { "lglobl", ppc_lglobl
, 0 },
214 { "rename", ppc_rename
, 0 },
215 { "section", ppc_named_section
, 0 },
216 { "stabx", ppc_stabx
, 0 },
217 { "text", ppc_section
, 't' },
218 { "toc", ppc_toc
, 0 },
219 { "long", ppc_xcoff_cons
, 2 },
220 { "llong", ppc_xcoff_cons
, 3 },
221 { "word", ppc_xcoff_cons
, 1 },
222 { "short", ppc_xcoff_cons
, 1 },
223 { "vbyte", ppc_vbyte
, 0 },
227 { "llong", ppc_elf_cons
, 8 },
228 { "quad", ppc_elf_cons
, 8 },
229 { "long", ppc_elf_cons
, 4 },
230 { "word", ppc_elf_cons
, 2 },
231 { "short", ppc_elf_cons
, 2 },
232 { "rdata", ppc_elf_rdata
, 0 },
233 { "rodata", ppc_elf_rdata
, 0 },
234 { "lcomm", ppc_elf_lcomm
, 0 },
235 { "file", dwarf2_directive_file
, 0 },
236 { "loc", dwarf2_directive_loc
, 0 },
240 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
241 { "previous", ppc_previous
, 0 },
242 { "pdata", ppc_pdata
, 0 },
243 { "ydata", ppc_ydata
, 0 },
244 { "reldata", ppc_reldata
, 0 },
245 { "rdata", ppc_rdata
, 0 },
246 { "ualong", ppc_ualong
, 0 },
247 { "znop", ppc_znop
, 0 },
248 { "comm", ppc_pe_comm
, 0 },
249 { "lcomm", ppc_pe_comm
, 1 },
250 { "section", ppc_pe_section
, 0 },
251 { "function", ppc_pe_function
,0 },
252 { "tocd", ppc_pe_tocd
, 0 },
255 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
257 { "machine", ppc_machine
, 0 },
264 /* Predefined register names if -mregnames (or default for Windows NT).
265 In general, there are lots of them, in an attempt to be compatible
266 with a number of other Windows NT assemblers. */
268 /* Structure to hold information about predefined registers. */
275 /* List of registers that are pre-defined:
277 Each general register has predefined names of the form:
278 1. r<reg_num> which has the value <reg_num>.
279 2. r.<reg_num> which has the value <reg_num>.
281 Each floating point register has predefined names of the form:
282 1. f<reg_num> which has the value <reg_num>.
283 2. f.<reg_num> which has the value <reg_num>.
285 Each vector unit register has predefined names of the form:
286 1. v<reg_num> which has the value <reg_num>.
287 2. v.<reg_num> which has the value <reg_num>.
289 Each condition register has predefined names of the form:
290 1. cr<reg_num> which has the value <reg_num>.
291 2. cr.<reg_num> which has the value <reg_num>.
293 There are individual registers as well:
294 sp or r.sp has the value 1
295 rtoc or r.toc has the value 2
296 fpscr has the value 0
302 dsisr has the value 18
304 sdr1 has the value 25
305 srr0 has the value 26
306 srr1 has the value 27
308 The table is sorted. Suitable for searching by a binary search. */
310 static const struct pd_reg pre_defined_registers
[] =
312 { "cr.0", 0 }, /* Condition Registers */
332 { "dar", 19 }, /* Data Access Register */
333 { "dec", 22 }, /* Decrementer */
334 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
336 { "f.0", 0 }, /* Floating point registers */
404 { "lr", 8 }, /* Link Register */
408 { "r.0", 0 }, /* General Purpose Registers */
441 { "r.sp", 1 }, /* Stack Pointer */
443 { "r.toc", 2 }, /* Pointer to the table of contents */
445 { "r0", 0 }, /* More general purpose registers */
478 { "rtoc", 2 }, /* Table of contents */
480 { "sdr1", 25 }, /* Storage Description Register 1 */
484 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
485 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
487 { "v.0", 0 }, /* Vector registers */
557 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
559 /* Given NAME, find the register number associated with that name, return
560 the integer value associated with the given name or -1 on failure. */
562 static int reg_name_search
563 PARAMS ((const struct pd_reg
*, int, const char * name
));
566 reg_name_search (regs
, regcount
, name
)
567 const struct pd_reg
*regs
;
571 int middle
, low
, high
;
579 middle
= (low
+ high
) / 2;
580 cmp
= strcasecmp (name
, regs
[middle
].name
);
586 return regs
[middle
].value
;
594 * Summary of register_name.
596 * in: Input_line_pointer points to 1st char of operand.
598 * out: A expressionS.
599 * The operand may have been a register: in this case, X_op == O_register,
600 * X_add_number is set to the register number, and truth is returned.
601 * Input_line_pointer->(next non-blank) char after operand, or is in its
606 register_name (expressionP
)
607 expressionS
*expressionP
;
614 /* Find the spelling of the operand. */
615 start
= name
= input_line_pointer
;
616 if (name
[0] == '%' && ISALPHA (name
[1]))
617 name
= ++input_line_pointer
;
619 else if (!reg_names_p
|| !ISALPHA (name
[0]))
622 c
= get_symbol_end ();
623 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
625 /* Put back the delimiting char. */
626 *input_line_pointer
= c
;
628 /* Look to see if it's in the register table. */
631 expressionP
->X_op
= O_register
;
632 expressionP
->X_add_number
= reg_number
;
634 /* Make the rest nice. */
635 expressionP
->X_add_symbol
= NULL
;
636 expressionP
->X_op_symbol
= NULL
;
640 /* Reset the line as if we had not done anything. */
641 input_line_pointer
= start
;
645 /* This function is called for each symbol seen in an expression. It
646 handles the special parsing which PowerPC assemblers are supposed
647 to use for condition codes. */
649 /* Whether to do the special parsing. */
650 static boolean cr_operand
;
652 /* Names to recognize in a condition code. This table is sorted. */
653 static const struct pd_reg cr_names
[] =
670 /* Parsing function. This returns non-zero if it recognized an
674 ppc_parse_name (name
, expr
)
683 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
688 expr
->X_op
= O_constant
;
689 expr
->X_add_number
= val
;
694 /* Local variables. */
696 /* The type of processor we are assembling for. This is one or more
697 of the PPC_OPCODE flags defined in opcode/ppc.h. */
698 static int ppc_cpu
= 0;
700 /* The size of the processor we are assembling for. This is either
701 PPC_OPCODE_32 or PPC_OPCODE_64. */
702 static unsigned long ppc_size
= (BFD_DEFAULT_TARGET_SIZE
== 64
706 /* Whether to target xcoff64. */
707 static int ppc_xcoff64
= 0;
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 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" */
799 const char *const md_shortopts
= "b:l:usm:K:VQ:";
801 const char *const md_shortopts
= "um:";
803 const struct option md_longopts
[] = {
804 {NULL
, no_argument
, NULL
, 0}
806 const size_t md_longopts_size
= sizeof (md_longopts
);
809 md_parse_option (c
, arg
)
816 /* -u means that any undefined symbols should be treated as
817 external, which is the default for gas anyhow. */
822 /* Solaris as takes -le (presumably for little endian). For completeness
823 sake, recognize -be also. */
824 if (strcmp (arg
, "e") == 0)
826 target_big_endian
= 0;
827 set_target_endian
= 1;
835 if (strcmp (arg
, "e") == 0)
837 target_big_endian
= 1;
838 set_target_endian
= 1;
846 /* Recognize -K PIC. */
847 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
850 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
858 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
860 if (strcmp (arg
, "64") == 0)
862 else if (strcmp (arg
, "32") == 0)
869 /* Most CPU's are 32 bit. Exceptions are listed below. */
870 ppc_size
= PPC_OPCODE_32
;
872 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
874 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
875 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
876 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
877 else if (strcmp (arg
, "pwr") == 0)
878 ppc_cpu
= PPC_OPCODE_POWER
;
879 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
880 instructions that are holdovers from the Power. */
881 else if (strcmp (arg
, "601") == 0)
882 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
883 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
884 Motorola PowerPC 603/604. */
885 else if (strcmp (arg
, "ppc") == 0
886 || strcmp (arg
, "ppc32") == 0
887 || strcmp (arg
, "603") == 0
888 || strcmp (arg
, "604") == 0)
889 ppc_cpu
= PPC_OPCODE_PPC
;
890 /* -m403 and -m405 mean to assemble for the Motorola PowerPC 403/405. */
891 else if (strcmp (arg
, "403") == 0
892 || strcmp (arg
, "405") == 0)
893 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_403
;
894 else if (strcmp (arg
, "7400") == 0
895 || strcmp (arg
, "7410") == 0
896 || strcmp (arg
, "7450") == 0
897 || strcmp (arg
, "7455") == 0)
898 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
;
899 else if (strcmp (arg
, "altivec") == 0)
900 ppc_cpu
|= PPC_OPCODE_ALTIVEC
;
901 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
903 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
905 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_64
;
906 ppc_size
= PPC_OPCODE_64
;
908 else if (strcmp (arg
, "ppc64bridge") == 0)
910 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_64_BRIDGE
| PPC_OPCODE_64
;
911 ppc_size
= PPC_OPCODE_64
;
913 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
914 else if (strcmp (arg
, "booke") == 0 || strcmp (arg
, "booke32") == 0)
915 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
;
916 /* -mbooke64 means enable 64-bit BookE support. */
917 else if (strcmp (arg
, "booke64") == 0)
919 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
|
920 PPC_OPCODE_BOOKE64
| PPC_OPCODE_64
;
921 ppc_size
= PPC_OPCODE_64
;
923 /* -mcom means assemble for the common intersection between Power
924 and PowerPC. At present, we just allow the union, rather
925 than the intersection. */
926 else if (strcmp (arg
, "com") == 0)
927 ppc_cpu
= PPC_OPCODE_COMMON
;
928 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
929 else if (strcmp (arg
, "any") == 0)
930 ppc_cpu
= PPC_OPCODE_ANY
;
932 else if (strcmp (arg
, "regnames") == 0)
935 else if (strcmp (arg
, "no-regnames") == 0)
939 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
940 that require relocation. */
941 else if (strcmp (arg
, "relocatable") == 0)
943 shlib
= SHLIB_MRELOCATABLE
;
944 ppc_flags
|= EF_PPC_RELOCATABLE
;
947 else if (strcmp (arg
, "relocatable-lib") == 0)
949 shlib
= SHLIB_MRELOCATABLE
;
950 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
953 /* -memb, set embedded bit. */
954 else if (strcmp (arg
, "emb") == 0)
955 ppc_flags
|= EF_PPC_EMB
;
957 /* -mlittle/-mbig set the endianess. */
958 else if (strcmp (arg
, "little") == 0
959 || strcmp (arg
, "little-endian") == 0)
961 target_big_endian
= 0;
962 set_target_endian
= 1;
965 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
967 target_big_endian
= 1;
968 set_target_endian
= 1;
971 else if (strcmp (arg
, "solaris") == 0)
974 ppc_comment_chars
= ppc_solaris_comment_chars
;
977 else if (strcmp (arg
, "no-solaris") == 0)
980 ppc_comment_chars
= ppc_eabi_comment_chars
;
985 as_bad (_("invalid switch -m%s"), arg
);
991 /* -V: SVR4 argument to print version ID. */
996 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
997 should be emitted or not. FIXME: Not implemented. */
1001 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1002 rather than .stabs.excl, which is ignored by the linker.
1003 FIXME: Not implemented. */
1019 md_show_usage (stream
)
1022 fprintf (stream
, _("\
1025 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
1026 -mpwr generate code for IBM POWER (RIOS1)\n\
1027 -m601 generate code for Motorola PowerPC 601\n\
1028 -mppc, -mppc32, -m603, -m604\n\
1029 generate code for Motorola PowerPC 603/604\n\
1030 -m403, -m405 generate code for Motorola PowerPC 403/405\n\
1031 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
1032 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1033 -mbooke64 generate code for 64-bit Motorola BookE\n\
1034 -mbooke, mbooke32 generate code for 32-bit Motorola BookE\n\
1035 -mcom generate code Power/PowerPC common instructions\n\
1036 -many generate code for any architecture (PWR/PWRX/PPC)\n\
1037 -mregnames Allow symbolic names for registers\n\
1038 -mno-regnames Do not allow symbolic names for registers\n"));
1040 fprintf (stream
, _("\
1041 -mrelocatable support for GCC's -mrelocatble option\n\
1042 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1043 -memb set PPC_EMB bit in ELF flags\n\
1044 -mlittle, -mlittle-endian\n\
1045 generate code for a little endian machine\n\
1046 -mbig, -mbig-endian generate code for a big endian machine\n\
1047 -msolaris generate code for Solaris\n\
1048 -mno-solaris do not generate code for Solaris\n\
1049 -V print assembler version number\n\
1050 -Qy, -Qn ignored\n"));
1054 /* Set ppc_cpu if it is not already set. */
1059 const char *default_os
= TARGET_OS
;
1060 const char *default_cpu
= TARGET_CPU
;
1064 if (strncmp (default_os
, "aix", 3) == 0
1065 && default_os
[3] >= '4' && default_os
[3] <= '9')
1066 ppc_cpu
= PPC_OPCODE_COMMON
;
1067 else if (strncmp (default_os
, "aix3", 4) == 0)
1068 ppc_cpu
= PPC_OPCODE_POWER
;
1069 else if (strcmp (default_cpu
, "rs6000") == 0)
1070 ppc_cpu
= PPC_OPCODE_POWER
;
1071 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1072 ppc_cpu
= PPC_OPCODE_PPC
;
1074 as_fatal (_("Unknown default cpu = %s, os = %s"),
1075 default_cpu
, default_os
);
1079 /* Figure out the BFD architecture to use. */
1081 enum bfd_architecture
1084 const char *default_cpu
= TARGET_CPU
;
1087 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1088 return bfd_arch_powerpc
;
1089 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1090 return bfd_arch_rs6000
;
1091 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1093 if (strcmp (default_cpu
, "rs6000") == 0)
1094 return bfd_arch_rs6000
;
1095 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1096 return bfd_arch_powerpc
;
1099 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1100 return bfd_arch_unknown
;
1106 return ppc_size
== PPC_OPCODE_64
? 620 : 0;
1113 return ppc_xcoff64
? 3 : 2;
1118 ppc_target_format ()
1122 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1124 return "xcoff-powermac";
1126 return ppc_xcoff64
? "aixcoff64-rs6000" : "aixcoff-rs6000";
1130 boolean is64
= BFD_DEFAULT_TARGET_SIZE
== 64 && ppc_size
== PPC_OPCODE_64
;
1132 return (target_big_endian
1133 ? (is64
? "elf64-powerpc" : "elf32-powerpc")
1134 : (is64
? "elf64-powerpcle" : "elf32-powerpcle"));
1138 /* This function is called when the assembler starts up. It is called
1139 after the options have been parsed and the output file has been
1145 register const struct powerpc_opcode
*op
;
1146 const struct powerpc_opcode
*op_end
;
1147 const struct powerpc_macro
*macro
;
1148 const struct powerpc_macro
*macro_end
;
1149 boolean dup_insn
= false;
1154 /* Set the ELF flags if desired. */
1155 if (ppc_flags
&& !msolaris
)
1156 bfd_set_private_flags (stdoutput
, ppc_flags
);
1159 /* Insert the opcodes into a hash table. */
1160 ppc_hash
= hash_new ();
1162 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1163 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1165 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1167 if ((op
->flags
& ppc_cpu
) != 0
1168 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1169 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
1170 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0))
1174 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1175 if (retval
!= (const char *) NULL
)
1177 /* Ignore Power duplicates for -m601. */
1178 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1179 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1182 as_bad (_("Internal assembler error for instruction %s"),
1189 /* Insert the macros into a hash table. */
1190 ppc_macro_hash
= hash_new ();
1192 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1193 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1195 if ((macro
->flags
& ppc_cpu
) != 0)
1199 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1200 if (retval
!= (const char *) NULL
)
1202 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1211 /* Tell the main code what the endianness is if it is not overidden
1213 if (!set_target_endian
)
1215 set_target_endian
= 1;
1216 target_big_endian
= PPC_BIG_ENDIAN
;
1220 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1222 /* Create dummy symbols to serve as initial csects. This forces the
1223 text csects to precede the data csects. These symbols will not
1225 ppc_text_csects
= symbol_make ("dummy\001");
1226 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1227 ppc_data_csects
= symbol_make ("dummy\001");
1228 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1233 ppc_current_section
= text_section
;
1234 ppc_previous_section
= 0;
1239 /* Insert an operand value into an instruction. */
1241 static unsigned long
1242 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1244 const struct powerpc_operand
*operand
;
1249 if (operand
->bits
!= 32)
1254 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1256 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1257 max
= (1 << operand
->bits
) - 1;
1259 max
= (1 << (operand
->bits
- 1)) - 1;
1260 min
= - (1 << (operand
->bits
- 1));
1262 if (ppc_size
== PPC_OPCODE_32
)
1264 /* Some people write 32 bit hex constants with the sign
1265 extension done by hand. This shouldn't really be
1266 valid, but, to permit this code to assemble on a 64
1267 bit host, we sign extend the 32 bit value. */
1269 && (val
& (offsetT
) 0x80000000) != 0
1270 && (val
& (offsetT
) 0xffffffff) == val
)
1279 max
= (1 << operand
->bits
) - 1;
1283 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1288 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1291 _("operand out of range (%s not between %ld and %ld)");
1294 sprint_value (buf
, test
);
1295 as_bad_where (file
, line
, err
, buf
, min
, max
);
1299 if (operand
->insert
)
1304 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1305 if (errmsg
!= (const char *) NULL
)
1306 as_bad_where (file
, line
, errmsg
);
1309 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1317 /* Parse @got, etc. and return the desired relocation. */
1318 static bfd_reloc_code_real_type
1319 ppc_elf_suffix (str_p
, exp_p
)
1334 const struct map_bfd
*ptr
;
1336 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1338 static const struct map_bfd mapping
[] = {
1339 MAP ("l", (int) BFD_RELOC_LO16
),
1340 MAP ("h", (int) BFD_RELOC_HI16
),
1341 MAP ("ha", (int) BFD_RELOC_HI16_S
),
1342 MAP ("brtaken", (int) BFD_RELOC_PPC_B16_BRTAKEN
),
1343 MAP ("brntaken", (int) BFD_RELOC_PPC_B16_BRNTAKEN
),
1344 MAP ("got", (int) BFD_RELOC_16_GOTOFF
),
1345 MAP ("got@l", (int) BFD_RELOC_LO16_GOTOFF
),
1346 MAP ("got@h", (int) BFD_RELOC_HI16_GOTOFF
),
1347 MAP ("got@ha", (int) BFD_RELOC_HI16_S_GOTOFF
),
1348 MAP ("fixup", (int) BFD_RELOC_CTOR
), /* warning with -mrelocatable */
1349 MAP ("plt", (int) BFD_RELOC_24_PLT_PCREL
),
1350 MAP ("pltrel24", (int) BFD_RELOC_24_PLT_PCREL
),
1351 MAP ("copy", (int) BFD_RELOC_PPC_COPY
),
1352 MAP ("globdat", (int) BFD_RELOC_PPC_GLOB_DAT
),
1353 MAP ("local24pc", (int) BFD_RELOC_PPC_LOCAL24PC
),
1354 MAP ("local", (int) BFD_RELOC_PPC_LOCAL24PC
),
1355 MAP ("pltrel", (int) BFD_RELOC_32_PLT_PCREL
),
1356 MAP ("plt@l", (int) BFD_RELOC_LO16_PLTOFF
),
1357 MAP ("plt@h", (int) BFD_RELOC_HI16_PLTOFF
),
1358 MAP ("plt@ha", (int) BFD_RELOC_HI16_S_PLTOFF
),
1359 MAP ("sdarel", (int) BFD_RELOC_GPREL16
),
1360 MAP ("sectoff", (int) BFD_RELOC_32_BASEREL
),
1361 MAP ("sectoff@l", (int) BFD_RELOC_LO16_BASEREL
),
1362 MAP ("sectoff@h", (int) BFD_RELOC_HI16_BASEREL
),
1363 MAP ("sectoff@ha", (int) BFD_RELOC_HI16_S_BASEREL
),
1364 MAP ("naddr", (int) BFD_RELOC_PPC_EMB_NADDR32
),
1365 MAP ("naddr16", (int) BFD_RELOC_PPC_EMB_NADDR16
),
1366 MAP ("naddr@l", (int) BFD_RELOC_PPC_EMB_NADDR16_LO
),
1367 MAP ("naddr@h", (int) BFD_RELOC_PPC_EMB_NADDR16_HI
),
1368 MAP ("naddr@ha", (int) BFD_RELOC_PPC_EMB_NADDR16_HA
),
1369 MAP ("sdai16", (int) BFD_RELOC_PPC_EMB_SDAI16
),
1370 MAP ("sda2rel", (int) BFD_RELOC_PPC_EMB_SDA2REL
),
1371 MAP ("sda2i16", (int) BFD_RELOC_PPC_EMB_SDA2I16
),
1372 MAP ("sda21", (int) BFD_RELOC_PPC_EMB_SDA21
),
1373 MAP ("mrkref", (int) BFD_RELOC_PPC_EMB_MRKREF
),
1374 MAP ("relsect", (int) BFD_RELOC_PPC_EMB_RELSEC16
),
1375 MAP ("relsect@l", (int) BFD_RELOC_PPC_EMB_RELST_LO
),
1376 MAP ("relsect@h", (int) BFD_RELOC_PPC_EMB_RELST_HI
),
1377 MAP ("relsect@ha", (int) BFD_RELOC_PPC_EMB_RELST_HA
),
1378 MAP ("bitfld", (int) BFD_RELOC_PPC_EMB_BIT_FLD
),
1379 MAP ("relsda", (int) BFD_RELOC_PPC_EMB_RELSDA
),
1380 MAP ("xgot", (int) BFD_RELOC_PPC_TOC16
),
1381 #if BFD_DEFAULT_TARGET_SIZE == 64
1382 MAP ("higher", - (int) BFD_RELOC_PPC64_HIGHER
),
1383 MAP ("highera", - (int) BFD_RELOC_PPC64_HIGHER_S
),
1384 MAP ("highest", - (int) BFD_RELOC_PPC64_HIGHEST
),
1385 MAP ("highesta", - (int) BFD_RELOC_PPC64_HIGHEST_S
),
1386 MAP ("tocbase", - (int) BFD_RELOC_PPC64_TOC
),
1387 MAP ("toc", - (int) BFD_RELOC_PPC_TOC16
),
1388 MAP ("toc@l", - (int) BFD_RELOC_PPC64_TOC16_LO
),
1389 MAP ("toc@h", - (int) BFD_RELOC_PPC64_TOC16_HI
),
1390 MAP ("toc@ha", - (int) BFD_RELOC_PPC64_TOC16_HA
),
1392 { (char *) 0, 0, (int) BFD_RELOC_UNUSED
}
1396 return BFD_RELOC_UNUSED
;
1398 for (ch
= *str
, str2
= ident
;
1399 (str2
< ident
+ sizeof (ident
) - 1
1400 && (ISALNUM (ch
) || ch
== '@'));
1403 *str2
++ = TOLOWER (ch
);
1410 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1411 if (ch
== ptr
->string
[0]
1412 && len
== ptr
->length
1413 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1415 int reloc
= ptr
->reloc
;
1417 if (BFD_DEFAULT_TARGET_SIZE
== 64 && reloc
< 0)
1419 if (ppc_size
!= PPC_OPCODE_64
)
1420 return BFD_RELOC_UNUSED
;
1424 if (exp_p
->X_add_number
!= 0
1425 && (reloc
== (int) BFD_RELOC_16_GOTOFF
1426 || reloc
== (int) BFD_RELOC_LO16_GOTOFF
1427 || reloc
== (int) BFD_RELOC_HI16_GOTOFF
1428 || reloc
== (int) BFD_RELOC_HI16_S_GOTOFF
))
1429 as_warn (_("identifier+constant@got means identifier@got+constant"));
1431 /* Now check for identifier@suffix+constant. */
1432 if (*str
== '-' || *str
== '+')
1434 char *orig_line
= input_line_pointer
;
1435 expressionS new_exp
;
1437 input_line_pointer
= str
;
1438 expression (&new_exp
);
1439 if (new_exp
.X_op
== O_constant
)
1441 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1442 str
= input_line_pointer
;
1445 if (&input_line_pointer
!= str_p
)
1446 input_line_pointer
= orig_line
;
1450 if (BFD_DEFAULT_TARGET_SIZE
== 64
1451 && reloc
== (int) BFD_RELOC_PPC64_TOC
1452 && exp_p
->X_op
== O_symbol
)
1454 /* This reloc type ignores the symbol. Change the symbol
1455 so that the dummy .TOC. symbol can be omitted from the
1457 exp_p
->X_add_symbol
= &abs_symbol
;
1460 return (bfd_reloc_code_real_type
) reloc
;
1463 return BFD_RELOC_UNUSED
;
1466 /* Like normal .long/.short/.word, except support @got, etc.
1467 Clobbers input_line_pointer, checks end-of-line. */
1469 ppc_elf_cons (nbytes
)
1470 register int nbytes
; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1473 bfd_reloc_code_real_type reloc
;
1475 if (is_it_end_of_statement ())
1477 demand_empty_rest_of_line ();
1484 if (exp
.X_op
== O_symbol
1485 && *input_line_pointer
== '@'
1486 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1487 &exp
)) != BFD_RELOC_UNUSED
)
1489 reloc_howto_type
*reloc_howto
;
1492 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1493 size
= bfd_get_reloc_size (reloc_howto
);
1497 as_bad (_("%s relocations do not fit in %d bytes\n"),
1498 reloc_howto
->name
, nbytes
);
1505 p
= frag_more (nbytes
);
1507 if (target_big_endian
)
1508 offset
= nbytes
- size
;
1509 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1514 emit_expr (&exp
, (unsigned int) nbytes
);
1516 while (*input_line_pointer
++ == ',');
1518 /* Put terminator back into stream. */
1519 input_line_pointer
--;
1520 demand_empty_rest_of_line ();
1523 /* Solaris pseduo op to change to the .rodata section. */
1528 char *save_line
= input_line_pointer
;
1529 static char section
[] = ".rodata\n";
1531 /* Just pretend this is .section .rodata */
1532 input_line_pointer
= section
;
1533 obj_elf_section (xxx
);
1535 input_line_pointer
= save_line
;
1538 /* Pseudo op to make file scope bss items. */
1541 int xxx ATTRIBUTE_UNUSED
;
1543 register char *name
;
1547 register symbolS
*symbolP
;
1554 name
= input_line_pointer
;
1555 c
= get_symbol_end ();
1557 /* just after name is now '\0'. */
1558 p
= input_line_pointer
;
1561 if (*input_line_pointer
!= ',')
1563 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1564 ignore_rest_of_line ();
1568 input_line_pointer
++; /* skip ',' */
1569 if ((size
= get_absolute_expression ()) < 0)
1571 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1572 ignore_rest_of_line ();
1576 /* The third argument to .lcomm is the alignment. */
1577 if (*input_line_pointer
!= ',')
1581 ++input_line_pointer
;
1582 align
= get_absolute_expression ();
1585 as_warn (_("ignoring bad alignment"));
1591 symbolP
= symbol_find_or_make (name
);
1594 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1596 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1597 S_GET_NAME (symbolP
));
1598 ignore_rest_of_line ();
1602 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1604 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1605 S_GET_NAME (symbolP
),
1606 (long) S_GET_VALUE (symbolP
),
1609 ignore_rest_of_line ();
1615 old_subsec
= now_subseg
;
1618 /* Convert to a power of 2 alignment. */
1619 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1622 as_bad (_("Common alignment not a power of 2"));
1623 ignore_rest_of_line ();
1630 record_alignment (bss_section
, align2
);
1631 subseg_set (bss_section
, 0);
1633 frag_align (align2
, 0, 0);
1634 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1635 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1636 symbol_set_frag (symbolP
, frag_now
);
1637 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1640 S_SET_SIZE (symbolP
, size
);
1641 S_SET_SEGMENT (symbolP
, bss_section
);
1642 subseg_set (old_sec
, old_subsec
);
1643 demand_empty_rest_of_line ();
1646 /* Validate any relocations emitted for -mrelocatable, possibly adding
1647 fixups for word relocations in writable segments, so we can adjust
1650 ppc_elf_validate_fix (fixp
, seg
)
1654 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1663 case SHLIB_MRELOCATABLE
:
1664 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1665 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1666 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1667 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1668 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1669 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1670 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1671 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1672 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1673 && (seg
->flags
& SEC_LOAD
) != 0
1674 && strcmp (segment_name (seg
), ".got2") != 0
1675 && strcmp (segment_name (seg
), ".dtors") != 0
1676 && strcmp (segment_name (seg
), ".ctors") != 0
1677 && strcmp (segment_name (seg
), ".fixup") != 0
1678 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1679 && strcmp (segment_name (seg
), ".eh_frame") != 0
1680 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1682 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1683 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1685 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1686 _("Relocation cannot be done when using -mrelocatable"));
1693 #if BFD_DEFAULT_TARGET_SIZE == 64
1694 /* Don't emit .TOC. symbol. */
1696 ppc_elf_frob_symbol (sym
)
1701 name
= S_GET_NAME (sym
);
1702 if (name
!= NULL
&& strcmp (name
, ".TOC.") == 0)
1704 S_CLEAR_EXTERNAL (sym
);
1711 #endif /* OBJ_ELF */
1716 * Summary of parse_toc_entry.
1718 * in: Input_line_pointer points to the '[' in one of:
1720 * [toc] [tocv] [toc32] [toc64]
1722 * Anything else is an error of one kind or another.
1725 * return value: success or failure
1726 * toc_kind: kind of toc reference
1727 * input_line_pointer:
1728 * success: first char after the ']'
1729 * failure: unchanged
1733 * [toc] - rv == success, toc_kind = default_toc
1734 * [tocv] - rv == success, toc_kind = data_in_toc
1735 * [toc32] - rv == success, toc_kind = must_be_32
1736 * [toc64] - rv == success, toc_kind = must_be_64
1740 enum toc_size_qualifier
1742 default_toc
, /* The toc cell constructed should be the system default size */
1743 data_in_toc
, /* This is a direct reference to a toc cell */
1744 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1745 must_be_64
/* The toc cell constructed must be 64 bits wide */
1749 parse_toc_entry (toc_kind
)
1750 enum toc_size_qualifier
*toc_kind
;
1755 enum toc_size_qualifier t
;
1757 /* Save the input_line_pointer. */
1758 start
= input_line_pointer
;
1760 /* Skip over the '[' , and whitespace. */
1761 ++input_line_pointer
;
1764 /* Find the spelling of the operand. */
1765 toc_spec
= input_line_pointer
;
1766 c
= get_symbol_end ();
1768 if (strcmp (toc_spec
, "toc") == 0)
1772 else if (strcmp (toc_spec
, "tocv") == 0)
1776 else if (strcmp (toc_spec
, "toc32") == 0)
1780 else if (strcmp (toc_spec
, "toc64") == 0)
1786 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1787 *input_line_pointer
= c
;
1788 input_line_pointer
= start
;
1792 /* Now find the ']'. */
1793 *input_line_pointer
= c
;
1795 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1796 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1800 as_bad (_("syntax error: expected `]', found `%c'"), c
);
1801 input_line_pointer
= start
;
1811 /* We need to keep a list of fixups. We can't simply generate them as
1812 we go, because that would require us to first create the frag, and
1813 that would screw up references to ``.''. */
1819 bfd_reloc_code_real_type reloc
;
1822 #define MAX_INSN_FIXUPS (5)
1824 /* This routine is called for each instruction to be assembled. */
1831 const struct powerpc_opcode
*opcode
;
1833 const unsigned char *opindex_ptr
;
1837 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1842 bfd_reloc_code_real_type reloc
;
1845 /* Get the opcode. */
1846 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1851 /* Look up the opcode in the hash table. */
1852 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1853 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1855 const struct powerpc_macro
*macro
;
1857 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1858 if (macro
== (const struct powerpc_macro
*) NULL
)
1859 as_bad (_("Unrecognized opcode: `%s'"), str
);
1861 ppc_macro (s
, macro
);
1866 insn
= opcode
->opcode
;
1869 while (ISSPACE (*str
))
1872 /* PowerPC operands are just expressions. The only real issue is
1873 that a few operand types are optional. All cases which might use
1874 an optional operand separate the operands only with commas (in
1875 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1876 cases never have optional operands). There is never more than
1877 one optional operand for an instruction. So, before we start
1878 seriously parsing the operands, we check to see if we have an
1879 optional operand, and, if we do, we count the number of commas to
1880 see whether the operand should be omitted. */
1882 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1884 const struct powerpc_operand
*operand
;
1886 operand
= &powerpc_operands
[*opindex_ptr
];
1887 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1889 unsigned int opcount
;
1891 /* There is an optional operand. Count the number of
1892 commas in the input line. */
1899 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1906 /* If there are fewer operands in the line then are called
1907 for by the instruction, we want to skip the optional
1909 if (opcount
< strlen (opcode
->operands
))
1916 /* Gather the operands. */
1920 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1922 const struct powerpc_operand
*operand
;
1928 if (next_opindex
== 0)
1929 operand
= &powerpc_operands
[*opindex_ptr
];
1932 operand
= &powerpc_operands
[next_opindex
];
1938 /* If this is a fake operand, then we do not expect anything
1940 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1942 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1943 if (errmsg
!= (const char *) NULL
)
1948 /* If this is an optional operand, and we are skipping it, just
1950 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1953 if (operand
->insert
)
1955 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1956 if (errmsg
!= (const char *) NULL
)
1959 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1960 next_opindex
= *opindex_ptr
+ 1;
1964 /* Gather the operand. */
1965 hold
= input_line_pointer
;
1966 input_line_pointer
= str
;
1969 if (*input_line_pointer
== '[')
1971 /* We are expecting something like the second argument here:
1973 * lwz r4,[toc].GS.0.static_int(rtoc)
1974 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1975 * The argument following the `]' must be a symbol name, and the
1976 * register must be the toc register: 'rtoc' or '2'
1978 * The effect is to 0 as the displacement field
1979 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1980 * the appropriate variation) reloc against it based on the symbol.
1981 * The linker will build the toc, and insert the resolved toc offset.
1984 * o The size of the toc entry is currently assumed to be
1985 * 32 bits. This should not be assumed to be a hard coded
1987 * o In an effort to cope with a change from 32 to 64 bits,
1988 * there are also toc entries that are specified to be
1989 * either 32 or 64 bits:
1990 * lwz r4,[toc32].GS.0.static_int(rtoc)
1991 * lwz r4,[toc64].GS.0.static_int(rtoc)
1992 * These demand toc entries of the specified size, and the
1993 * instruction probably requires it.
1997 enum toc_size_qualifier toc_kind
;
1998 bfd_reloc_code_real_type toc_reloc
;
2000 /* Go parse off the [tocXX] part. */
2001 valid_toc
= parse_toc_entry (&toc_kind
);
2005 /* Note: message has already been issued.
2006 FIXME: what sort of recovery should we do?
2007 demand_rest_of_line (); return; ? */
2010 /* Now get the symbol following the ']'. */
2016 /* In this case, we may not have seen the symbol yet,
2017 since it is allowed to appear on a .extern or .globl
2018 or just be a label in the .data section. */
2019 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2022 /* 1. The symbol must be defined and either in the toc
2023 section, or a global.
2024 2. The reloc generated must have the TOCDEFN flag set
2025 in upper bit mess of the reloc type.
2026 FIXME: It's a little confusing what the tocv
2027 qualifier can be used for. At the very least, I've
2028 seen three uses, only one of which I'm sure I can
2030 if (ex
.X_op
== O_symbol
)
2032 assert (ex
.X_add_symbol
!= NULL
);
2033 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2036 as_bad (_("[tocv] symbol is not a toc symbol"));
2040 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2043 /* FIXME: these next two specifically specify 32/64 bit
2044 toc entries. We don't support them today. Is this
2045 the right way to say that? */
2046 toc_reloc
= BFD_RELOC_UNUSED
;
2047 as_bad (_("Unimplemented toc32 expression modifier"));
2050 /* FIXME: see above. */
2051 toc_reloc
= BFD_RELOC_UNUSED
;
2052 as_bad (_("Unimplemented toc64 expression modifier"));
2056 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2062 /* We need to generate a fixup for this expression. */
2063 if (fc
>= MAX_INSN_FIXUPS
)
2064 as_fatal (_("too many fixups"));
2066 fixups
[fc
].reloc
= toc_reloc
;
2067 fixups
[fc
].exp
= ex
;
2068 fixups
[fc
].opindex
= *opindex_ptr
;
2071 /* Ok. We've set up the fixup for the instruction. Now make it
2072 look like the constant 0 was found here. */
2074 ex
.X_op
= O_constant
;
2075 ex
.X_add_number
= 0;
2076 ex
.X_add_symbol
= NULL
;
2077 ex
.X_op_symbol
= NULL
;
2083 if (! register_name (&ex
))
2085 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
2092 str
= input_line_pointer
;
2093 input_line_pointer
= hold
;
2095 if (ex
.X_op
== O_illegal
)
2096 as_bad (_("illegal operand"));
2097 else if (ex
.X_op
== O_absent
)
2098 as_bad (_("missing operand"));
2099 else if (ex
.X_op
== O_register
)
2101 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2104 else if (ex
.X_op
== O_constant
)
2107 /* Allow @HA, @L, @H on constants. */
2108 char *orig_str
= str
;
2110 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2117 case BFD_RELOC_LO16
:
2118 /* X_unsigned is the default, so if the user has done
2119 something which cleared it, we always produce a
2121 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2122 ex
.X_add_number
&= 0xffff;
2124 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2127 case BFD_RELOC_HI16
:
2128 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2129 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2131 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2134 case BFD_RELOC_HI16_S
:
2135 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2136 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2138 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2141 #if BFD_DEFAULT_TARGET_SIZE == 64
2142 case BFD_RELOC_PPC64_HIGHER
:
2143 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2144 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2146 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2149 case BFD_RELOC_PPC64_HIGHER_S
:
2150 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2151 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2153 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2156 case BFD_RELOC_PPC64_HIGHEST
:
2157 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2158 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2160 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2163 case BFD_RELOC_PPC64_HIGHEST_S
:
2164 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2165 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2167 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2169 #endif /* BFD_DEFAULT_TARGET_SIZE == 64 */
2171 #endif /* OBJ_ELF */
2172 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2176 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2178 /* For the absolute forms of branches, convert the PC
2179 relative form back into the absolute. */
2180 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2184 case BFD_RELOC_PPC_B26
:
2185 reloc
= BFD_RELOC_PPC_BA26
;
2187 case BFD_RELOC_PPC_B16
:
2188 reloc
= BFD_RELOC_PPC_BA16
;
2190 case BFD_RELOC_PPC_B16_BRTAKEN
:
2191 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2193 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2194 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2201 if (BFD_DEFAULT_TARGET_SIZE
== 64
2202 && ppc_size
== PPC_OPCODE_64
2203 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
2208 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
2210 case BFD_RELOC_LO16
:
2211 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
2213 case BFD_RELOC_16_GOTOFF
:
2214 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
2216 case BFD_RELOC_LO16_GOTOFF
:
2217 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
2219 case BFD_RELOC_LO16_PLTOFF
:
2220 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
2222 case BFD_RELOC_32_BASEREL
:
2223 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
2225 case BFD_RELOC_LO16_BASEREL
:
2226 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
2228 case BFD_RELOC_PPC_TOC16
:
2229 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
2231 case BFD_RELOC_PPC64_TOC16_LO
:
2232 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
2234 case BFD_RELOC_PPC64_PLTGOT16
:
2235 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
2237 case BFD_RELOC_PPC64_PLTGOT16_LO
:
2238 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
2241 as_bad (_("unsupported relocation for DS offset field"));
2246 /* We need to generate a fixup for this expression. */
2247 if (fc
>= MAX_INSN_FIXUPS
)
2248 as_fatal (_("too many fixups"));
2249 fixups
[fc
].exp
= ex
;
2250 fixups
[fc
].opindex
= 0;
2251 fixups
[fc
].reloc
= reloc
;
2254 #endif /* OBJ_ELF */
2258 /* We need to generate a fixup for this expression. */
2259 if (fc
>= MAX_INSN_FIXUPS
)
2260 as_fatal (_("too many fixups"));
2261 fixups
[fc
].exp
= ex
;
2262 fixups
[fc
].opindex
= *opindex_ptr
;
2263 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2272 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2280 /* The call to expression should have advanced str past any
2283 && (endc
!= ',' || *str
!= '\0'))
2285 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2293 while (ISSPACE (*str
))
2297 as_bad (_("junk at end of line: `%s'"), str
);
2299 /* Write out the instruction. */
2301 md_number_to_chars (f
, insn
, 4);
2304 dwarf2_emit_insn (4);
2307 /* Create any fixups. At this point we do not use a
2308 bfd_reloc_code_real_type, but instead just use the
2309 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2310 handle fixups for any operand type, although that is admittedly
2311 not a very exciting feature. We pick a BFD reloc type in
2313 for (i
= 0; i
< fc
; i
++)
2315 const struct powerpc_operand
*operand
;
2317 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2318 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2320 reloc_howto_type
*reloc_howto
;
2325 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2329 size
= bfd_get_reloc_size (reloc_howto
);
2330 offset
= target_big_endian
? (4 - size
) : 0;
2332 if (size
< 1 || size
> 4)
2335 fixP
= fix_new_exp (frag_now
,
2336 f
- frag_now
->fr_literal
+ offset
,
2339 reloc_howto
->pc_relative
,
2342 /* Turn off complaints that the addend is too large for things like
2344 switch (fixups
[i
].reloc
)
2346 case BFD_RELOC_16_GOTOFF
:
2347 case BFD_RELOC_PPC_TOC16
:
2348 case BFD_RELOC_LO16
:
2349 case BFD_RELOC_HI16
:
2350 case BFD_RELOC_HI16_S
:
2352 #if BFD_DEFAULT_TARGET_SIZE == 64
2353 case BFD_RELOC_PPC64_HIGHER
:
2354 case BFD_RELOC_PPC64_HIGHER_S
:
2355 case BFD_RELOC_PPC64_HIGHEST
:
2356 case BFD_RELOC_PPC64_HIGHEST_S
:
2359 fixP
->fx_no_overflow
= 1;
2366 fix_new_exp (frag_now
,
2367 f
- frag_now
->fr_literal
,
2370 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2371 ((bfd_reloc_code_real_type
)
2372 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2376 /* Handle a macro. Gather all the operands, transform them as
2377 described by the macro, and call md_assemble recursively. All the
2378 operands are separated by commas; we don't accept parentheses
2379 around operands here. */
2382 ppc_macro (str
, macro
)
2384 const struct powerpc_macro
*macro
;
2395 /* Gather the users operands into the operands array. */
2400 if (count
>= sizeof operands
/ sizeof operands
[0])
2402 operands
[count
++] = s
;
2403 s
= strchr (s
, ',');
2404 if (s
== (char *) NULL
)
2409 if (count
!= macro
->operands
)
2411 as_bad (_("wrong number of operands"));
2415 /* Work out how large the string must be (the size is unbounded
2416 because it includes user input). */
2418 format
= macro
->format
;
2419 while (*format
!= '\0')
2428 arg
= strtol (format
+ 1, &send
, 10);
2429 know (send
!= format
&& arg
>= 0 && arg
< count
);
2430 len
+= strlen (operands
[arg
]);
2435 /* Put the string together. */
2436 complete
= s
= (char *) alloca (len
+ 1);
2437 format
= macro
->format
;
2438 while (*format
!= '\0')
2444 arg
= strtol (format
+ 1, &send
, 10);
2445 strcpy (s
, operands
[arg
]);
2452 /* Assemble the constructed instruction. */
2453 md_assemble (complete
);
2457 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2460 ppc_section_letter (letter
, ptr_msg
)
2467 *ptr_msg
= _("Bad .section directive: want a,e,w,x,M,S in string");
2472 ppc_section_word (str
, len
)
2476 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2483 ppc_section_type (str
, len
)
2487 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2494 ppc_section_flags (flags
, attr
, type
)
2499 if (type
== SHT_ORDERED
)
2500 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2502 if (attr
& SHF_EXCLUDE
)
2503 flags
|= SEC_EXCLUDE
;
2507 #endif /* OBJ_ELF */
2510 /* Pseudo-op handling. */
2512 /* The .byte pseudo-op. This is similar to the normal .byte
2513 pseudo-op, but it can also take a single ASCII string. */
2517 int ignore ATTRIBUTE_UNUSED
;
2519 if (*input_line_pointer
!= '\"')
2525 /* Gather characters. A real double quote is doubled. Unusual
2526 characters are not permitted. */
2527 ++input_line_pointer
;
2532 c
= *input_line_pointer
++;
2536 if (*input_line_pointer
!= '\"')
2538 ++input_line_pointer
;
2541 FRAG_APPEND_1_CHAR (c
);
2544 demand_empty_rest_of_line ();
2549 /* XCOFF specific pseudo-op handling. */
2551 /* This is set if we are creating a .stabx symbol, since we don't want
2552 to handle symbol suffixes for such symbols. */
2553 static boolean ppc_stab_symbol
;
2555 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2556 symbols in the .bss segment as though they were local common
2557 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2558 aligns .comm and .lcomm to 4 bytes. */
2564 asection
*current_seg
= now_seg
;
2565 subsegT current_subseg
= now_subseg
;
2571 symbolS
*lcomm_sym
= NULL
;
2575 name
= input_line_pointer
;
2576 endc
= get_symbol_end ();
2577 end_name
= input_line_pointer
;
2580 if (*input_line_pointer
!= ',')
2582 as_bad (_("missing size"));
2583 ignore_rest_of_line ();
2586 ++input_line_pointer
;
2588 size
= get_absolute_expression ();
2591 as_bad (_("negative size"));
2592 ignore_rest_of_line ();
2598 /* The third argument to .comm is the alignment. */
2599 if (*input_line_pointer
!= ',')
2603 ++input_line_pointer
;
2604 align
= get_absolute_expression ();
2607 as_warn (_("ignoring bad alignment"));
2622 /* The third argument to .lcomm appears to be the real local
2623 common symbol to create. References to the symbol named in
2624 the first argument are turned into references to the third
2626 if (*input_line_pointer
!= ',')
2628 as_bad (_("missing real symbol name"));
2629 ignore_rest_of_line ();
2632 ++input_line_pointer
;
2634 lcomm_name
= input_line_pointer
;
2635 lcomm_endc
= get_symbol_end ();
2637 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2639 *input_line_pointer
= lcomm_endc
;
2643 sym
= symbol_find_or_make (name
);
2646 if (S_IS_DEFINED (sym
)
2647 || S_GET_VALUE (sym
) != 0)
2649 as_bad (_("attempt to redefine symbol"));
2650 ignore_rest_of_line ();
2654 record_alignment (bss_section
, align
);
2657 || ! S_IS_DEFINED (lcomm_sym
))
2666 S_SET_EXTERNAL (sym
);
2670 symbol_get_tc (lcomm_sym
)->output
= 1;
2671 def_sym
= lcomm_sym
;
2675 subseg_set (bss_section
, 1);
2676 frag_align (align
, 0, 0);
2678 symbol_set_frag (def_sym
, frag_now
);
2679 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2680 def_size
, (char *) NULL
);
2682 S_SET_SEGMENT (def_sym
, bss_section
);
2683 symbol_get_tc (def_sym
)->align
= align
;
2687 /* Align the size of lcomm_sym. */
2688 symbol_get_frag (lcomm_sym
)->fr_offset
=
2689 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
2690 &~ ((1 << align
) - 1));
2691 if (align
> symbol_get_tc (lcomm_sym
)->align
)
2692 symbol_get_tc (lcomm_sym
)->align
= align
;
2697 /* Make sym an offset from lcomm_sym. */
2698 S_SET_SEGMENT (sym
, bss_section
);
2699 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
2700 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
2701 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
2704 subseg_set (current_seg
, current_subseg
);
2706 demand_empty_rest_of_line ();
2709 /* The .csect pseudo-op. This switches us into a different
2710 subsegment. The first argument is a symbol whose value is the
2711 start of the .csect. In COFF, csect symbols get special aux
2712 entries defined by the x_csect field of union internal_auxent. The
2713 optional second argument is the alignment (the default is 2). */
2717 int ignore ATTRIBUTE_UNUSED
;
2723 name
= input_line_pointer
;
2724 endc
= get_symbol_end ();
2726 sym
= symbol_find_or_make (name
);
2728 *input_line_pointer
= endc
;
2730 if (S_GET_NAME (sym
)[0] == '\0')
2732 /* An unnamed csect is assumed to be [PR]. */
2733 symbol_get_tc (sym
)->class = XMC_PR
;
2736 ppc_change_csect (sym
);
2738 if (*input_line_pointer
== ',')
2740 ++input_line_pointer
;
2741 symbol_get_tc (sym
)->align
= get_absolute_expression ();
2744 demand_empty_rest_of_line ();
2747 /* Change to a different csect. */
2750 ppc_change_csect (sym
)
2753 if (S_IS_DEFINED (sym
))
2754 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
2762 /* This is a new csect. We need to look at the symbol class to
2763 figure out whether it should go in the text section or the
2766 switch (symbol_get_tc (sym
)->class)
2776 S_SET_SEGMENT (sym
, text_section
);
2777 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
2778 ++ppc_text_subsegment
;
2779 list_ptr
= &ppc_text_csects
;
2788 if (ppc_toc_csect
!= NULL
2789 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
2790 == ppc_data_subsegment
))
2792 S_SET_SEGMENT (sym
, data_section
);
2793 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
2794 ++ppc_data_subsegment
;
2795 list_ptr
= &ppc_data_csects
;
2801 /* We set the obstack chunk size to a small value before
2802 changing subsegments, so that we don't use a lot of memory
2803 space for what may be a small section. */
2804 hold_chunksize
= chunksize
;
2807 subseg_new (segment_name (S_GET_SEGMENT (sym
)),
2808 symbol_get_tc (sym
)->subseg
);
2810 chunksize
= hold_chunksize
;
2813 ppc_after_toc_frag
= frag_now
;
2815 symbol_set_frag (sym
, frag_now
);
2816 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2818 symbol_get_tc (sym
)->align
= (ppc_xcoff64
) ? 3 : 2;
2819 symbol_get_tc (sym
)->output
= 1;
2820 symbol_get_tc (sym
)->within
= sym
;
2822 for (list
= *list_ptr
;
2823 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
2824 list
= symbol_get_tc (list
)->next
)
2826 symbol_get_tc (list
)->next
= sym
;
2828 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2829 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
2833 ppc_current_csect
= sym
;
2836 /* This function handles the .text and .data pseudo-ops. These
2837 pseudo-ops aren't really used by XCOFF; we implement them for the
2838 convenience of people who aren't used to XCOFF. */
2849 else if (type
== 'd')
2854 sym
= symbol_find_or_make (name
);
2856 ppc_change_csect (sym
);
2858 demand_empty_rest_of_line ();
2861 /* This function handles the .section pseudo-op. This is mostly to
2862 give an error, since XCOFF only supports .text, .data and .bss, but
2863 we do permit the user to name the text or data section. */
2866 ppc_named_section (ignore
)
2867 int ignore ATTRIBUTE_UNUSED
;
2870 const char *real_name
;
2874 user_name
= input_line_pointer
;
2875 c
= get_symbol_end ();
2877 if (strcmp (user_name
, ".text") == 0)
2878 real_name
= ".text[PR]";
2879 else if (strcmp (user_name
, ".data") == 0)
2880 real_name
= ".data[RW]";
2883 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2884 *input_line_pointer
= c
;
2885 ignore_rest_of_line ();
2889 *input_line_pointer
= c
;
2891 sym
= symbol_find_or_make (real_name
);
2893 ppc_change_csect (sym
);
2895 demand_empty_rest_of_line ();
2898 /* The .extern pseudo-op. We create an undefined symbol. */
2902 int ignore ATTRIBUTE_UNUSED
;
2907 name
= input_line_pointer
;
2908 endc
= get_symbol_end ();
2910 (void) symbol_find_or_make (name
);
2912 *input_line_pointer
= endc
;
2914 demand_empty_rest_of_line ();
2917 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2921 int ignore ATTRIBUTE_UNUSED
;
2927 name
= input_line_pointer
;
2928 endc
= get_symbol_end ();
2930 sym
= symbol_find_or_make (name
);
2932 *input_line_pointer
= endc
;
2934 symbol_get_tc (sym
)->output
= 1;
2936 demand_empty_rest_of_line ();
2939 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2940 although I don't know why it bothers. */
2944 int ignore ATTRIBUTE_UNUSED
;
2951 name
= input_line_pointer
;
2952 endc
= get_symbol_end ();
2954 sym
= symbol_find_or_make (name
);
2956 *input_line_pointer
= endc
;
2958 if (*input_line_pointer
!= ',')
2960 as_bad (_("missing rename string"));
2961 ignore_rest_of_line ();
2964 ++input_line_pointer
;
2966 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
2968 demand_empty_rest_of_line ();
2971 /* The .stabx pseudo-op. This is similar to a normal .stabs
2972 pseudo-op, but slightly different. A sample is
2973 .stabx "main:F-1",.main,142,0
2974 The first argument is the symbol name to create. The second is the
2975 value, and the third is the storage class. The fourth seems to be
2976 always zero, and I am assuming it is the type. */
2980 int ignore ATTRIBUTE_UNUSED
;
2987 name
= demand_copy_C_string (&len
);
2989 if (*input_line_pointer
!= ',')
2991 as_bad (_("missing value"));
2994 ++input_line_pointer
;
2996 ppc_stab_symbol
= true;
2997 sym
= symbol_make (name
);
2998 ppc_stab_symbol
= false;
3000 symbol_get_tc (sym
)->real_name
= name
;
3002 (void) expression (&exp
);
3009 as_bad (_("illegal .stabx expression; zero assumed"));
3010 exp
.X_add_number
= 0;
3013 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
3014 symbol_set_frag (sym
, &zero_address_frag
);
3018 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
3019 symbol_set_value_expression (sym
, &exp
);
3023 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
3024 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
3029 /* The value is some complex expression. This will probably
3030 fail at some later point, but this is probably the right
3031 thing to do here. */
3032 symbol_set_value_expression (sym
, &exp
);
3036 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3037 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3039 if (*input_line_pointer
!= ',')
3041 as_bad (_("missing class"));
3044 ++input_line_pointer
;
3046 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
3048 if (*input_line_pointer
!= ',')
3050 as_bad (_("missing type"));
3053 ++input_line_pointer
;
3055 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
3057 symbol_get_tc (sym
)->output
= 1;
3059 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
3061 symbol_get_tc (sym
)->within
= ppc_current_block
;
3066 .stabx "z",arrays_,133,0
3069 .comm arrays_,13768,3
3071 resolve_symbol_value will copy the exp's "within" into sym's when the
3072 offset is 0. Since this seems to be corner case problem,
3073 only do the correction for storage class C_STSYM. A better solution
3074 would be to have the tc field updated in ppc_symbol_new_hook. */
3076 if (exp
.X_op
== O_symbol
)
3078 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
3082 if (exp
.X_op
!= O_symbol
3083 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
3084 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
3085 ppc_frob_label (sym
);
3088 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3089 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
3090 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
3091 symbol_get_tc (ppc_current_csect
)->within
= sym
;
3094 demand_empty_rest_of_line ();
3097 /* The .function pseudo-op. This takes several arguments. The first
3098 argument seems to be the external name of the symbol. The second
3099 argment seems to be the label for the start of the function. gcc
3100 uses the same name for both. I have no idea what the third and
3101 fourth arguments are meant to be. The optional fifth argument is
3102 an expression for the size of the function. In COFF this symbol
3103 gets an aux entry like that used for a csect. */
3106 ppc_function (ignore
)
3107 int ignore ATTRIBUTE_UNUSED
;
3115 name
= input_line_pointer
;
3116 endc
= get_symbol_end ();
3118 /* Ignore any [PR] suffix. */
3119 name
= ppc_canonicalize_symbol_name (name
);
3120 s
= strchr (name
, '[');
3121 if (s
!= (char *) NULL
3122 && strcmp (s
+ 1, "PR]") == 0)
3125 ext_sym
= symbol_find_or_make (name
);
3127 *input_line_pointer
= endc
;
3129 if (*input_line_pointer
!= ',')
3131 as_bad (_("missing symbol name"));
3132 ignore_rest_of_line ();
3135 ++input_line_pointer
;
3137 name
= input_line_pointer
;
3138 endc
= get_symbol_end ();
3140 lab_sym
= symbol_find_or_make (name
);
3142 *input_line_pointer
= endc
;
3144 if (ext_sym
!= lab_sym
)
3148 exp
.X_op
= O_symbol
;
3149 exp
.X_add_symbol
= lab_sym
;
3150 exp
.X_op_symbol
= NULL
;
3151 exp
.X_add_number
= 0;
3153 symbol_set_value_expression (ext_sym
, &exp
);
3156 if (symbol_get_tc (ext_sym
)->class == -1)
3157 symbol_get_tc (ext_sym
)->class = XMC_PR
;
3158 symbol_get_tc (ext_sym
)->output
= 1;
3160 if (*input_line_pointer
== ',')
3164 /* Ignore the third argument. */
3165 ++input_line_pointer
;
3166 expression (&ignore
);
3167 if (*input_line_pointer
== ',')
3169 /* Ignore the fourth argument. */
3170 ++input_line_pointer
;
3171 expression (&ignore
);
3172 if (*input_line_pointer
== ',')
3174 /* The fifth argument is the function size. */
3175 ++input_line_pointer
;
3176 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
3179 &zero_address_frag
);
3180 pseudo_set (symbol_get_tc (ext_sym
)->size
);
3185 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3186 SF_SET_FUNCTION (ext_sym
);
3187 SF_SET_PROCESS (ext_sym
);
3188 coff_add_linesym (ext_sym
);
3190 demand_empty_rest_of_line ();
3193 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3194 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3195 with the correct line number */
3197 static symbolS
*saved_bi_sym
= 0;
3201 int ignore ATTRIBUTE_UNUSED
;
3205 sym
= symbol_make (".bf");
3206 S_SET_SEGMENT (sym
, text_section
);
3207 symbol_set_frag (sym
, frag_now
);
3208 S_SET_VALUE (sym
, frag_now_fix ());
3209 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3211 coff_line_base
= get_absolute_expression ();
3213 S_SET_NUMBER_AUXILIARY (sym
, 1);
3214 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3216 /* Line number for bi. */
3219 S_SET_VALUE (saved_bi_sym
, coff_n_line_nos
);
3224 symbol_get_tc (sym
)->output
= 1;
3226 ppc_frob_label (sym
);
3228 demand_empty_rest_of_line ();
3231 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3232 ".ef", except that the line number is absolute, not relative to the
3233 most recent ".bf" symbol. */
3237 int ignore ATTRIBUTE_UNUSED
;
3241 sym
= symbol_make (".ef");
3242 S_SET_SEGMENT (sym
, text_section
);
3243 symbol_set_frag (sym
, frag_now
);
3244 S_SET_VALUE (sym
, frag_now_fix ());
3245 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3246 S_SET_NUMBER_AUXILIARY (sym
, 1);
3247 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3248 symbol_get_tc (sym
)->output
= 1;
3250 ppc_frob_label (sym
);
3252 demand_empty_rest_of_line ();
3255 /* The .bi and .ei pseudo-ops. These take a string argument and
3256 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3257 the symbol list. The value of .bi will be know when the next .bf
3264 static symbolS
*last_biei
;
3271 name
= demand_copy_C_string (&len
);
3273 /* The value of these symbols is actually file offset. Here we set
3274 the value to the index into the line number entries. In
3275 ppc_frob_symbols we set the fix_line field, which will cause BFD
3276 to do the right thing. */
3278 sym
= symbol_make (name
);
3279 /* obj-coff.c currently only handles line numbers correctly in the
3281 S_SET_SEGMENT (sym
, text_section
);
3282 S_SET_VALUE (sym
, coff_n_line_nos
);
3283 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3285 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3286 symbol_get_tc (sym
)->output
= 1;
3294 for (look
= last_biei
? last_biei
: symbol_rootP
;
3295 (look
!= (symbolS
*) NULL
3296 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3297 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3298 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3299 look
= symbol_next (look
))
3301 if (look
!= (symbolS
*) NULL
)
3303 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3304 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3308 demand_empty_rest_of_line ();
3311 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3312 There is one argument, which is a csect symbol. The value of the
3313 .bs symbol is the index of this csect symbol. */
3317 int ignore ATTRIBUTE_UNUSED
;
3324 if (ppc_current_block
!= NULL
)
3325 as_bad (_("nested .bs blocks"));
3327 name
= input_line_pointer
;
3328 endc
= get_symbol_end ();
3330 csect
= symbol_find_or_make (name
);
3332 *input_line_pointer
= endc
;
3334 sym
= symbol_make (".bs");
3335 S_SET_SEGMENT (sym
, now_seg
);
3336 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3337 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3338 symbol_get_tc (sym
)->output
= 1;
3340 symbol_get_tc (sym
)->within
= csect
;
3342 ppc_frob_label (sym
);
3344 ppc_current_block
= sym
;
3346 demand_empty_rest_of_line ();
3349 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3353 int ignore ATTRIBUTE_UNUSED
;
3357 if (ppc_current_block
== NULL
)
3358 as_bad (_(".es without preceding .bs"));
3360 sym
= symbol_make (".es");
3361 S_SET_SEGMENT (sym
, now_seg
);
3362 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3363 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3364 symbol_get_tc (sym
)->output
= 1;
3366 ppc_frob_label (sym
);
3368 ppc_current_block
= NULL
;
3370 demand_empty_rest_of_line ();
3373 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3378 int ignore ATTRIBUTE_UNUSED
;
3382 sym
= symbol_make (".bb");
3383 S_SET_SEGMENT (sym
, text_section
);
3384 symbol_set_frag (sym
, frag_now
);
3385 S_SET_VALUE (sym
, frag_now_fix ());
3386 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3388 S_SET_NUMBER_AUXILIARY (sym
, 1);
3389 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3391 symbol_get_tc (sym
)->output
= 1;
3393 SF_SET_PROCESS (sym
);
3395 ppc_frob_label (sym
);
3397 demand_empty_rest_of_line ();
3400 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3405 int ignore ATTRIBUTE_UNUSED
;
3409 sym
= symbol_make (".eb");
3410 S_SET_SEGMENT (sym
, text_section
);
3411 symbol_set_frag (sym
, frag_now
);
3412 S_SET_VALUE (sym
, frag_now_fix ());
3413 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3414 S_SET_NUMBER_AUXILIARY (sym
, 1);
3415 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3416 symbol_get_tc (sym
)->output
= 1;
3418 SF_SET_PROCESS (sym
);
3420 ppc_frob_label (sym
);
3422 demand_empty_rest_of_line ();
3425 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3430 int ignore ATTRIBUTE_UNUSED
;
3436 name
= demand_copy_C_string (&len
);
3437 sym
= symbol_make (name
);
3438 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3439 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3440 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3441 S_SET_VALUE (sym
, 0);
3442 symbol_get_tc (sym
)->output
= 1;
3444 ppc_frob_label (sym
);
3446 demand_empty_rest_of_line ();
3449 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3453 int ignore ATTRIBUTE_UNUSED
;
3457 sym
= symbol_make (".ec");
3458 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3459 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3460 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3461 S_SET_VALUE (sym
, 0);
3462 symbol_get_tc (sym
)->output
= 1;
3464 ppc_frob_label (sym
);
3466 demand_empty_rest_of_line ();
3469 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3473 int ignore ATTRIBUTE_UNUSED
;
3475 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3476 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3483 subseg
= ppc_data_subsegment
;
3484 ++ppc_data_subsegment
;
3486 subseg_new (segment_name (data_section
), subseg
);
3487 ppc_toc_frag
= frag_now
;
3489 sym
= symbol_find_or_make ("TOC[TC0]");
3490 symbol_set_frag (sym
, frag_now
);
3491 S_SET_SEGMENT (sym
, data_section
);
3492 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3493 symbol_get_tc (sym
)->subseg
= subseg
;
3494 symbol_get_tc (sym
)->output
= 1;
3495 symbol_get_tc (sym
)->within
= sym
;
3497 ppc_toc_csect
= sym
;
3499 for (list
= ppc_data_csects
;
3500 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3501 list
= symbol_get_tc (list
)->next
)
3503 symbol_get_tc (list
)->next
= sym
;
3505 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3506 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3510 ppc_current_csect
= ppc_toc_csect
;
3512 demand_empty_rest_of_line ();
3515 /* The AIX assembler automatically aligns the operands of a .long or
3516 .short pseudo-op, and we want to be compatible. */
3519 ppc_xcoff_cons (log_size
)
3522 frag_align (log_size
, 0, 0);
3523 record_alignment (now_seg
, log_size
);
3524 cons (1 << log_size
);
3529 int dummy ATTRIBUTE_UNUSED
;
3534 (void) expression (&exp
);
3536 if (exp
.X_op
!= O_constant
)
3538 as_bad (_("non-constant byte count"));
3542 byte_count
= exp
.X_add_number
;
3544 if (*input_line_pointer
!= ',')
3546 as_bad (_("missing value"));
3550 ++input_line_pointer
;
3554 #endif /* OBJ_XCOFF */
3555 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3557 /* The .tc pseudo-op. This is used when generating either XCOFF or
3558 ELF. This takes two or more arguments.
3560 When generating XCOFF output, the first argument is the name to
3561 give to this location in the toc; this will be a symbol with class
3562 TC. The rest of the arguments are N-byte values to actually put at
3563 this location in the TOC; often there is just one more argument, a
3564 relocateable symbol reference. The size of the value to store
3565 depends on target word size. A 32-bit target uses 4-byte values, a
3566 64-bit target uses 8-byte values.
3568 When not generating XCOFF output, the arguments are the same, but
3569 the first argument is simply ignored. */
3573 int ignore ATTRIBUTE_UNUSED
;
3577 /* Define the TOC symbol name. */
3583 if (ppc_toc_csect
== (symbolS
*) NULL
3584 || ppc_toc_csect
!= ppc_current_csect
)
3586 as_bad (_(".tc not in .toc section"));
3587 ignore_rest_of_line ();
3591 name
= input_line_pointer
;
3592 endc
= get_symbol_end ();
3594 sym
= symbol_find_or_make (name
);
3596 *input_line_pointer
= endc
;
3598 if (S_IS_DEFINED (sym
))
3602 label
= symbol_get_tc (ppc_current_csect
)->within
;
3603 if (symbol_get_tc (label
)->class != XMC_TC0
)
3605 as_bad (_(".tc with no label"));
3606 ignore_rest_of_line ();
3610 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3611 symbol_set_frag (label
, symbol_get_frag (sym
));
3612 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3614 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3615 ++input_line_pointer
;
3620 S_SET_SEGMENT (sym
, now_seg
);
3621 symbol_set_frag (sym
, frag_now
);
3622 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3623 symbol_get_tc (sym
)->class = XMC_TC
;
3624 symbol_get_tc (sym
)->output
= 1;
3626 ppc_frob_label (sym
);
3629 #endif /* OBJ_XCOFF */
3633 /* Skip the TOC symbol name. */
3634 while (is_part_of_name (*input_line_pointer
)
3635 || *input_line_pointer
== '['
3636 || *input_line_pointer
== ']'
3637 || *input_line_pointer
== '{'
3638 || *input_line_pointer
== '}')
3639 ++input_line_pointer
;
3641 /* Align to a four/eight byte boundary. */
3642 align
= BFD_DEFAULT_TARGET_SIZE
== 64 && ppc_size
== PPC_OPCODE_64
? 3 : 2;
3643 frag_align (align
, 0, 0);
3644 record_alignment (now_seg
, align
);
3645 #endif /* OBJ_ELF */
3647 if (*input_line_pointer
!= ',')
3648 demand_empty_rest_of_line ();
3651 ++input_line_pointer
;
3652 cons ((ppc_size
== PPC_OPCODE_64
) ? 8 : 4);
3656 /* Pseudo-op .machine. */
3657 /* FIXME: `.machine' is a nop for the moment. It would be nice to
3658 accept this directive on the first line of input and set ppc_size
3659 and the target format accordingly. Unfortunately, the target
3660 format is selected in output-file.c:output_file_create before we
3661 even get to md_begin, so it's not possible without changing
3665 ppc_machine (ignore
)
3666 int ignore ATTRIBUTE_UNUSED
;
3668 discard_rest_of_line ();
3671 /* See whether a symbol is in the TOC section. */
3674 ppc_is_toc_sym (sym
)
3678 return symbol_get_tc (sym
)->class == XMC_TC
;
3681 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
3682 if (BFD_DEFAULT_TARGET_SIZE
== 64 && ppc_size
== PPC_OPCODE_64
)
3683 return strcmp (sname
, ".toc") == 0;
3685 return strcmp (sname
, ".got") == 0;
3688 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
3692 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
3694 /* Set the current section. */
3696 ppc_set_current_section (new)
3699 ppc_previous_section
= ppc_current_section
;
3700 ppc_current_section
= new;
3703 /* pseudo-op: .previous
3704 behaviour: toggles the current section with the previous section.
3706 warnings: "No previous section" */
3709 ppc_previous (ignore
)
3710 int ignore ATTRIBUTE_UNUSED
;
3714 if (ppc_previous_section
== NULL
)
3716 as_warn (_("No previous section to return to. Directive ignored."));
3720 subseg_set (ppc_previous_section
, 0);
3722 ppc_set_current_section (ppc_previous_section
);
3725 /* pseudo-op: .pdata
3726 behaviour: predefined read only data section
3730 initial: .section .pdata "adr3"
3731 a - don't know -- maybe a misprint
3732 d - initialized data
3734 3 - double word aligned (that would be 4 byte boundary)
3737 Tag index tables (also known as the function table) for exception
3738 handling, debugging, etc. */
3742 int ignore ATTRIBUTE_UNUSED
;
3744 if (pdata_section
== 0)
3746 pdata_section
= subseg_new (".pdata", 0);
3748 bfd_set_section_flags (stdoutput
, pdata_section
,
3749 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3750 | SEC_READONLY
| SEC_DATA
));
3752 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3756 pdata_section
= subseg_new (".pdata", 0);
3758 ppc_set_current_section (pdata_section
);
3761 /* pseudo-op: .ydata
3762 behaviour: predefined read only data section
3766 initial: .section .ydata "drw3"
3767 a - don't know -- maybe a misprint
3768 d - initialized data
3770 3 - double word aligned (that would be 4 byte boundary)
3772 Tag tables (also known as the scope table) for exception handling,
3777 int ignore ATTRIBUTE_UNUSED
;
3779 if (ydata_section
== 0)
3781 ydata_section
= subseg_new (".ydata", 0);
3782 bfd_set_section_flags (stdoutput
, ydata_section
,
3783 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3784 | SEC_READONLY
| SEC_DATA
));
3786 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3790 ydata_section
= subseg_new (".ydata", 0);
3792 ppc_set_current_section (ydata_section
);
3795 /* pseudo-op: .reldata
3796 behaviour: predefined read write data section
3797 double word aligned (4-byte)
3798 FIXME: relocation is applied to it
3799 FIXME: what's the difference between this and .data?
3802 initial: .section .reldata "drw3"
3803 d - initialized data
3806 3 - double word aligned (that would be 8 byte boundary)
3809 Like .data, but intended to hold data subject to relocation, such as
3810 function descriptors, etc. */
3813 ppc_reldata (ignore
)
3814 int ignore ATTRIBUTE_UNUSED
;
3816 if (reldata_section
== 0)
3818 reldata_section
= subseg_new (".reldata", 0);
3820 bfd_set_section_flags (stdoutput
, reldata_section
,
3821 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3824 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3828 reldata_section
= subseg_new (".reldata", 0);
3830 ppc_set_current_section (reldata_section
);
3833 /* pseudo-op: .rdata
3834 behaviour: predefined read only data section
3838 initial: .section .rdata "dr3"
3839 d - initialized data
3841 3 - double word aligned (that would be 4 byte boundary) */
3845 int ignore ATTRIBUTE_UNUSED
;
3847 if (rdata_section
== 0)
3849 rdata_section
= subseg_new (".rdata", 0);
3850 bfd_set_section_flags (stdoutput
, rdata_section
,
3851 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3852 | SEC_READONLY
| SEC_DATA
));
3854 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3858 rdata_section
= subseg_new (".rdata", 0);
3860 ppc_set_current_section (rdata_section
);
3863 /* pseudo-op: .ualong
3864 behaviour: much like .int, with the exception that no alignment is
3866 FIXME: test the alignment statement
3872 int ignore ATTRIBUTE_UNUSED
;
3878 /* pseudo-op: .znop <symbol name>
3879 behaviour: Issue a nop instruction
3880 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3881 the supplied symbol name.
3883 warnings: Missing symbol name */
3887 int ignore ATTRIBUTE_UNUSED
;
3890 const struct powerpc_opcode
*opcode
;
3901 /* Strip out the symbol name. */
3902 symbol_name
= input_line_pointer
;
3903 c
= get_symbol_end ();
3905 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3906 strcpy (name
, symbol_name
);
3908 sym
= symbol_find_or_make (name
);
3910 *input_line_pointer
= c
;
3914 /* Look up the opcode in the hash table. */
3915 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3917 /* Stick in the nop. */
3918 insn
= opcode
->opcode
;
3920 /* Write out the instruction. */
3922 md_number_to_chars (f
, insn
, 4);
3924 f
- frag_now
->fr_literal
,
3929 BFD_RELOC_16_GOT_PCREL
);
3942 register char *name
;
3946 register symbolS
*symbolP
;
3949 name
= input_line_pointer
;
3950 c
= get_symbol_end ();
3952 /* just after name is now '\0'. */
3953 p
= input_line_pointer
;
3956 if (*input_line_pointer
!= ',')
3958 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3959 ignore_rest_of_line ();
3963 input_line_pointer
++; /* skip ',' */
3964 if ((temp
= get_absolute_expression ()) < 0)
3966 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
3967 ignore_rest_of_line ();
3973 /* The third argument to .comm is the alignment. */
3974 if (*input_line_pointer
!= ',')
3978 ++input_line_pointer
;
3979 align
= get_absolute_expression ();
3982 as_warn (_("ignoring bad alignment"));
3989 symbolP
= symbol_find_or_make (name
);
3992 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3994 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3995 S_GET_NAME (symbolP
));
3996 ignore_rest_of_line ();
4000 if (S_GET_VALUE (symbolP
))
4002 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
4003 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4004 S_GET_NAME (symbolP
),
4005 (long) S_GET_VALUE (symbolP
),
4010 S_SET_VALUE (symbolP
, (valueT
) temp
);
4011 S_SET_EXTERNAL (symbolP
);
4014 demand_empty_rest_of_line ();
4018 * implement the .section pseudo op:
4019 * .section name {, "flags"}
4021 * | +--- optional flags: 'b' for bss
4023 * +-- section name 'l' for lib
4027 * 'd' (apparently m88k for data)
4029 * But if the argument is not a quoted string, treat it as a
4030 * subsegment number.
4032 * FIXME: this is a copy of the section processing from obj-coff.c, with
4033 * additions/changes for the moto-pas assembler support. There are three
4036 * FIXME: I just noticed this. This doesn't work at all really. It it
4037 * setting bits that bfd probably neither understands or uses. The
4038 * correct approach (?) will have to incorporate extra fields attached
4039 * to the section to hold the system specific stuff. (krk)
4042 * 'a' - unknown - referred to in documentation, but no definition supplied
4043 * 'c' - section has code
4044 * 'd' - section has initialized data
4045 * 'u' - section has uninitialized data
4046 * 'i' - section contains directives (info)
4047 * 'n' - section can be discarded
4048 * 'R' - remove section at link time
4050 * Section Protection:
4051 * 'r' - section is readable
4052 * 'w' - section is writeable
4053 * 'x' - section is executable
4054 * 's' - section is sharable
4056 * Section Alignment:
4057 * '0' - align to byte boundary
4058 * '1' - align to halfword undary
4059 * '2' - align to word boundary
4060 * '3' - align to doubleword boundary
4061 * '4' - align to quadword boundary
4062 * '5' - align to 32 byte boundary
4063 * '6' - align to 64 byte boundary
4068 ppc_pe_section (ignore
)
4069 int ignore ATTRIBUTE_UNUSED
;
4071 /* Strip out the section name. */
4080 section_name
= input_line_pointer
;
4081 c
= get_symbol_end ();
4083 name
= xmalloc (input_line_pointer
- section_name
+ 1);
4084 strcpy (name
, section_name
);
4086 *input_line_pointer
= c
;
4091 flags
= SEC_NO_FLAGS
;
4093 if (strcmp (name
, ".idata$2") == 0)
4097 else if (strcmp (name
, ".idata$3") == 0)
4101 else if (strcmp (name
, ".idata$4") == 0)
4105 else if (strcmp (name
, ".idata$5") == 0)
4109 else if (strcmp (name
, ".idata$6") == 0)
4114 /* Default alignment to 16 byte boundary. */
4117 if (*input_line_pointer
== ',')
4119 ++input_line_pointer
;
4121 if (*input_line_pointer
!= '"')
4122 exp
= get_absolute_expression ();
4125 ++input_line_pointer
;
4126 while (*input_line_pointer
!= '"'
4127 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4129 switch (*input_line_pointer
)
4131 /* Section Contents */
4132 case 'a': /* unknown */
4133 as_bad (_("Unsupported section attribute -- 'a'"));
4135 case 'c': /* code section */
4138 case 'd': /* section has initialized data */
4141 case 'u': /* section has uninitialized data */
4142 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4146 case 'i': /* section contains directives (info) */
4147 /* FIXME: This is IMAGE_SCN_LNK_INFO
4149 flags
|= SEC_HAS_CONTENTS
;
4151 case 'n': /* section can be discarded */
4154 case 'R': /* Remove section at link time */
4155 flags
|= SEC_NEVER_LOAD
;
4158 /* Section Protection */
4159 case 'r': /* section is readable */
4160 flags
|= IMAGE_SCN_MEM_READ
;
4162 case 'w': /* section is writeable */
4163 flags
|= IMAGE_SCN_MEM_WRITE
;
4165 case 'x': /* section is executable */
4166 flags
|= IMAGE_SCN_MEM_EXECUTE
;
4168 case 's': /* section is sharable */
4169 flags
|= IMAGE_SCN_MEM_SHARED
;
4172 /* Section Alignment */
4173 case '0': /* align to byte boundary */
4174 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
4177 case '1': /* align to halfword boundary */
4178 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
4181 case '2': /* align to word boundary */
4182 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
4185 case '3': /* align to doubleword boundary */
4186 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
4189 case '4': /* align to quadword boundary */
4190 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
4193 case '5': /* align to 32 byte boundary */
4194 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
4197 case '6': /* align to 64 byte boundary */
4198 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
4203 as_bad (_("unknown section attribute '%c'"),
4204 *input_line_pointer
);
4207 ++input_line_pointer
;
4209 if (*input_line_pointer
== '"')
4210 ++input_line_pointer
;
4214 sec
= subseg_new (name
, (subsegT
) exp
);
4216 ppc_set_current_section (sec
);
4218 if (flags
!= SEC_NO_FLAGS
)
4220 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
4221 as_bad (_("error setting flags for \"%s\": %s"),
4222 bfd_section_name (stdoutput
, sec
),
4223 bfd_errmsg (bfd_get_error ()));
4226 bfd_set_section_alignment (stdoutput
, sec
, align
);
4231 ppc_pe_function (ignore
)
4232 int ignore ATTRIBUTE_UNUSED
;
4238 name
= input_line_pointer
;
4239 endc
= get_symbol_end ();
4241 ext_sym
= symbol_find_or_make (name
);
4243 *input_line_pointer
= endc
;
4245 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4246 SF_SET_FUNCTION (ext_sym
);
4247 SF_SET_PROCESS (ext_sym
);
4248 coff_add_linesym (ext_sym
);
4250 demand_empty_rest_of_line ();
4254 ppc_pe_tocd (ignore
)
4255 int ignore ATTRIBUTE_UNUSED
;
4257 if (tocdata_section
== 0)
4259 tocdata_section
= subseg_new (".tocd", 0);
4260 /* FIXME: section flags won't work. */
4261 bfd_set_section_flags (stdoutput
, tocdata_section
,
4262 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4263 | SEC_READONLY
| SEC_DATA
));
4265 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4269 rdata_section
= subseg_new (".tocd", 0);
4272 ppc_set_current_section (tocdata_section
);
4274 demand_empty_rest_of_line ();
4277 /* Don't adjust TOC relocs to use the section symbol. */
4280 ppc_pe_fix_adjustable (fix
)
4283 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4290 /* XCOFF specific symbol and file handling. */
4292 /* Canonicalize the symbol name. We use the to force the suffix, if
4293 any, to use square brackets, and to be in upper case. */
4296 ppc_canonicalize_symbol_name (name
)
4301 if (ppc_stab_symbol
)
4304 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4318 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4321 if (*s
== '\0' || s
[1] != '\0')
4322 as_bad (_("bad symbol suffix"));
4330 /* Set the class of a symbol based on the suffix, if any. This is
4331 called whenever a new symbol is created. */
4334 ppc_symbol_new_hook (sym
)
4337 struct ppc_tc_sy
*tc
;
4340 tc
= symbol_get_tc (sym
);
4344 tc
->real_name
= NULL
;
4350 if (ppc_stab_symbol
)
4353 s
= strchr (S_GET_NAME (sym
), '[');
4354 if (s
== (const char *) NULL
)
4356 /* There is no suffix. */
4365 if (strcmp (s
, "BS]") == 0)
4369 if (strcmp (s
, "DB]") == 0)
4371 else if (strcmp (s
, "DS]") == 0)
4375 if (strcmp (s
, "GL]") == 0)
4379 if (strcmp (s
, "PR]") == 0)
4383 if (strcmp (s
, "RO]") == 0)
4385 else if (strcmp (s
, "RW]") == 0)
4389 if (strcmp (s
, "SV]") == 0)
4393 if (strcmp (s
, "TC]") == 0)
4395 else if (strcmp (s
, "TI]") == 0)
4397 else if (strcmp (s
, "TB]") == 0)
4399 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4400 tc
->class = XMC_TC0
;
4403 if (strcmp (s
, "UA]") == 0)
4405 else if (strcmp (s
, "UC]") == 0)
4409 if (strcmp (s
, "XO]") == 0)
4414 if (tc
->class == -1)
4415 as_bad (_("Unrecognized symbol suffix"));
4418 /* Set the class of a label based on where it is defined. This
4419 handles symbols without suffixes. Also, move the symbol so that it
4420 follows the csect symbol. */
4423 ppc_frob_label (sym
)
4426 if (ppc_current_csect
!= (symbolS
*) NULL
)
4428 if (symbol_get_tc (sym
)->class == -1)
4429 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4431 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4432 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4433 &symbol_rootP
, &symbol_lastP
);
4434 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4438 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4439 seen. It tells ppc_adjust_symtab whether it needs to look through
4442 static boolean ppc_saw_abs
;
4444 /* Change the name of a symbol just before writing it out. Set the
4445 real name if the .rename pseudo-op was used. Otherwise, remove any
4446 class suffix. Return 1 if the symbol should not be included in the
4450 ppc_frob_symbol (sym
)
4453 static symbolS
*ppc_last_function
;
4454 static symbolS
*set_end
;
4456 /* Discard symbols that should not be included in the output symbol
4458 if (! symbol_used_in_reloc_p (sym
)
4459 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4460 || (! S_IS_EXTERNAL (sym
)
4461 && ! symbol_get_tc (sym
)->output
4462 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4465 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4466 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4472 name
= S_GET_NAME (sym
);
4473 s
= strchr (name
, '[');
4474 if (s
!= (char *) NULL
)
4480 snew
= xmalloc (len
+ 1);
4481 memcpy (snew
, name
, len
);
4484 S_SET_NAME (sym
, snew
);
4488 if (set_end
!= (symbolS
*) NULL
)
4490 SA_SET_SYM_ENDNDX (set_end
, sym
);
4494 if (SF_GET_FUNCTION (sym
))
4496 if (ppc_last_function
!= (symbolS
*) NULL
)
4497 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4498 ppc_last_function
= sym
;
4499 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4501 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4502 SA_SET_SYM_FSIZE (sym
,
4503 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4506 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4507 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4509 if (ppc_last_function
== (symbolS
*) NULL
)
4510 as_bad (_(".ef with no preceding .function"));
4513 set_end
= ppc_last_function
;
4514 ppc_last_function
= NULL
;
4516 /* We don't have a C_EFCN symbol, but we need to force the
4517 COFF backend to believe that it has seen one. */
4518 coff_last_function
= NULL
;
4522 if (! S_IS_EXTERNAL (sym
)
4523 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4524 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4525 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4526 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4527 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4528 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4529 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4530 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4531 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4532 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4534 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4535 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4538 union internal_auxent
*a
;
4540 /* Create a csect aux. */
4541 i
= S_GET_NUMBER_AUXILIARY (sym
);
4542 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4543 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4544 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4546 /* This is the TOC table. */
4547 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4548 a
->x_csect
.x_scnlen
.l
= 0;
4549 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4551 else if (symbol_get_tc (sym
)->subseg
!= 0)
4553 /* This is a csect symbol. x_scnlen is the size of the
4555 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4556 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4557 S_GET_SEGMENT (sym
))
4558 - S_GET_VALUE (sym
));
4561 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4562 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4563 - S_GET_VALUE (sym
));
4565 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4567 else if (S_GET_SEGMENT (sym
) == bss_section
)
4569 /* This is a common symbol. */
4570 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4571 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4572 if (S_IS_EXTERNAL (sym
))
4573 symbol_get_tc (sym
)->class = XMC_RW
;
4575 symbol_get_tc (sym
)->class = XMC_BS
;
4577 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4579 /* This is an absolute symbol. The csect will be created by
4580 ppc_adjust_symtab. */
4582 a
->x_csect
.x_smtyp
= XTY_LD
;
4583 if (symbol_get_tc (sym
)->class == -1)
4584 symbol_get_tc (sym
)->class = XMC_XO
;
4586 else if (! S_IS_DEFINED (sym
))
4588 /* This is an external symbol. */
4589 a
->x_csect
.x_scnlen
.l
= 0;
4590 a
->x_csect
.x_smtyp
= XTY_ER
;
4592 else if (symbol_get_tc (sym
)->class == XMC_TC
)
4596 /* This is a TOC definition. x_scnlen is the size of the
4598 next
= symbol_next (sym
);
4599 while (symbol_get_tc (next
)->class == XMC_TC0
)
4600 next
= symbol_next (next
);
4601 if (next
== (symbolS
*) NULL
4602 || symbol_get_tc (next
)->class != XMC_TC
)
4604 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4605 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4607 - S_GET_VALUE (sym
));
4609 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4610 - S_GET_VALUE (sym
));
4614 resolve_symbol_value (next
);
4615 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4616 - S_GET_VALUE (sym
));
4618 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4624 /* This is a normal symbol definition. x_scnlen is the
4625 symbol index of the containing csect. */
4626 if (S_GET_SEGMENT (sym
) == text_section
)
4627 csect
= ppc_text_csects
;
4628 else if (S_GET_SEGMENT (sym
) == data_section
)
4629 csect
= ppc_data_csects
;
4633 /* Skip the initial dummy symbol. */
4634 csect
= symbol_get_tc (csect
)->next
;
4636 if (csect
== (symbolS
*) NULL
)
4638 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4639 a
->x_csect
.x_scnlen
.l
= 0;
4643 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
4645 resolve_symbol_value (symbol_get_tc (csect
)->next
);
4646 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
4647 > S_GET_VALUE (sym
))
4649 csect
= symbol_get_tc (csect
)->next
;
4652 a
->x_csect
.x_scnlen
.p
=
4653 coffsymbol (symbol_get_bfdsym (csect
))->native
;
4654 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
4657 a
->x_csect
.x_smtyp
= XTY_LD
;
4660 a
->x_csect
.x_parmhash
= 0;
4661 a
->x_csect
.x_snhash
= 0;
4662 if (symbol_get_tc (sym
)->class == -1)
4663 a
->x_csect
.x_smclas
= XMC_PR
;
4665 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
4666 a
->x_csect
.x_stab
= 0;
4667 a
->x_csect
.x_snstab
= 0;
4669 /* Don't let the COFF backend resort these symbols. */
4670 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
4672 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4674 /* We want the value to be the symbol index of the referenced
4675 csect symbol. BFD will do that for us if we set the right
4679 coffsymbol (symbol_get_bfdsym
4680 (symbol_get_tc (sym
)->within
))->native
));
4681 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
4683 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4688 /* The value is the offset from the enclosing csect. */
4689 block
= symbol_get_tc (sym
)->within
;
4690 csect
= symbol_get_tc (block
)->within
;
4691 resolve_symbol_value (csect
);
4692 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4694 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4695 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4697 /* We want the value to be a file offset into the line numbers.
4698 BFD will do that for us if we set the right flags. We have
4699 already set the value correctly. */
4700 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
4706 /* Adjust the symbol table. This creates csect symbols for all
4707 absolute symbols. */
4710 ppc_adjust_symtab ()
4717 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4721 union internal_auxent
*a
;
4723 if (S_GET_SEGMENT (sym
) != absolute_section
)
4726 csect
= symbol_create (".abs[XO]", absolute_section
,
4727 S_GET_VALUE (sym
), &zero_address_frag
);
4728 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
4729 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4730 i
= S_GET_NUMBER_AUXILIARY (csect
);
4731 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4732 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
4733 a
->x_csect
.x_scnlen
.l
= 0;
4734 a
->x_csect
.x_smtyp
= XTY_SD
;
4735 a
->x_csect
.x_parmhash
= 0;
4736 a
->x_csect
.x_snhash
= 0;
4737 a
->x_csect
.x_smclas
= XMC_XO
;
4738 a
->x_csect
.x_stab
= 0;
4739 a
->x_csect
.x_snstab
= 0;
4741 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4743 i
= S_GET_NUMBER_AUXILIARY (sym
);
4744 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
4745 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
4746 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
4749 ppc_saw_abs
= false;
4752 /* Set the VMA for a section. This is called on all the sections in
4756 ppc_frob_section (sec
)
4759 static bfd_size_type vma
= 0;
4761 bfd_set_section_vma (stdoutput
, sec
, vma
);
4762 vma
+= bfd_section_size (stdoutput
, sec
);
4765 #endif /* OBJ_XCOFF */
4767 /* Turn a string in input_line_pointer into a floating point constant
4768 of type TYPE, and store the appropriate bytes in *LITP. The number
4769 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4770 returned, or NULL on OK. */
4773 md_atof (type
, litp
, sizep
)
4779 LITTLENUM_TYPE words
[4];
4795 return _("bad call to md_atof");
4798 t
= atof_ieee (input_line_pointer
, type
, words
);
4800 input_line_pointer
= t
;
4804 if (target_big_endian
)
4806 for (i
= 0; i
< prec
; i
++)
4808 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4814 for (i
= prec
- 1; i
>= 0; i
--)
4816 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4824 /* Write a value out to the object file, using the appropriate
4828 md_number_to_chars (buf
, val
, n
)
4833 if (target_big_endian
)
4834 number_to_chars_bigendian (buf
, val
, n
);
4836 number_to_chars_littleendian (buf
, val
, n
);
4839 /* Align a section (I don't know why this is machine dependent). */
4842 md_section_align (seg
, addr
)
4846 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4848 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4851 /* We don't have any form of relaxing. */
4854 md_estimate_size_before_relax (fragp
, seg
)
4855 fragS
*fragp ATTRIBUTE_UNUSED
;
4856 asection
*seg ATTRIBUTE_UNUSED
;
4862 /* Convert a machine dependent frag. We never generate these. */
4865 md_convert_frag (abfd
, sec
, fragp
)
4866 bfd
*abfd ATTRIBUTE_UNUSED
;
4867 asection
*sec ATTRIBUTE_UNUSED
;
4868 fragS
*fragp ATTRIBUTE_UNUSED
;
4873 /* We have no need to default values of symbols. */
4876 md_undefined_symbol (name
)
4877 char *name ATTRIBUTE_UNUSED
;
4882 /* Functions concerning relocs. */
4884 /* The location from which a PC relative jump should be calculated,
4885 given a PC relative reloc. */
4888 md_pcrel_from_section (fixp
, sec
)
4890 segT sec ATTRIBUTE_UNUSED
;
4892 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4897 /* This is called to see whether a fixup should be adjusted to use a
4898 section symbol. We take the opportunity to change a fixup against
4899 a symbol in the TOC subsegment into a reloc against the
4900 corresponding .tc symbol. */
4903 ppc_fix_adjustable (fix
)
4908 resolve_symbol_value (fix
->fx_addsy
);
4909 val
= S_GET_VALUE (fix
->fx_addsy
);
4910 if (ppc_toc_csect
!= (symbolS
*) NULL
4911 && fix
->fx_addsy
!= (symbolS
*) NULL
4912 && fix
->fx_addsy
!= ppc_toc_csect
4913 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4914 && val
>= ppc_toc_frag
->fr_address
4915 && (ppc_after_toc_frag
== (fragS
*) NULL
4916 || val
< ppc_after_toc_frag
->fr_address
))
4920 for (sy
= symbol_next (ppc_toc_csect
);
4921 sy
!= (symbolS
*) NULL
;
4922 sy
= symbol_next (sy
))
4924 if (symbol_get_tc (sy
)->class == XMC_TC0
)
4926 if (symbol_get_tc (sy
)->class != XMC_TC
)
4928 resolve_symbol_value (sy
);
4929 if (val
== S_GET_VALUE (sy
))
4932 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4937 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4938 _("symbol in .toc does not match any .tc"));
4941 /* Possibly adjust the reloc to be against the csect. */
4942 if (fix
->fx_addsy
!= (symbolS
*) NULL
4943 && symbol_get_tc (fix
->fx_addsy
)->subseg
== 0
4944 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC0
4945 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC
4946 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
4947 /* Don't adjust if this is a reloc in the toc section. */
4948 && (S_GET_SEGMENT (fix
->fx_addsy
) != data_section
4949 || ppc_toc_csect
== NULL
4950 || val
< ppc_toc_frag
->fr_address
4951 || (ppc_after_toc_frag
!= NULL
4952 && val
>= ppc_after_toc_frag
->fr_address
)))
4956 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4957 csect
= ppc_text_csects
;
4958 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4959 csect
= ppc_data_csects
;
4963 /* Skip the initial dummy symbol. */
4964 csect
= symbol_get_tc (csect
)->next
;
4966 if (csect
!= (symbolS
*) NULL
)
4968 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
4969 && (symbol_get_frag (symbol_get_tc (csect
)->next
)->fr_address
4972 /* If the csect address equals the symbol value, then we
4973 have to look through the full symbol table to see
4974 whether this is the csect we want. Note that we will
4975 only get here if the csect has zero length. */
4976 if ((symbol_get_frag (csect
)->fr_address
== val
)
4977 && S_GET_VALUE (csect
) == S_GET_VALUE (fix
->fx_addsy
))
4981 for (scan
= symbol_next (csect
);
4983 scan
= symbol_next (scan
))
4985 if (symbol_get_tc (scan
)->subseg
!= 0)
4987 if (scan
== fix
->fx_addsy
)
4991 /* If we found the symbol before the next csect
4992 symbol, then this is the csect we want. */
4993 if (scan
== fix
->fx_addsy
)
4997 csect
= symbol_get_tc (csect
)->next
;
5000 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
5001 - symbol_get_frag (csect
)->fr_address
);
5002 fix
->fx_addsy
= csect
;
5006 /* Adjust a reloc against a .lcomm symbol to be against the base
5008 if (fix
->fx_addsy
!= (symbolS
*) NULL
5009 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
5010 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
5012 resolve_symbol_value (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
);
5014 (S_GET_VALUE (fix
->fx_addsy
)
5015 - S_GET_VALUE (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
));
5016 fix
->fx_addsy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
5022 /* A reloc from one csect to another must be kept. The assembler
5023 will, of course, keep relocs between sections, and it will keep
5024 absolute relocs, but we need to force it to keep PC relative relocs
5025 between two csects in the same section. */
5028 ppc_force_relocation (fix
)
5031 /* At this point fix->fx_addsy should already have been converted to
5032 a csect symbol. If the csect does not include the fragment, then
5033 we need to force the relocation. */
5035 && fix
->fx_addsy
!= NULL
5036 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
5037 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
5038 > fix
->fx_frag
->fr_address
)
5039 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
5040 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
5041 <= fix
->fx_frag
->fr_address
))))
5047 #endif /* OBJ_XCOFF */
5051 ppc_fix_adjustable (fix
)
5054 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
5055 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
5056 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
5057 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
5058 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
5059 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
5060 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
5061 && ! S_IS_EXTERNAL (fix
->fx_addsy
)
5062 && ! S_IS_WEAK (fix
->fx_addsy
)
5064 || (fix
->fx_subsy
!= NULL
5065 && (S_GET_SEGMENT (fix
->fx_subsy
)
5066 == S_GET_SEGMENT (fix
->fx_addsy
)))
5067 || S_IS_LOCAL (fix
->fx_addsy
)));
5071 /* Apply a fixup to the object code. This is called for all the
5072 fixups we generated by the call to fix_new_exp, above. In the call
5073 above we used a reloc code which was the largest legal reloc code
5074 plus the operand index. Here we undo that to recover the operand
5075 index. At this point all symbol values should be fully resolved,
5076 and we attempt to completely resolve the reloc. If we can not do
5077 that, we determine the correct reloc code and put it back in the
5081 md_apply_fix3 (fixp
, valuep
, seg
)
5084 segT seg ATTRIBUTE_UNUSED
;
5090 if (fixp
->fx_addsy
!= NULL
)
5092 /* `*valuep' may contain the value of the symbol on which the reloc
5093 will be based; we have to remove it. */
5094 if (symbol_used_in_reloc_p (fixp
->fx_addsy
)
5095 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
5096 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
5097 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
5098 value
-= S_GET_VALUE (fixp
->fx_addsy
);
5100 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
5101 supposed to be? I think this is related to various similar
5102 FIXMEs in tc-i386.c and tc-sparc.c. */
5104 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5111 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
5112 the symbol values. Since we are using BFD_ASSEMBLER, if we are
5113 doing this relocation the code in write.c is going to call
5114 bfd_install_relocation, which is also going to use the symbol
5115 value. That means that if the reloc is fully resolved we want to
5116 use *valuep since bfd_install_relocation is not being used.
5117 However, if the reloc is not fully resolved we do not want to use
5118 *valuep, and must use fx_offset instead. However, if the reloc
5119 is PC relative, we do want to use *valuep since it includes the
5120 result of md_pcrel_from. This is confusing. */
5121 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
5126 else if (fixp
->fx_pcrel
)
5130 value
= fixp
->fx_offset
;
5131 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
5133 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
5134 value
-= S_GET_VALUE (fixp
->fx_subsy
);
5137 /* We can't actually support subtracting a symbol. */
5138 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5139 _("expression too complex"));
5145 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
5148 const struct powerpc_operand
*operand
;
5152 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
5154 operand
= &powerpc_operands
[opindex
];
5157 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5158 does not generate a reloc. It uses the offset of `sym' within its
5159 csect. Other usages, such as `.long sym', generate relocs. This
5160 is the documented behaviour of non-TOC symbols. */
5161 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5162 && operand
->bits
== 16
5163 && operand
->shift
== 0
5164 && operand
->insert
== NULL
5165 && fixp
->fx_addsy
!= NULL
5166 && symbol_get_tc (fixp
->fx_addsy
)->subseg
!= 0
5167 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC
5168 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC0
5169 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
5171 value
= fixp
->fx_offset
;
5176 /* Fetch the instruction, insert the fully resolved operand
5177 value, and stuff the instruction back again. */
5178 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5179 if (target_big_endian
)
5180 insn
= bfd_getb32 ((unsigned char *) where
);
5182 insn
= bfd_getl32 ((unsigned char *) where
);
5183 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
5184 fixp
->fx_file
, fixp
->fx_line
);
5185 if (target_big_endian
)
5186 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5188 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5192 /* Nothing else to do here. */
5196 assert (fixp
->fx_addsy
!= NULL
);
5198 /* Determine a BFD reloc value based on the operand information.
5199 We are only prepared to turn a few of the operands into
5201 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5202 && operand
->bits
== 26
5203 && operand
->shift
== 0)
5204 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
5205 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5206 && operand
->bits
== 16
5207 && operand
->shift
== 0)
5208 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
5209 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5210 && operand
->bits
== 26
5211 && operand
->shift
== 0)
5212 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
5213 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5214 && operand
->bits
== 16
5215 && operand
->shift
== 0)
5216 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
5217 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5218 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5219 && operand
->bits
== 16
5220 && operand
->shift
== 0
5221 && ppc_is_toc_sym (fixp
->fx_addsy
))
5223 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
5225 if (BFD_DEFAULT_TARGET_SIZE
== 64
5226 && ppc_size
== PPC_OPCODE_64
5227 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5228 fixp
->fx_r_type
= BFD_RELOC_PPC64_TOC16_DS
;
5231 if (target_big_endian
)
5232 fixp
->fx_where
+= 2;
5234 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5240 /* Use expr_symbol_where to see if this is an expression
5242 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
5243 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5244 _("unresolved expression that must be resolved"));
5246 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5247 _("unsupported relocation against %s"),
5248 S_GET_NAME (fixp
->fx_addsy
));
5256 ppc_elf_validate_fix (fixp
, seg
);
5258 switch (fixp
->fx_r_type
)
5260 case BFD_RELOC_CTOR
:
5261 if (BFD_DEFAULT_TARGET_SIZE
== 64 && ppc_size
== PPC_OPCODE_64
)
5267 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
5271 case BFD_RELOC_32_PCREL
:
5272 case BFD_RELOC_32_BASEREL
:
5273 case BFD_RELOC_PPC_EMB_NADDR32
:
5274 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5281 fixp
->fx_r_type
= BFD_RELOC_64_PCREL
;
5284 case BFD_RELOC_64_PCREL
:
5285 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5289 case BFD_RELOC_LO16
:
5291 case BFD_RELOC_GPREL16
:
5292 case BFD_RELOC_16_GOT_PCREL
:
5293 case BFD_RELOC_16_GOTOFF
:
5294 case BFD_RELOC_LO16_GOTOFF
:
5295 case BFD_RELOC_HI16_GOTOFF
:
5296 case BFD_RELOC_HI16_S_GOTOFF
:
5297 case BFD_RELOC_LO16_BASEREL
:
5298 case BFD_RELOC_HI16_BASEREL
:
5299 case BFD_RELOC_HI16_S_BASEREL
:
5300 case BFD_RELOC_PPC_EMB_NADDR16
:
5301 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5302 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5303 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5304 case BFD_RELOC_PPC_EMB_SDAI16
:
5305 case BFD_RELOC_PPC_EMB_SDA2REL
:
5306 case BFD_RELOC_PPC_EMB_SDA2I16
:
5307 case BFD_RELOC_PPC_EMB_RELSEC16
:
5308 case BFD_RELOC_PPC_EMB_RELST_LO
:
5309 case BFD_RELOC_PPC_EMB_RELST_HI
:
5310 case BFD_RELOC_PPC_EMB_RELST_HA
:
5311 case BFD_RELOC_PPC_EMB_RELSDA
:
5312 case BFD_RELOC_PPC_TOC16
:
5314 #if BFD_DEFAULT_TARGET_SIZE == 64
5315 case BFD_RELOC_PPC64_TOC16_LO
:
5316 case BFD_RELOC_PPC64_TOC16_HI
:
5317 case BFD_RELOC_PPC64_TOC16_HA
:
5322 if (fixp
->fx_addsy
!= NULL
)
5323 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5324 _("cannot emit PC relative %s relocation against %s"),
5325 bfd_get_reloc_code_name (fixp
->fx_r_type
),
5326 S_GET_NAME (fixp
->fx_addsy
));
5328 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5329 _("cannot emit PC relative %s relocation"),
5330 bfd_get_reloc_code_name (fixp
->fx_r_type
));
5333 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5337 /* This case happens when you write, for example,
5339 where L1 and L2 are defined later. */
5340 case BFD_RELOC_HI16
:
5343 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5347 case BFD_RELOC_HI16_S
:
5350 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5355 #if BFD_DEFAULT_TARGET_SIZE == 64
5356 case BFD_RELOC_PPC64_HIGHER
:
5359 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5360 PPC_HIGHER (value
), 2);
5363 case BFD_RELOC_PPC64_HIGHER_S
:
5366 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5367 PPC_HIGHERA (value
), 2);
5370 case BFD_RELOC_PPC64_HIGHEST
:
5373 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5374 PPC_HIGHEST (value
), 2);
5377 case BFD_RELOC_PPC64_HIGHEST_S
:
5380 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5381 PPC_HIGHESTA (value
), 2);
5384 case BFD_RELOC_PPC64_ADDR16_DS
:
5385 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
5386 case BFD_RELOC_PPC64_GOT16_DS
:
5387 case BFD_RELOC_PPC64_GOT16_LO_DS
:
5388 case BFD_RELOC_PPC64_PLT16_LO_DS
:
5389 case BFD_RELOC_PPC64_SECTOFF_DS
:
5390 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
5391 case BFD_RELOC_PPC64_TOC16_DS
:
5392 case BFD_RELOC_PPC64_TOC16_LO_DS
:
5393 case BFD_RELOC_PPC64_PLTGOT16_DS
:
5394 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
5398 unsigned char *where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5401 if (target_big_endian
)
5402 val
= bfd_getb16 (where
);
5404 val
= bfd_getl16 (where
);
5405 val
|= (value
& 0xfffc);
5406 if (target_big_endian
)
5407 bfd_putb16 ((bfd_vma
) val
, where
);
5409 bfd_putl16 ((bfd_vma
) val
, where
);
5414 /* Because SDA21 modifies the register field, the size is set to 4
5415 bytes, rather than 2, so offset it here appropriately. */
5416 case BFD_RELOC_PPC_EMB_SDA21
:
5420 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
5421 + ((target_big_endian
) ? 2 : 0),
5429 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5433 case BFD_RELOC_24_PLT_PCREL
:
5434 case BFD_RELOC_PPC_LOCAL24PC
:
5435 if (!fixp
->fx_pcrel
&& !fixp
->fx_done
)
5443 /* Fetch the instruction, insert the fully resolved operand
5444 value, and stuff the instruction back again. */
5445 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5446 if (target_big_endian
)
5447 insn
= bfd_getb32 ((unsigned char *) where
);
5449 insn
= bfd_getl32 ((unsigned char *) where
);
5450 if ((value
& 3) != 0)
5451 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5452 _("must branch to an address a multiple of 4"));
5453 if ((offsetT
) value
< -0x40000000
5454 || (offsetT
) value
>= 0x40000000)
5455 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5456 _("@local or @plt branch destination is too far away, %ld bytes"),
5458 insn
= insn
| (value
& 0x03fffffc);
5459 if (target_big_endian
)
5460 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5462 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5466 case BFD_RELOC_VTABLE_INHERIT
:
5469 && !S_IS_DEFINED (fixp
->fx_addsy
)
5470 && !S_IS_WEAK (fixp
->fx_addsy
))
5471 S_SET_WEAK (fixp
->fx_addsy
);
5474 case BFD_RELOC_VTABLE_ENTRY
:
5479 #if BFD_DEFAULT_TARGET_SIZE == 64
5480 /* Generated by reference to `sym@tocbase'. The sym is
5481 ignored by the linker. */
5482 case BFD_RELOC_PPC64_TOC
:
5489 _("Gas failure, reloc value %d\n"), fixp
->fx_r_type
);
5496 fixp
->fx_addnumber
= value
;
5498 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
5499 fixp
->fx_addnumber
= 0;
5503 fixp
->fx_addnumber
= 0;
5505 /* We want to use the offset within the data segment of the
5506 symbol, not the actual VMA of the symbol. */
5507 fixp
->fx_addnumber
=
5508 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
5516 /* Generate a reloc for a fixup. */
5519 tc_gen_reloc (seg
, fixp
)
5520 asection
*seg ATTRIBUTE_UNUSED
;
5525 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5527 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5528 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5529 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5530 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5531 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
5533 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5534 _("reloc %d not supported by object file format"),
5535 (int) fixp
->fx_r_type
);
5538 reloc
->addend
= fixp
->fx_addnumber
;