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) ((((v) >> 16) + (((v) >> 15) & 1)) & 0xffff)
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) \
76 ((((v) >> 32) + (((v) & 0xffff8000) == 0xffff8000)) & 0xffff)
78 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
79 #define PPC_HIGHEST(v) (((v) >> 48) & 0xffff)
81 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
82 compensating for #lo being treated as a signed number.
83 Generate 0xffffffff8000 with arithmetic here, for portability. */
84 #define PPC_HIGHESTA(v) \
86 + (((v) & (((valueT) 1 << 48) - 0x8000)) == ((valueT) 1 << 48) - 0x8000)) \
89 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
91 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
93 static boolean register_name
PARAMS ((expressionS
*));
94 static void ppc_set_cpu
PARAMS ((void));
95 static unsigned long ppc_insert_operand
96 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
97 offsetT val
, char *file
, unsigned int line
));
98 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
99 static void ppc_byte
PARAMS ((int));
101 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
102 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
103 static void ppc_tc
PARAMS ((int));
104 static void ppc_machine
PARAMS ((int));
108 static void ppc_comm
PARAMS ((int));
109 static void ppc_bb
PARAMS ((int));
110 static void ppc_bc
PARAMS ((int));
111 static void ppc_bf
PARAMS ((int));
112 static void ppc_biei
PARAMS ((int));
113 static void ppc_bs
PARAMS ((int));
114 static void ppc_eb
PARAMS ((int));
115 static void ppc_ec
PARAMS ((int));
116 static void ppc_ef
PARAMS ((int));
117 static void ppc_es
PARAMS ((int));
118 static void ppc_csect
PARAMS ((int));
119 static void ppc_change_csect
PARAMS ((symbolS
*));
120 static void ppc_function
PARAMS ((int));
121 static void ppc_extern
PARAMS ((int));
122 static void ppc_lglobl
PARAMS ((int));
123 static void ppc_section
PARAMS ((int));
124 static void ppc_named_section
PARAMS ((int));
125 static void ppc_stabx
PARAMS ((int));
126 static void ppc_rename
PARAMS ((int));
127 static void ppc_toc
PARAMS ((int));
128 static void ppc_xcoff_cons
PARAMS ((int));
129 static void ppc_vbyte
PARAMS ((int));
133 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
134 static void ppc_elf_cons
PARAMS ((int));
135 static void ppc_elf_rdata
PARAMS ((int));
136 static void ppc_elf_lcomm
PARAMS ((int));
137 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
141 static void ppc_set_current_section
PARAMS ((segT
));
142 static void ppc_previous
PARAMS ((int));
143 static void ppc_pdata
PARAMS ((int));
144 static void ppc_ydata
PARAMS ((int));
145 static void ppc_reldata
PARAMS ((int));
146 static void ppc_rdata
PARAMS ((int));
147 static void ppc_ualong
PARAMS ((int));
148 static void ppc_znop
PARAMS ((int));
149 static void ppc_pe_comm
PARAMS ((int));
150 static void ppc_pe_section
PARAMS ((int));
151 static void ppc_pe_function
PARAMS ((int));
152 static void ppc_pe_tocd
PARAMS ((int));
155 /* Generic assembler global variables which must be defined by all
159 /* This string holds the chars that always start a comment. If the
160 pre-processor is disabled, these aren't very useful. The macro
161 tc_comment_chars points to this. We use this, rather than the
162 usual comment_chars, so that we can switch for Solaris conventions. */
163 static const char ppc_solaris_comment_chars
[] = "#!";
164 static const char ppc_eabi_comment_chars
[] = "#";
166 #ifdef TARGET_SOLARIS_COMMENT
167 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
169 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
172 const char comment_chars
[] = "#";
175 /* Characters which start a comment at the beginning of a line. */
176 const char line_comment_chars
[] = "#";
178 /* Characters which may be used to separate multiple commands on a
180 const char line_separator_chars
[] = ";";
182 /* Characters which are used to indicate an exponent in a floating
184 const char EXP_CHARS
[] = "eE";
186 /* Characters which mean that a number is a floating point constant,
188 const char FLT_CHARS
[] = "dD";
190 /* The target specific pseudo-ops which we support. */
192 const pseudo_typeS md_pseudo_table
[] =
194 /* Pseudo-ops which must be overridden. */
195 { "byte", ppc_byte
, 0 },
198 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
199 legitimately belong in the obj-*.c file. However, XCOFF is based
200 on COFF, and is only implemented for the RS/6000. We just use
201 obj-coff.c, and add what we need here. */
202 { "comm", ppc_comm
, 0 },
203 { "lcomm", ppc_comm
, 1 },
207 { "bi", ppc_biei
, 0 },
209 { "csect", ppc_csect
, 0 },
210 { "data", ppc_section
, 'd' },
214 { "ei", ppc_biei
, 1 },
216 { "extern", ppc_extern
, 0 },
217 { "function", ppc_function
, 0 },
218 { "lglobl", ppc_lglobl
, 0 },
219 { "rename", ppc_rename
, 0 },
220 { "section", ppc_named_section
, 0 },
221 { "stabx", ppc_stabx
, 0 },
222 { "text", ppc_section
, 't' },
223 { "toc", ppc_toc
, 0 },
224 { "long", ppc_xcoff_cons
, 2 },
225 { "llong", ppc_xcoff_cons
, 3 },
226 { "word", ppc_xcoff_cons
, 1 },
227 { "short", ppc_xcoff_cons
, 1 },
228 { "vbyte", ppc_vbyte
, 0 },
232 { "llong", ppc_elf_cons
, 8 },
233 { "quad", ppc_elf_cons
, 8 },
234 { "long", ppc_elf_cons
, 4 },
235 { "word", ppc_elf_cons
, 2 },
236 { "short", ppc_elf_cons
, 2 },
237 { "rdata", ppc_elf_rdata
, 0 },
238 { "rodata", ppc_elf_rdata
, 0 },
239 { "lcomm", ppc_elf_lcomm
, 0 },
240 { "file", dwarf2_directive_file
, 0 },
241 { "loc", dwarf2_directive_loc
, 0 },
245 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
246 { "previous", ppc_previous
, 0 },
247 { "pdata", ppc_pdata
, 0 },
248 { "ydata", ppc_ydata
, 0 },
249 { "reldata", ppc_reldata
, 0 },
250 { "rdata", ppc_rdata
, 0 },
251 { "ualong", ppc_ualong
, 0 },
252 { "znop", ppc_znop
, 0 },
253 { "comm", ppc_pe_comm
, 0 },
254 { "lcomm", ppc_pe_comm
, 1 },
255 { "section", ppc_pe_section
, 0 },
256 { "function", ppc_pe_function
,0 },
257 { "tocd", ppc_pe_tocd
, 0 },
260 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
262 { "machine", ppc_machine
, 0 },
269 /* Predefined register names if -mregnames (or default for Windows NT).
270 In general, there are lots of them, in an attempt to be compatible
271 with a number of other Windows NT assemblers. */
273 /* Structure to hold information about predefined registers. */
280 /* List of registers that are pre-defined:
282 Each general register has predefined names of the form:
283 1. r<reg_num> which has the value <reg_num>.
284 2. r.<reg_num> which has the value <reg_num>.
286 Each floating point register has predefined names of the form:
287 1. f<reg_num> which has the value <reg_num>.
288 2. f.<reg_num> which has the value <reg_num>.
290 Each vector unit register has predefined names of the form:
291 1. v<reg_num> which has the value <reg_num>.
292 2. v.<reg_num> which has the value <reg_num>.
294 Each condition register has predefined names of the form:
295 1. cr<reg_num> which has the value <reg_num>.
296 2. cr.<reg_num> which has the value <reg_num>.
298 There are individual registers as well:
299 sp or r.sp has the value 1
300 rtoc or r.toc has the value 2
301 fpscr has the value 0
307 dsisr has the value 18
309 sdr1 has the value 25
310 srr0 has the value 26
311 srr1 has the value 27
313 The table is sorted. Suitable for searching by a binary search. */
315 static const struct pd_reg pre_defined_registers
[] =
317 { "cr.0", 0 }, /* Condition Registers */
337 { "dar", 19 }, /* Data Access Register */
338 { "dec", 22 }, /* Decrementer */
339 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
341 { "f.0", 0 }, /* Floating point registers */
409 { "lr", 8 }, /* Link Register */
413 { "r.0", 0 }, /* General Purpose Registers */
446 { "r.sp", 1 }, /* Stack Pointer */
448 { "r.toc", 2 }, /* Pointer to the table of contents */
450 { "r0", 0 }, /* More general purpose registers */
483 { "rtoc", 2 }, /* Table of contents */
485 { "sdr1", 25 }, /* Storage Description Register 1 */
489 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
490 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
492 { "v.0", 0 }, /* Vector registers */
562 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
564 /* Given NAME, find the register number associated with that name, return
565 the integer value associated with the given name or -1 on failure. */
567 static int reg_name_search
568 PARAMS ((const struct pd_reg
*, int, const char * name
));
571 reg_name_search (regs
, regcount
, name
)
572 const struct pd_reg
*regs
;
576 int middle
, low
, high
;
584 middle
= (low
+ high
) / 2;
585 cmp
= strcasecmp (name
, regs
[middle
].name
);
591 return regs
[middle
].value
;
599 * Summary of register_name.
601 * in: Input_line_pointer points to 1st char of operand.
603 * out: A expressionS.
604 * The operand may have been a register: in this case, X_op == O_register,
605 * X_add_number is set to the register number, and truth is returned.
606 * Input_line_pointer->(next non-blank) char after operand, or is in its
611 register_name (expressionP
)
612 expressionS
*expressionP
;
619 /* Find the spelling of the operand. */
620 start
= name
= input_line_pointer
;
621 if (name
[0] == '%' && ISALPHA (name
[1]))
622 name
= ++input_line_pointer
;
624 else if (!reg_names_p
|| !ISALPHA (name
[0]))
627 c
= get_symbol_end ();
628 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
630 /* Put back the delimiting char. */
631 *input_line_pointer
= c
;
633 /* Look to see if it's in the register table. */
636 expressionP
->X_op
= O_register
;
637 expressionP
->X_add_number
= reg_number
;
639 /* Make the rest nice. */
640 expressionP
->X_add_symbol
= NULL
;
641 expressionP
->X_op_symbol
= NULL
;
645 /* Reset the line as if we had not done anything. */
646 input_line_pointer
= start
;
650 /* This function is called for each symbol seen in an expression. It
651 handles the special parsing which PowerPC assemblers are supposed
652 to use for condition codes. */
654 /* Whether to do the special parsing. */
655 static boolean cr_operand
;
657 /* Names to recognize in a condition code. This table is sorted. */
658 static const struct pd_reg cr_names
[] =
675 /* Parsing function. This returns non-zero if it recognized an
679 ppc_parse_name (name
, expr
)
688 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
693 expr
->X_op
= O_constant
;
694 expr
->X_add_number
= val
;
699 /* Local variables. */
701 /* The type of processor we are assembling for. This is one or more
702 of the PPC_OPCODE flags defined in opcode/ppc.h. */
703 static int ppc_cpu
= 0;
705 /* The size of the processor we are assembling for. This is either
706 PPC_OPCODE_32 or PPC_OPCODE_64. */
707 static unsigned long ppc_size
= PPC_OPCODE_32
;
709 /* Whether to target xcoff64. */
710 static int ppc_xcoff64
= 0;
712 /* Opcode hash table. */
713 static struct hash_control
*ppc_hash
;
715 /* Macro hash table. */
716 static struct hash_control
*ppc_macro_hash
;
719 /* What type of shared library support to use. */
720 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
722 /* Flags to set in the elf header. */
723 static flagword ppc_flags
= 0;
725 /* Whether this is Solaris or not. */
726 #ifdef TARGET_SOLARIS_COMMENT
727 #define SOLARIS_P true
729 #define SOLARIS_P false
732 static boolean msolaris
= SOLARIS_P
;
737 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
738 using a bunch of different sections. These assembler sections,
739 however, are all encompassed within the .text or .data sections of
740 the final output file. We handle this by using different
741 subsegments within these main segments. */
743 /* Next subsegment to allocate within the .text segment. */
744 static subsegT ppc_text_subsegment
= 2;
746 /* Linked list of csects in the text section. */
747 static symbolS
*ppc_text_csects
;
749 /* Next subsegment to allocate within the .data segment. */
750 static subsegT ppc_data_subsegment
= 2;
752 /* Linked list of csects in the data section. */
753 static symbolS
*ppc_data_csects
;
755 /* The current csect. */
756 static symbolS
*ppc_current_csect
;
758 /* The RS/6000 assembler uses a TOC which holds addresses of functions
759 and variables. Symbols are put in the TOC with the .tc pseudo-op.
760 A special relocation is used when accessing TOC entries. We handle
761 the TOC as a subsegment within the .data segment. We set it up if
762 we see a .toc pseudo-op, and save the csect symbol here. */
763 static symbolS
*ppc_toc_csect
;
765 /* The first frag in the TOC subsegment. */
766 static fragS
*ppc_toc_frag
;
768 /* The first frag in the first subsegment after the TOC in the .data
769 segment. NULL if there are no subsegments after the TOC. */
770 static fragS
*ppc_after_toc_frag
;
772 /* The current static block. */
773 static symbolS
*ppc_current_block
;
775 /* The COFF debugging section; set by md_begin. This is not the
776 .debug section, but is instead the secret BFD section which will
777 cause BFD to set the section number of a symbol to N_DEBUG. */
778 static asection
*ppc_coff_debug_section
;
780 #endif /* OBJ_XCOFF */
784 /* Various sections that we need for PE coff support. */
785 static segT ydata_section
;
786 static segT pdata_section
;
787 static segT reldata_section
;
788 static segT rdata_section
;
789 static segT tocdata_section
;
791 /* The current section and the previous section. See ppc_previous. */
792 static segT ppc_previous_section
;
793 static segT ppc_current_section
;
798 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
802 CONST
char *md_shortopts
= "b:l:usm:K:VQ:";
804 CONST
char *md_shortopts
= "um:";
806 struct option md_longopts
[] = {
807 {NULL
, no_argument
, NULL
, 0}
809 size_t md_longopts_size
= sizeof (md_longopts
);
812 md_parse_option (c
, arg
)
819 /* -u means that any undefined symbols should be treated as
820 external, which is the default for gas anyhow. */
825 /* Solaris as takes -le (presumably for little endian). For completeness
826 sake, recognize -be also. */
827 if (strcmp (arg
, "e") == 0)
829 target_big_endian
= 0;
830 set_target_endian
= 1;
838 if (strcmp (arg
, "e") == 0)
840 target_big_endian
= 1;
841 set_target_endian
= 1;
849 /* Recognize -K PIC. */
850 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
853 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
861 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
863 if (strcmp (arg
, "64") == 0)
865 else if (strcmp (arg
, "32") == 0)
872 /* Most CPU's are 32 bit. Exceptions are listed below. */
873 ppc_size
= PPC_OPCODE_32
;
875 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
877 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
878 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
879 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
880 else if (strcmp (arg
, "pwr") == 0)
881 ppc_cpu
= PPC_OPCODE_POWER
;
882 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
883 instructions that are holdovers from the Power. */
884 else if (strcmp (arg
, "601") == 0)
885 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
886 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
887 Motorola PowerPC 603/604. */
888 else if (strcmp (arg
, "ppc") == 0
889 || strcmp (arg
, "ppc32") == 0
890 || strcmp (arg
, "403") == 0
891 || strcmp (arg
, "405") == 0
892 || strcmp (arg
, "603") == 0
893 || strcmp (arg
, "604") == 0)
894 ppc_cpu
= PPC_OPCODE_PPC
;
895 else if (strcmp (arg
, "7400") == 0)
896 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
;
897 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
899 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
901 ppc_cpu
= PPC_OPCODE_PPC
;
902 ppc_size
= PPC_OPCODE_64
;
904 else if (strcmp (arg
, "ppc64bridge") == 0)
906 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_64_BRIDGE
;
907 ppc_size
= PPC_OPCODE_64
;
909 /* -mcom means assemble for the common intersection between Power
910 and PowerPC. At present, we just allow the union, rather
911 than the intersection. */
912 else if (strcmp (arg
, "com") == 0)
913 ppc_cpu
= PPC_OPCODE_COMMON
;
914 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
915 else if (strcmp (arg
, "any") == 0)
916 ppc_cpu
= PPC_OPCODE_ANY
;
918 else if (strcmp (arg
, "regnames") == 0)
921 else if (strcmp (arg
, "no-regnames") == 0)
925 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
926 that require relocation. */
927 else if (strcmp (arg
, "relocatable") == 0)
929 shlib
= SHLIB_MRELOCATABLE
;
930 ppc_flags
|= EF_PPC_RELOCATABLE
;
933 else if (strcmp (arg
, "relocatable-lib") == 0)
935 shlib
= SHLIB_MRELOCATABLE
;
936 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
939 /* -memb, set embedded bit. */
940 else if (strcmp (arg
, "emb") == 0)
941 ppc_flags
|= EF_PPC_EMB
;
943 /* -mlittle/-mbig set the endianess. */
944 else if (strcmp (arg
, "little") == 0
945 || strcmp (arg
, "little-endian") == 0)
947 target_big_endian
= 0;
948 set_target_endian
= 1;
951 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
953 target_big_endian
= 1;
954 set_target_endian
= 1;
957 else if (strcmp (arg
, "solaris") == 0)
960 ppc_comment_chars
= ppc_solaris_comment_chars
;
963 else if (strcmp (arg
, "no-solaris") == 0)
966 ppc_comment_chars
= ppc_eabi_comment_chars
;
971 as_bad (_("invalid switch -m%s"), arg
);
977 /* -V: SVR4 argument to print version ID. */
982 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
983 should be emitted or not. FIXME: Not implemented. */
987 /* Solaris takes -s to specify that .stabs go in a .stabs section,
988 rather than .stabs.excl, which is ignored by the linker.
989 FIXME: Not implemented. */
1005 md_show_usage (stream
)
1008 fprintf (stream
, _("\
1011 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
1012 -mpwr generate code for IBM POWER (RIOS1)\n\
1013 -m601 generate code for Motorola PowerPC 601\n\
1014 -mppc, -mppc32, -m403, -m405, -m603, -m604\n\
1015 generate code for Motorola PowerPC 603/604\n\
1016 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
1017 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1018 -mcom generate code Power/PowerPC common instructions\n\
1019 -many generate code for any architecture (PWR/PWRX/PPC)\n\
1020 -mregnames Allow symbolic names for registers\n\
1021 -mno-regnames Do not allow symbolic names for registers\n"));
1023 fprintf (stream
, _("\
1024 -mrelocatable support for GCC's -mrelocatble option\n\
1025 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1026 -memb set PPC_EMB bit in ELF flags\n\
1027 -mlittle, -mlittle-endian\n\
1028 generate code for a little endian machine\n\
1029 -mbig, -mbig-endian generate code for a big endian machine\n\
1030 -msolaris generate code for Solaris\n\
1031 -mno-solaris do not generate code for Solaris\n\
1032 -V print assembler version number\n\
1033 -Qy, -Qn ignored\n"));
1037 /* Set ppc_cpu if it is not already set. */
1042 const char *default_os
= TARGET_OS
;
1043 const char *default_cpu
= TARGET_CPU
;
1047 if (strncmp (default_os
, "aix", 3) == 0
1048 && default_os
[3] >= '4' && default_os
[3] <= '9')
1049 ppc_cpu
= PPC_OPCODE_COMMON
;
1050 else if (strncmp (default_os
, "aix3", 4) == 0)
1051 ppc_cpu
= PPC_OPCODE_POWER
;
1052 else if (strcmp (default_cpu
, "rs6000") == 0)
1053 ppc_cpu
= PPC_OPCODE_POWER
;
1054 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1055 ppc_cpu
= PPC_OPCODE_PPC
;
1057 as_fatal (_("Unknown default cpu = %s, os = %s"),
1058 default_cpu
, default_os
);
1062 /* Figure out the BFD architecture to use. */
1064 enum bfd_architecture
1067 const char *default_cpu
= TARGET_CPU
;
1070 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1071 return bfd_arch_powerpc
;
1072 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1073 return bfd_arch_rs6000
;
1074 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1076 if (strcmp (default_cpu
, "rs6000") == 0)
1077 return bfd_arch_rs6000
;
1078 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1079 return bfd_arch_powerpc
;
1082 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1083 return bfd_arch_unknown
;
1089 return ppc_size
== PPC_OPCODE_64
? 620 : 0;
1096 return ppc_xcoff64
? 3 : 2;
1101 ppc_target_format ()
1105 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1107 return "xcoff-powermac";
1109 return ppc_xcoff64
? "aixcoff64-rs6000" : "aixcoff-rs6000";
1113 return (target_big_endian
1114 ? (BFD_DEFAULT_TARGET_SIZE
== 64 ? "elf64-powerpc" : "elf32-powerpc")
1115 : (BFD_DEFAULT_TARGET_SIZE
== 64 ? "elf64-powerpcle" : "elf32-powerpcle"));
1119 /* This function is called when the assembler starts up. It is called
1120 after the options have been parsed and the output file has been
1126 register const struct powerpc_opcode
*op
;
1127 const struct powerpc_opcode
*op_end
;
1128 const struct powerpc_macro
*macro
;
1129 const struct powerpc_macro
*macro_end
;
1130 boolean dup_insn
= false;
1135 /* If we're going to generate a 64-bit ABI file, then we need
1136 the 64-bit capable instructions. */
1137 if (BFD_DEFAULT_TARGET_SIZE
== 64)
1138 ppc_size
= PPC_OPCODE_64
;
1140 /* Set the ELF flags if desired. */
1141 if (ppc_flags
&& !msolaris
)
1142 bfd_set_private_flags (stdoutput
, ppc_flags
);
1145 /* Insert the opcodes into a hash table. */
1146 ppc_hash
= hash_new ();
1148 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1149 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1151 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1153 if ((op
->flags
& ppc_cpu
) != 0
1154 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1155 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
1156 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0))
1160 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1161 if (retval
!= (const char *) NULL
)
1163 /* Ignore Power duplicates for -m601. */
1164 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1165 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1168 as_bad (_("Internal assembler error for instruction %s"),
1175 /* Insert the macros into a hash table. */
1176 ppc_macro_hash
= hash_new ();
1178 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1179 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1181 if ((macro
->flags
& ppc_cpu
) != 0)
1185 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1186 if (retval
!= (const char *) NULL
)
1188 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1197 /* Tell the main code what the endianness is if it is not overidden
1199 if (!set_target_endian
)
1201 set_target_endian
= 1;
1202 target_big_endian
= PPC_BIG_ENDIAN
;
1206 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1208 /* Create dummy symbols to serve as initial csects. This forces the
1209 text csects to precede the data csects. These symbols will not
1211 ppc_text_csects
= symbol_make ("dummy\001");
1212 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1213 ppc_data_csects
= symbol_make ("dummy\001");
1214 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1219 ppc_current_section
= text_section
;
1220 ppc_previous_section
= 0;
1225 /* Insert an operand value into an instruction. */
1227 static unsigned long
1228 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1230 const struct powerpc_operand
*operand
;
1235 if (operand
->bits
!= 32)
1240 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1242 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1243 max
= (1 << operand
->bits
) - 1;
1245 max
= (1 << (operand
->bits
- 1)) - 1;
1246 min
= - (1 << (operand
->bits
- 1));
1248 if (ppc_size
== PPC_OPCODE_32
)
1250 /* Some people write 32 bit hex constants with the sign
1251 extension done by hand. This shouldn't really be
1252 valid, but, to permit this code to assemble on a 64
1253 bit host, we sign extend the 32 bit value. */
1255 && (val
& (offsetT
) 0x80000000) != 0
1256 && (val
& (offsetT
) 0xffffffff) == val
)
1265 max
= (1 << operand
->bits
) - 1;
1269 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1274 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1277 _("operand out of range (%s not between %ld and %ld)");
1280 sprint_value (buf
, test
);
1281 as_bad_where (file
, line
, err
, buf
, min
, max
);
1285 if (operand
->insert
)
1290 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1291 if (errmsg
!= (const char *) NULL
)
1292 as_bad_where (file
, line
, errmsg
);
1295 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1303 /* Parse @got, etc. and return the desired relocation. */
1304 static bfd_reloc_code_real_type
1305 ppc_elf_suffix (str_p
, exp_p
)
1312 bfd_reloc_code_real_type reloc
;
1320 struct map_bfd
*ptr
;
1322 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1324 static struct map_bfd mapping
[] = {
1325 MAP ("l", BFD_RELOC_LO16
),
1326 MAP ("h", BFD_RELOC_HI16
),
1327 MAP ("ha", BFD_RELOC_HI16_S
),
1328 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1329 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1330 MAP ("got", BFD_RELOC_16_GOTOFF
),
1331 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1332 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1333 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1334 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1335 MAP ("plt", BFD_RELOC_24_PLT_PCREL
),
1336 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1337 MAP ("copy", BFD_RELOC_PPC_COPY
),
1338 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1339 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1340 MAP ("local", BFD_RELOC_PPC_LOCAL24PC
),
1341 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1342 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1343 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1344 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1345 MAP ("sdarel", BFD_RELOC_GPREL16
),
1346 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1347 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1348 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1349 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1350 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1351 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1352 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1353 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1354 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1355 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1356 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1357 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1358 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1359 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1360 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1361 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1362 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1363 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1364 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1365 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1366 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1367 #if BFD_DEFAULT_TARGET_SIZE == 64
1368 MAP ("higher", BFD_RELOC_PPC64_HIGHER
),
1369 MAP ("highera", BFD_RELOC_PPC64_HIGHER_S
),
1370 MAP ("highest", BFD_RELOC_PPC64_HIGHEST
),
1371 MAP ("highesta", BFD_RELOC_PPC64_HIGHEST_S
),
1372 MAP ("tocbase", BFD_RELOC_PPC64_TOC
),
1373 MAP ("toc", BFD_RELOC_PPC_TOC16
),
1374 MAP ("toc@l", BFD_RELOC_PPC64_TOC16_LO
),
1375 MAP ("toc@h", BFD_RELOC_PPC64_TOC16_HI
),
1376 MAP ("toc@ha", BFD_RELOC_PPC64_TOC16_HA
),
1378 { (char *) 0, 0, BFD_RELOC_UNUSED
}
1382 return BFD_RELOC_UNUSED
;
1384 for (ch
= *str
, str2
= ident
;
1385 (str2
< ident
+ sizeof (ident
) - 1
1386 && (ISALNUM (ch
) || ch
== '@'));
1389 *str2
++ = TOLOWER (ch
);
1396 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1397 if (ch
== ptr
->string
[0]
1398 && len
== ptr
->length
1399 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1401 if (exp_p
->X_add_number
!= 0
1402 && (ptr
->reloc
== BFD_RELOC_16_GOTOFF
1403 || ptr
->reloc
== BFD_RELOC_LO16_GOTOFF
1404 || ptr
->reloc
== BFD_RELOC_HI16_GOTOFF
1405 || ptr
->reloc
== BFD_RELOC_HI16_S_GOTOFF
))
1406 as_warn (_("identifier+constant@got means identifier@got+constant"));
1408 /* Now check for identifier@suffix+constant. */
1409 if (*str
== '-' || *str
== '+')
1411 char *orig_line
= input_line_pointer
;
1412 expressionS new_exp
;
1414 input_line_pointer
= str
;
1415 expression (&new_exp
);
1416 if (new_exp
.X_op
== O_constant
)
1418 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1419 str
= input_line_pointer
;
1422 if (&input_line_pointer
!= str_p
)
1423 input_line_pointer
= orig_line
;
1427 if (BFD_DEFAULT_TARGET_SIZE
== 64
1428 && ptr
->reloc
== BFD_RELOC_PPC64_TOC
1429 && exp_p
->X_op
== O_symbol
)
1431 /* This reloc type ignores the symbol. Change the symbol
1432 so that the dummy .TOC. symbol can be omitted from the
1434 exp_p
->X_add_symbol
= &abs_symbol
;
1440 return BFD_RELOC_UNUSED
;
1443 /* Like normal .long/.short/.word, except support @got, etc.
1444 Clobbers input_line_pointer, checks end-of-line. */
1446 ppc_elf_cons (nbytes
)
1447 register int nbytes
; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1450 bfd_reloc_code_real_type reloc
;
1452 if (is_it_end_of_statement ())
1454 demand_empty_rest_of_line ();
1461 if (exp
.X_op
== O_symbol
1462 && *input_line_pointer
== '@'
1463 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1464 &exp
)) != BFD_RELOC_UNUSED
)
1466 reloc_howto_type
*reloc_howto
;
1469 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1470 size
= bfd_get_reloc_size (reloc_howto
);
1474 as_bad (_("%s relocations do not fit in %d bytes\n"),
1475 reloc_howto
->name
, nbytes
);
1482 p
= frag_more (nbytes
);
1484 if (target_big_endian
)
1485 offset
= nbytes
- size
;
1486 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1491 emit_expr (&exp
, (unsigned int) nbytes
);
1493 while (*input_line_pointer
++ == ',');
1495 /* Put terminator back into stream. */
1496 input_line_pointer
--;
1497 demand_empty_rest_of_line ();
1500 /* Solaris pseduo op to change to the .rodata section. */
1505 char *save_line
= input_line_pointer
;
1506 static char section
[] = ".rodata\n";
1508 /* Just pretend this is .section .rodata */
1509 input_line_pointer
= section
;
1510 obj_elf_section (xxx
);
1512 input_line_pointer
= save_line
;
1515 /* Pseudo op to make file scope bss items. */
1518 int xxx ATTRIBUTE_UNUSED
;
1520 register char *name
;
1524 register symbolS
*symbolP
;
1531 name
= input_line_pointer
;
1532 c
= get_symbol_end ();
1534 /* just after name is now '\0'. */
1535 p
= input_line_pointer
;
1538 if (*input_line_pointer
!= ',')
1540 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1541 ignore_rest_of_line ();
1545 input_line_pointer
++; /* skip ',' */
1546 if ((size
= get_absolute_expression ()) < 0)
1548 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1549 ignore_rest_of_line ();
1553 /* The third argument to .lcomm is the alignment. */
1554 if (*input_line_pointer
!= ',')
1558 ++input_line_pointer
;
1559 align
= get_absolute_expression ();
1562 as_warn (_("ignoring bad alignment"));
1568 symbolP
= symbol_find_or_make (name
);
1571 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1573 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1574 S_GET_NAME (symbolP
));
1575 ignore_rest_of_line ();
1579 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1581 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1582 S_GET_NAME (symbolP
),
1583 (long) S_GET_VALUE (symbolP
),
1586 ignore_rest_of_line ();
1592 old_subsec
= now_subseg
;
1595 /* Convert to a power of 2 alignment. */
1596 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1599 as_bad (_("Common alignment not a power of 2"));
1600 ignore_rest_of_line ();
1607 record_alignment (bss_section
, align2
);
1608 subseg_set (bss_section
, 0);
1610 frag_align (align2
, 0, 0);
1611 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1612 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1613 symbol_set_frag (symbolP
, frag_now
);
1614 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1617 S_SET_SIZE (symbolP
, size
);
1618 S_SET_SEGMENT (symbolP
, bss_section
);
1619 subseg_set (old_sec
, old_subsec
);
1620 demand_empty_rest_of_line ();
1623 /* Validate any relocations emitted for -mrelocatable, possibly adding
1624 fixups for word relocations in writable segments, so we can adjust
1627 ppc_elf_validate_fix (fixp
, seg
)
1631 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1640 case SHLIB_MRELOCATABLE
:
1641 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1642 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1643 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1644 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1645 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1646 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1647 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1648 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1649 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1650 && (seg
->flags
& SEC_LOAD
) != 0
1651 && strcmp (segment_name (seg
), ".got2") != 0
1652 && strcmp (segment_name (seg
), ".dtors") != 0
1653 && strcmp (segment_name (seg
), ".ctors") != 0
1654 && strcmp (segment_name (seg
), ".fixup") != 0
1655 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1656 && strcmp (segment_name (seg
), ".eh_frame") != 0
1657 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1659 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1660 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1662 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1663 _("Relocation cannot be done when using -mrelocatable"));
1670 #if BFD_DEFAULT_TARGET_SIZE == 64
1671 /* Don't emit .TOC. symbol. */
1673 ppc_elf_frob_symbol (sym
)
1678 name
= S_GET_NAME (sym
);
1679 if (name
!= NULL
&& strcmp (name
, ".TOC.") == 0)
1681 S_CLEAR_EXTERNAL (sym
);
1688 #endif /* OBJ_ELF */
1693 * Summary of parse_toc_entry.
1695 * in: Input_line_pointer points to the '[' in one of:
1697 * [toc] [tocv] [toc32] [toc64]
1699 * Anything else is an error of one kind or another.
1702 * return value: success or failure
1703 * toc_kind: kind of toc reference
1704 * input_line_pointer:
1705 * success: first char after the ']'
1706 * failure: unchanged
1710 * [toc] - rv == success, toc_kind = default_toc
1711 * [tocv] - rv == success, toc_kind = data_in_toc
1712 * [toc32] - rv == success, toc_kind = must_be_32
1713 * [toc64] - rv == success, toc_kind = must_be_64
1717 enum toc_size_qualifier
1719 default_toc
, /* The toc cell constructed should be the system default size */
1720 data_in_toc
, /* This is a direct reference to a toc cell */
1721 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1722 must_be_64
/* The toc cell constructed must be 64 bits wide */
1726 parse_toc_entry (toc_kind
)
1727 enum toc_size_qualifier
*toc_kind
;
1732 enum toc_size_qualifier t
;
1734 /* Save the input_line_pointer. */
1735 start
= input_line_pointer
;
1737 /* Skip over the '[' , and whitespace. */
1738 ++input_line_pointer
;
1741 /* Find the spelling of the operand. */
1742 toc_spec
= input_line_pointer
;
1743 c
= get_symbol_end ();
1745 if (strcmp (toc_spec
, "toc") == 0)
1749 else if (strcmp (toc_spec
, "tocv") == 0)
1753 else if (strcmp (toc_spec
, "toc32") == 0)
1757 else if (strcmp (toc_spec
, "toc64") == 0)
1763 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1764 *input_line_pointer
= c
;
1765 input_line_pointer
= start
;
1769 /* Now find the ']'. */
1770 *input_line_pointer
= c
;
1772 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1773 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1777 as_bad (_("syntax error: expected `]', found `%c'"), c
);
1778 input_line_pointer
= start
;
1788 /* We need to keep a list of fixups. We can't simply generate them as
1789 we go, because that would require us to first create the frag, and
1790 that would screw up references to ``.''. */
1796 bfd_reloc_code_real_type reloc
;
1799 #define MAX_INSN_FIXUPS (5)
1801 /* This routine is called for each instruction to be assembled. */
1808 const struct powerpc_opcode
*opcode
;
1810 const unsigned char *opindex_ptr
;
1814 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1819 bfd_reloc_code_real_type reloc
;
1822 /* Get the opcode. */
1823 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1828 /* Look up the opcode in the hash table. */
1829 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1830 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1832 const struct powerpc_macro
*macro
;
1834 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1835 if (macro
== (const struct powerpc_macro
*) NULL
)
1836 as_bad (_("Unrecognized opcode: `%s'"), str
);
1838 ppc_macro (s
, macro
);
1843 insn
= opcode
->opcode
;
1846 while (ISSPACE (*str
))
1849 /* PowerPC operands are just expressions. The only real issue is
1850 that a few operand types are optional. All cases which might use
1851 an optional operand separate the operands only with commas (in
1852 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1853 cases never have optional operands). There is never more than
1854 one optional operand for an instruction. So, before we start
1855 seriously parsing the operands, we check to see if we have an
1856 optional operand, and, if we do, we count the number of commas to
1857 see whether the operand should be omitted. */
1859 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1861 const struct powerpc_operand
*operand
;
1863 operand
= &powerpc_operands
[*opindex_ptr
];
1864 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1866 unsigned int opcount
;
1868 /* There is an optional operand. Count the number of
1869 commas in the input line. */
1876 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1883 /* If there are fewer operands in the line then are called
1884 for by the instruction, we want to skip the optional
1886 if (opcount
< strlen (opcode
->operands
))
1893 /* Gather the operands. */
1897 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1899 const struct powerpc_operand
*operand
;
1905 if (next_opindex
== 0)
1906 operand
= &powerpc_operands
[*opindex_ptr
];
1909 operand
= &powerpc_operands
[next_opindex
];
1915 /* If this is a fake operand, then we do not expect anything
1917 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1919 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1920 if (errmsg
!= (const char *) NULL
)
1925 /* If this is an optional operand, and we are skipping it, just
1927 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1930 if (operand
->insert
)
1932 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1933 if (errmsg
!= (const char *) NULL
)
1936 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1937 next_opindex
= *opindex_ptr
+ 1;
1941 /* Gather the operand. */
1942 hold
= input_line_pointer
;
1943 input_line_pointer
= str
;
1946 if (*input_line_pointer
== '[')
1948 /* We are expecting something like the second argument here:
1950 * lwz r4,[toc].GS.0.static_int(rtoc)
1951 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1952 * The argument following the `]' must be a symbol name, and the
1953 * register must be the toc register: 'rtoc' or '2'
1955 * The effect is to 0 as the displacement field
1956 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1957 * the appropriate variation) reloc against it based on the symbol.
1958 * The linker will build the toc, and insert the resolved toc offset.
1961 * o The size of the toc entry is currently assumed to be
1962 * 32 bits. This should not be assumed to be a hard coded
1964 * o In an effort to cope with a change from 32 to 64 bits,
1965 * there are also toc entries that are specified to be
1966 * either 32 or 64 bits:
1967 * lwz r4,[toc32].GS.0.static_int(rtoc)
1968 * lwz r4,[toc64].GS.0.static_int(rtoc)
1969 * These demand toc entries of the specified size, and the
1970 * instruction probably requires it.
1974 enum toc_size_qualifier toc_kind
;
1975 bfd_reloc_code_real_type toc_reloc
;
1977 /* Go parse off the [tocXX] part. */
1978 valid_toc
= parse_toc_entry (&toc_kind
);
1982 /* Note: message has already been issued.
1983 FIXME: what sort of recovery should we do?
1984 demand_rest_of_line (); return; ? */
1987 /* Now get the symbol following the ']'. */
1993 /* In this case, we may not have seen the symbol yet,
1994 since it is allowed to appear on a .extern or .globl
1995 or just be a label in the .data section. */
1996 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1999 /* 1. The symbol must be defined and either in the toc
2000 section, or a global.
2001 2. The reloc generated must have the TOCDEFN flag set
2002 in upper bit mess of the reloc type.
2003 FIXME: It's a little confusing what the tocv
2004 qualifier can be used for. At the very least, I've
2005 seen three uses, only one of which I'm sure I can
2007 if (ex
.X_op
== O_symbol
)
2009 assert (ex
.X_add_symbol
!= NULL
);
2010 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2013 as_bad (_("[tocv] symbol is not a toc symbol"));
2017 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2020 /* FIXME: these next two specifically specify 32/64 bit
2021 toc entries. We don't support them today. Is this
2022 the right way to say that? */
2023 toc_reloc
= BFD_RELOC_UNUSED
;
2024 as_bad (_("Unimplemented toc32 expression modifier"));
2027 /* FIXME: see above. */
2028 toc_reloc
= BFD_RELOC_UNUSED
;
2029 as_bad (_("Unimplemented toc64 expression modifier"));
2033 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2039 /* We need to generate a fixup for this expression. */
2040 if (fc
>= MAX_INSN_FIXUPS
)
2041 as_fatal (_("too many fixups"));
2043 fixups
[fc
].reloc
= toc_reloc
;
2044 fixups
[fc
].exp
= ex
;
2045 fixups
[fc
].opindex
= *opindex_ptr
;
2048 /* Ok. We've set up the fixup for the instruction. Now make it
2049 look like the constant 0 was found here. */
2051 ex
.X_op
= O_constant
;
2052 ex
.X_add_number
= 0;
2053 ex
.X_add_symbol
= NULL
;
2054 ex
.X_op_symbol
= NULL
;
2060 if (! register_name (&ex
))
2062 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
2069 str
= input_line_pointer
;
2070 input_line_pointer
= hold
;
2072 if (ex
.X_op
== O_illegal
)
2073 as_bad (_("illegal operand"));
2074 else if (ex
.X_op
== O_absent
)
2075 as_bad (_("missing operand"));
2076 else if (ex
.X_op
== O_register
)
2078 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2081 else if (ex
.X_op
== O_constant
)
2084 /* Allow @HA, @L, @H on constants. */
2085 char *orig_str
= str
;
2087 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2094 case BFD_RELOC_LO16
:
2095 /* X_unsigned is the default, so if the user has done
2096 something which cleared it, we always produce a
2098 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2099 ex
.X_add_number
&= 0xffff;
2101 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2104 case BFD_RELOC_HI16
:
2105 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2106 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2108 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2111 case BFD_RELOC_HI16_S
:
2112 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2113 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2115 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2118 #if BFD_DEFAULT_TARGET_SIZE == 64
2119 case BFD_RELOC_PPC64_HIGHER
:
2120 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2121 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2123 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2126 case BFD_RELOC_PPC64_HIGHER_S
:
2127 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2128 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2130 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2133 case BFD_RELOC_PPC64_HIGHEST
:
2134 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2135 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2137 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2140 case BFD_RELOC_PPC64_HIGHEST_S
:
2141 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2142 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2144 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2146 #endif /* BFD_DEFAULT_TARGET_SIZE == 64 */
2148 #endif /* OBJ_ELF */
2149 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2153 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2155 /* For the absolute forms of branches, convert the PC
2156 relative form back into the absolute. */
2157 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2161 case BFD_RELOC_PPC_B26
:
2162 reloc
= BFD_RELOC_PPC_BA26
;
2164 case BFD_RELOC_PPC_B16
:
2165 reloc
= BFD_RELOC_PPC_BA16
;
2167 case BFD_RELOC_PPC_B16_BRTAKEN
:
2168 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2170 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2171 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2178 if (BFD_DEFAULT_TARGET_SIZE
== 64
2179 && ppc_size
== PPC_OPCODE_64
2180 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
2185 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
2187 case BFD_RELOC_LO16
:
2188 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
2190 case BFD_RELOC_16_GOTOFF
:
2191 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
2193 case BFD_RELOC_LO16_GOTOFF
:
2194 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
2196 case BFD_RELOC_LO16_PLTOFF
:
2197 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
2199 case BFD_RELOC_32_BASEREL
:
2200 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
2202 case BFD_RELOC_LO16_BASEREL
:
2203 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
2205 case BFD_RELOC_PPC_TOC16
:
2206 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
2208 case BFD_RELOC_PPC64_TOC16_LO
:
2209 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
2211 case BFD_RELOC_PPC64_PLTGOT16
:
2212 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
2214 case BFD_RELOC_PPC64_PLTGOT16_LO
:
2215 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
2218 as_bad (_("unsupported relocation for DS offset field"));
2223 /* We need to generate a fixup for this expression. */
2224 if (fc
>= MAX_INSN_FIXUPS
)
2225 as_fatal (_("too many fixups"));
2226 fixups
[fc
].exp
= ex
;
2227 fixups
[fc
].opindex
= 0;
2228 fixups
[fc
].reloc
= reloc
;
2231 #endif /* OBJ_ELF */
2235 /* We need to generate a fixup for this expression. */
2236 if (fc
>= MAX_INSN_FIXUPS
)
2237 as_fatal (_("too many fixups"));
2238 fixups
[fc
].exp
= ex
;
2239 fixups
[fc
].opindex
= *opindex_ptr
;
2240 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2249 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2257 /* The call to expression should have advanced str past any
2260 && (endc
!= ',' || *str
!= '\0'))
2262 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2270 while (ISSPACE (*str
))
2274 as_bad (_("junk at end of line: `%s'"), str
);
2276 /* Write out the instruction. */
2278 md_number_to_chars (f
, insn
, 4);
2281 dwarf2_emit_insn (4);
2284 /* Create any fixups. At this point we do not use a
2285 bfd_reloc_code_real_type, but instead just use the
2286 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2287 handle fixups for any operand type, although that is admittedly
2288 not a very exciting feature. We pick a BFD reloc type in
2290 for (i
= 0; i
< fc
; i
++)
2292 const struct powerpc_operand
*operand
;
2294 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2295 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2297 reloc_howto_type
*reloc_howto
;
2302 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2306 size
= bfd_get_reloc_size (reloc_howto
);
2307 offset
= target_big_endian
? (4 - size
) : 0;
2309 if (size
< 1 || size
> 4)
2312 fixP
= fix_new_exp (frag_now
,
2313 f
- frag_now
->fr_literal
+ offset
,
2316 reloc_howto
->pc_relative
,
2319 /* Turn off complaints that the addend is too large for things like
2321 switch (fixups
[i
].reloc
)
2323 case BFD_RELOC_16_GOTOFF
:
2324 case BFD_RELOC_PPC_TOC16
:
2325 case BFD_RELOC_LO16
:
2326 case BFD_RELOC_HI16
:
2327 case BFD_RELOC_HI16_S
:
2329 #if BFD_DEFAULT_TARGET_SIZE == 64
2330 case BFD_RELOC_PPC64_HIGHER
:
2331 case BFD_RELOC_PPC64_HIGHER_S
:
2332 case BFD_RELOC_PPC64_HIGHEST
:
2333 case BFD_RELOC_PPC64_HIGHEST_S
:
2336 fixP
->fx_no_overflow
= 1;
2343 fix_new_exp (frag_now
,
2344 f
- frag_now
->fr_literal
,
2347 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2348 ((bfd_reloc_code_real_type
)
2349 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2353 /* Handle a macro. Gather all the operands, transform them as
2354 described by the macro, and call md_assemble recursively. All the
2355 operands are separated by commas; we don't accept parentheses
2356 around operands here. */
2359 ppc_macro (str
, macro
)
2361 const struct powerpc_macro
*macro
;
2372 /* Gather the users operands into the operands array. */
2377 if (count
>= sizeof operands
/ sizeof operands
[0])
2379 operands
[count
++] = s
;
2380 s
= strchr (s
, ',');
2381 if (s
== (char *) NULL
)
2386 if (count
!= macro
->operands
)
2388 as_bad (_("wrong number of operands"));
2392 /* Work out how large the string must be (the size is unbounded
2393 because it includes user input). */
2395 format
= macro
->format
;
2396 while (*format
!= '\0')
2405 arg
= strtol (format
+ 1, &send
, 10);
2406 know (send
!= format
&& arg
>= 0 && arg
< count
);
2407 len
+= strlen (operands
[arg
]);
2412 /* Put the string together. */
2413 complete
= s
= (char *) alloca (len
+ 1);
2414 format
= macro
->format
;
2415 while (*format
!= '\0')
2421 arg
= strtol (format
+ 1, &send
, 10);
2422 strcpy (s
, operands
[arg
]);
2429 /* Assemble the constructed instruction. */
2430 md_assemble (complete
);
2434 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2437 ppc_section_letter (letter
, ptr_msg
)
2444 *ptr_msg
= _("Bad .section directive: want a,e,w,x,M,S in string");
2449 ppc_section_word (str
, len
)
2453 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2460 ppc_section_type (str
, len
)
2464 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2471 ppc_section_flags (flags
, attr
, type
)
2476 if (type
== SHT_ORDERED
)
2477 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2479 if (attr
& SHF_EXCLUDE
)
2480 flags
|= SEC_EXCLUDE
;
2484 #endif /* OBJ_ELF */
2487 /* Pseudo-op handling. */
2489 /* The .byte pseudo-op. This is similar to the normal .byte
2490 pseudo-op, but it can also take a single ASCII string. */
2494 int ignore ATTRIBUTE_UNUSED
;
2496 if (*input_line_pointer
!= '\"')
2502 /* Gather characters. A real double quote is doubled. Unusual
2503 characters are not permitted. */
2504 ++input_line_pointer
;
2509 c
= *input_line_pointer
++;
2513 if (*input_line_pointer
!= '\"')
2515 ++input_line_pointer
;
2518 FRAG_APPEND_1_CHAR (c
);
2521 demand_empty_rest_of_line ();
2526 /* XCOFF specific pseudo-op handling. */
2528 /* This is set if we are creating a .stabx symbol, since we don't want
2529 to handle symbol suffixes for such symbols. */
2530 static boolean ppc_stab_symbol
;
2532 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2533 symbols in the .bss segment as though they were local common
2534 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2535 aligns .comm and .lcomm to 4 bytes. */
2541 asection
*current_seg
= now_seg
;
2542 subsegT current_subseg
= now_subseg
;
2548 symbolS
*lcomm_sym
= NULL
;
2552 name
= input_line_pointer
;
2553 endc
= get_symbol_end ();
2554 end_name
= input_line_pointer
;
2557 if (*input_line_pointer
!= ',')
2559 as_bad (_("missing size"));
2560 ignore_rest_of_line ();
2563 ++input_line_pointer
;
2565 size
= get_absolute_expression ();
2568 as_bad (_("negative size"));
2569 ignore_rest_of_line ();
2575 /* The third argument to .comm is the alignment. */
2576 if (*input_line_pointer
!= ',')
2580 ++input_line_pointer
;
2581 align
= get_absolute_expression ();
2584 as_warn (_("ignoring bad alignment"));
2599 /* The third argument to .lcomm appears to be the real local
2600 common symbol to create. References to the symbol named in
2601 the first argument are turned into references to the third
2603 if (*input_line_pointer
!= ',')
2605 as_bad (_("missing real symbol name"));
2606 ignore_rest_of_line ();
2609 ++input_line_pointer
;
2611 lcomm_name
= input_line_pointer
;
2612 lcomm_endc
= get_symbol_end ();
2614 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2616 *input_line_pointer
= lcomm_endc
;
2620 sym
= symbol_find_or_make (name
);
2623 if (S_IS_DEFINED (sym
)
2624 || S_GET_VALUE (sym
) != 0)
2626 as_bad (_("attempt to redefine symbol"));
2627 ignore_rest_of_line ();
2631 record_alignment (bss_section
, align
);
2634 || ! S_IS_DEFINED (lcomm_sym
))
2643 S_SET_EXTERNAL (sym
);
2647 symbol_get_tc (lcomm_sym
)->output
= 1;
2648 def_sym
= lcomm_sym
;
2652 subseg_set (bss_section
, 1);
2653 frag_align (align
, 0, 0);
2655 symbol_set_frag (def_sym
, frag_now
);
2656 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2657 def_size
, (char *) NULL
);
2659 S_SET_SEGMENT (def_sym
, bss_section
);
2660 symbol_get_tc (def_sym
)->align
= align
;
2664 /* Align the size of lcomm_sym. */
2665 symbol_get_frag (lcomm_sym
)->fr_offset
=
2666 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
2667 &~ ((1 << align
) - 1));
2668 if (align
> symbol_get_tc (lcomm_sym
)->align
)
2669 symbol_get_tc (lcomm_sym
)->align
= align
;
2674 /* Make sym an offset from lcomm_sym. */
2675 S_SET_SEGMENT (sym
, bss_section
);
2676 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
2677 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
2678 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
2681 subseg_set (current_seg
, current_subseg
);
2683 demand_empty_rest_of_line ();
2686 /* The .csect pseudo-op. This switches us into a different
2687 subsegment. The first argument is a symbol whose value is the
2688 start of the .csect. In COFF, csect symbols get special aux
2689 entries defined by the x_csect field of union internal_auxent. The
2690 optional second argument is the alignment (the default is 2). */
2694 int ignore ATTRIBUTE_UNUSED
;
2700 name
= input_line_pointer
;
2701 endc
= get_symbol_end ();
2703 sym
= symbol_find_or_make (name
);
2705 *input_line_pointer
= endc
;
2707 if (S_GET_NAME (sym
)[0] == '\0')
2709 /* An unnamed csect is assumed to be [PR]. */
2710 symbol_get_tc (sym
)->class = XMC_PR
;
2713 ppc_change_csect (sym
);
2715 if (*input_line_pointer
== ',')
2717 ++input_line_pointer
;
2718 symbol_get_tc (sym
)->align
= get_absolute_expression ();
2721 demand_empty_rest_of_line ();
2724 /* Change to a different csect. */
2727 ppc_change_csect (sym
)
2730 if (S_IS_DEFINED (sym
))
2731 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
2739 /* This is a new csect. We need to look at the symbol class to
2740 figure out whether it should go in the text section or the
2743 switch (symbol_get_tc (sym
)->class)
2753 S_SET_SEGMENT (sym
, text_section
);
2754 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
2755 ++ppc_text_subsegment
;
2756 list_ptr
= &ppc_text_csects
;
2765 if (ppc_toc_csect
!= NULL
2766 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
2767 == ppc_data_subsegment
))
2769 S_SET_SEGMENT (sym
, data_section
);
2770 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
2771 ++ppc_data_subsegment
;
2772 list_ptr
= &ppc_data_csects
;
2778 /* We set the obstack chunk size to a small value before
2779 changing subsegments, so that we don't use a lot of memory
2780 space for what may be a small section. */
2781 hold_chunksize
= chunksize
;
2784 subseg_new (segment_name (S_GET_SEGMENT (sym
)),
2785 symbol_get_tc (sym
)->subseg
);
2787 chunksize
= hold_chunksize
;
2790 ppc_after_toc_frag
= frag_now
;
2792 symbol_set_frag (sym
, frag_now
);
2793 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2795 symbol_get_tc (sym
)->align
= (ppc_xcoff64
) ? 3 : 2;
2796 symbol_get_tc (sym
)->output
= 1;
2797 symbol_get_tc (sym
)->within
= sym
;
2799 for (list
= *list_ptr
;
2800 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
2801 list
= symbol_get_tc (list
)->next
)
2803 symbol_get_tc (list
)->next
= sym
;
2805 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2806 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
2810 ppc_current_csect
= sym
;
2813 /* This function handles the .text and .data pseudo-ops. These
2814 pseudo-ops aren't really used by XCOFF; we implement them for the
2815 convenience of people who aren't used to XCOFF. */
2826 else if (type
== 'd')
2831 sym
= symbol_find_or_make (name
);
2833 ppc_change_csect (sym
);
2835 demand_empty_rest_of_line ();
2838 /* This function handles the .section pseudo-op. This is mostly to
2839 give an error, since XCOFF only supports .text, .data and .bss, but
2840 we do permit the user to name the text or data section. */
2843 ppc_named_section (ignore
)
2844 int ignore ATTRIBUTE_UNUSED
;
2847 const char *real_name
;
2851 user_name
= input_line_pointer
;
2852 c
= get_symbol_end ();
2854 if (strcmp (user_name
, ".text") == 0)
2855 real_name
= ".text[PR]";
2856 else if (strcmp (user_name
, ".data") == 0)
2857 real_name
= ".data[RW]";
2860 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2861 *input_line_pointer
= c
;
2862 ignore_rest_of_line ();
2866 *input_line_pointer
= c
;
2868 sym
= symbol_find_or_make (real_name
);
2870 ppc_change_csect (sym
);
2872 demand_empty_rest_of_line ();
2875 /* The .extern pseudo-op. We create an undefined symbol. */
2879 int ignore ATTRIBUTE_UNUSED
;
2884 name
= input_line_pointer
;
2885 endc
= get_symbol_end ();
2887 (void) symbol_find_or_make (name
);
2889 *input_line_pointer
= endc
;
2891 demand_empty_rest_of_line ();
2894 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2898 int ignore ATTRIBUTE_UNUSED
;
2904 name
= input_line_pointer
;
2905 endc
= get_symbol_end ();
2907 sym
= symbol_find_or_make (name
);
2909 *input_line_pointer
= endc
;
2911 symbol_get_tc (sym
)->output
= 1;
2913 demand_empty_rest_of_line ();
2916 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2917 although I don't know why it bothers. */
2921 int ignore ATTRIBUTE_UNUSED
;
2928 name
= input_line_pointer
;
2929 endc
= get_symbol_end ();
2931 sym
= symbol_find_or_make (name
);
2933 *input_line_pointer
= endc
;
2935 if (*input_line_pointer
!= ',')
2937 as_bad (_("missing rename string"));
2938 ignore_rest_of_line ();
2941 ++input_line_pointer
;
2943 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
2945 demand_empty_rest_of_line ();
2948 /* The .stabx pseudo-op. This is similar to a normal .stabs
2949 pseudo-op, but slightly different. A sample is
2950 .stabx "main:F-1",.main,142,0
2951 The first argument is the symbol name to create. The second is the
2952 value, and the third is the storage class. The fourth seems to be
2953 always zero, and I am assuming it is the type. */
2957 int ignore ATTRIBUTE_UNUSED
;
2964 name
= demand_copy_C_string (&len
);
2966 if (*input_line_pointer
!= ',')
2968 as_bad (_("missing value"));
2971 ++input_line_pointer
;
2973 ppc_stab_symbol
= true;
2974 sym
= symbol_make (name
);
2975 ppc_stab_symbol
= false;
2977 symbol_get_tc (sym
)->real_name
= name
;
2979 (void) expression (&exp
);
2986 as_bad (_("illegal .stabx expression; zero assumed"));
2987 exp
.X_add_number
= 0;
2990 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2991 symbol_set_frag (sym
, &zero_address_frag
);
2995 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2996 symbol_set_value_expression (sym
, &exp
);
3000 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
3001 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
3006 /* The value is some complex expression. This will probably
3007 fail at some later point, but this is probably the right
3008 thing to do here. */
3009 symbol_set_value_expression (sym
, &exp
);
3013 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3014 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3016 if (*input_line_pointer
!= ',')
3018 as_bad (_("missing class"));
3021 ++input_line_pointer
;
3023 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
3025 if (*input_line_pointer
!= ',')
3027 as_bad (_("missing type"));
3030 ++input_line_pointer
;
3032 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
3034 symbol_get_tc (sym
)->output
= 1;
3036 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
3038 symbol_get_tc (sym
)->within
= ppc_current_block
;
3043 .stabx "z",arrays_,133,0
3046 .comm arrays_,13768,3
3048 resolve_symbol_value will copy the exp's "within" into sym's when the
3049 offset is 0. Since this seems to be corner case problem,
3050 only do the correction for storage class C_STSYM. A better solution
3051 would be to have the tc field updated in ppc_symbol_new_hook. */
3053 if (exp
.X_op
== O_symbol
)
3055 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
3059 if (exp
.X_op
!= O_symbol
3060 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
3061 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
3062 ppc_frob_label (sym
);
3065 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3066 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
3067 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
3068 symbol_get_tc (ppc_current_csect
)->within
= sym
;
3071 demand_empty_rest_of_line ();
3074 /* The .function pseudo-op. This takes several arguments. The first
3075 argument seems to be the external name of the symbol. The second
3076 argment seems to be the label for the start of the function. gcc
3077 uses the same name for both. I have no idea what the third and
3078 fourth arguments are meant to be. The optional fifth argument is
3079 an expression for the size of the function. In COFF this symbol
3080 gets an aux entry like that used for a csect. */
3083 ppc_function (ignore
)
3084 int ignore ATTRIBUTE_UNUSED
;
3092 name
= input_line_pointer
;
3093 endc
= get_symbol_end ();
3095 /* Ignore any [PR] suffix. */
3096 name
= ppc_canonicalize_symbol_name (name
);
3097 s
= strchr (name
, '[');
3098 if (s
!= (char *) NULL
3099 && strcmp (s
+ 1, "PR]") == 0)
3102 ext_sym
= symbol_find_or_make (name
);
3104 *input_line_pointer
= endc
;
3106 if (*input_line_pointer
!= ',')
3108 as_bad (_("missing symbol name"));
3109 ignore_rest_of_line ();
3112 ++input_line_pointer
;
3114 name
= input_line_pointer
;
3115 endc
= get_symbol_end ();
3117 lab_sym
= symbol_find_or_make (name
);
3119 *input_line_pointer
= endc
;
3121 if (ext_sym
!= lab_sym
)
3125 exp
.X_op
= O_symbol
;
3126 exp
.X_add_symbol
= lab_sym
;
3127 exp
.X_op_symbol
= NULL
;
3128 exp
.X_add_number
= 0;
3130 symbol_set_value_expression (ext_sym
, &exp
);
3133 if (symbol_get_tc (ext_sym
)->class == -1)
3134 symbol_get_tc (ext_sym
)->class = XMC_PR
;
3135 symbol_get_tc (ext_sym
)->output
= 1;
3137 if (*input_line_pointer
== ',')
3141 /* Ignore the third argument. */
3142 ++input_line_pointer
;
3143 expression (&ignore
);
3144 if (*input_line_pointer
== ',')
3146 /* Ignore the fourth argument. */
3147 ++input_line_pointer
;
3148 expression (&ignore
);
3149 if (*input_line_pointer
== ',')
3151 /* The fifth argument is the function size. */
3152 ++input_line_pointer
;
3153 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
3156 &zero_address_frag
);
3157 pseudo_set (symbol_get_tc (ext_sym
)->size
);
3162 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3163 SF_SET_FUNCTION (ext_sym
);
3164 SF_SET_PROCESS (ext_sym
);
3165 coff_add_linesym (ext_sym
);
3167 demand_empty_rest_of_line ();
3170 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3175 int ignore ATTRIBUTE_UNUSED
;
3179 sym
= symbol_make (".bf");
3180 S_SET_SEGMENT (sym
, text_section
);
3181 symbol_set_frag (sym
, frag_now
);
3182 S_SET_VALUE (sym
, frag_now_fix ());
3183 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3185 coff_line_base
= get_absolute_expression ();
3187 S_SET_NUMBER_AUXILIARY (sym
, 1);
3188 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3190 symbol_get_tc (sym
)->output
= 1;
3192 ppc_frob_label (sym
);
3194 demand_empty_rest_of_line ();
3197 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3198 ".ef", except that the line number is absolute, not relative to the
3199 most recent ".bf" symbol. */
3203 int ignore ATTRIBUTE_UNUSED
;
3207 sym
= symbol_make (".ef");
3208 S_SET_SEGMENT (sym
, text_section
);
3209 symbol_set_frag (sym
, frag_now
);
3210 S_SET_VALUE (sym
, frag_now_fix ());
3211 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3212 S_SET_NUMBER_AUXILIARY (sym
, 1);
3213 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3214 symbol_get_tc (sym
)->output
= 1;
3216 ppc_frob_label (sym
);
3218 demand_empty_rest_of_line ();
3221 /* The .bi and .ei pseudo-ops. These take a string argument and
3222 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3229 static symbolS
*last_biei
;
3236 name
= demand_copy_C_string (&len
);
3238 /* The value of these symbols is actually file offset. Here we set
3239 the value to the index into the line number entries. In
3240 ppc_frob_symbols we set the fix_line field, which will cause BFD
3241 to do the right thing. */
3243 sym
= symbol_make (name
);
3244 /* obj-coff.c currently only handles line numbers correctly in the
3246 S_SET_SEGMENT (sym
, text_section
);
3247 S_SET_VALUE (sym
, coff_n_line_nos
);
3248 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3250 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3251 symbol_get_tc (sym
)->output
= 1;
3253 for (look
= last_biei
? last_biei
: symbol_rootP
;
3254 (look
!= (symbolS
*) NULL
3255 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3256 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3257 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3258 look
= symbol_next (look
))
3260 if (look
!= (symbolS
*) NULL
)
3262 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3263 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3267 demand_empty_rest_of_line ();
3270 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3271 There is one argument, which is a csect symbol. The value of the
3272 .bs symbol is the index of this csect symbol. */
3276 int ignore ATTRIBUTE_UNUSED
;
3283 if (ppc_current_block
!= NULL
)
3284 as_bad (_("nested .bs blocks"));
3286 name
= input_line_pointer
;
3287 endc
= get_symbol_end ();
3289 csect
= symbol_find_or_make (name
);
3291 *input_line_pointer
= endc
;
3293 sym
= symbol_make (".bs");
3294 S_SET_SEGMENT (sym
, now_seg
);
3295 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3296 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3297 symbol_get_tc (sym
)->output
= 1;
3299 symbol_get_tc (sym
)->within
= csect
;
3301 ppc_frob_label (sym
);
3303 ppc_current_block
= sym
;
3305 demand_empty_rest_of_line ();
3308 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3312 int ignore ATTRIBUTE_UNUSED
;
3316 if (ppc_current_block
== NULL
)
3317 as_bad (_(".es without preceding .bs"));
3319 sym
= symbol_make (".es");
3320 S_SET_SEGMENT (sym
, now_seg
);
3321 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3322 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3323 symbol_get_tc (sym
)->output
= 1;
3325 ppc_frob_label (sym
);
3327 ppc_current_block
= NULL
;
3329 demand_empty_rest_of_line ();
3332 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3337 int ignore ATTRIBUTE_UNUSED
;
3341 sym
= symbol_make (".bb");
3342 S_SET_SEGMENT (sym
, text_section
);
3343 symbol_set_frag (sym
, frag_now
);
3344 S_SET_VALUE (sym
, frag_now_fix ());
3345 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3347 S_SET_NUMBER_AUXILIARY (sym
, 1);
3348 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3350 symbol_get_tc (sym
)->output
= 1;
3352 SF_SET_PROCESS (sym
);
3354 ppc_frob_label (sym
);
3356 demand_empty_rest_of_line ();
3359 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3364 int ignore ATTRIBUTE_UNUSED
;
3368 sym
= symbol_make (".eb");
3369 S_SET_SEGMENT (sym
, text_section
);
3370 symbol_set_frag (sym
, frag_now
);
3371 S_SET_VALUE (sym
, frag_now_fix ());
3372 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3373 S_SET_NUMBER_AUXILIARY (sym
, 1);
3374 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3375 symbol_get_tc (sym
)->output
= 1;
3377 SF_SET_PROCESS (sym
);
3379 ppc_frob_label (sym
);
3381 demand_empty_rest_of_line ();
3384 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3389 int ignore ATTRIBUTE_UNUSED
;
3395 name
= demand_copy_C_string (&len
);
3396 sym
= symbol_make (name
);
3397 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3398 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3399 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3400 S_SET_VALUE (sym
, 0);
3401 symbol_get_tc (sym
)->output
= 1;
3403 ppc_frob_label (sym
);
3405 demand_empty_rest_of_line ();
3408 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3412 int ignore ATTRIBUTE_UNUSED
;
3416 sym
= symbol_make (".ec");
3417 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3418 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3419 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3420 S_SET_VALUE (sym
, 0);
3421 symbol_get_tc (sym
)->output
= 1;
3423 ppc_frob_label (sym
);
3425 demand_empty_rest_of_line ();
3428 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3432 int ignore ATTRIBUTE_UNUSED
;
3434 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3435 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3442 subseg
= ppc_data_subsegment
;
3443 ++ppc_data_subsegment
;
3445 subseg_new (segment_name (data_section
), subseg
);
3446 ppc_toc_frag
= frag_now
;
3448 sym
= symbol_find_or_make ("TOC[TC0]");
3449 symbol_set_frag (sym
, frag_now
);
3450 S_SET_SEGMENT (sym
, data_section
);
3451 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3452 symbol_get_tc (sym
)->subseg
= subseg
;
3453 symbol_get_tc (sym
)->output
= 1;
3454 symbol_get_tc (sym
)->within
= sym
;
3456 ppc_toc_csect
= sym
;
3458 for (list
= ppc_data_csects
;
3459 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3460 list
= symbol_get_tc (list
)->next
)
3462 symbol_get_tc (list
)->next
= sym
;
3464 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3465 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3469 ppc_current_csect
= ppc_toc_csect
;
3471 demand_empty_rest_of_line ();
3474 /* The AIX assembler automatically aligns the operands of a .long or
3475 .short pseudo-op, and we want to be compatible. */
3478 ppc_xcoff_cons (log_size
)
3481 frag_align (log_size
, 0, 0);
3482 record_alignment (now_seg
, log_size
);
3483 cons (1 << log_size
);
3488 int dummy ATTRIBUTE_UNUSED
;
3493 (void) expression (&exp
);
3495 if (exp
.X_op
!= O_constant
)
3497 as_bad (_("non-constant byte count"));
3501 byte_count
= exp
.X_add_number
;
3503 if (*input_line_pointer
!= ',')
3505 as_bad (_("missing value"));
3509 ++input_line_pointer
;
3513 #endif /* OBJ_XCOFF */
3514 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3516 /* The .tc pseudo-op. This is used when generating either XCOFF or
3517 ELF. This takes two or more arguments.
3519 When generating XCOFF output, the first argument is the name to
3520 give to this location in the toc; this will be a symbol with class
3521 TC. The rest of the arguments are N-byte values to actually put at
3522 this location in the TOC; often there is just one more argument, a
3523 relocateable symbol reference. The size of the value to store
3524 depends on target word size. A 32-bit target uses 4-byte values, a
3525 64-bit target uses 8-byte values.
3527 When not generating XCOFF output, the arguments are the same, but
3528 the first argument is simply ignored. */
3532 int ignore ATTRIBUTE_UNUSED
;
3536 /* Define the TOC symbol name. */
3542 if (ppc_toc_csect
== (symbolS
*) NULL
3543 || ppc_toc_csect
!= ppc_current_csect
)
3545 as_bad (_(".tc not in .toc section"));
3546 ignore_rest_of_line ();
3550 name
= input_line_pointer
;
3551 endc
= get_symbol_end ();
3553 sym
= symbol_find_or_make (name
);
3555 *input_line_pointer
= endc
;
3557 if (S_IS_DEFINED (sym
))
3561 label
= symbol_get_tc (ppc_current_csect
)->within
;
3562 if (symbol_get_tc (label
)->class != XMC_TC0
)
3564 as_bad (_(".tc with no label"));
3565 ignore_rest_of_line ();
3569 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3570 symbol_set_frag (label
, symbol_get_frag (sym
));
3571 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3573 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3574 ++input_line_pointer
;
3579 S_SET_SEGMENT (sym
, now_seg
);
3580 symbol_set_frag (sym
, frag_now
);
3581 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3582 symbol_get_tc (sym
)->class = XMC_TC
;
3583 symbol_get_tc (sym
)->output
= 1;
3585 ppc_frob_label (sym
);
3588 #endif /* OBJ_XCOFF */
3592 /* Skip the TOC symbol name. */
3593 while (is_part_of_name (*input_line_pointer
)
3594 || *input_line_pointer
== '['
3595 || *input_line_pointer
== ']'
3596 || *input_line_pointer
== '{'
3597 || *input_line_pointer
== '}')
3598 ++input_line_pointer
;
3600 /* Align to a four/eight byte boundary. */
3601 align
= BFD_DEFAULT_TARGET_SIZE
== 64 && ppc_size
== PPC_OPCODE_64
? 3 : 2;
3602 frag_align (align
, 0, 0);
3603 record_alignment (now_seg
, align
);
3604 #endif /* OBJ_ELF */
3606 if (*input_line_pointer
!= ',')
3607 demand_empty_rest_of_line ();
3610 ++input_line_pointer
;
3611 cons ((ppc_size
== PPC_OPCODE_64
) ? 8 : 4);
3615 /* Pseudo-op .machine. */
3616 /* FIXME: `.machine' is a nop for the moment. */
3619 ppc_machine (ignore
)
3620 int ignore ATTRIBUTE_UNUSED
;
3622 discard_rest_of_line ();
3625 /* See whether a symbol is in the TOC section. */
3628 ppc_is_toc_sym (sym
)
3632 return symbol_get_tc (sym
)->class == XMC_TC
;
3635 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
3636 if (BFD_DEFAULT_TARGET_SIZE
== 64 && ppc_size
== PPC_OPCODE_64
)
3637 return strcmp (sname
, ".toc") == 0;
3639 return strcmp (sname
, ".got") == 0;
3642 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
3646 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
3648 /* Set the current section. */
3650 ppc_set_current_section (new)
3653 ppc_previous_section
= ppc_current_section
;
3654 ppc_current_section
= new;
3657 /* pseudo-op: .previous
3658 behaviour: toggles the current section with the previous section.
3660 warnings: "No previous section" */
3663 ppc_previous (ignore
)
3664 int ignore ATTRIBUTE_UNUSED
;
3668 if (ppc_previous_section
== NULL
)
3670 as_warn (_("No previous section to return to. Directive ignored."));
3674 subseg_set (ppc_previous_section
, 0);
3676 ppc_set_current_section (ppc_previous_section
);
3679 /* pseudo-op: .pdata
3680 behaviour: predefined read only data section
3684 initial: .section .pdata "adr3"
3685 a - don't know -- maybe a misprint
3686 d - initialized data
3688 3 - double word aligned (that would be 4 byte boundary)
3691 Tag index tables (also known as the function table) for exception
3692 handling, debugging, etc. */
3696 int ignore ATTRIBUTE_UNUSED
;
3698 if (pdata_section
== 0)
3700 pdata_section
= subseg_new (".pdata", 0);
3702 bfd_set_section_flags (stdoutput
, pdata_section
,
3703 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3704 | SEC_READONLY
| SEC_DATA
));
3706 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3710 pdata_section
= subseg_new (".pdata", 0);
3712 ppc_set_current_section (pdata_section
);
3715 /* pseudo-op: .ydata
3716 behaviour: predefined read only data section
3720 initial: .section .ydata "drw3"
3721 a - don't know -- maybe a misprint
3722 d - initialized data
3724 3 - double word aligned (that would be 4 byte boundary)
3726 Tag tables (also known as the scope table) for exception handling,
3731 int ignore ATTRIBUTE_UNUSED
;
3733 if (ydata_section
== 0)
3735 ydata_section
= subseg_new (".ydata", 0);
3736 bfd_set_section_flags (stdoutput
, ydata_section
,
3737 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3738 | SEC_READONLY
| SEC_DATA
));
3740 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3744 ydata_section
= subseg_new (".ydata", 0);
3746 ppc_set_current_section (ydata_section
);
3749 /* pseudo-op: .reldata
3750 behaviour: predefined read write data section
3751 double word aligned (4-byte)
3752 FIXME: relocation is applied to it
3753 FIXME: what's the difference between this and .data?
3756 initial: .section .reldata "drw3"
3757 d - initialized data
3760 3 - double word aligned (that would be 8 byte boundary)
3763 Like .data, but intended to hold data subject to relocation, such as
3764 function descriptors, etc. */
3767 ppc_reldata (ignore
)
3768 int ignore ATTRIBUTE_UNUSED
;
3770 if (reldata_section
== 0)
3772 reldata_section
= subseg_new (".reldata", 0);
3774 bfd_set_section_flags (stdoutput
, reldata_section
,
3775 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3778 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3782 reldata_section
= subseg_new (".reldata", 0);
3784 ppc_set_current_section (reldata_section
);
3787 /* pseudo-op: .rdata
3788 behaviour: predefined read only data section
3792 initial: .section .rdata "dr3"
3793 d - initialized data
3795 3 - double word aligned (that would be 4 byte boundary) */
3799 int ignore ATTRIBUTE_UNUSED
;
3801 if (rdata_section
== 0)
3803 rdata_section
= subseg_new (".rdata", 0);
3804 bfd_set_section_flags (stdoutput
, rdata_section
,
3805 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3806 | SEC_READONLY
| SEC_DATA
));
3808 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3812 rdata_section
= subseg_new (".rdata", 0);
3814 ppc_set_current_section (rdata_section
);
3817 /* pseudo-op: .ualong
3818 behaviour: much like .int, with the exception that no alignment is
3820 FIXME: test the alignment statement
3826 int ignore ATTRIBUTE_UNUSED
;
3832 /* pseudo-op: .znop <symbol name>
3833 behaviour: Issue a nop instruction
3834 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3835 the supplied symbol name.
3837 warnings: Missing symbol name */
3841 int ignore ATTRIBUTE_UNUSED
;
3844 const struct powerpc_opcode
*opcode
;
3855 /* Strip out the symbol name. */
3856 symbol_name
= input_line_pointer
;
3857 c
= get_symbol_end ();
3859 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3860 strcpy (name
, symbol_name
);
3862 sym
= symbol_find_or_make (name
);
3864 *input_line_pointer
= c
;
3868 /* Look up the opcode in the hash table. */
3869 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3871 /* Stick in the nop. */
3872 insn
= opcode
->opcode
;
3874 /* Write out the instruction. */
3876 md_number_to_chars (f
, insn
, 4);
3878 f
- frag_now
->fr_literal
,
3883 BFD_RELOC_16_GOT_PCREL
);
3896 register char *name
;
3900 register symbolS
*symbolP
;
3903 name
= input_line_pointer
;
3904 c
= get_symbol_end ();
3906 /* just after name is now '\0'. */
3907 p
= input_line_pointer
;
3910 if (*input_line_pointer
!= ',')
3912 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3913 ignore_rest_of_line ();
3917 input_line_pointer
++; /* skip ',' */
3918 if ((temp
= get_absolute_expression ()) < 0)
3920 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
3921 ignore_rest_of_line ();
3927 /* The third argument to .comm is the alignment. */
3928 if (*input_line_pointer
!= ',')
3932 ++input_line_pointer
;
3933 align
= get_absolute_expression ();
3936 as_warn (_("ignoring bad alignment"));
3943 symbolP
= symbol_find_or_make (name
);
3946 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3948 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3949 S_GET_NAME (symbolP
));
3950 ignore_rest_of_line ();
3954 if (S_GET_VALUE (symbolP
))
3956 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3957 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3958 S_GET_NAME (symbolP
),
3959 (long) S_GET_VALUE (symbolP
),
3964 S_SET_VALUE (symbolP
, (valueT
) temp
);
3965 S_SET_EXTERNAL (symbolP
);
3968 demand_empty_rest_of_line ();
3972 * implement the .section pseudo op:
3973 * .section name {, "flags"}
3975 * | +--- optional flags: 'b' for bss
3977 * +-- section name 'l' for lib
3981 * 'd' (apparently m88k for data)
3983 * But if the argument is not a quoted string, treat it as a
3984 * subsegment number.
3986 * FIXME: this is a copy of the section processing from obj-coff.c, with
3987 * additions/changes for the moto-pas assembler support. There are three
3990 * FIXME: I just noticed this. This doesn't work at all really. It it
3991 * setting bits that bfd probably neither understands or uses. The
3992 * correct approach (?) will have to incorporate extra fields attached
3993 * to the section to hold the system specific stuff. (krk)
3996 * 'a' - unknown - referred to in documentation, but no definition supplied
3997 * 'c' - section has code
3998 * 'd' - section has initialized data
3999 * 'u' - section has uninitialized data
4000 * 'i' - section contains directives (info)
4001 * 'n' - section can be discarded
4002 * 'R' - remove section at link time
4004 * Section Protection:
4005 * 'r' - section is readable
4006 * 'w' - section is writeable
4007 * 'x' - section is executable
4008 * 's' - section is sharable
4010 * Section Alignment:
4011 * '0' - align to byte boundary
4012 * '1' - align to halfword undary
4013 * '2' - align to word boundary
4014 * '3' - align to doubleword boundary
4015 * '4' - align to quadword boundary
4016 * '5' - align to 32 byte boundary
4017 * '6' - align to 64 byte boundary
4022 ppc_pe_section (ignore
)
4023 int ignore ATTRIBUTE_UNUSED
;
4025 /* Strip out the section name. */
4034 section_name
= input_line_pointer
;
4035 c
= get_symbol_end ();
4037 name
= xmalloc (input_line_pointer
- section_name
+ 1);
4038 strcpy (name
, section_name
);
4040 *input_line_pointer
= c
;
4045 flags
= SEC_NO_FLAGS
;
4047 if (strcmp (name
, ".idata$2") == 0)
4051 else if (strcmp (name
, ".idata$3") == 0)
4055 else if (strcmp (name
, ".idata$4") == 0)
4059 else if (strcmp (name
, ".idata$5") == 0)
4063 else if (strcmp (name
, ".idata$6") == 0)
4068 /* Default alignment to 16 byte boundary. */
4071 if (*input_line_pointer
== ',')
4073 ++input_line_pointer
;
4075 if (*input_line_pointer
!= '"')
4076 exp
= get_absolute_expression ();
4079 ++input_line_pointer
;
4080 while (*input_line_pointer
!= '"'
4081 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4083 switch (*input_line_pointer
)
4085 /* Section Contents */
4086 case 'a': /* unknown */
4087 as_bad (_("Unsupported section attribute -- 'a'"));
4089 case 'c': /* code section */
4092 case 'd': /* section has initialized data */
4095 case 'u': /* section has uninitialized data */
4096 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4100 case 'i': /* section contains directives (info) */
4101 /* FIXME: This is IMAGE_SCN_LNK_INFO
4103 flags
|= SEC_HAS_CONTENTS
;
4105 case 'n': /* section can be discarded */
4108 case 'R': /* Remove section at link time */
4109 flags
|= SEC_NEVER_LOAD
;
4112 /* Section Protection */
4113 case 'r': /* section is readable */
4114 flags
|= IMAGE_SCN_MEM_READ
;
4116 case 'w': /* section is writeable */
4117 flags
|= IMAGE_SCN_MEM_WRITE
;
4119 case 'x': /* section is executable */
4120 flags
|= IMAGE_SCN_MEM_EXECUTE
;
4122 case 's': /* section is sharable */
4123 flags
|= IMAGE_SCN_MEM_SHARED
;
4126 /* Section Alignment */
4127 case '0': /* align to byte boundary */
4128 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
4131 case '1': /* align to halfword boundary */
4132 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
4135 case '2': /* align to word boundary */
4136 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
4139 case '3': /* align to doubleword boundary */
4140 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
4143 case '4': /* align to quadword boundary */
4144 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
4147 case '5': /* align to 32 byte boundary */
4148 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
4151 case '6': /* align to 64 byte boundary */
4152 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
4157 as_bad (_("unknown section attribute '%c'"),
4158 *input_line_pointer
);
4161 ++input_line_pointer
;
4163 if (*input_line_pointer
== '"')
4164 ++input_line_pointer
;
4168 sec
= subseg_new (name
, (subsegT
) exp
);
4170 ppc_set_current_section (sec
);
4172 if (flags
!= SEC_NO_FLAGS
)
4174 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
4175 as_bad (_("error setting flags for \"%s\": %s"),
4176 bfd_section_name (stdoutput
, sec
),
4177 bfd_errmsg (bfd_get_error ()));
4180 bfd_set_section_alignment (stdoutput
, sec
, align
);
4185 ppc_pe_function (ignore
)
4186 int ignore ATTRIBUTE_UNUSED
;
4192 name
= input_line_pointer
;
4193 endc
= get_symbol_end ();
4195 ext_sym
= symbol_find_or_make (name
);
4197 *input_line_pointer
= endc
;
4199 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4200 SF_SET_FUNCTION (ext_sym
);
4201 SF_SET_PROCESS (ext_sym
);
4202 coff_add_linesym (ext_sym
);
4204 demand_empty_rest_of_line ();
4208 ppc_pe_tocd (ignore
)
4209 int ignore ATTRIBUTE_UNUSED
;
4211 if (tocdata_section
== 0)
4213 tocdata_section
= subseg_new (".tocd", 0);
4214 /* FIXME: section flags won't work. */
4215 bfd_set_section_flags (stdoutput
, tocdata_section
,
4216 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4217 | SEC_READONLY
| SEC_DATA
));
4219 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4223 rdata_section
= subseg_new (".tocd", 0);
4226 ppc_set_current_section (tocdata_section
);
4228 demand_empty_rest_of_line ();
4231 /* Don't adjust TOC relocs to use the section symbol. */
4234 ppc_pe_fix_adjustable (fix
)
4237 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4244 /* XCOFF specific symbol and file handling. */
4246 /* Canonicalize the symbol name. We use the to force the suffix, if
4247 any, to use square brackets, and to be in upper case. */
4250 ppc_canonicalize_symbol_name (name
)
4255 if (ppc_stab_symbol
)
4258 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4272 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4275 if (*s
== '\0' || s
[1] != '\0')
4276 as_bad (_("bad symbol suffix"));
4284 /* Set the class of a symbol based on the suffix, if any. This is
4285 called whenever a new symbol is created. */
4288 ppc_symbol_new_hook (sym
)
4291 struct ppc_tc_sy
*tc
;
4294 tc
= symbol_get_tc (sym
);
4298 tc
->real_name
= NULL
;
4304 if (ppc_stab_symbol
)
4307 s
= strchr (S_GET_NAME (sym
), '[');
4308 if (s
== (const char *) NULL
)
4310 /* There is no suffix. */
4319 if (strcmp (s
, "BS]") == 0)
4323 if (strcmp (s
, "DB]") == 0)
4325 else if (strcmp (s
, "DS]") == 0)
4329 if (strcmp (s
, "GL]") == 0)
4333 if (strcmp (s
, "PR]") == 0)
4337 if (strcmp (s
, "RO]") == 0)
4339 else if (strcmp (s
, "RW]") == 0)
4343 if (strcmp (s
, "SV]") == 0)
4347 if (strcmp (s
, "TC]") == 0)
4349 else if (strcmp (s
, "TI]") == 0)
4351 else if (strcmp (s
, "TB]") == 0)
4353 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4354 tc
->class = XMC_TC0
;
4357 if (strcmp (s
, "UA]") == 0)
4359 else if (strcmp (s
, "UC]") == 0)
4363 if (strcmp (s
, "XO]") == 0)
4368 if (tc
->class == -1)
4369 as_bad (_("Unrecognized symbol suffix"));
4372 /* Set the class of a label based on where it is defined. This
4373 handles symbols without suffixes. Also, move the symbol so that it
4374 follows the csect symbol. */
4377 ppc_frob_label (sym
)
4380 if (ppc_current_csect
!= (symbolS
*) NULL
)
4382 if (symbol_get_tc (sym
)->class == -1)
4383 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4385 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4386 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4387 &symbol_rootP
, &symbol_lastP
);
4388 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4392 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4393 seen. It tells ppc_adjust_symtab whether it needs to look through
4396 static boolean ppc_saw_abs
;
4398 /* Change the name of a symbol just before writing it out. Set the
4399 real name if the .rename pseudo-op was used. Otherwise, remove any
4400 class suffix. Return 1 if the symbol should not be included in the
4404 ppc_frob_symbol (sym
)
4407 static symbolS
*ppc_last_function
;
4408 static symbolS
*set_end
;
4410 /* Discard symbols that should not be included in the output symbol
4412 if (! symbol_used_in_reloc_p (sym
)
4413 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4414 || (! S_IS_EXTERNAL (sym
)
4415 && ! symbol_get_tc (sym
)->output
4416 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4419 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4420 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4426 name
= S_GET_NAME (sym
);
4427 s
= strchr (name
, '[');
4428 if (s
!= (char *) NULL
)
4434 snew
= xmalloc (len
+ 1);
4435 memcpy (snew
, name
, len
);
4438 S_SET_NAME (sym
, snew
);
4442 if (set_end
!= (symbolS
*) NULL
)
4444 SA_SET_SYM_ENDNDX (set_end
, sym
);
4448 if (SF_GET_FUNCTION (sym
))
4450 if (ppc_last_function
!= (symbolS
*) NULL
)
4451 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4452 ppc_last_function
= sym
;
4453 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4455 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4456 SA_SET_SYM_FSIZE (sym
,
4457 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4460 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4461 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4463 if (ppc_last_function
== (symbolS
*) NULL
)
4464 as_bad (_(".ef with no preceding .function"));
4467 set_end
= ppc_last_function
;
4468 ppc_last_function
= NULL
;
4470 /* We don't have a C_EFCN symbol, but we need to force the
4471 COFF backend to believe that it has seen one. */
4472 coff_last_function
= NULL
;
4476 if (! S_IS_EXTERNAL (sym
)
4477 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4478 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4479 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4480 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4481 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4482 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4483 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4484 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4485 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4486 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4488 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4489 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4492 union internal_auxent
*a
;
4494 /* Create a csect aux. */
4495 i
= S_GET_NUMBER_AUXILIARY (sym
);
4496 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4497 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4498 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4500 /* This is the TOC table. */
4501 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4502 a
->x_csect
.x_scnlen
.l
= 0;
4503 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4505 else if (symbol_get_tc (sym
)->subseg
!= 0)
4507 /* This is a csect symbol. x_scnlen is the size of the
4509 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4510 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4511 S_GET_SEGMENT (sym
))
4512 - S_GET_VALUE (sym
));
4515 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4516 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4517 - S_GET_VALUE (sym
));
4519 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4521 else if (S_GET_SEGMENT (sym
) == bss_section
)
4523 /* This is a common symbol. */
4524 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4525 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4526 if (S_IS_EXTERNAL (sym
))
4527 symbol_get_tc (sym
)->class = XMC_RW
;
4529 symbol_get_tc (sym
)->class = XMC_BS
;
4531 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4533 /* This is an absolute symbol. The csect will be created by
4534 ppc_adjust_symtab. */
4536 a
->x_csect
.x_smtyp
= XTY_LD
;
4537 if (symbol_get_tc (sym
)->class == -1)
4538 symbol_get_tc (sym
)->class = XMC_XO
;
4540 else if (! S_IS_DEFINED (sym
))
4542 /* This is an external symbol. */
4543 a
->x_csect
.x_scnlen
.l
= 0;
4544 a
->x_csect
.x_smtyp
= XTY_ER
;
4546 else if (symbol_get_tc (sym
)->class == XMC_TC
)
4550 /* This is a TOC definition. x_scnlen is the size of the
4552 next
= symbol_next (sym
);
4553 while (symbol_get_tc (next
)->class == XMC_TC0
)
4554 next
= symbol_next (next
);
4555 if (next
== (symbolS
*) NULL
4556 || symbol_get_tc (next
)->class != XMC_TC
)
4558 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4559 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4561 - S_GET_VALUE (sym
));
4563 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4564 - S_GET_VALUE (sym
));
4568 resolve_symbol_value (next
);
4569 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4570 - S_GET_VALUE (sym
));
4572 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4578 /* This is a normal symbol definition. x_scnlen is the
4579 symbol index of the containing csect. */
4580 if (S_GET_SEGMENT (sym
) == text_section
)
4581 csect
= ppc_text_csects
;
4582 else if (S_GET_SEGMENT (sym
) == data_section
)
4583 csect
= ppc_data_csects
;
4587 /* Skip the initial dummy symbol. */
4588 csect
= symbol_get_tc (csect
)->next
;
4590 if (csect
== (symbolS
*) NULL
)
4592 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4593 a
->x_csect
.x_scnlen
.l
= 0;
4597 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
4599 resolve_symbol_value (symbol_get_tc (csect
)->next
);
4600 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
4601 > S_GET_VALUE (sym
))
4603 csect
= symbol_get_tc (csect
)->next
;
4606 a
->x_csect
.x_scnlen
.p
=
4607 coffsymbol (symbol_get_bfdsym (csect
))->native
;
4608 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
4611 a
->x_csect
.x_smtyp
= XTY_LD
;
4614 a
->x_csect
.x_parmhash
= 0;
4615 a
->x_csect
.x_snhash
= 0;
4616 if (symbol_get_tc (sym
)->class == -1)
4617 a
->x_csect
.x_smclas
= XMC_PR
;
4619 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
4620 a
->x_csect
.x_stab
= 0;
4621 a
->x_csect
.x_snstab
= 0;
4623 /* Don't let the COFF backend resort these symbols. */
4624 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
4626 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4628 /* We want the value to be the symbol index of the referenced
4629 csect symbol. BFD will do that for us if we set the right
4633 coffsymbol (symbol_get_bfdsym
4634 (symbol_get_tc (sym
)->within
))->native
));
4635 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
4637 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4642 /* The value is the offset from the enclosing csect. */
4643 block
= symbol_get_tc (sym
)->within
;
4644 csect
= symbol_get_tc (block
)->within
;
4645 resolve_symbol_value (csect
);
4646 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4648 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4649 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4651 /* We want the value to be a file offset into the line numbers.
4652 BFD will do that for us if we set the right flags. We have
4653 already set the value correctly. */
4654 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
4660 /* Adjust the symbol table. This creates csect symbols for all
4661 absolute symbols. */
4664 ppc_adjust_symtab ()
4671 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4675 union internal_auxent
*a
;
4677 if (S_GET_SEGMENT (sym
) != absolute_section
)
4680 csect
= symbol_create (".abs[XO]", absolute_section
,
4681 S_GET_VALUE (sym
), &zero_address_frag
);
4682 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
4683 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4684 i
= S_GET_NUMBER_AUXILIARY (csect
);
4685 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4686 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
4687 a
->x_csect
.x_scnlen
.l
= 0;
4688 a
->x_csect
.x_smtyp
= XTY_SD
;
4689 a
->x_csect
.x_parmhash
= 0;
4690 a
->x_csect
.x_snhash
= 0;
4691 a
->x_csect
.x_smclas
= XMC_XO
;
4692 a
->x_csect
.x_stab
= 0;
4693 a
->x_csect
.x_snstab
= 0;
4695 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4697 i
= S_GET_NUMBER_AUXILIARY (sym
);
4698 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
4699 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
4700 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
4703 ppc_saw_abs
= false;
4706 /* Set the VMA for a section. This is called on all the sections in
4710 ppc_frob_section (sec
)
4713 static bfd_size_type vma
= 0;
4715 bfd_set_section_vma (stdoutput
, sec
, vma
);
4716 vma
+= bfd_section_size (stdoutput
, sec
);
4719 #endif /* OBJ_XCOFF */
4721 /* Turn a string in input_line_pointer into a floating point constant
4722 of type TYPE, and store the appropriate bytes in *LITP. The number
4723 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4724 returned, or NULL on OK. */
4727 md_atof (type
, litp
, sizep
)
4733 LITTLENUM_TYPE words
[4];
4749 return _("bad call to md_atof");
4752 t
= atof_ieee (input_line_pointer
, type
, words
);
4754 input_line_pointer
= t
;
4758 if (target_big_endian
)
4760 for (i
= 0; i
< prec
; i
++)
4762 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4768 for (i
= prec
- 1; i
>= 0; i
--)
4770 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4778 /* Write a value out to the object file, using the appropriate
4782 md_number_to_chars (buf
, val
, n
)
4787 if (target_big_endian
)
4788 number_to_chars_bigendian (buf
, val
, n
);
4790 number_to_chars_littleendian (buf
, val
, n
);
4793 /* Align a section (I don't know why this is machine dependent). */
4796 md_section_align (seg
, addr
)
4800 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4802 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4805 /* We don't have any form of relaxing. */
4808 md_estimate_size_before_relax (fragp
, seg
)
4809 fragS
*fragp ATTRIBUTE_UNUSED
;
4810 asection
*seg ATTRIBUTE_UNUSED
;
4816 /* Convert a machine dependent frag. We never generate these. */
4819 md_convert_frag (abfd
, sec
, fragp
)
4820 bfd
*abfd ATTRIBUTE_UNUSED
;
4821 asection
*sec ATTRIBUTE_UNUSED
;
4822 fragS
*fragp ATTRIBUTE_UNUSED
;
4827 /* We have no need to default values of symbols. */
4830 md_undefined_symbol (name
)
4831 char *name ATTRIBUTE_UNUSED
;
4836 /* Functions concerning relocs. */
4838 /* The location from which a PC relative jump should be calculated,
4839 given a PC relative reloc. */
4842 md_pcrel_from_section (fixp
, sec
)
4844 segT sec ATTRIBUTE_UNUSED
;
4846 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4851 /* This is called to see whether a fixup should be adjusted to use a
4852 section symbol. We take the opportunity to change a fixup against
4853 a symbol in the TOC subsegment into a reloc against the
4854 corresponding .tc symbol. */
4857 ppc_fix_adjustable (fix
)
4862 resolve_symbol_value (fix
->fx_addsy
);
4863 val
= S_GET_VALUE (fix
->fx_addsy
);
4864 if (ppc_toc_csect
!= (symbolS
*) NULL
4865 && fix
->fx_addsy
!= (symbolS
*) NULL
4866 && fix
->fx_addsy
!= ppc_toc_csect
4867 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4868 && val
>= ppc_toc_frag
->fr_address
4869 && (ppc_after_toc_frag
== (fragS
*) NULL
4870 || val
< ppc_after_toc_frag
->fr_address
))
4874 for (sy
= symbol_next (ppc_toc_csect
);
4875 sy
!= (symbolS
*) NULL
;
4876 sy
= symbol_next (sy
))
4878 if (symbol_get_tc (sy
)->class == XMC_TC0
)
4880 if (symbol_get_tc (sy
)->class != XMC_TC
)
4882 resolve_symbol_value (sy
);
4883 if (val
== S_GET_VALUE (sy
))
4886 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4891 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4892 _("symbol in .toc does not match any .tc"));
4895 /* Possibly adjust the reloc to be against the csect. */
4896 if (fix
->fx_addsy
!= (symbolS
*) NULL
4897 && symbol_get_tc (fix
->fx_addsy
)->subseg
== 0
4898 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC0
4899 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC
4900 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
4901 /* Don't adjust if this is a reloc in the toc section. */
4902 && (S_GET_SEGMENT (fix
->fx_addsy
) != data_section
4903 || ppc_toc_csect
== NULL
4904 || val
< ppc_toc_frag
->fr_address
4905 || (ppc_after_toc_frag
!= NULL
4906 && val
>= ppc_after_toc_frag
->fr_address
)))
4910 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4911 csect
= ppc_text_csects
;
4912 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4913 csect
= ppc_data_csects
;
4917 /* Skip the initial dummy symbol. */
4918 csect
= symbol_get_tc (csect
)->next
;
4920 if (csect
!= (symbolS
*) NULL
)
4922 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
4923 && (symbol_get_frag (symbol_get_tc (csect
)->next
)->fr_address
4926 /* If the csect address equals the symbol value, then we
4927 have to look through the full symbol table to see
4928 whether this is the csect we want. Note that we will
4929 only get here if the csect has zero length. */
4930 if ((symbol_get_frag (csect
)->fr_address
== val
)
4931 && S_GET_VALUE (csect
) == S_GET_VALUE (fix
->fx_addsy
))
4935 for (scan
= symbol_next (csect
);
4937 scan
= symbol_next (scan
))
4939 if (symbol_get_tc (scan
)->subseg
!= 0)
4941 if (scan
== fix
->fx_addsy
)
4945 /* If we found the symbol before the next csect
4946 symbol, then this is the csect we want. */
4947 if (scan
== fix
->fx_addsy
)
4951 csect
= symbol_get_tc (csect
)->next
;
4954 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4955 - symbol_get_frag (csect
)->fr_address
);
4956 fix
->fx_addsy
= csect
;
4960 /* Adjust a reloc against a .lcomm symbol to be against the base
4962 if (fix
->fx_addsy
!= (symbolS
*) NULL
4963 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4964 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4966 resolve_symbol_value (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
);
4968 (S_GET_VALUE (fix
->fx_addsy
)
4969 - S_GET_VALUE (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
));
4970 fix
->fx_addsy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
4976 /* A reloc from one csect to another must be kept. The assembler
4977 will, of course, keep relocs between sections, and it will keep
4978 absolute relocs, but we need to force it to keep PC relative relocs
4979 between two csects in the same section. */
4982 ppc_force_relocation (fix
)
4985 /* At this point fix->fx_addsy should already have been converted to
4986 a csect symbol. If the csect does not include the fragment, then
4987 we need to force the relocation. */
4989 && fix
->fx_addsy
!= NULL
4990 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
4991 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
4992 > fix
->fx_frag
->fr_address
)
4993 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
4994 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
4995 <= fix
->fx_frag
->fr_address
))))
5001 #endif /* OBJ_XCOFF */
5005 ppc_fix_adjustable (fix
)
5008 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
5009 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
5010 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
5011 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
5012 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
5013 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
5014 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
5015 && ! S_IS_EXTERNAL (fix
->fx_addsy
)
5016 && ! S_IS_WEAK (fix
->fx_addsy
)
5018 || (fix
->fx_subsy
!= NULL
5019 && (S_GET_SEGMENT (fix
->fx_subsy
)
5020 == S_GET_SEGMENT (fix
->fx_addsy
)))
5021 || S_IS_LOCAL (fix
->fx_addsy
)));
5025 /* Apply a fixup to the object code. This is called for all the
5026 fixups we generated by the call to fix_new_exp, above. In the call
5027 above we used a reloc code which was the largest legal reloc code
5028 plus the operand index. Here we undo that to recover the operand
5029 index. At this point all symbol values should be fully resolved,
5030 and we attempt to completely resolve the reloc. If we can not do
5031 that, we determine the correct reloc code and put it back in the
5035 md_apply_fix3 (fixp
, valuep
, seg
)
5038 segT seg ATTRIBUTE_UNUSED
;
5044 if (fixp
->fx_addsy
!= NULL
)
5046 /* `*valuep' may contain the value of the symbol on which the reloc
5047 will be based; we have to remove it. */
5048 if (symbol_used_in_reloc_p (fixp
->fx_addsy
)
5049 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
5050 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
5051 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
5052 value
-= S_GET_VALUE (fixp
->fx_addsy
);
5054 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
5055 supposed to be? I think this is related to various similar
5056 FIXMEs in tc-i386.c and tc-sparc.c. */
5058 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5065 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
5066 the symbol values. Since we are using BFD_ASSEMBLER, if we are
5067 doing this relocation the code in write.c is going to call
5068 bfd_install_relocation, which is also going to use the symbol
5069 value. That means that if the reloc is fully resolved we want to
5070 use *valuep since bfd_install_relocation is not being used.
5071 However, if the reloc is not fully resolved we do not want to use
5072 *valuep, and must use fx_offset instead. However, if the reloc
5073 is PC relative, we do want to use *valuep since it includes the
5074 result of md_pcrel_from. This is confusing. */
5075 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
5080 else if (fixp
->fx_pcrel
)
5084 value
= fixp
->fx_offset
;
5085 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
5087 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
5088 value
-= S_GET_VALUE (fixp
->fx_subsy
);
5091 /* We can't actually support subtracting a symbol. */
5092 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5093 _("expression too complex"));
5099 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
5102 const struct powerpc_operand
*operand
;
5106 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
5108 operand
= &powerpc_operands
[opindex
];
5111 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5112 does not generate a reloc. It uses the offset of `sym' within its
5113 csect. Other usages, such as `.long sym', generate relocs. This
5114 is the documented behaviour of non-TOC symbols. */
5115 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5116 && operand
->bits
== 16
5117 && operand
->shift
== 0
5118 && operand
->insert
== NULL
5119 && fixp
->fx_addsy
!= NULL
5120 && symbol_get_tc (fixp
->fx_addsy
)->subseg
!= 0
5121 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC
5122 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC0
5123 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
5125 value
= fixp
->fx_offset
;
5130 /* Fetch the instruction, insert the fully resolved operand
5131 value, and stuff the instruction back again. */
5132 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5133 if (target_big_endian
)
5134 insn
= bfd_getb32 ((unsigned char *) where
);
5136 insn
= bfd_getl32 ((unsigned char *) where
);
5137 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
5138 fixp
->fx_file
, fixp
->fx_line
);
5139 if (target_big_endian
)
5140 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5142 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5146 /* Nothing else to do here. */
5150 assert (fixp
->fx_addsy
!= NULL
);
5152 /* Determine a BFD reloc value based on the operand information.
5153 We are only prepared to turn a few of the operands into
5155 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5156 && operand
->bits
== 26
5157 && operand
->shift
== 0)
5158 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
5159 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5160 && operand
->bits
== 16
5161 && operand
->shift
== 0)
5162 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
5163 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5164 && operand
->bits
== 26
5165 && operand
->shift
== 0)
5166 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
5167 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5168 && operand
->bits
== 16
5169 && operand
->shift
== 0)
5170 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
5171 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5172 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5173 && operand
->bits
== 16
5174 && operand
->shift
== 0
5175 && ppc_is_toc_sym (fixp
->fx_addsy
))
5177 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
5179 if (BFD_DEFAULT_TARGET_SIZE
== 64
5180 && ppc_size
== PPC_OPCODE_64
5181 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5182 fixp
->fx_r_type
= BFD_RELOC_PPC64_TOC16_DS
;
5185 if (target_big_endian
)
5186 fixp
->fx_where
+= 2;
5188 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5194 /* Use expr_symbol_where to see if this is an expression
5196 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
5197 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5198 _("unresolved expression that must be resolved"));
5200 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5201 _("unsupported relocation against %s"),
5202 S_GET_NAME (fixp
->fx_addsy
));
5210 ppc_elf_validate_fix (fixp
, seg
);
5212 switch (fixp
->fx_r_type
)
5214 case BFD_RELOC_CTOR
:
5215 if (BFD_DEFAULT_TARGET_SIZE
== 64 && ppc_size
== PPC_OPCODE_64
)
5221 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
5225 case BFD_RELOC_32_PCREL
:
5226 case BFD_RELOC_32_BASEREL
:
5227 case BFD_RELOC_PPC_EMB_NADDR32
:
5228 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5235 fixp
->fx_r_type
= BFD_RELOC_64_PCREL
;
5238 case BFD_RELOC_64_PCREL
:
5239 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5243 case BFD_RELOC_LO16
:
5245 case BFD_RELOC_GPREL16
:
5246 case BFD_RELOC_16_GOT_PCREL
:
5247 case BFD_RELOC_16_GOTOFF
:
5248 case BFD_RELOC_LO16_GOTOFF
:
5249 case BFD_RELOC_HI16_GOTOFF
:
5250 case BFD_RELOC_HI16_S_GOTOFF
:
5251 case BFD_RELOC_LO16_BASEREL
:
5252 case BFD_RELOC_HI16_BASEREL
:
5253 case BFD_RELOC_HI16_S_BASEREL
:
5254 case BFD_RELOC_PPC_EMB_NADDR16
:
5255 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5256 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5257 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5258 case BFD_RELOC_PPC_EMB_SDAI16
:
5259 case BFD_RELOC_PPC_EMB_SDA2REL
:
5260 case BFD_RELOC_PPC_EMB_SDA2I16
:
5261 case BFD_RELOC_PPC_EMB_RELSEC16
:
5262 case BFD_RELOC_PPC_EMB_RELST_LO
:
5263 case BFD_RELOC_PPC_EMB_RELST_HI
:
5264 case BFD_RELOC_PPC_EMB_RELST_HA
:
5265 case BFD_RELOC_PPC_EMB_RELSDA
:
5266 case BFD_RELOC_PPC_TOC16
:
5268 #if BFD_DEFAULT_TARGET_SIZE == 64
5269 case BFD_RELOC_PPC64_TOC16_LO
:
5270 case BFD_RELOC_PPC64_TOC16_HI
:
5271 case BFD_RELOC_PPC64_TOC16_HA
:
5276 if (fixp
->fx_addsy
!= NULL
)
5277 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5278 _("cannot emit PC relative %s relocation against %s"),
5279 bfd_get_reloc_code_name (fixp
->fx_r_type
),
5280 S_GET_NAME (fixp
->fx_addsy
));
5282 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5283 _("cannot emit PC relative %s relocation"),
5284 bfd_get_reloc_code_name (fixp
->fx_r_type
));
5287 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5291 /* This case happens when you write, for example,
5293 where L1 and L2 are defined later. */
5294 case BFD_RELOC_HI16
:
5297 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5301 case BFD_RELOC_HI16_S
:
5304 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5309 #if BFD_DEFAULT_TARGET_SIZE == 64
5310 case BFD_RELOC_PPC64_HIGHER
:
5313 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5314 PPC_HIGHER (value
), 2);
5317 case BFD_RELOC_PPC64_HIGHER_S
:
5320 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5321 PPC_HIGHERA (value
), 2);
5324 case BFD_RELOC_PPC64_HIGHEST
:
5327 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5328 PPC_HIGHEST (value
), 2);
5331 case BFD_RELOC_PPC64_HIGHEST_S
:
5334 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5335 PPC_HIGHESTA (value
), 2);
5338 case BFD_RELOC_PPC64_ADDR16_DS
:
5339 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
5340 case BFD_RELOC_PPC64_GOT16_DS
:
5341 case BFD_RELOC_PPC64_GOT16_LO_DS
:
5342 case BFD_RELOC_PPC64_PLT16_LO_DS
:
5343 case BFD_RELOC_PPC64_SECTOFF_DS
:
5344 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
5345 case BFD_RELOC_PPC64_TOC16_DS
:
5346 case BFD_RELOC_PPC64_TOC16_LO_DS
:
5347 case BFD_RELOC_PPC64_PLTGOT16_DS
:
5348 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
5352 unsigned char *where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5355 if (target_big_endian
)
5356 val
= bfd_getb16 (where
);
5358 val
= bfd_getl16 (where
);
5359 val
|= (value
& 0xfffc);
5360 if (target_big_endian
)
5361 bfd_putb16 ((bfd_vma
) val
, where
);
5363 bfd_putl16 ((bfd_vma
) val
, where
);
5368 /* Because SDA21 modifies the register field, the size is set to 4
5369 bytes, rather than 2, so offset it here appropriately. */
5370 case BFD_RELOC_PPC_EMB_SDA21
:
5374 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
5375 + ((target_big_endian
) ? 2 : 0),
5383 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5387 case BFD_RELOC_24_PLT_PCREL
:
5388 case BFD_RELOC_PPC_LOCAL24PC
:
5389 if (!fixp
->fx_pcrel
&& !fixp
->fx_done
)
5397 /* Fetch the instruction, insert the fully resolved operand
5398 value, and stuff the instruction back again. */
5399 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5400 if (target_big_endian
)
5401 insn
= bfd_getb32 ((unsigned char *) where
);
5403 insn
= bfd_getl32 ((unsigned char *) where
);
5404 if ((value
& 3) != 0)
5405 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5406 _("must branch to an address a multiple of 4"));
5407 if ((offsetT
) value
< -0x40000000
5408 || (offsetT
) value
>= 0x40000000)
5409 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5410 _("@local or @plt branch destination is too far away, %ld bytes"),
5412 insn
= insn
| (value
& 0x03fffffc);
5413 if (target_big_endian
)
5414 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5416 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5420 case BFD_RELOC_VTABLE_INHERIT
:
5423 && !S_IS_DEFINED (fixp
->fx_addsy
)
5424 && !S_IS_WEAK (fixp
->fx_addsy
))
5425 S_SET_WEAK (fixp
->fx_addsy
);
5428 case BFD_RELOC_VTABLE_ENTRY
:
5433 #if BFD_DEFAULT_TARGET_SIZE == 64
5434 /* Generated by reference to `sym@tocbase'. The sym is
5435 ignored by the linker. */
5436 case BFD_RELOC_PPC64_TOC
:
5443 _("Gas failure, reloc value %d\n"), fixp
->fx_r_type
);
5450 fixp
->fx_addnumber
= value
;
5452 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
5453 fixp
->fx_addnumber
= 0;
5457 fixp
->fx_addnumber
= 0;
5459 /* We want to use the offset within the data segment of the
5460 symbol, not the actual VMA of the symbol. */
5461 fixp
->fx_addnumber
=
5462 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
5470 /* Generate a reloc for a fixup. */
5473 tc_gen_reloc (seg
, fixp
)
5474 asection
*seg ATTRIBUTE_UNUSED
;
5479 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5481 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5482 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5483 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5484 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5485 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
5487 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5488 _("reloc %d not supported by object file format"),
5489 (int) fixp
->fx_r_type
);
5492 reloc
->addend
= fixp
->fx_addnumber
;