1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "safe-ctype.h"
28 #include "opcode/ppc.h"
32 #include "dwarf2dbg.h"
39 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
41 /* Tell the main code what the endianness is. */
42 extern int target_big_endian
;
44 /* Whether or not, we've set target_big_endian. */
45 static int set_target_endian
= 0;
47 /* Whether to use user friendly register names. */
48 #ifndef TARGET_REG_NAMES_P
50 #define TARGET_REG_NAMES_P TRUE
52 #define TARGET_REG_NAMES_P FALSE
56 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
59 /* #lo(value) denotes the least significant 16 bits of the indicated. */
60 #define PPC_LO(v) ((v) & 0xffff)
62 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
63 #define PPC_HI(v) (((v) >> 16) & 0xffff)
65 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
66 the indicated value, compensating for #lo() being treated as a
68 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
70 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
71 #define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
73 /* #highera(value) denotes bits 32 through 47 of the indicated value,
74 compensating for #lo() being treated as a signed number. */
75 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
77 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
78 #define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
80 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
81 compensating for #lo being treated as a signed number. */
82 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
84 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
86 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
88 static bfd_boolean register_name
PARAMS ((expressionS
*));
89 static void ppc_set_cpu
PARAMS ((void));
90 static unsigned long ppc_insert_operand
91 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
92 offsetT val
, char *file
, unsigned int line
));
93 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
94 static void ppc_byte
PARAMS ((int));
96 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
97 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
98 static void ppc_tc
PARAMS ((int));
99 static void ppc_machine
PARAMS ((int));
103 static void ppc_comm
PARAMS ((int));
104 static void ppc_bb
PARAMS ((int));
105 static void ppc_bc
PARAMS ((int));
106 static void ppc_bf
PARAMS ((int));
107 static void ppc_biei
PARAMS ((int));
108 static void ppc_bs
PARAMS ((int));
109 static void ppc_eb
PARAMS ((int));
110 static void ppc_ec
PARAMS ((int));
111 static void ppc_ef
PARAMS ((int));
112 static void ppc_es
PARAMS ((int));
113 static void ppc_csect
PARAMS ((int));
114 static void ppc_change_csect
PARAMS ((symbolS
*));
115 static void ppc_function
PARAMS ((int));
116 static void ppc_extern
PARAMS ((int));
117 static void ppc_lglobl
PARAMS ((int));
118 static void ppc_section
PARAMS ((int));
119 static void ppc_named_section
PARAMS ((int));
120 static void ppc_stabx
PARAMS ((int));
121 static void ppc_rename
PARAMS ((int));
122 static void ppc_toc
PARAMS ((int));
123 static void ppc_xcoff_cons
PARAMS ((int));
124 static void ppc_vbyte
PARAMS ((int));
128 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
129 static void ppc_elf_cons
PARAMS ((int));
130 static void ppc_elf_rdata
PARAMS ((int));
131 static void ppc_elf_lcomm
PARAMS ((int));
132 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
133 static void ppc_apuinfo_section_add
PARAMS ((unsigned int apu
, unsigned int version
));
137 static void ppc_set_current_section
PARAMS ((segT
));
138 static void ppc_previous
PARAMS ((int));
139 static void ppc_pdata
PARAMS ((int));
140 static void ppc_ydata
PARAMS ((int));
141 static void ppc_reldata
PARAMS ((int));
142 static void ppc_rdata
PARAMS ((int));
143 static void ppc_ualong
PARAMS ((int));
144 static void ppc_znop
PARAMS ((int));
145 static void ppc_pe_comm
PARAMS ((int));
146 static void ppc_pe_section
PARAMS ((int));
147 static void ppc_pe_function
PARAMS ((int));
148 static void ppc_pe_tocd
PARAMS ((int));
151 /* Generic assembler global variables which must be defined by all
155 /* This string holds the chars that always start a comment. If the
156 pre-processor is disabled, these aren't very useful. The macro
157 tc_comment_chars points to this. We use this, rather than the
158 usual comment_chars, so that we can switch for Solaris conventions. */
159 static const char ppc_solaris_comment_chars
[] = "#!";
160 static const char ppc_eabi_comment_chars
[] = "#";
162 #ifdef TARGET_SOLARIS_COMMENT
163 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
165 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
168 const char comment_chars
[] = "#";
171 /* Characters which start a comment at the beginning of a line. */
172 const char line_comment_chars
[] = "#";
174 /* Characters which may be used to separate multiple commands on a
176 const char line_separator_chars
[] = ";";
178 /* Characters which are used to indicate an exponent in a floating
180 const char EXP_CHARS
[] = "eE";
182 /* Characters which mean that a number is a floating point constant,
184 const char FLT_CHARS
[] = "dD";
186 /* '+' and '-' can be used as postfix predicate predictors for conditional
187 branches. So they need to be accepted as symbol characters. */
188 const char ppc_symbol_chars
[] = "+-";
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", (void (*) PARAMS ((int))) 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 bfd_boolean cr_operand
;
657 /* Names to recognize in a condition code. This table is sorted. */
658 static const struct pd_reg cr_names
[] =
675 /* Parsing function. This returns non-zero if it recognized an
679 ppc_parse_name (name
, expr
)
688 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
693 expr
->X_op
= O_constant
;
694 expr
->X_add_number
= val
;
699 /* Local variables. */
701 /* The type of processor we are assembling for. This is one or more
702 of the PPC_OPCODE flags defined in opcode/ppc.h. */
703 static unsigned long ppc_cpu
= 0;
705 /* Whether to target xcoff64/elf64. */
706 static unsigned int ppc_obj64
= BFD_DEFAULT_TARGET_SIZE
== 64;
708 /* Opcode hash table. */
709 static struct hash_control
*ppc_hash
;
711 /* Macro hash table. */
712 static struct hash_control
*ppc_macro_hash
;
715 /* What type of shared library support to use. */
716 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
718 /* Flags to set in the elf header. */
719 static flagword ppc_flags
= 0;
721 /* Whether this is Solaris or not. */
722 #ifdef TARGET_SOLARIS_COMMENT
723 #define SOLARIS_P TRUE
725 #define SOLARIS_P FALSE
728 static bfd_boolean msolaris
= SOLARIS_P
;
733 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
734 using a bunch of different sections. These assembler sections,
735 however, are all encompassed within the .text or .data sections of
736 the final output file. We handle this by using different
737 subsegments within these main segments. */
739 /* Next subsegment to allocate within the .text segment. */
740 static subsegT ppc_text_subsegment
= 2;
742 /* Linked list of csects in the text section. */
743 static symbolS
*ppc_text_csects
;
745 /* Next subsegment to allocate within the .data segment. */
746 static subsegT ppc_data_subsegment
= 2;
748 /* Linked list of csects in the data section. */
749 static symbolS
*ppc_data_csects
;
751 /* The current csect. */
752 static symbolS
*ppc_current_csect
;
754 /* The RS/6000 assembler uses a TOC which holds addresses of functions
755 and variables. Symbols are put in the TOC with the .tc pseudo-op.
756 A special relocation is used when accessing TOC entries. We handle
757 the TOC as a subsegment within the .data segment. We set it up if
758 we see a .toc pseudo-op, and save the csect symbol here. */
759 static symbolS
*ppc_toc_csect
;
761 /* The first frag in the TOC subsegment. */
762 static fragS
*ppc_toc_frag
;
764 /* The first frag in the first subsegment after the TOC in the .data
765 segment. NULL if there are no subsegments after the TOC. */
766 static fragS
*ppc_after_toc_frag
;
768 /* The current static block. */
769 static symbolS
*ppc_current_block
;
771 /* The COFF debugging section; set by md_begin. This is not the
772 .debug section, but is instead the secret BFD section which will
773 cause BFD to set the section number of a symbol to N_DEBUG. */
774 static asection
*ppc_coff_debug_section
;
776 #endif /* OBJ_XCOFF */
780 /* Various sections that we need for PE coff support. */
781 static segT ydata_section
;
782 static segT pdata_section
;
783 static segT reldata_section
;
784 static segT rdata_section
;
785 static segT tocdata_section
;
787 /* The current section and the previous section. See ppc_previous. */
788 static segT ppc_previous_section
;
789 static segT ppc_current_section
;
794 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
795 #define PPC_APUINFO_ISEL 0x40
796 #define PPC_APUINFO_PMR 0x41
797 #define PPC_APUINFO_RFMCI 0x42
798 #define PPC_APUINFO_CACHELCK 0x43
799 #define PPC_APUINFO_SPE 0x100
800 #define PPC_APUINFO_EFS 0x101
801 #define PPC_APUINFO_BRLOCK 0x102
804 * We keep a list of APUinfo
806 unsigned long *ppc_apuinfo_list
;
807 unsigned int ppc_apuinfo_num
;
808 unsigned int ppc_apuinfo_num_alloc
;
812 const char *const md_shortopts
= "b:l:usm:K:VQ:";
814 const char *const md_shortopts
= "um:";
816 const struct option md_longopts
[] = {
817 {NULL
, no_argument
, NULL
, 0}
819 const size_t md_longopts_size
= sizeof (md_longopts
);
822 md_parse_option (c
, arg
)
829 /* -u means that any undefined symbols should be treated as
830 external, which is the default for gas anyhow. */
835 /* Solaris as takes -le (presumably for little endian). For completeness
836 sake, recognize -be also. */
837 if (strcmp (arg
, "e") == 0)
839 target_big_endian
= 0;
840 set_target_endian
= 1;
848 if (strcmp (arg
, "e") == 0)
850 target_big_endian
= 1;
851 set_target_endian
= 1;
859 /* Recognize -K PIC. */
860 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
863 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
871 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
873 if (strcmp (arg
, "64") == 0)
878 as_fatal (_("%s unsupported"), "-a64");
881 else if (strcmp (arg
, "32") == 0)
888 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
890 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
891 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_32
;
892 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
893 else if (strcmp (arg
, "pwr") == 0)
894 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
895 /* -m601 means to assemble for the PowerPC 601, which includes
896 instructions that are holdovers from the Power. */
897 else if (strcmp (arg
, "601") == 0)
898 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
899 | PPC_OPCODE_601
| PPC_OPCODE_32
);
900 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
902 else if (strcmp (arg
, "ppc") == 0
903 || strcmp (arg
, "ppc32") == 0
904 || strcmp (arg
, "603") == 0
905 || strcmp (arg
, "604") == 0)
906 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
907 /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */
908 else if (strcmp (arg
, "403") == 0
909 || strcmp (arg
, "405") == 0)
910 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
911 | PPC_OPCODE_403
| PPC_OPCODE_32
);
912 else if (strcmp (arg
, "7400") == 0
913 || strcmp (arg
, "7410") == 0
914 || strcmp (arg
, "7450") == 0
915 || strcmp (arg
, "7455") == 0)
916 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
917 | PPC_OPCODE_ALTIVEC
| PPC_OPCODE_32
);
918 else if (strcmp (arg
, "altivec") == 0)
921 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_ALTIVEC
;
923 ppc_cpu
|= PPC_OPCODE_ALTIVEC
;
925 else if (strcmp (arg
, "e500") == 0 || strcmp (arg
, "e500x2") == 0)
927 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
928 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
929 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
932 else if (strcmp (arg
, "spe") == 0)
935 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_SPE
| PPC_OPCODE_EFS
;
937 ppc_cpu
|= PPC_OPCODE_SPE
;
939 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
941 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
943 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
945 else if (strcmp (arg
, "ppc64bridge") == 0)
947 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
948 | PPC_OPCODE_64_BRIDGE
| PPC_OPCODE_64
);
950 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
951 else if (strcmp (arg
, "booke") == 0 || strcmp (arg
, "booke32") == 0)
953 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
;
955 /* -mbooke64 means enable 64-bit BookE support. */
956 else if (strcmp (arg
, "booke64") == 0)
958 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
959 | PPC_OPCODE_BOOKE64
| PPC_OPCODE_64
);
961 else if (strcmp (arg
, "power4") == 0)
963 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
964 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
);
966 /* -mcom means assemble for the common intersection between Power
967 and PowerPC. At present, we just allow the union, rather
968 than the intersection. */
969 else if (strcmp (arg
, "com") == 0)
970 ppc_cpu
= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
971 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
972 else if (strcmp (arg
, "any") == 0)
973 ppc_cpu
= PPC_OPCODE_ANY
| PPC_OPCODE_32
;
975 else if (strcmp (arg
, "regnames") == 0)
978 else if (strcmp (arg
, "no-regnames") == 0)
982 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
983 that require relocation. */
984 else if (strcmp (arg
, "relocatable") == 0)
986 shlib
= SHLIB_MRELOCATABLE
;
987 ppc_flags
|= EF_PPC_RELOCATABLE
;
990 else if (strcmp (arg
, "relocatable-lib") == 0)
992 shlib
= SHLIB_MRELOCATABLE
;
993 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
996 /* -memb, set embedded bit. */
997 else if (strcmp (arg
, "emb") == 0)
998 ppc_flags
|= EF_PPC_EMB
;
1000 /* -mlittle/-mbig set the endianess. */
1001 else if (strcmp (arg
, "little") == 0
1002 || strcmp (arg
, "little-endian") == 0)
1004 target_big_endian
= 0;
1005 set_target_endian
= 1;
1008 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
1010 target_big_endian
= 1;
1011 set_target_endian
= 1;
1014 else if (strcmp (arg
, "solaris") == 0)
1017 ppc_comment_chars
= ppc_solaris_comment_chars
;
1020 else if (strcmp (arg
, "no-solaris") == 0)
1023 ppc_comment_chars
= ppc_eabi_comment_chars
;
1028 as_bad (_("invalid switch -m%s"), arg
);
1034 /* -V: SVR4 argument to print version ID. */
1036 print_version_id ();
1039 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1040 should be emitted or not. FIXME: Not implemented. */
1044 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1045 rather than .stabs.excl, which is ignored by the linker.
1046 FIXME: Not implemented. */
1062 md_show_usage (stream
)
1065 fprintf (stream
, _("\
1068 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1069 -mpwr generate code for POWER (RIOS1)\n\
1070 -m601 generate code for PowerPC 601\n\
1071 -mppc, -mppc32, -m603, -m604\n\
1072 generate code for PowerPC 603/604\n\
1073 -m403, -m405 generate code for PowerPC 403/405\n\
1074 -m7400, -m7410, -m7450, -m7455\n\
1075 generate code For PowerPC 7400/7410/7450/7455\n\
1076 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1077 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1078 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1079 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1080 -mpower4 generate code for Power4 architecture\n\
1081 -maltivec generate code for AltiVec\n\
1082 -mcom generate code Power/PowerPC common instructions\n\
1083 -many generate code for any architecture (PWR/PWRX/PPC)\n\
1084 -mregnames Allow symbolic names for registers\n\
1085 -mno-regnames Do not allow symbolic names for registers\n"));
1086 fprintf (stream
, _("\
1087 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1088 -mspe generate code for Motorola SPE instructions\n"));
1090 fprintf (stream
, _("\
1091 -mrelocatable support for GCC's -mrelocatble option\n\
1092 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1093 -memb set PPC_EMB bit in ELF flags\n\
1094 -mlittle, -mlittle-endian\n\
1095 generate code for a little endian machine\n\
1096 -mbig, -mbig-endian generate code for a big endian machine\n\
1097 -msolaris generate code for Solaris\n\
1098 -mno-solaris do not generate code for Solaris\n\
1099 -V print assembler version number\n\
1100 -Qy, -Qn ignored\n"));
1104 /* Set ppc_cpu if it is not already set. */
1109 const char *default_os
= TARGET_OS
;
1110 const char *default_cpu
= TARGET_CPU
;
1115 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
1116 else if (strncmp (default_os
, "aix", 3) == 0
1117 && default_os
[3] >= '4' && default_os
[3] <= '9')
1118 ppc_cpu
= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
1119 else if (strncmp (default_os
, "aix3", 4) == 0)
1120 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1121 else if (strcmp (default_cpu
, "rs6000") == 0)
1122 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1123 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1125 if (default_cpu
[7] == '6' && default_cpu
[8] == '4')
1126 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
1128 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
1131 as_fatal (_("Unknown default cpu = %s, os = %s"),
1132 default_cpu
, default_os
);
1136 /* Figure out the BFD architecture to use. */
1138 enum bfd_architecture
1141 const char *default_cpu
= TARGET_CPU
;
1144 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1145 return bfd_arch_powerpc
;
1146 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1147 return bfd_arch_rs6000
;
1148 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1150 if (strcmp (default_cpu
, "rs6000") == 0)
1151 return bfd_arch_rs6000
;
1152 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1153 return bfd_arch_powerpc
;
1156 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1157 return bfd_arch_unknown
;
1164 return bfd_mach_ppc64
;
1165 else if (ppc_arch () == bfd_arch_rs6000
)
1166 return bfd_mach_rs6k
;
1168 return bfd_mach_ppc
;
1172 ppc_target_format ()
1176 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1178 return "xcoff-powermac";
1181 return (ppc_obj64
? "aix5coff64-rs6000" : "aixcoff-rs6000");
1183 return (ppc_obj64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1188 return (target_big_endian
1189 ? (ppc_obj64
? "elf64-powerpc" : "elf32-powerpc")
1190 : (ppc_obj64
? "elf64-powerpcle" : "elf32-powerpcle"));
1194 /* This function is called when the assembler starts up. It is called
1195 after the options have been parsed and the output file has been
1201 register const struct powerpc_opcode
*op
;
1202 const struct powerpc_opcode
*op_end
;
1203 const struct powerpc_macro
*macro
;
1204 const struct powerpc_macro
*macro_end
;
1205 bfd_boolean dup_insn
= FALSE
;
1210 /* Set the ELF flags if desired. */
1211 if (ppc_flags
&& !msolaris
)
1212 bfd_set_private_flags (stdoutput
, ppc_flags
);
1215 /* Insert the opcodes into a hash table. */
1216 ppc_hash
= hash_new ();
1218 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1219 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1221 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1223 if ((op
->flags
& ppc_cpu
& ~(PPC_OPCODE_32
| PPC_OPCODE_64
)) != 0
1224 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1225 || ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
))
1226 == (ppc_cpu
& (PPC_OPCODE_32
| PPC_OPCODE_64
)))
1227 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0)
1228 /* Certain instructions (eg: extsw) do not exist in the
1229 32-bit BookE instruction set, but they do exist in the
1230 64-bit BookE instruction set, and other PPC instruction
1231 sets. Check to see if the opcode has the BOOKE64 flag set.
1232 If it does make sure that the target CPU is not the BookE32. */
1233 && ((op
->flags
& PPC_OPCODE_BOOKE64
) == 0
1234 || (ppc_cpu
& PPC_OPCODE_BOOKE64
) == PPC_OPCODE_BOOKE64
1235 || (ppc_cpu
& PPC_OPCODE_BOOKE
) == 0)
1236 && ((op
->flags
& (PPC_OPCODE_POWER4
| PPC_OPCODE_NOPOWER4
)) == 0
1237 || ((op
->flags
& PPC_OPCODE_POWER4
)
1238 == (ppc_cpu
& PPC_OPCODE_POWER4
))))
1242 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1243 if (retval
!= (const char *) NULL
)
1245 /* Ignore Power duplicates for -m601. */
1246 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1247 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1250 as_bad (_("Internal assembler error for instruction %s"),
1257 /* Insert the macros into a hash table. */
1258 ppc_macro_hash
= hash_new ();
1260 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1261 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1263 if ((macro
->flags
& ppc_cpu
) != 0)
1267 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1268 if (retval
!= (const char *) NULL
)
1270 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1279 /* Tell the main code what the endianness is if it is not overidden
1281 if (!set_target_endian
)
1283 set_target_endian
= 1;
1284 target_big_endian
= PPC_BIG_ENDIAN
;
1288 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1290 /* Create dummy symbols to serve as initial csects. This forces the
1291 text csects to precede the data csects. These symbols will not
1293 ppc_text_csects
= symbol_make ("dummy\001");
1294 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1295 ppc_data_csects
= symbol_make ("dummy\001");
1296 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1301 ppc_current_section
= text_section
;
1302 ppc_previous_section
= 0;
1311 if (ppc_apuinfo_list
== NULL
)
1314 /* Ok, so write the section info out. We have this layout:
1318 0 8 length of "APUinfo\0"
1319 4 (n*4) number of APU's (4 bytes each)
1322 20 APU#1 first APU's info
1323 24 APU#2 second APU's info
1328 asection
*seg
= now_seg
;
1329 subsegT subseg
= now_subseg
;
1330 asection
*apuinfo_secp
= (asection
*) NULL
;
1333 /* Create the .PPC.EMB.apuinfo section. */
1334 apuinfo_secp
= subseg_new (".PPC.EMB.apuinfo", 0);
1335 bfd_set_section_flags (stdoutput
,
1337 SEC_HAS_CONTENTS
| SEC_READONLY
);
1340 md_number_to_chars (p
, (valueT
) 8, 4);
1343 md_number_to_chars (p
, (valueT
) ppc_apuinfo_num
, 4);
1346 md_number_to_chars (p
, (valueT
) 2, 4);
1349 strcpy (p
, "APUinfo");
1351 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
1354 md_number_to_chars (p
, (valueT
) ppc_apuinfo_list
[i
], 4);
1357 frag_align (2, 0, 0);
1359 /* We probably can't restore the current segment, for there likely
1362 subseg_set (seg
, subseg
);
1367 /* Insert an operand value into an instruction. */
1369 static unsigned long
1370 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1372 const struct powerpc_operand
*operand
;
1377 if (operand
->bits
!= 32)
1382 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1384 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1385 max
= (1 << operand
->bits
) - 1;
1387 max
= (1 << (operand
->bits
- 1)) - 1;
1388 min
= - (1 << (operand
->bits
- 1));
1392 /* Some people write 32 bit hex constants with the sign
1393 extension done by hand. This shouldn't really be
1394 valid, but, to permit this code to assemble on a 64
1395 bit host, we sign extend the 32 bit value. */
1397 && (val
& (offsetT
) 0x80000000) != 0
1398 && (val
& (offsetT
) 0xffffffff) == val
)
1407 max
= (1 << operand
->bits
) - 1;
1411 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1416 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1419 _("operand out of range (%s not between %ld and %ld)");
1422 sprint_value (buf
, test
);
1423 as_bad_where (file
, line
, err
, buf
, min
, max
);
1427 if (operand
->insert
)
1432 insn
= (*operand
->insert
) (insn
, (long) val
, ppc_cpu
, &errmsg
);
1433 if (errmsg
!= (const char *) NULL
)
1434 as_bad_where (file
, line
, errmsg
);
1437 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1445 /* Parse @got, etc. and return the desired relocation. */
1446 static bfd_reloc_code_real_type
1447 ppc_elf_suffix (str_p
, exp_p
)
1462 const struct map_bfd
*ptr
;
1464 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1466 static const struct map_bfd mapping
[] = {
1467 MAP ("l", (int) BFD_RELOC_LO16
),
1468 MAP ("h", (int) BFD_RELOC_HI16
),
1469 MAP ("ha", (int) BFD_RELOC_HI16_S
),
1470 MAP ("brtaken", (int) BFD_RELOC_PPC_B16_BRTAKEN
),
1471 MAP ("brntaken", (int) BFD_RELOC_PPC_B16_BRNTAKEN
),
1472 MAP ("got", (int) BFD_RELOC_16_GOTOFF
),
1473 MAP ("got@l", (int) BFD_RELOC_LO16_GOTOFF
),
1474 MAP ("got@h", (int) BFD_RELOC_HI16_GOTOFF
),
1475 MAP ("got@ha", (int) BFD_RELOC_HI16_S_GOTOFF
),
1476 MAP ("fixup", (int) BFD_RELOC_CTOR
),
1477 MAP ("plt", (int) BFD_RELOC_24_PLT_PCREL
),
1478 MAP ("pltrel24", (int) BFD_RELOC_24_PLT_PCREL
),
1479 MAP ("copy", (int) BFD_RELOC_PPC_COPY
),
1480 MAP ("globdat", (int) BFD_RELOC_PPC_GLOB_DAT
),
1481 MAP ("local24pc", (int) BFD_RELOC_PPC_LOCAL24PC
),
1482 MAP ("local", (int) BFD_RELOC_PPC_LOCAL24PC
),
1483 MAP ("pltrel", (int) BFD_RELOC_32_PLT_PCREL
),
1484 MAP ("plt@l", (int) BFD_RELOC_LO16_PLTOFF
),
1485 MAP ("plt@h", (int) BFD_RELOC_HI16_PLTOFF
),
1486 MAP ("plt@ha", (int) BFD_RELOC_HI16_S_PLTOFF
),
1487 MAP ("sdarel", (int) BFD_RELOC_GPREL16
),
1488 MAP ("sectoff", (int) BFD_RELOC_16_BASEREL
),
1489 MAP ("sectoff@l", (int) BFD_RELOC_LO16_BASEREL
),
1490 MAP ("sectoff@h", (int) BFD_RELOC_HI16_BASEREL
),
1491 MAP ("sectoff@ha", (int) BFD_RELOC_HI16_S_BASEREL
),
1492 MAP ("naddr", (int) BFD_RELOC_PPC_EMB_NADDR32
),
1493 MAP ("naddr16", (int) BFD_RELOC_PPC_EMB_NADDR16
),
1494 MAP ("naddr@l", (int) BFD_RELOC_PPC_EMB_NADDR16_LO
),
1495 MAP ("naddr@h", (int) BFD_RELOC_PPC_EMB_NADDR16_HI
),
1496 MAP ("naddr@ha", (int) BFD_RELOC_PPC_EMB_NADDR16_HA
),
1497 MAP ("sdai16", (int) BFD_RELOC_PPC_EMB_SDAI16
),
1498 MAP ("sda2rel", (int) BFD_RELOC_PPC_EMB_SDA2REL
),
1499 MAP ("sda2i16", (int) BFD_RELOC_PPC_EMB_SDA2I16
),
1500 MAP ("sda21", (int) BFD_RELOC_PPC_EMB_SDA21
),
1501 MAP ("mrkref", (int) BFD_RELOC_PPC_EMB_MRKREF
),
1502 MAP ("relsect", (int) BFD_RELOC_PPC_EMB_RELSEC16
),
1503 MAP ("relsect@l", (int) BFD_RELOC_PPC_EMB_RELST_LO
),
1504 MAP ("relsect@h", (int) BFD_RELOC_PPC_EMB_RELST_HI
),
1505 MAP ("relsect@ha", (int) BFD_RELOC_PPC_EMB_RELST_HA
),
1506 MAP ("bitfld", (int) BFD_RELOC_PPC_EMB_BIT_FLD
),
1507 MAP ("relsda", (int) BFD_RELOC_PPC_EMB_RELSDA
),
1508 MAP ("xgot", (int) BFD_RELOC_PPC_TOC16
),
1509 MAP ("tls", (int) BFD_RELOC_PPC_TLS
),
1510 MAP ("dtpmod", (int) BFD_RELOC_PPC_DTPMOD
),
1511 MAP ("dtprel", (int) BFD_RELOC_PPC_DTPREL
),
1512 MAP ("dtprel@l", (int) BFD_RELOC_PPC_DTPREL16_LO
),
1513 MAP ("dtprel@h", (int) BFD_RELOC_PPC_DTPREL16_HI
),
1514 MAP ("dtprel@ha", (int) BFD_RELOC_PPC_DTPREL16_HA
),
1515 MAP ("tprel", (int) BFD_RELOC_PPC_TPREL
),
1516 MAP ("tprel@l", (int) BFD_RELOC_PPC_TPREL16_LO
),
1517 MAP ("tprel@h", (int) BFD_RELOC_PPC_TPREL16_HI
),
1518 MAP ("tprel@ha", (int) BFD_RELOC_PPC_TPREL16_HA
),
1519 MAP ("got@tlsgd", (int) BFD_RELOC_PPC_GOT_TLSGD16
),
1520 MAP ("got@tlsgd@l", (int) BFD_RELOC_PPC_GOT_TLSGD16_LO
),
1521 MAP ("got@tlsgd@h", (int) BFD_RELOC_PPC_GOT_TLSGD16_HI
),
1522 MAP ("got@tlsgd@ha", (int) BFD_RELOC_PPC_GOT_TLSGD16_HA
),
1523 MAP ("got@tlsld", (int) BFD_RELOC_PPC_GOT_TLSLD16
),
1524 MAP ("got@tlsld@l", (int) BFD_RELOC_PPC_GOT_TLSLD16_LO
),
1525 MAP ("got@tlsld@h", (int) BFD_RELOC_PPC_GOT_TLSLD16_HI
),
1526 MAP ("got@tlsld@ha", (int) BFD_RELOC_PPC_GOT_TLSLD16_HA
),
1527 MAP ("got@dtprel", (int) BFD_RELOC_PPC_GOT_DTPREL16
),
1528 MAP ("got@dtprel@l", (int) BFD_RELOC_PPC_GOT_DTPREL16_LO
),
1529 MAP ("got@dtprel@h", (int) BFD_RELOC_PPC_GOT_DTPREL16_HI
),
1530 MAP ("got@dtprel@ha", (int) BFD_RELOC_PPC_GOT_DTPREL16_HA
),
1531 MAP ("got@tprel", (int) BFD_RELOC_PPC_GOT_TPREL16
),
1532 MAP ("got@tprel@l", (int) BFD_RELOC_PPC_GOT_TPREL16_LO
),
1533 MAP ("got@tprel@h", (int) BFD_RELOC_PPC_GOT_TPREL16_HI
),
1534 MAP ("got@tprel@ha", (int) BFD_RELOC_PPC_GOT_TPREL16_HA
),
1535 /* The following are only valid for ppc64. Negative values are
1536 used instead of a flag. */
1537 MAP ("higher", - (int) BFD_RELOC_PPC64_HIGHER
),
1538 MAP ("highera", - (int) BFD_RELOC_PPC64_HIGHER_S
),
1539 MAP ("highest", - (int) BFD_RELOC_PPC64_HIGHEST
),
1540 MAP ("highesta", - (int) BFD_RELOC_PPC64_HIGHEST_S
),
1541 MAP ("tocbase", - (int) BFD_RELOC_PPC64_TOC
),
1542 MAP ("toc", - (int) BFD_RELOC_PPC_TOC16
),
1543 MAP ("toc@l", - (int) BFD_RELOC_PPC64_TOC16_LO
),
1544 MAP ("toc@h", - (int) BFD_RELOC_PPC64_TOC16_HI
),
1545 MAP ("toc@ha", - (int) BFD_RELOC_PPC64_TOC16_HA
),
1546 MAP ("dtprel@higher", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHER
),
1547 MAP ("dtprel@highera", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHERA
),
1548 MAP ("dtprel@highest", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHEST
),
1549 MAP ("dtprel@highesta", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHESTA
),
1550 MAP ("tprel@higher", - (int) BFD_RELOC_PPC64_TPREL16_HIGHER
),
1551 MAP ("tprel@highera", - (int) BFD_RELOC_PPC64_TPREL16_HIGHERA
),
1552 MAP ("tprel@highest", - (int) BFD_RELOC_PPC64_TPREL16_HIGHEST
),
1553 MAP ("tprel@highesta", - (int) BFD_RELOC_PPC64_TPREL16_HIGHESTA
),
1554 { (char *) 0, 0, (int) BFD_RELOC_UNUSED
}
1558 return BFD_RELOC_UNUSED
;
1560 for (ch
= *str
, str2
= ident
;
1561 (str2
< ident
+ sizeof (ident
) - 1
1562 && (ISALNUM (ch
) || ch
== '@'));
1565 *str2
++ = TOLOWER (ch
);
1572 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1573 if (ch
== ptr
->string
[0]
1574 && len
== ptr
->length
1575 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1577 int reloc
= ptr
->reloc
;
1582 return BFD_RELOC_UNUSED
;
1587 if (exp_p
->X_add_number
!= 0
1588 && (reloc
== (int) BFD_RELOC_16_GOTOFF
1589 || reloc
== (int) BFD_RELOC_LO16_GOTOFF
1590 || reloc
== (int) BFD_RELOC_HI16_GOTOFF
1591 || reloc
== (int) BFD_RELOC_HI16_S_GOTOFF
))
1592 as_warn (_("identifier+constant@got means identifier@got+constant"));
1594 /* Now check for identifier@suffix+constant. */
1595 if (*str
== '-' || *str
== '+')
1597 char *orig_line
= input_line_pointer
;
1598 expressionS new_exp
;
1600 input_line_pointer
= str
;
1601 expression (&new_exp
);
1602 if (new_exp
.X_op
== O_constant
)
1604 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1605 str
= input_line_pointer
;
1608 if (&input_line_pointer
!= str_p
)
1609 input_line_pointer
= orig_line
;
1613 if (reloc
== (int) BFD_RELOC_PPC64_TOC
1614 && exp_p
->X_op
== O_symbol
)
1616 /* This reloc type ignores the symbol. Change the symbol
1617 so that the dummy .TOC. symbol can be omitted from the
1619 exp_p
->X_add_symbol
= &abs_symbol
;
1622 return (bfd_reloc_code_real_type
) reloc
;
1625 return BFD_RELOC_UNUSED
;
1628 /* Like normal .long/.short/.word, except support @got, etc.
1629 Clobbers input_line_pointer, checks end-of-line. */
1631 ppc_elf_cons (nbytes
)
1632 register int nbytes
; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1635 bfd_reloc_code_real_type reloc
;
1637 if (is_it_end_of_statement ())
1639 demand_empty_rest_of_line ();
1646 if (exp
.X_op
== O_symbol
1647 && *input_line_pointer
== '@'
1648 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1649 &exp
)) != BFD_RELOC_UNUSED
)
1651 reloc_howto_type
*reloc_howto
;
1654 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1655 size
= bfd_get_reloc_size (reloc_howto
);
1659 as_bad (_("%s relocations do not fit in %d bytes\n"),
1660 reloc_howto
->name
, nbytes
);
1667 p
= frag_more (nbytes
);
1669 if (target_big_endian
)
1670 offset
= nbytes
- size
;
1671 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1676 emit_expr (&exp
, (unsigned int) nbytes
);
1678 while (*input_line_pointer
++ == ',');
1680 /* Put terminator back into stream. */
1681 input_line_pointer
--;
1682 demand_empty_rest_of_line ();
1685 /* Solaris pseduo op to change to the .rodata section. */
1690 char *save_line
= input_line_pointer
;
1691 static char section
[] = ".rodata\n";
1693 /* Just pretend this is .section .rodata */
1694 input_line_pointer
= section
;
1695 obj_elf_section (xxx
);
1697 input_line_pointer
= save_line
;
1700 /* Pseudo op to make file scope bss items. */
1703 int xxx ATTRIBUTE_UNUSED
;
1705 register char *name
;
1709 register symbolS
*symbolP
;
1716 name
= input_line_pointer
;
1717 c
= get_symbol_end ();
1719 /* just after name is now '\0'. */
1720 p
= input_line_pointer
;
1723 if (*input_line_pointer
!= ',')
1725 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1726 ignore_rest_of_line ();
1730 input_line_pointer
++; /* skip ',' */
1731 if ((size
= get_absolute_expression ()) < 0)
1733 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1734 ignore_rest_of_line ();
1738 /* The third argument to .lcomm is the alignment. */
1739 if (*input_line_pointer
!= ',')
1743 ++input_line_pointer
;
1744 align
= get_absolute_expression ();
1747 as_warn (_("ignoring bad alignment"));
1753 symbolP
= symbol_find_or_make (name
);
1756 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1758 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1759 S_GET_NAME (symbolP
));
1760 ignore_rest_of_line ();
1764 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1766 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1767 S_GET_NAME (symbolP
),
1768 (long) S_GET_VALUE (symbolP
),
1771 ignore_rest_of_line ();
1777 old_subsec
= now_subseg
;
1780 /* Convert to a power of 2 alignment. */
1781 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1784 as_bad (_("Common alignment not a power of 2"));
1785 ignore_rest_of_line ();
1792 record_alignment (bss_section
, align2
);
1793 subseg_set (bss_section
, 0);
1795 frag_align (align2
, 0, 0);
1796 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1797 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1798 symbol_set_frag (symbolP
, frag_now
);
1799 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1802 S_SET_SIZE (symbolP
, size
);
1803 S_SET_SEGMENT (symbolP
, bss_section
);
1804 subseg_set (old_sec
, old_subsec
);
1805 demand_empty_rest_of_line ();
1808 /* Validate any relocations emitted for -mrelocatable, possibly adding
1809 fixups for word relocations in writable segments, so we can adjust
1812 ppc_elf_validate_fix (fixp
, seg
)
1816 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1825 case SHLIB_MRELOCATABLE
:
1826 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1827 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1828 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1829 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1830 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1831 && fixp
->fx_r_type
!= BFD_RELOC_16_BASEREL
1832 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1833 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1834 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1835 && (seg
->flags
& SEC_LOAD
) != 0
1836 && strcmp (segment_name (seg
), ".got2") != 0
1837 && strcmp (segment_name (seg
), ".dtors") != 0
1838 && strcmp (segment_name (seg
), ".ctors") != 0
1839 && strcmp (segment_name (seg
), ".fixup") != 0
1840 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1841 && strcmp (segment_name (seg
), ".eh_frame") != 0
1842 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1844 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1845 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1847 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1848 _("Relocation cannot be done when using -mrelocatable"));
1855 /* Prevent elf_frob_file_before_adjust removing a weak undefined
1856 function descriptor sym if the corresponding code sym is used. */
1859 ppc_frob_file_before_adjust ()
1866 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1873 name
= S_GET_NAME (symp
);
1877 if (! S_IS_WEAK (symp
)
1878 || S_IS_DEFINED (symp
))
1881 len
= strlen (name
) + 1;
1882 dotname
= xmalloc (len
+ 1);
1884 memcpy (dotname
+ 1, name
, len
);
1885 dotsym
= symbol_find (dotname
);
1887 if (dotsym
!= NULL
&& (symbol_used_p (dotsym
)
1888 || symbol_used_in_reloc_p (dotsym
)))
1890 symbol_mark_used (symp
);
1894 /* Don't emit .TOC. symbol. */
1895 symp
= symbol_find (".TOC.");
1897 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1899 #endif /* OBJ_ELF */
1904 * Summary of parse_toc_entry.
1906 * in: Input_line_pointer points to the '[' in one of:
1908 * [toc] [tocv] [toc32] [toc64]
1910 * Anything else is an error of one kind or another.
1913 * return value: success or failure
1914 * toc_kind: kind of toc reference
1915 * input_line_pointer:
1916 * success: first char after the ']'
1917 * failure: unchanged
1921 * [toc] - rv == success, toc_kind = default_toc
1922 * [tocv] - rv == success, toc_kind = data_in_toc
1923 * [toc32] - rv == success, toc_kind = must_be_32
1924 * [toc64] - rv == success, toc_kind = must_be_64
1928 enum toc_size_qualifier
1930 default_toc
, /* The toc cell constructed should be the system default size */
1931 data_in_toc
, /* This is a direct reference to a toc cell */
1932 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1933 must_be_64
/* The toc cell constructed must be 64 bits wide */
1937 parse_toc_entry (toc_kind
)
1938 enum toc_size_qualifier
*toc_kind
;
1943 enum toc_size_qualifier t
;
1945 /* Save the input_line_pointer. */
1946 start
= input_line_pointer
;
1948 /* Skip over the '[' , and whitespace. */
1949 ++input_line_pointer
;
1952 /* Find the spelling of the operand. */
1953 toc_spec
= input_line_pointer
;
1954 c
= get_symbol_end ();
1956 if (strcmp (toc_spec
, "toc") == 0)
1960 else if (strcmp (toc_spec
, "tocv") == 0)
1964 else if (strcmp (toc_spec
, "toc32") == 0)
1968 else if (strcmp (toc_spec
, "toc64") == 0)
1974 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1975 *input_line_pointer
= c
;
1976 input_line_pointer
= start
;
1980 /* Now find the ']'. */
1981 *input_line_pointer
= c
;
1983 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1984 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1988 as_bad (_("syntax error: expected `]', found `%c'"), c
);
1989 input_line_pointer
= start
;
2000 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2002 ppc_apuinfo_section_add (apu
, version
)
2003 unsigned int apu
, version
;
2007 /* Check we don't already exist. */
2008 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
2009 if (ppc_apuinfo_list
[i
] == APUID (apu
, version
))
2012 if (ppc_apuinfo_num
== ppc_apuinfo_num_alloc
)
2014 if (ppc_apuinfo_num_alloc
== 0)
2016 ppc_apuinfo_num_alloc
= 4;
2017 ppc_apuinfo_list
= (unsigned long *)
2018 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2022 ppc_apuinfo_num_alloc
+= 4;
2023 ppc_apuinfo_list
= (unsigned long *) xrealloc (ppc_apuinfo_list
,
2024 sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2027 ppc_apuinfo_list
[ppc_apuinfo_num
++] = APUID (apu
, version
);
2033 /* We need to keep a list of fixups. We can't simply generate them as
2034 we go, because that would require us to first create the frag, and
2035 that would screw up references to ``.''. */
2041 bfd_reloc_code_real_type reloc
;
2044 #define MAX_INSN_FIXUPS (5)
2046 /* This routine is called for each instruction to be assembled. */
2053 const struct powerpc_opcode
*opcode
;
2055 const unsigned char *opindex_ptr
;
2059 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
2064 bfd_reloc_code_real_type reloc
;
2067 /* Get the opcode. */
2068 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
2073 /* Look up the opcode in the hash table. */
2074 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
2075 if (opcode
== (const struct powerpc_opcode
*) NULL
)
2077 const struct powerpc_macro
*macro
;
2079 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
2080 if (macro
== (const struct powerpc_macro
*) NULL
)
2081 as_bad (_("Unrecognized opcode: `%s'"), str
);
2083 ppc_macro (s
, macro
);
2088 insn
= opcode
->opcode
;
2091 while (ISSPACE (*str
))
2094 /* PowerPC operands are just expressions. The only real issue is
2095 that a few operand types are optional. All cases which might use
2096 an optional operand separate the operands only with commas (in
2097 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
2098 cases never have optional operands). There is never more than
2099 one optional operand for an instruction. So, before we start
2100 seriously parsing the operands, we check to see if we have an
2101 optional operand, and, if we do, we count the number of commas to
2102 see whether the operand should be omitted. */
2104 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2106 const struct powerpc_operand
*operand
;
2108 operand
= &powerpc_operands
[*opindex_ptr
];
2109 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
2111 unsigned int opcount
;
2112 unsigned int num_operands_expected
;
2115 /* There is an optional operand. Count the number of
2116 commas in the input line. */
2123 while ((s
= strchr (s
, ',')) != (char *) NULL
)
2130 /* Compute the number of expected operands.
2131 Do not count fake operands. */
2132 for (num_operands_expected
= 0, i
= 0; opcode
->operands
[i
]; i
++)
2133 if ((powerpc_operands
[opcode
->operands
[i
]].flags
& PPC_OPERAND_FAKE
) == 0)
2134 ++ num_operands_expected
;
2136 /* If there are fewer operands in the line then are called
2137 for by the instruction, we want to skip the optional
2139 if (opcount
< num_operands_expected
)
2146 /* Gather the operands. */
2150 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2152 const struct powerpc_operand
*operand
;
2158 if (next_opindex
== 0)
2159 operand
= &powerpc_operands
[*opindex_ptr
];
2162 operand
= &powerpc_operands
[next_opindex
];
2167 /* If this is a fake operand, then we do not expect anything
2169 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
2171 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2172 if (errmsg
!= (const char *) NULL
)
2177 /* If this is an optional operand, and we are skipping it, just
2179 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
2182 if (operand
->insert
)
2184 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2185 if (errmsg
!= (const char *) NULL
)
2188 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
2189 next_opindex
= *opindex_ptr
+ 1;
2193 /* Gather the operand. */
2194 hold
= input_line_pointer
;
2195 input_line_pointer
= str
;
2198 if (*input_line_pointer
== '[')
2200 /* We are expecting something like the second argument here:
2202 * lwz r4,[toc].GS.0.static_int(rtoc)
2203 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2204 * The argument following the `]' must be a symbol name, and the
2205 * register must be the toc register: 'rtoc' or '2'
2207 * The effect is to 0 as the displacement field
2208 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2209 * the appropriate variation) reloc against it based on the symbol.
2210 * The linker will build the toc, and insert the resolved toc offset.
2213 * o The size of the toc entry is currently assumed to be
2214 * 32 bits. This should not be assumed to be a hard coded
2216 * o In an effort to cope with a change from 32 to 64 bits,
2217 * there are also toc entries that are specified to be
2218 * either 32 or 64 bits:
2219 * lwz r4,[toc32].GS.0.static_int(rtoc)
2220 * lwz r4,[toc64].GS.0.static_int(rtoc)
2221 * These demand toc entries of the specified size, and the
2222 * instruction probably requires it.
2226 enum toc_size_qualifier toc_kind
;
2227 bfd_reloc_code_real_type toc_reloc
;
2229 /* Go parse off the [tocXX] part. */
2230 valid_toc
= parse_toc_entry (&toc_kind
);
2234 /* Note: message has already been issued.
2235 FIXME: what sort of recovery should we do?
2236 demand_rest_of_line (); return; ? */
2239 /* Now get the symbol following the ']'. */
2245 /* In this case, we may not have seen the symbol yet,
2246 since it is allowed to appear on a .extern or .globl
2247 or just be a label in the .data section. */
2248 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2251 /* 1. The symbol must be defined and either in the toc
2252 section, or a global.
2253 2. The reloc generated must have the TOCDEFN flag set
2254 in upper bit mess of the reloc type.
2255 FIXME: It's a little confusing what the tocv
2256 qualifier can be used for. At the very least, I've
2257 seen three uses, only one of which I'm sure I can
2259 if (ex
.X_op
== O_symbol
)
2261 assert (ex
.X_add_symbol
!= NULL
);
2262 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2265 as_bad (_("[tocv] symbol is not a toc symbol"));
2269 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2272 /* FIXME: these next two specifically specify 32/64 bit
2273 toc entries. We don't support them today. Is this
2274 the right way to say that? */
2275 toc_reloc
= BFD_RELOC_UNUSED
;
2276 as_bad (_("Unimplemented toc32 expression modifier"));
2279 /* FIXME: see above. */
2280 toc_reloc
= BFD_RELOC_UNUSED
;
2281 as_bad (_("Unimplemented toc64 expression modifier"));
2285 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2291 /* We need to generate a fixup for this expression. */
2292 if (fc
>= MAX_INSN_FIXUPS
)
2293 as_fatal (_("too many fixups"));
2295 fixups
[fc
].reloc
= toc_reloc
;
2296 fixups
[fc
].exp
= ex
;
2297 fixups
[fc
].opindex
= *opindex_ptr
;
2300 /* Ok. We've set up the fixup for the instruction. Now make it
2301 look like the constant 0 was found here. */
2303 ex
.X_op
= O_constant
;
2304 ex
.X_add_number
= 0;
2305 ex
.X_add_symbol
= NULL
;
2306 ex
.X_op_symbol
= NULL
;
2312 if (! register_name (&ex
))
2314 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
2321 str
= input_line_pointer
;
2322 input_line_pointer
= hold
;
2324 if (ex
.X_op
== O_illegal
)
2325 as_bad (_("illegal operand"));
2326 else if (ex
.X_op
== O_absent
)
2327 as_bad (_("missing operand"));
2328 else if (ex
.X_op
== O_register
)
2330 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2333 else if (ex
.X_op
== O_constant
)
2336 /* Allow @HA, @L, @H on constants. */
2337 char *orig_str
= str
;
2339 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2346 case BFD_RELOC_LO16
:
2347 /* X_unsigned is the default, so if the user has done
2348 something which cleared it, we always produce a
2350 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2351 ex
.X_add_number
&= 0xffff;
2353 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2356 case BFD_RELOC_HI16
:
2357 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2358 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2360 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2363 case BFD_RELOC_HI16_S
:
2364 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2365 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2367 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2370 case BFD_RELOC_PPC64_HIGHER
:
2371 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2372 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2374 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2377 case BFD_RELOC_PPC64_HIGHER_S
:
2378 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2379 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2381 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2384 case BFD_RELOC_PPC64_HIGHEST
:
2385 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2386 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2388 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2391 case BFD_RELOC_PPC64_HIGHEST_S
:
2392 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2393 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2395 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2398 #endif /* OBJ_ELF */
2399 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2403 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2405 /* Some TLS tweaks. */
2410 case BFD_RELOC_PPC_TLS
:
2411 insn
= ppc_insert_operand (insn
, operand
, ppc_obj64
? 13 : 2,
2414 /* We'll only use the 32 (or 64) bit form of these relocations
2415 in constants. Instructions get the 16 bit form. */
2416 case BFD_RELOC_PPC_DTPREL
:
2417 reloc
= BFD_RELOC_PPC_DTPREL16
;
2419 case BFD_RELOC_PPC_TPREL
:
2420 reloc
= BFD_RELOC_PPC_TPREL16
;
2424 /* For the absolute forms of branches, convert the PC
2425 relative form back into the absolute. */
2426 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2430 case BFD_RELOC_PPC_B26
:
2431 reloc
= BFD_RELOC_PPC_BA26
;
2433 case BFD_RELOC_PPC_B16
:
2434 reloc
= BFD_RELOC_PPC_BA16
;
2436 case BFD_RELOC_PPC_B16_BRTAKEN
:
2437 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2439 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2440 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2448 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
2453 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
2455 case BFD_RELOC_LO16
:
2456 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
2458 case BFD_RELOC_16_GOTOFF
:
2459 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
2461 case BFD_RELOC_LO16_GOTOFF
:
2462 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
2464 case BFD_RELOC_LO16_PLTOFF
:
2465 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
2467 case BFD_RELOC_16_BASEREL
:
2468 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
2470 case BFD_RELOC_LO16_BASEREL
:
2471 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
2473 case BFD_RELOC_PPC_TOC16
:
2474 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
2476 case BFD_RELOC_PPC64_TOC16_LO
:
2477 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
2479 case BFD_RELOC_PPC64_PLTGOT16
:
2480 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
2482 case BFD_RELOC_PPC64_PLTGOT16_LO
:
2483 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
2485 case BFD_RELOC_PPC_DTPREL16
:
2486 reloc
= BFD_RELOC_PPC64_DTPREL16_DS
;
2488 case BFD_RELOC_PPC_DTPREL16_LO
:
2489 reloc
= BFD_RELOC_PPC64_DTPREL16_LO_DS
;
2491 case BFD_RELOC_PPC_TPREL16
:
2492 reloc
= BFD_RELOC_PPC64_TPREL16_DS
;
2494 case BFD_RELOC_PPC_TPREL16_LO
:
2495 reloc
= BFD_RELOC_PPC64_TPREL16_LO_DS
;
2497 case BFD_RELOC_PPC_GOT_DTPREL16
:
2498 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
2499 case BFD_RELOC_PPC_GOT_TPREL16
:
2500 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
2503 as_bad (_("unsupported relocation for DS offset field"));
2508 /* We need to generate a fixup for this expression. */
2509 if (fc
>= MAX_INSN_FIXUPS
)
2510 as_fatal (_("too many fixups"));
2511 fixups
[fc
].exp
= ex
;
2512 fixups
[fc
].opindex
= 0;
2513 fixups
[fc
].reloc
= reloc
;
2516 #endif /* OBJ_ELF */
2520 /* We need to generate a fixup for this expression. */
2521 if (fc
>= MAX_INSN_FIXUPS
)
2522 as_fatal (_("too many fixups"));
2523 fixups
[fc
].exp
= ex
;
2524 fixups
[fc
].opindex
= *opindex_ptr
;
2525 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2534 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2542 /* The call to expression should have advanced str past any
2545 && (endc
!= ',' || *str
!= '\0'))
2547 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2555 while (ISSPACE (*str
))
2559 as_bad (_("junk at end of line: `%s'"), str
);
2562 /* Do we need/want a APUinfo section? */
2563 if (ppc_cpu
& (PPC_OPCODE_SPE
2564 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
2565 | PPC_OPCODE_BRLOCK
| PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
2566 | PPC_OPCODE_RFMCI
))
2568 /* These are all version "1". */
2569 if (opcode
->flags
& PPC_OPCODE_SPE
)
2570 ppc_apuinfo_section_add (PPC_APUINFO_SPE
, 1);
2571 if (opcode
->flags
& PPC_OPCODE_ISEL
)
2572 ppc_apuinfo_section_add (PPC_APUINFO_ISEL
, 1);
2573 if (opcode
->flags
& PPC_OPCODE_EFS
)
2574 ppc_apuinfo_section_add (PPC_APUINFO_EFS
, 1);
2575 if (opcode
->flags
& PPC_OPCODE_BRLOCK
)
2576 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK
, 1);
2577 if (opcode
->flags
& PPC_OPCODE_PMR
)
2578 ppc_apuinfo_section_add (PPC_APUINFO_PMR
, 1);
2579 if (opcode
->flags
& PPC_OPCODE_CACHELCK
)
2580 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK
, 1);
2581 if (opcode
->flags
& PPC_OPCODE_RFMCI
)
2582 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI
, 1);
2586 /* Write out the instruction. */
2588 md_number_to_chars (f
, insn
, 4);
2591 dwarf2_emit_insn (4);
2594 /* Create any fixups. At this point we do not use a
2595 bfd_reloc_code_real_type, but instead just use the
2596 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2597 handle fixups for any operand type, although that is admittedly
2598 not a very exciting feature. We pick a BFD reloc type in
2600 for (i
= 0; i
< fc
; i
++)
2602 const struct powerpc_operand
*operand
;
2604 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2605 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2607 reloc_howto_type
*reloc_howto
;
2612 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2616 size
= bfd_get_reloc_size (reloc_howto
);
2617 offset
= target_big_endian
? (4 - size
) : 0;
2619 if (size
< 1 || size
> 4)
2622 fixP
= fix_new_exp (frag_now
,
2623 f
- frag_now
->fr_literal
+ offset
,
2626 reloc_howto
->pc_relative
,
2629 /* Turn off complaints that the addend is too large for things like
2631 switch (fixups
[i
].reloc
)
2633 case BFD_RELOC_16_GOTOFF
:
2634 case BFD_RELOC_PPC_TOC16
:
2635 case BFD_RELOC_LO16
:
2636 case BFD_RELOC_HI16
:
2637 case BFD_RELOC_HI16_S
:
2639 case BFD_RELOC_PPC64_HIGHER
:
2640 case BFD_RELOC_PPC64_HIGHER_S
:
2641 case BFD_RELOC_PPC64_HIGHEST
:
2642 case BFD_RELOC_PPC64_HIGHEST_S
:
2644 fixP
->fx_no_overflow
= 1;
2651 fix_new_exp (frag_now
,
2652 f
- frag_now
->fr_literal
,
2655 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2656 ((bfd_reloc_code_real_type
)
2657 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2661 /* Handle a macro. Gather all the operands, transform them as
2662 described by the macro, and call md_assemble recursively. All the
2663 operands are separated by commas; we don't accept parentheses
2664 around operands here. */
2667 ppc_macro (str
, macro
)
2669 const struct powerpc_macro
*macro
;
2680 /* Gather the users operands into the operands array. */
2685 if (count
>= sizeof operands
/ sizeof operands
[0])
2687 operands
[count
++] = s
;
2688 s
= strchr (s
, ',');
2689 if (s
== (char *) NULL
)
2694 if (count
!= macro
->operands
)
2696 as_bad (_("wrong number of operands"));
2700 /* Work out how large the string must be (the size is unbounded
2701 because it includes user input). */
2703 format
= macro
->format
;
2704 while (*format
!= '\0')
2713 arg
= strtol (format
+ 1, &send
, 10);
2714 know (send
!= format
&& arg
>= 0 && arg
< count
);
2715 len
+= strlen (operands
[arg
]);
2720 /* Put the string together. */
2721 complete
= s
= (char *) alloca (len
+ 1);
2722 format
= macro
->format
;
2723 while (*format
!= '\0')
2729 arg
= strtol (format
+ 1, &send
, 10);
2730 strcpy (s
, operands
[arg
]);
2737 /* Assemble the constructed instruction. */
2738 md_assemble (complete
);
2742 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2745 ppc_section_letter (letter
, ptr_msg
)
2752 *ptr_msg
= _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
2757 ppc_section_word (str
, len
)
2761 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2768 ppc_section_type (str
, len
)
2772 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2779 ppc_section_flags (flags
, attr
, type
)
2784 if (type
== SHT_ORDERED
)
2785 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2787 if (attr
& SHF_EXCLUDE
)
2788 flags
|= SEC_EXCLUDE
;
2792 #endif /* OBJ_ELF */
2795 /* Pseudo-op handling. */
2797 /* The .byte pseudo-op. This is similar to the normal .byte
2798 pseudo-op, but it can also take a single ASCII string. */
2802 int ignore ATTRIBUTE_UNUSED
;
2804 if (*input_line_pointer
!= '\"')
2810 /* Gather characters. A real double quote is doubled. Unusual
2811 characters are not permitted. */
2812 ++input_line_pointer
;
2817 c
= *input_line_pointer
++;
2821 if (*input_line_pointer
!= '\"')
2823 ++input_line_pointer
;
2826 FRAG_APPEND_1_CHAR (c
);
2829 demand_empty_rest_of_line ();
2834 /* XCOFF specific pseudo-op handling. */
2836 /* This is set if we are creating a .stabx symbol, since we don't want
2837 to handle symbol suffixes for such symbols. */
2838 static bfd_boolean ppc_stab_symbol
;
2840 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2841 symbols in the .bss segment as though they were local common
2842 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2843 aligns .comm and .lcomm to 4 bytes. */
2849 asection
*current_seg
= now_seg
;
2850 subsegT current_subseg
= now_subseg
;
2856 symbolS
*lcomm_sym
= NULL
;
2860 name
= input_line_pointer
;
2861 endc
= get_symbol_end ();
2862 end_name
= input_line_pointer
;
2865 if (*input_line_pointer
!= ',')
2867 as_bad (_("missing size"));
2868 ignore_rest_of_line ();
2871 ++input_line_pointer
;
2873 size
= get_absolute_expression ();
2876 as_bad (_("negative size"));
2877 ignore_rest_of_line ();
2883 /* The third argument to .comm is the alignment. */
2884 if (*input_line_pointer
!= ',')
2888 ++input_line_pointer
;
2889 align
= get_absolute_expression ();
2892 as_warn (_("ignoring bad alignment"));
2907 /* The third argument to .lcomm appears to be the real local
2908 common symbol to create. References to the symbol named in
2909 the first argument are turned into references to the third
2911 if (*input_line_pointer
!= ',')
2913 as_bad (_("missing real symbol name"));
2914 ignore_rest_of_line ();
2917 ++input_line_pointer
;
2919 lcomm_name
= input_line_pointer
;
2920 lcomm_endc
= get_symbol_end ();
2922 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2924 *input_line_pointer
= lcomm_endc
;
2928 sym
= symbol_find_or_make (name
);
2931 if (S_IS_DEFINED (sym
)
2932 || S_GET_VALUE (sym
) != 0)
2934 as_bad (_("attempt to redefine symbol"));
2935 ignore_rest_of_line ();
2939 record_alignment (bss_section
, align
);
2942 || ! S_IS_DEFINED (lcomm_sym
))
2951 S_SET_EXTERNAL (sym
);
2955 symbol_get_tc (lcomm_sym
)->output
= 1;
2956 def_sym
= lcomm_sym
;
2960 subseg_set (bss_section
, 1);
2961 frag_align (align
, 0, 0);
2963 symbol_set_frag (def_sym
, frag_now
);
2964 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2965 def_size
, (char *) NULL
);
2967 S_SET_SEGMENT (def_sym
, bss_section
);
2968 symbol_get_tc (def_sym
)->align
= align
;
2972 /* Align the size of lcomm_sym. */
2973 symbol_get_frag (lcomm_sym
)->fr_offset
=
2974 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
2975 &~ ((1 << align
) - 1));
2976 if (align
> symbol_get_tc (lcomm_sym
)->align
)
2977 symbol_get_tc (lcomm_sym
)->align
= align
;
2982 /* Make sym an offset from lcomm_sym. */
2983 S_SET_SEGMENT (sym
, bss_section
);
2984 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
2985 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
2986 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
2989 subseg_set (current_seg
, current_subseg
);
2991 demand_empty_rest_of_line ();
2994 /* The .csect pseudo-op. This switches us into a different
2995 subsegment. The first argument is a symbol whose value is the
2996 start of the .csect. In COFF, csect symbols get special aux
2997 entries defined by the x_csect field of union internal_auxent. The
2998 optional second argument is the alignment (the default is 2). */
3002 int ignore ATTRIBUTE_UNUSED
;
3008 name
= input_line_pointer
;
3009 endc
= get_symbol_end ();
3011 sym
= symbol_find_or_make (name
);
3013 *input_line_pointer
= endc
;
3015 if (S_GET_NAME (sym
)[0] == '\0')
3017 /* An unnamed csect is assumed to be [PR]. */
3018 symbol_get_tc (sym
)->class = XMC_PR
;
3021 ppc_change_csect (sym
);
3023 if (*input_line_pointer
== ',')
3025 ++input_line_pointer
;
3026 symbol_get_tc (sym
)->align
= get_absolute_expression ();
3029 demand_empty_rest_of_line ();
3032 /* Change to a different csect. */
3035 ppc_change_csect (sym
)
3038 if (S_IS_DEFINED (sym
))
3039 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
3047 /* This is a new csect. We need to look at the symbol class to
3048 figure out whether it should go in the text section or the
3051 switch (symbol_get_tc (sym
)->class)
3061 S_SET_SEGMENT (sym
, text_section
);
3062 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
3063 ++ppc_text_subsegment
;
3064 list_ptr
= &ppc_text_csects
;
3073 if (ppc_toc_csect
!= NULL
3074 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
3075 == ppc_data_subsegment
))
3077 S_SET_SEGMENT (sym
, data_section
);
3078 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
3079 ++ppc_data_subsegment
;
3080 list_ptr
= &ppc_data_csects
;
3086 /* We set the obstack chunk size to a small value before
3087 changing subsegments, so that we don't use a lot of memory
3088 space for what may be a small section. */
3089 hold_chunksize
= chunksize
;
3092 subseg_new (segment_name (S_GET_SEGMENT (sym
)),
3093 symbol_get_tc (sym
)->subseg
);
3095 chunksize
= hold_chunksize
;
3098 ppc_after_toc_frag
= frag_now
;
3100 symbol_set_frag (sym
, frag_now
);
3101 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3103 symbol_get_tc (sym
)->align
= 2;
3104 symbol_get_tc (sym
)->output
= 1;
3105 symbol_get_tc (sym
)->within
= sym
;
3107 for (list
= *list_ptr
;
3108 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3109 list
= symbol_get_tc (list
)->next
)
3111 symbol_get_tc (list
)->next
= sym
;
3113 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3114 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3118 ppc_current_csect
= sym
;
3121 /* This function handles the .text and .data pseudo-ops. These
3122 pseudo-ops aren't really used by XCOFF; we implement them for the
3123 convenience of people who aren't used to XCOFF. */
3134 else if (type
== 'd')
3139 sym
= symbol_find_or_make (name
);
3141 ppc_change_csect (sym
);
3143 demand_empty_rest_of_line ();
3146 /* This function handles the .section pseudo-op. This is mostly to
3147 give an error, since XCOFF only supports .text, .data and .bss, but
3148 we do permit the user to name the text or data section. */
3151 ppc_named_section (ignore
)
3152 int ignore ATTRIBUTE_UNUSED
;
3155 const char *real_name
;
3159 user_name
= input_line_pointer
;
3160 c
= get_symbol_end ();
3162 if (strcmp (user_name
, ".text") == 0)
3163 real_name
= ".text[PR]";
3164 else if (strcmp (user_name
, ".data") == 0)
3165 real_name
= ".data[RW]";
3168 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3169 *input_line_pointer
= c
;
3170 ignore_rest_of_line ();
3174 *input_line_pointer
= c
;
3176 sym
= symbol_find_or_make (real_name
);
3178 ppc_change_csect (sym
);
3180 demand_empty_rest_of_line ();
3183 /* The .extern pseudo-op. We create an undefined symbol. */
3187 int ignore ATTRIBUTE_UNUSED
;
3192 name
= input_line_pointer
;
3193 endc
= get_symbol_end ();
3195 (void) symbol_find_or_make (name
);
3197 *input_line_pointer
= endc
;
3199 demand_empty_rest_of_line ();
3202 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3206 int ignore ATTRIBUTE_UNUSED
;
3212 name
= input_line_pointer
;
3213 endc
= get_symbol_end ();
3215 sym
= symbol_find_or_make (name
);
3217 *input_line_pointer
= endc
;
3219 symbol_get_tc (sym
)->output
= 1;
3221 demand_empty_rest_of_line ();
3224 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3225 although I don't know why it bothers. */
3229 int ignore ATTRIBUTE_UNUSED
;
3236 name
= input_line_pointer
;
3237 endc
= get_symbol_end ();
3239 sym
= symbol_find_or_make (name
);
3241 *input_line_pointer
= endc
;
3243 if (*input_line_pointer
!= ',')
3245 as_bad (_("missing rename string"));
3246 ignore_rest_of_line ();
3249 ++input_line_pointer
;
3251 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
3253 demand_empty_rest_of_line ();
3256 /* The .stabx pseudo-op. This is similar to a normal .stabs
3257 pseudo-op, but slightly different. A sample is
3258 .stabx "main:F-1",.main,142,0
3259 The first argument is the symbol name to create. The second is the
3260 value, and the third is the storage class. The fourth seems to be
3261 always zero, and I am assuming it is the type. */
3265 int ignore ATTRIBUTE_UNUSED
;
3272 name
= demand_copy_C_string (&len
);
3274 if (*input_line_pointer
!= ',')
3276 as_bad (_("missing value"));
3279 ++input_line_pointer
;
3281 ppc_stab_symbol
= TRUE
;
3282 sym
= symbol_make (name
);
3283 ppc_stab_symbol
= FALSE
;
3285 symbol_get_tc (sym
)->real_name
= name
;
3287 (void) expression (&exp
);
3294 as_bad (_("illegal .stabx expression; zero assumed"));
3295 exp
.X_add_number
= 0;
3298 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
3299 symbol_set_frag (sym
, &zero_address_frag
);
3303 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
3304 symbol_set_value_expression (sym
, &exp
);
3308 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
3309 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
3314 /* The value is some complex expression. This will probably
3315 fail at some later point, but this is probably the right
3316 thing to do here. */
3317 symbol_set_value_expression (sym
, &exp
);
3321 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3322 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3324 if (*input_line_pointer
!= ',')
3326 as_bad (_("missing class"));
3329 ++input_line_pointer
;
3331 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
3333 if (*input_line_pointer
!= ',')
3335 as_bad (_("missing type"));
3338 ++input_line_pointer
;
3340 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
3342 symbol_get_tc (sym
)->output
= 1;
3344 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
3346 symbol_get_tc (sym
)->within
= ppc_current_block
;
3351 .stabx "z",arrays_,133,0
3354 .comm arrays_,13768,3
3356 resolve_symbol_value will copy the exp's "within" into sym's when the
3357 offset is 0. Since this seems to be corner case problem,
3358 only do the correction for storage class C_STSYM. A better solution
3359 would be to have the tc field updated in ppc_symbol_new_hook. */
3361 if (exp
.X_op
== O_symbol
)
3363 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
3367 if (exp
.X_op
!= O_symbol
3368 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
3369 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
3370 ppc_frob_label (sym
);
3373 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3374 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
3375 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
3376 symbol_get_tc (ppc_current_csect
)->within
= sym
;
3379 demand_empty_rest_of_line ();
3382 /* The .function pseudo-op. This takes several arguments. The first
3383 argument seems to be the external name of the symbol. The second
3384 argment seems to be the label for the start of the function. gcc
3385 uses the same name for both. I have no idea what the third and
3386 fourth arguments are meant to be. The optional fifth argument is
3387 an expression for the size of the function. In COFF this symbol
3388 gets an aux entry like that used for a csect. */
3391 ppc_function (ignore
)
3392 int ignore ATTRIBUTE_UNUSED
;
3400 name
= input_line_pointer
;
3401 endc
= get_symbol_end ();
3403 /* Ignore any [PR] suffix. */
3404 name
= ppc_canonicalize_symbol_name (name
);
3405 s
= strchr (name
, '[');
3406 if (s
!= (char *) NULL
3407 && strcmp (s
+ 1, "PR]") == 0)
3410 ext_sym
= symbol_find_or_make (name
);
3412 *input_line_pointer
= endc
;
3414 if (*input_line_pointer
!= ',')
3416 as_bad (_("missing symbol name"));
3417 ignore_rest_of_line ();
3420 ++input_line_pointer
;
3422 name
= input_line_pointer
;
3423 endc
= get_symbol_end ();
3425 lab_sym
= symbol_find_or_make (name
);
3427 *input_line_pointer
= endc
;
3429 if (ext_sym
!= lab_sym
)
3433 exp
.X_op
= O_symbol
;
3434 exp
.X_add_symbol
= lab_sym
;
3435 exp
.X_op_symbol
= NULL
;
3436 exp
.X_add_number
= 0;
3438 symbol_set_value_expression (ext_sym
, &exp
);
3441 if (symbol_get_tc (ext_sym
)->class == -1)
3442 symbol_get_tc (ext_sym
)->class = XMC_PR
;
3443 symbol_get_tc (ext_sym
)->output
= 1;
3445 if (*input_line_pointer
== ',')
3449 /* Ignore the third argument. */
3450 ++input_line_pointer
;
3451 expression (&ignore
);
3452 if (*input_line_pointer
== ',')
3454 /* Ignore the fourth argument. */
3455 ++input_line_pointer
;
3456 expression (&ignore
);
3457 if (*input_line_pointer
== ',')
3459 /* The fifth argument is the function size. */
3460 ++input_line_pointer
;
3461 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
3464 &zero_address_frag
);
3465 pseudo_set (symbol_get_tc (ext_sym
)->size
);
3470 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3471 SF_SET_FUNCTION (ext_sym
);
3472 SF_SET_PROCESS (ext_sym
);
3473 coff_add_linesym (ext_sym
);
3475 demand_empty_rest_of_line ();
3478 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3479 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3480 with the correct line number */
3482 static symbolS
*saved_bi_sym
= 0;
3486 int ignore ATTRIBUTE_UNUSED
;
3490 sym
= symbol_make (".bf");
3491 S_SET_SEGMENT (sym
, text_section
);
3492 symbol_set_frag (sym
, frag_now
);
3493 S_SET_VALUE (sym
, frag_now_fix ());
3494 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3496 coff_line_base
= get_absolute_expression ();
3498 S_SET_NUMBER_AUXILIARY (sym
, 1);
3499 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3501 /* Line number for bi. */
3504 S_SET_VALUE (saved_bi_sym
, coff_n_line_nos
);
3509 symbol_get_tc (sym
)->output
= 1;
3511 ppc_frob_label (sym
);
3513 demand_empty_rest_of_line ();
3516 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3517 ".ef", except that the line number is absolute, not relative to the
3518 most recent ".bf" symbol. */
3522 int ignore ATTRIBUTE_UNUSED
;
3526 sym
= symbol_make (".ef");
3527 S_SET_SEGMENT (sym
, text_section
);
3528 symbol_set_frag (sym
, frag_now
);
3529 S_SET_VALUE (sym
, frag_now_fix ());
3530 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3531 S_SET_NUMBER_AUXILIARY (sym
, 1);
3532 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3533 symbol_get_tc (sym
)->output
= 1;
3535 ppc_frob_label (sym
);
3537 demand_empty_rest_of_line ();
3540 /* The .bi and .ei pseudo-ops. These take a string argument and
3541 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3542 the symbol list. The value of .bi will be know when the next .bf
3549 static symbolS
*last_biei
;
3556 name
= demand_copy_C_string (&len
);
3558 /* The value of these symbols is actually file offset. Here we set
3559 the value to the index into the line number entries. In
3560 ppc_frob_symbols we set the fix_line field, which will cause BFD
3561 to do the right thing. */
3563 sym
= symbol_make (name
);
3564 /* obj-coff.c currently only handles line numbers correctly in the
3566 S_SET_SEGMENT (sym
, text_section
);
3567 S_SET_VALUE (sym
, coff_n_line_nos
);
3568 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3570 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3571 symbol_get_tc (sym
)->output
= 1;
3579 for (look
= last_biei
? last_biei
: symbol_rootP
;
3580 (look
!= (symbolS
*) NULL
3581 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3582 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3583 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3584 look
= symbol_next (look
))
3586 if (look
!= (symbolS
*) NULL
)
3588 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3589 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3593 demand_empty_rest_of_line ();
3596 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3597 There is one argument, which is a csect symbol. The value of the
3598 .bs symbol is the index of this csect symbol. */
3602 int ignore ATTRIBUTE_UNUSED
;
3609 if (ppc_current_block
!= NULL
)
3610 as_bad (_("nested .bs blocks"));
3612 name
= input_line_pointer
;
3613 endc
= get_symbol_end ();
3615 csect
= symbol_find_or_make (name
);
3617 *input_line_pointer
= endc
;
3619 sym
= symbol_make (".bs");
3620 S_SET_SEGMENT (sym
, now_seg
);
3621 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3622 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3623 symbol_get_tc (sym
)->output
= 1;
3625 symbol_get_tc (sym
)->within
= csect
;
3627 ppc_frob_label (sym
);
3629 ppc_current_block
= sym
;
3631 demand_empty_rest_of_line ();
3634 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3638 int ignore ATTRIBUTE_UNUSED
;
3642 if (ppc_current_block
== NULL
)
3643 as_bad (_(".es without preceding .bs"));
3645 sym
= symbol_make (".es");
3646 S_SET_SEGMENT (sym
, now_seg
);
3647 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3648 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3649 symbol_get_tc (sym
)->output
= 1;
3651 ppc_frob_label (sym
);
3653 ppc_current_block
= NULL
;
3655 demand_empty_rest_of_line ();
3658 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3663 int ignore ATTRIBUTE_UNUSED
;
3667 sym
= symbol_make (".bb");
3668 S_SET_SEGMENT (sym
, text_section
);
3669 symbol_set_frag (sym
, frag_now
);
3670 S_SET_VALUE (sym
, frag_now_fix ());
3671 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3673 S_SET_NUMBER_AUXILIARY (sym
, 1);
3674 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3676 symbol_get_tc (sym
)->output
= 1;
3678 SF_SET_PROCESS (sym
);
3680 ppc_frob_label (sym
);
3682 demand_empty_rest_of_line ();
3685 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3690 int ignore ATTRIBUTE_UNUSED
;
3694 sym
= symbol_make (".eb");
3695 S_SET_SEGMENT (sym
, text_section
);
3696 symbol_set_frag (sym
, frag_now
);
3697 S_SET_VALUE (sym
, frag_now_fix ());
3698 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3699 S_SET_NUMBER_AUXILIARY (sym
, 1);
3700 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3701 symbol_get_tc (sym
)->output
= 1;
3703 SF_SET_PROCESS (sym
);
3705 ppc_frob_label (sym
);
3707 demand_empty_rest_of_line ();
3710 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3715 int ignore ATTRIBUTE_UNUSED
;
3721 name
= demand_copy_C_string (&len
);
3722 sym
= symbol_make (name
);
3723 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3724 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3725 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3726 S_SET_VALUE (sym
, 0);
3727 symbol_get_tc (sym
)->output
= 1;
3729 ppc_frob_label (sym
);
3731 demand_empty_rest_of_line ();
3734 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3738 int ignore ATTRIBUTE_UNUSED
;
3742 sym
= symbol_make (".ec");
3743 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3744 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3745 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3746 S_SET_VALUE (sym
, 0);
3747 symbol_get_tc (sym
)->output
= 1;
3749 ppc_frob_label (sym
);
3751 demand_empty_rest_of_line ();
3754 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3758 int ignore ATTRIBUTE_UNUSED
;
3760 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3761 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3768 subseg
= ppc_data_subsegment
;
3769 ++ppc_data_subsegment
;
3771 subseg_new (segment_name (data_section
), subseg
);
3772 ppc_toc_frag
= frag_now
;
3774 sym
= symbol_find_or_make ("TOC[TC0]");
3775 symbol_set_frag (sym
, frag_now
);
3776 S_SET_SEGMENT (sym
, data_section
);
3777 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3778 symbol_get_tc (sym
)->subseg
= subseg
;
3779 symbol_get_tc (sym
)->output
= 1;
3780 symbol_get_tc (sym
)->within
= sym
;
3782 ppc_toc_csect
= sym
;
3784 for (list
= ppc_data_csects
;
3785 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3786 list
= symbol_get_tc (list
)->next
)
3788 symbol_get_tc (list
)->next
= sym
;
3790 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3791 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3795 ppc_current_csect
= ppc_toc_csect
;
3797 demand_empty_rest_of_line ();
3800 /* The AIX assembler automatically aligns the operands of a .long or
3801 .short pseudo-op, and we want to be compatible. */
3804 ppc_xcoff_cons (log_size
)
3807 frag_align (log_size
, 0, 0);
3808 record_alignment (now_seg
, log_size
);
3809 cons (1 << log_size
);
3814 int dummy ATTRIBUTE_UNUSED
;
3819 (void) expression (&exp
);
3821 if (exp
.X_op
!= O_constant
)
3823 as_bad (_("non-constant byte count"));
3827 byte_count
= exp
.X_add_number
;
3829 if (*input_line_pointer
!= ',')
3831 as_bad (_("missing value"));
3835 ++input_line_pointer
;
3839 #endif /* OBJ_XCOFF */
3840 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3842 /* The .tc pseudo-op. This is used when generating either XCOFF or
3843 ELF. This takes two or more arguments.
3845 When generating XCOFF output, the first argument is the name to
3846 give to this location in the toc; this will be a symbol with class
3847 TC. The rest of the arguments are N-byte values to actually put at
3848 this location in the TOC; often there is just one more argument, a
3849 relocateable symbol reference. The size of the value to store
3850 depends on target word size. A 32-bit target uses 4-byte values, a
3851 64-bit target uses 8-byte values.
3853 When not generating XCOFF output, the arguments are the same, but
3854 the first argument is simply ignored. */
3858 int ignore ATTRIBUTE_UNUSED
;
3862 /* Define the TOC symbol name. */
3868 if (ppc_toc_csect
== (symbolS
*) NULL
3869 || ppc_toc_csect
!= ppc_current_csect
)
3871 as_bad (_(".tc not in .toc section"));
3872 ignore_rest_of_line ();
3876 name
= input_line_pointer
;
3877 endc
= get_symbol_end ();
3879 sym
= symbol_find_or_make (name
);
3881 *input_line_pointer
= endc
;
3883 if (S_IS_DEFINED (sym
))
3887 label
= symbol_get_tc (ppc_current_csect
)->within
;
3888 if (symbol_get_tc (label
)->class != XMC_TC0
)
3890 as_bad (_(".tc with no label"));
3891 ignore_rest_of_line ();
3895 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3896 symbol_set_frag (label
, symbol_get_frag (sym
));
3897 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3899 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3900 ++input_line_pointer
;
3905 S_SET_SEGMENT (sym
, now_seg
);
3906 symbol_set_frag (sym
, frag_now
);
3907 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3908 symbol_get_tc (sym
)->class = XMC_TC
;
3909 symbol_get_tc (sym
)->output
= 1;
3911 ppc_frob_label (sym
);
3914 #endif /* OBJ_XCOFF */
3918 /* Skip the TOC symbol name. */
3919 while (is_part_of_name (*input_line_pointer
)
3920 || *input_line_pointer
== '['
3921 || *input_line_pointer
== ']'
3922 || *input_line_pointer
== '{'
3923 || *input_line_pointer
== '}')
3924 ++input_line_pointer
;
3926 /* Align to a four/eight byte boundary. */
3927 align
= ppc_obj64
? 3 : 2;
3928 frag_align (align
, 0, 0);
3929 record_alignment (now_seg
, align
);
3930 #endif /* OBJ_ELF */
3932 if (*input_line_pointer
!= ',')
3933 demand_empty_rest_of_line ();
3936 ++input_line_pointer
;
3937 cons (ppc_obj64
? 8 : 4);
3941 /* Pseudo-op .machine. */
3942 /* FIXME: `.machine' is a nop for the moment. It would be nice to
3943 accept this directive on the first line of input and set ppc_obj64
3944 and the target format accordingly. Unfortunately, the target
3945 format is selected in output-file.c:output_file_create before we
3946 even get to md_begin, so it's not possible without changing
3950 ppc_machine (ignore
)
3951 int ignore ATTRIBUTE_UNUSED
;
3953 discard_rest_of_line ();
3956 /* See whether a symbol is in the TOC section. */
3959 ppc_is_toc_sym (sym
)
3963 return symbol_get_tc (sym
)->class == XMC_TC
;
3966 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
3968 return strcmp (sname
, ".toc") == 0;
3970 return strcmp (sname
, ".got") == 0;
3973 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
3977 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
3979 /* Set the current section. */
3981 ppc_set_current_section (new)
3984 ppc_previous_section
= ppc_current_section
;
3985 ppc_current_section
= new;
3988 /* pseudo-op: .previous
3989 behaviour: toggles the current section with the previous section.
3991 warnings: "No previous section" */
3994 ppc_previous (ignore
)
3995 int ignore ATTRIBUTE_UNUSED
;
3999 if (ppc_previous_section
== NULL
)
4001 as_warn (_("No previous section to return to. Directive ignored."));
4005 subseg_set (ppc_previous_section
, 0);
4007 ppc_set_current_section (ppc_previous_section
);
4010 /* pseudo-op: .pdata
4011 behaviour: predefined read only data section
4015 initial: .section .pdata "adr3"
4016 a - don't know -- maybe a misprint
4017 d - initialized data
4019 3 - double word aligned (that would be 4 byte boundary)
4022 Tag index tables (also known as the function table) for exception
4023 handling, debugging, etc. */
4027 int ignore ATTRIBUTE_UNUSED
;
4029 if (pdata_section
== 0)
4031 pdata_section
= subseg_new (".pdata", 0);
4033 bfd_set_section_flags (stdoutput
, pdata_section
,
4034 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4035 | SEC_READONLY
| SEC_DATA
));
4037 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
4041 pdata_section
= subseg_new (".pdata", 0);
4043 ppc_set_current_section (pdata_section
);
4046 /* pseudo-op: .ydata
4047 behaviour: predefined read only data section
4051 initial: .section .ydata "drw3"
4052 a - don't know -- maybe a misprint
4053 d - initialized data
4055 3 - double word aligned (that would be 4 byte boundary)
4057 Tag tables (also known as the scope table) for exception handling,
4062 int ignore ATTRIBUTE_UNUSED
;
4064 if (ydata_section
== 0)
4066 ydata_section
= subseg_new (".ydata", 0);
4067 bfd_set_section_flags (stdoutput
, ydata_section
,
4068 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4069 | SEC_READONLY
| SEC_DATA
));
4071 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
4075 ydata_section
= subseg_new (".ydata", 0);
4077 ppc_set_current_section (ydata_section
);
4080 /* pseudo-op: .reldata
4081 behaviour: predefined read write data section
4082 double word aligned (4-byte)
4083 FIXME: relocation is applied to it
4084 FIXME: what's the difference between this and .data?
4087 initial: .section .reldata "drw3"
4088 d - initialized data
4091 3 - double word aligned (that would be 8 byte boundary)
4094 Like .data, but intended to hold data subject to relocation, such as
4095 function descriptors, etc. */
4098 ppc_reldata (ignore
)
4099 int ignore ATTRIBUTE_UNUSED
;
4101 if (reldata_section
== 0)
4103 reldata_section
= subseg_new (".reldata", 0);
4105 bfd_set_section_flags (stdoutput
, reldata_section
,
4106 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4109 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
4113 reldata_section
= subseg_new (".reldata", 0);
4115 ppc_set_current_section (reldata_section
);
4118 /* pseudo-op: .rdata
4119 behaviour: predefined read only data section
4123 initial: .section .rdata "dr3"
4124 d - initialized data
4126 3 - double word aligned (that would be 4 byte boundary) */
4130 int ignore ATTRIBUTE_UNUSED
;
4132 if (rdata_section
== 0)
4134 rdata_section
= subseg_new (".rdata", 0);
4135 bfd_set_section_flags (stdoutput
, rdata_section
,
4136 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4137 | SEC_READONLY
| SEC_DATA
));
4139 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
4143 rdata_section
= subseg_new (".rdata", 0);
4145 ppc_set_current_section (rdata_section
);
4148 /* pseudo-op: .ualong
4149 behaviour: much like .int, with the exception that no alignment is
4151 FIXME: test the alignment statement
4157 int ignore ATTRIBUTE_UNUSED
;
4163 /* pseudo-op: .znop <symbol name>
4164 behaviour: Issue a nop instruction
4165 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4166 the supplied symbol name.
4168 warnings: Missing symbol name */
4172 int ignore ATTRIBUTE_UNUSED
;
4175 const struct powerpc_opcode
*opcode
;
4186 /* Strip out the symbol name. */
4187 symbol_name
= input_line_pointer
;
4188 c
= get_symbol_end ();
4190 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
4191 strcpy (name
, symbol_name
);
4193 sym
= symbol_find_or_make (name
);
4195 *input_line_pointer
= c
;
4199 /* Look up the opcode in the hash table. */
4200 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
4202 /* Stick in the nop. */
4203 insn
= opcode
->opcode
;
4205 /* Write out the instruction. */
4207 md_number_to_chars (f
, insn
, 4);
4209 f
- frag_now
->fr_literal
,
4214 BFD_RELOC_16_GOT_PCREL
);
4227 register char *name
;
4231 register symbolS
*symbolP
;
4234 name
= input_line_pointer
;
4235 c
= get_symbol_end ();
4237 /* just after name is now '\0'. */
4238 p
= input_line_pointer
;
4241 if (*input_line_pointer
!= ',')
4243 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4244 ignore_rest_of_line ();
4248 input_line_pointer
++; /* skip ',' */
4249 if ((temp
= get_absolute_expression ()) < 0)
4251 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
4252 ignore_rest_of_line ();
4258 /* The third argument to .comm is the alignment. */
4259 if (*input_line_pointer
!= ',')
4263 ++input_line_pointer
;
4264 align
= get_absolute_expression ();
4267 as_warn (_("ignoring bad alignment"));
4274 symbolP
= symbol_find_or_make (name
);
4277 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
4279 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4280 S_GET_NAME (symbolP
));
4281 ignore_rest_of_line ();
4285 if (S_GET_VALUE (symbolP
))
4287 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
4288 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4289 S_GET_NAME (symbolP
),
4290 (long) S_GET_VALUE (symbolP
),
4295 S_SET_VALUE (symbolP
, (valueT
) temp
);
4296 S_SET_EXTERNAL (symbolP
);
4299 demand_empty_rest_of_line ();
4303 * implement the .section pseudo op:
4304 * .section name {, "flags"}
4306 * | +--- optional flags: 'b' for bss
4308 * +-- section name 'l' for lib
4312 * 'd' (apparently m88k for data)
4314 * But if the argument is not a quoted string, treat it as a
4315 * subsegment number.
4317 * FIXME: this is a copy of the section processing from obj-coff.c, with
4318 * additions/changes for the moto-pas assembler support. There are three
4321 * FIXME: I just noticed this. This doesn't work at all really. It it
4322 * setting bits that bfd probably neither understands or uses. The
4323 * correct approach (?) will have to incorporate extra fields attached
4324 * to the section to hold the system specific stuff. (krk)
4327 * 'a' - unknown - referred to in documentation, but no definition supplied
4328 * 'c' - section has code
4329 * 'd' - section has initialized data
4330 * 'u' - section has uninitialized data
4331 * 'i' - section contains directives (info)
4332 * 'n' - section can be discarded
4333 * 'R' - remove section at link time
4335 * Section Protection:
4336 * 'r' - section is readable
4337 * 'w' - section is writeable
4338 * 'x' - section is executable
4339 * 's' - section is sharable
4341 * Section Alignment:
4342 * '0' - align to byte boundary
4343 * '1' - align to halfword undary
4344 * '2' - align to word boundary
4345 * '3' - align to doubleword boundary
4346 * '4' - align to quadword boundary
4347 * '5' - align to 32 byte boundary
4348 * '6' - align to 64 byte boundary
4353 ppc_pe_section (ignore
)
4354 int ignore ATTRIBUTE_UNUSED
;
4356 /* Strip out the section name. */
4365 section_name
= input_line_pointer
;
4366 c
= get_symbol_end ();
4368 name
= xmalloc (input_line_pointer
- section_name
+ 1);
4369 strcpy (name
, section_name
);
4371 *input_line_pointer
= c
;
4376 flags
= SEC_NO_FLAGS
;
4378 if (strcmp (name
, ".idata$2") == 0)
4382 else if (strcmp (name
, ".idata$3") == 0)
4386 else if (strcmp (name
, ".idata$4") == 0)
4390 else if (strcmp (name
, ".idata$5") == 0)
4394 else if (strcmp (name
, ".idata$6") == 0)
4399 /* Default alignment to 16 byte boundary. */
4402 if (*input_line_pointer
== ',')
4404 ++input_line_pointer
;
4406 if (*input_line_pointer
!= '"')
4407 exp
= get_absolute_expression ();
4410 ++input_line_pointer
;
4411 while (*input_line_pointer
!= '"'
4412 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4414 switch (*input_line_pointer
)
4416 /* Section Contents */
4417 case 'a': /* unknown */
4418 as_bad (_("Unsupported section attribute -- 'a'"));
4420 case 'c': /* code section */
4423 case 'd': /* section has initialized data */
4426 case 'u': /* section has uninitialized data */
4427 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4431 case 'i': /* section contains directives (info) */
4432 /* FIXME: This is IMAGE_SCN_LNK_INFO
4434 flags
|= SEC_HAS_CONTENTS
;
4436 case 'n': /* section can be discarded */
4439 case 'R': /* Remove section at link time */
4440 flags
|= SEC_NEVER_LOAD
;
4443 /* Section Protection */
4444 case 'r': /* section is readable */
4445 flags
|= IMAGE_SCN_MEM_READ
;
4447 case 'w': /* section is writeable */
4448 flags
|= IMAGE_SCN_MEM_WRITE
;
4450 case 'x': /* section is executable */
4451 flags
|= IMAGE_SCN_MEM_EXECUTE
;
4453 case 's': /* section is sharable */
4454 flags
|= IMAGE_SCN_MEM_SHARED
;
4457 /* Section Alignment */
4458 case '0': /* align to byte boundary */
4459 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
4462 case '1': /* align to halfword boundary */
4463 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
4466 case '2': /* align to word boundary */
4467 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
4470 case '3': /* align to doubleword boundary */
4471 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
4474 case '4': /* align to quadword boundary */
4475 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
4478 case '5': /* align to 32 byte boundary */
4479 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
4482 case '6': /* align to 64 byte boundary */
4483 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
4488 as_bad (_("unknown section attribute '%c'"),
4489 *input_line_pointer
);
4492 ++input_line_pointer
;
4494 if (*input_line_pointer
== '"')
4495 ++input_line_pointer
;
4499 sec
= subseg_new (name
, (subsegT
) exp
);
4501 ppc_set_current_section (sec
);
4503 if (flags
!= SEC_NO_FLAGS
)
4505 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
4506 as_bad (_("error setting flags for \"%s\": %s"),
4507 bfd_section_name (stdoutput
, sec
),
4508 bfd_errmsg (bfd_get_error ()));
4511 bfd_set_section_alignment (stdoutput
, sec
, align
);
4516 ppc_pe_function (ignore
)
4517 int ignore ATTRIBUTE_UNUSED
;
4523 name
= input_line_pointer
;
4524 endc
= get_symbol_end ();
4526 ext_sym
= symbol_find_or_make (name
);
4528 *input_line_pointer
= endc
;
4530 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4531 SF_SET_FUNCTION (ext_sym
);
4532 SF_SET_PROCESS (ext_sym
);
4533 coff_add_linesym (ext_sym
);
4535 demand_empty_rest_of_line ();
4539 ppc_pe_tocd (ignore
)
4540 int ignore ATTRIBUTE_UNUSED
;
4542 if (tocdata_section
== 0)
4544 tocdata_section
= subseg_new (".tocd", 0);
4545 /* FIXME: section flags won't work. */
4546 bfd_set_section_flags (stdoutput
, tocdata_section
,
4547 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4548 | SEC_READONLY
| SEC_DATA
));
4550 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4554 rdata_section
= subseg_new (".tocd", 0);
4557 ppc_set_current_section (tocdata_section
);
4559 demand_empty_rest_of_line ();
4562 /* Don't adjust TOC relocs to use the section symbol. */
4565 ppc_pe_fix_adjustable (fix
)
4568 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4575 /* XCOFF specific symbol and file handling. */
4577 /* Canonicalize the symbol name. We use the to force the suffix, if
4578 any, to use square brackets, and to be in upper case. */
4581 ppc_canonicalize_symbol_name (name
)
4586 if (ppc_stab_symbol
)
4589 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4603 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4606 if (*s
== '\0' || s
[1] != '\0')
4607 as_bad (_("bad symbol suffix"));
4615 /* Set the class of a symbol based on the suffix, if any. This is
4616 called whenever a new symbol is created. */
4619 ppc_symbol_new_hook (sym
)
4622 struct ppc_tc_sy
*tc
;
4625 tc
= symbol_get_tc (sym
);
4629 tc
->real_name
= NULL
;
4635 if (ppc_stab_symbol
)
4638 s
= strchr (S_GET_NAME (sym
), '[');
4639 if (s
== (const char *) NULL
)
4641 /* There is no suffix. */
4650 if (strcmp (s
, "BS]") == 0)
4654 if (strcmp (s
, "DB]") == 0)
4656 else if (strcmp (s
, "DS]") == 0)
4660 if (strcmp (s
, "GL]") == 0)
4664 if (strcmp (s
, "PR]") == 0)
4668 if (strcmp (s
, "RO]") == 0)
4670 else if (strcmp (s
, "RW]") == 0)
4674 if (strcmp (s
, "SV]") == 0)
4678 if (strcmp (s
, "TC]") == 0)
4680 else if (strcmp (s
, "TI]") == 0)
4682 else if (strcmp (s
, "TB]") == 0)
4684 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4685 tc
->class = XMC_TC0
;
4688 if (strcmp (s
, "UA]") == 0)
4690 else if (strcmp (s
, "UC]") == 0)
4694 if (strcmp (s
, "XO]") == 0)
4699 if (tc
->class == -1)
4700 as_bad (_("Unrecognized symbol suffix"));
4703 /* Set the class of a label based on where it is defined. This
4704 handles symbols without suffixes. Also, move the symbol so that it
4705 follows the csect symbol. */
4708 ppc_frob_label (sym
)
4711 if (ppc_current_csect
!= (symbolS
*) NULL
)
4713 if (symbol_get_tc (sym
)->class == -1)
4714 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4716 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4717 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4718 &symbol_rootP
, &symbol_lastP
);
4719 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4723 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4724 seen. It tells ppc_adjust_symtab whether it needs to look through
4727 static bfd_boolean ppc_saw_abs
;
4729 /* Change the name of a symbol just before writing it out. Set the
4730 real name if the .rename pseudo-op was used. Otherwise, remove any
4731 class suffix. Return 1 if the symbol should not be included in the
4735 ppc_frob_symbol (sym
)
4738 static symbolS
*ppc_last_function
;
4739 static symbolS
*set_end
;
4741 /* Discard symbols that should not be included in the output symbol
4743 if (! symbol_used_in_reloc_p (sym
)
4744 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4745 || (! S_IS_EXTERNAL (sym
)
4746 && ! symbol_get_tc (sym
)->output
4747 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4750 /* This one will disappear anyway. Don't make a csect sym for it. */
4751 if (sym
== abs_section_sym
)
4754 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4755 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4761 name
= S_GET_NAME (sym
);
4762 s
= strchr (name
, '[');
4763 if (s
!= (char *) NULL
)
4769 snew
= xmalloc (len
+ 1);
4770 memcpy (snew
, name
, len
);
4773 S_SET_NAME (sym
, snew
);
4777 if (set_end
!= (symbolS
*) NULL
)
4779 SA_SET_SYM_ENDNDX (set_end
, sym
);
4783 if (SF_GET_FUNCTION (sym
))
4785 if (ppc_last_function
!= (symbolS
*) NULL
)
4786 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4787 ppc_last_function
= sym
;
4788 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4790 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4791 SA_SET_SYM_FSIZE (sym
,
4792 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4795 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4796 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4798 if (ppc_last_function
== (symbolS
*) NULL
)
4799 as_bad (_(".ef with no preceding .function"));
4802 set_end
= ppc_last_function
;
4803 ppc_last_function
= NULL
;
4805 /* We don't have a C_EFCN symbol, but we need to force the
4806 COFF backend to believe that it has seen one. */
4807 coff_last_function
= NULL
;
4811 if (! S_IS_EXTERNAL (sym
)
4812 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4813 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4814 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4815 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4816 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4817 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4818 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4819 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4820 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4821 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4823 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4824 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4827 union internal_auxent
*a
;
4829 /* Create a csect aux. */
4830 i
= S_GET_NUMBER_AUXILIARY (sym
);
4831 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4832 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4833 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4835 /* This is the TOC table. */
4836 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4837 a
->x_csect
.x_scnlen
.l
= 0;
4838 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4840 else if (symbol_get_tc (sym
)->subseg
!= 0)
4842 /* This is a csect symbol. x_scnlen is the size of the
4844 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4845 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4846 S_GET_SEGMENT (sym
))
4847 - S_GET_VALUE (sym
));
4850 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4851 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4852 - S_GET_VALUE (sym
));
4854 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4856 else if (S_GET_SEGMENT (sym
) == bss_section
)
4858 /* This is a common symbol. */
4859 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4860 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4861 if (S_IS_EXTERNAL (sym
))
4862 symbol_get_tc (sym
)->class = XMC_RW
;
4864 symbol_get_tc (sym
)->class = XMC_BS
;
4866 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4868 /* This is an absolute symbol. The csect will be created by
4869 ppc_adjust_symtab. */
4871 a
->x_csect
.x_smtyp
= XTY_LD
;
4872 if (symbol_get_tc (sym
)->class == -1)
4873 symbol_get_tc (sym
)->class = XMC_XO
;
4875 else if (! S_IS_DEFINED (sym
))
4877 /* This is an external symbol. */
4878 a
->x_csect
.x_scnlen
.l
= 0;
4879 a
->x_csect
.x_smtyp
= XTY_ER
;
4881 else if (symbol_get_tc (sym
)->class == XMC_TC
)
4885 /* This is a TOC definition. x_scnlen is the size of the
4887 next
= symbol_next (sym
);
4888 while (symbol_get_tc (next
)->class == XMC_TC0
)
4889 next
= symbol_next (next
);
4890 if (next
== (symbolS
*) NULL
4891 || symbol_get_tc (next
)->class != XMC_TC
)
4893 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4894 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4896 - S_GET_VALUE (sym
));
4898 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4899 - S_GET_VALUE (sym
));
4903 resolve_symbol_value (next
);
4904 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4905 - S_GET_VALUE (sym
));
4907 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4913 /* This is a normal symbol definition. x_scnlen is the
4914 symbol index of the containing csect. */
4915 if (S_GET_SEGMENT (sym
) == text_section
)
4916 csect
= ppc_text_csects
;
4917 else if (S_GET_SEGMENT (sym
) == data_section
)
4918 csect
= ppc_data_csects
;
4922 /* Skip the initial dummy symbol. */
4923 csect
= symbol_get_tc (csect
)->next
;
4925 if (csect
== (symbolS
*) NULL
)
4927 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4928 a
->x_csect
.x_scnlen
.l
= 0;
4932 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
4934 resolve_symbol_value (symbol_get_tc (csect
)->next
);
4935 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
4936 > S_GET_VALUE (sym
))
4938 csect
= symbol_get_tc (csect
)->next
;
4941 a
->x_csect
.x_scnlen
.p
=
4942 coffsymbol (symbol_get_bfdsym (csect
))->native
;
4943 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
4946 a
->x_csect
.x_smtyp
= XTY_LD
;
4949 a
->x_csect
.x_parmhash
= 0;
4950 a
->x_csect
.x_snhash
= 0;
4951 if (symbol_get_tc (sym
)->class == -1)
4952 a
->x_csect
.x_smclas
= XMC_PR
;
4954 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
4955 a
->x_csect
.x_stab
= 0;
4956 a
->x_csect
.x_snstab
= 0;
4958 /* Don't let the COFF backend resort these symbols. */
4959 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
4961 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4963 /* We want the value to be the symbol index of the referenced
4964 csect symbol. BFD will do that for us if we set the right
4966 asymbol
*bsym
= symbol_get_bfdsym (symbol_get_tc (sym
)->within
);
4967 combined_entry_type
*c
= coffsymbol (bsym
)->native
;
4969 S_SET_VALUE (sym
, (valueT
) (size_t) c
);
4970 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
4972 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4977 /* The value is the offset from the enclosing csect. */
4978 block
= symbol_get_tc (sym
)->within
;
4979 csect
= symbol_get_tc (block
)->within
;
4980 resolve_symbol_value (csect
);
4981 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4983 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4984 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4986 /* We want the value to be a file offset into the line numbers.
4987 BFD will do that for us if we set the right flags. We have
4988 already set the value correctly. */
4989 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
4995 /* Adjust the symbol table. This creates csect symbols for all
4996 absolute symbols. */
4999 ppc_adjust_symtab ()
5006 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
5010 union internal_auxent
*a
;
5012 if (S_GET_SEGMENT (sym
) != absolute_section
)
5015 csect
= symbol_create (".abs[XO]", absolute_section
,
5016 S_GET_VALUE (sym
), &zero_address_frag
);
5017 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
5018 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
5019 i
= S_GET_NUMBER_AUXILIARY (csect
);
5020 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
5021 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
5022 a
->x_csect
.x_scnlen
.l
= 0;
5023 a
->x_csect
.x_smtyp
= XTY_SD
;
5024 a
->x_csect
.x_parmhash
= 0;
5025 a
->x_csect
.x_snhash
= 0;
5026 a
->x_csect
.x_smclas
= XMC_XO
;
5027 a
->x_csect
.x_stab
= 0;
5028 a
->x_csect
.x_snstab
= 0;
5030 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
5032 i
= S_GET_NUMBER_AUXILIARY (sym
);
5033 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
5034 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
5035 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
5038 ppc_saw_abs
= FALSE
;
5041 /* Set the VMA for a section. This is called on all the sections in
5045 ppc_frob_section (sec
)
5048 static bfd_size_type vma
= 0;
5050 bfd_set_section_vma (stdoutput
, sec
, vma
);
5051 vma
+= bfd_section_size (stdoutput
, sec
);
5054 #endif /* OBJ_XCOFF */
5056 /* Turn a string in input_line_pointer into a floating point constant
5057 of type TYPE, and store the appropriate bytes in *LITP. The number
5058 of LITTLENUMS emitted is stored in *SIZEP. An error message is
5059 returned, or NULL on OK. */
5062 md_atof (type
, litp
, sizep
)
5068 LITTLENUM_TYPE words
[4];
5084 return _("bad call to md_atof");
5087 t
= atof_ieee (input_line_pointer
, type
, words
);
5089 input_line_pointer
= t
;
5093 if (target_big_endian
)
5095 for (i
= 0; i
< prec
; i
++)
5097 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5103 for (i
= prec
- 1; i
>= 0; i
--)
5105 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5113 /* Write a value out to the object file, using the appropriate
5117 md_number_to_chars (buf
, val
, n
)
5122 if (target_big_endian
)
5123 number_to_chars_bigendian (buf
, val
, n
);
5125 number_to_chars_littleendian (buf
, val
, n
);
5128 /* Align a section (I don't know why this is machine dependent). */
5131 md_section_align (seg
, addr
)
5135 int align
= bfd_get_section_alignment (stdoutput
, seg
);
5137 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
5140 /* We don't have any form of relaxing. */
5143 md_estimate_size_before_relax (fragp
, seg
)
5144 fragS
*fragp ATTRIBUTE_UNUSED
;
5145 asection
*seg ATTRIBUTE_UNUSED
;
5151 /* Convert a machine dependent frag. We never generate these. */
5154 md_convert_frag (abfd
, sec
, fragp
)
5155 bfd
*abfd ATTRIBUTE_UNUSED
;
5156 asection
*sec ATTRIBUTE_UNUSED
;
5157 fragS
*fragp ATTRIBUTE_UNUSED
;
5162 /* We have no need to default values of symbols. */
5165 md_undefined_symbol (name
)
5166 char *name ATTRIBUTE_UNUSED
;
5171 /* Functions concerning relocs. */
5173 /* The location from which a PC relative jump should be calculated,
5174 given a PC relative reloc. */
5177 md_pcrel_from_section (fixp
, sec
)
5179 segT sec ATTRIBUTE_UNUSED
;
5181 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5186 /* This is called to see whether a fixup should be adjusted to use a
5187 section symbol. We take the opportunity to change a fixup against
5188 a symbol in the TOC subsegment into a reloc against the
5189 corresponding .tc symbol. */
5192 ppc_fix_adjustable (fix
)
5195 valueT val
= resolve_symbol_value (fix
->fx_addsy
);
5196 segT symseg
= S_GET_SEGMENT (fix
->fx_addsy
);
5197 TC_SYMFIELD_TYPE
*tc
;
5199 if (symseg
== absolute_section
)
5202 if (ppc_toc_csect
!= (symbolS
*) NULL
5203 && fix
->fx_addsy
!= ppc_toc_csect
5204 && symseg
== data_section
5205 && val
>= ppc_toc_frag
->fr_address
5206 && (ppc_after_toc_frag
== (fragS
*) NULL
5207 || val
< ppc_after_toc_frag
->fr_address
))
5211 for (sy
= symbol_next (ppc_toc_csect
);
5212 sy
!= (symbolS
*) NULL
;
5213 sy
= symbol_next (sy
))
5215 TC_SYMFIELD_TYPE
*sy_tc
= symbol_get_tc (sy
);
5217 if (sy_tc
->class == XMC_TC0
)
5219 if (sy_tc
->class != XMC_TC
)
5221 if (val
== resolve_symbol_value (sy
))
5224 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
5229 as_bad_where (fix
->fx_file
, fix
->fx_line
,
5230 _("symbol in .toc does not match any .tc"));
5233 /* Possibly adjust the reloc to be against the csect. */
5234 tc
= symbol_get_tc (fix
->fx_addsy
);
5236 && tc
->class != XMC_TC0
5237 && tc
->class != XMC_TC
5238 && symseg
!= bss_section
5239 /* Don't adjust if this is a reloc in the toc section. */
5240 && (symseg
!= data_section
5241 || ppc_toc_csect
== NULL
5242 || val
< ppc_toc_frag
->fr_address
5243 || (ppc_after_toc_frag
!= NULL
5244 && val
>= ppc_after_toc_frag
->fr_address
)))
5247 symbolS
*next_csect
;
5249 if (symseg
== text_section
)
5250 csect
= ppc_text_csects
;
5251 else if (symseg
== data_section
)
5252 csect
= ppc_data_csects
;
5256 /* Skip the initial dummy symbol. */
5257 csect
= symbol_get_tc (csect
)->next
;
5259 if (csect
!= (symbolS
*) NULL
)
5261 while ((next_csect
= symbol_get_tc (csect
)->next
) != (symbolS
*) NULL
5262 && (symbol_get_frag (next_csect
)->fr_address
<= val
))
5264 /* If the csect address equals the symbol value, then we
5265 have to look through the full symbol table to see
5266 whether this is the csect we want. Note that we will
5267 only get here if the csect has zero length. */
5268 if (symbol_get_frag (csect
)->fr_address
== val
5269 && S_GET_VALUE (csect
) == val
)
5273 for (scan
= symbol_next (csect
);
5275 scan
= symbol_next (scan
))
5277 if (symbol_get_tc (scan
)->subseg
!= 0)
5279 if (scan
== fix
->fx_addsy
)
5283 /* If we found the symbol before the next csect
5284 symbol, then this is the csect we want. */
5285 if (scan
== fix
->fx_addsy
)
5292 fix
->fx_offset
+= val
- symbol_get_frag (csect
)->fr_address
;
5293 fix
->fx_addsy
= csect
;
5298 /* Adjust a reloc against a .lcomm symbol to be against the base
5300 if (symseg
== bss_section
5301 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
5303 symbolS
*sy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
5305 fix
->fx_offset
+= val
- resolve_symbol_value (sy
);
5312 /* A reloc from one csect to another must be kept. The assembler
5313 will, of course, keep relocs between sections, and it will keep
5314 absolute relocs, but we need to force it to keep PC relative relocs
5315 between two csects in the same section. */
5318 ppc_force_relocation (fix
)
5321 /* At this point fix->fx_addsy should already have been converted to
5322 a csect symbol. If the csect does not include the fragment, then
5323 we need to force the relocation. */
5325 && fix
->fx_addsy
!= NULL
5326 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
5327 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
5328 > fix
->fx_frag
->fr_address
)
5329 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
5330 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
5331 <= fix
->fx_frag
->fr_address
))))
5334 return generic_force_reloc (fix
);
5337 #endif /* OBJ_XCOFF */
5340 /* If this function returns non-zero, it guarantees that a relocation
5341 will be emitted for a fixup. */
5344 ppc_force_relocation (fix
)
5347 /* Branch prediction relocations must force a relocation, as must
5348 the vtable description relocs. */
5349 switch (fix
->fx_r_type
)
5351 case BFD_RELOC_PPC_B16_BRTAKEN
:
5352 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5353 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5354 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5355 case BFD_RELOC_PPC64_TOC
:
5361 if (fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5362 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
5365 return generic_force_reloc (fix
);
5369 ppc_fix_adjustable (fix
)
5372 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
5373 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
5374 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
5375 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
5376 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
5377 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
5378 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
5379 && !(fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5380 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
5382 || (fix
->fx_subsy
!= NULL
5383 && (S_GET_SEGMENT (fix
->fx_subsy
)
5384 == S_GET_SEGMENT (fix
->fx_addsy
)))
5385 || S_IS_LOCAL (fix
->fx_addsy
)));
5389 /* Apply a fixup to the object code. This is called for all the
5390 fixups we generated by the call to fix_new_exp, above. In the call
5391 above we used a reloc code which was the largest legal reloc code
5392 plus the operand index. Here we undo that to recover the operand
5393 index. At this point all symbol values should be fully resolved,
5394 and we attempt to completely resolve the reloc. If we can not do
5395 that, we determine the correct reloc code and put it back in the
5399 md_apply_fix3 (fixP
, valP
, seg
)
5402 segT seg ATTRIBUTE_UNUSED
;
5404 valueT value
= * valP
;
5407 if (fixP
->fx_addsy
!= NULL
)
5409 /* Hack around bfd_install_relocation brain damage. */
5411 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5416 /* FIXME FIXME FIXME: The value we are passed in *valP includes
5417 the symbol values. Since we are using BFD_ASSEMBLER, if we are
5418 doing this relocation the code in write.c is going to call
5419 bfd_install_relocation, which is also going to use the symbol
5420 value. That means that if the reloc is fully resolved we want to
5421 use *valP since bfd_install_relocation is not being used.
5422 However, if the reloc is not fully resolved we do not want to use
5423 *valP, and must use fx_offset instead. However, if the reloc
5424 is PC relative, we do want to use *valP since it includes the
5425 result of md_pcrel_from. This is confusing. */
5426 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
5429 else if (fixP
->fx_pcrel
)
5433 value
= fixP
->fx_offset
;
5436 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
5438 /* We can't actually support subtracting a symbol. */
5439 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
5442 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
5445 const struct powerpc_operand
*operand
;
5449 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
5451 operand
= &powerpc_operands
[opindex
];
5454 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5455 does not generate a reloc. It uses the offset of `sym' within its
5456 csect. Other usages, such as `.long sym', generate relocs. This
5457 is the documented behaviour of non-TOC symbols. */
5458 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5459 && operand
->bits
== 16
5460 && operand
->shift
== 0
5461 && (operand
->insert
== NULL
|| ppc_obj64
)
5462 && fixP
->fx_addsy
!= NULL
5463 && symbol_get_tc (fixP
->fx_addsy
)->subseg
!= 0
5464 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC
5465 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC0
5466 && S_GET_SEGMENT (fixP
->fx_addsy
) != bss_section
)
5468 value
= fixP
->fx_offset
;
5473 /* Fetch the instruction, insert the fully resolved operand
5474 value, and stuff the instruction back again. */
5475 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5476 if (target_big_endian
)
5477 insn
= bfd_getb32 ((unsigned char *) where
);
5479 insn
= bfd_getl32 ((unsigned char *) where
);
5480 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
5481 fixP
->fx_file
, fixP
->fx_line
);
5482 if (target_big_endian
)
5483 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5485 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5488 /* Nothing else to do here. */
5491 assert (fixP
->fx_addsy
!= NULL
);
5493 /* Determine a BFD reloc value based on the operand information.
5494 We are only prepared to turn a few of the operands into
5496 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5497 && operand
->bits
== 26
5498 && operand
->shift
== 0)
5499 fixP
->fx_r_type
= BFD_RELOC_PPC_B26
;
5500 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5501 && operand
->bits
== 16
5502 && operand
->shift
== 0)
5504 fixP
->fx_r_type
= BFD_RELOC_PPC_B16
;
5507 if (target_big_endian
)
5508 fixP
->fx_where
+= 2;
5511 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5512 && operand
->bits
== 26
5513 && operand
->shift
== 0)
5514 fixP
->fx_r_type
= BFD_RELOC_PPC_BA26
;
5515 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5516 && operand
->bits
== 16
5517 && operand
->shift
== 0)
5519 fixP
->fx_r_type
= BFD_RELOC_PPC_BA16
;
5522 if (target_big_endian
)
5523 fixP
->fx_where
+= 2;
5526 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5527 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5528 && operand
->bits
== 16
5529 && operand
->shift
== 0)
5531 if (ppc_is_toc_sym (fixP
->fx_addsy
))
5533 fixP
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
5536 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5537 fixP
->fx_r_type
= BFD_RELOC_PPC64_TOC16_DS
;
5542 fixP
->fx_r_type
= BFD_RELOC_16
;
5545 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5546 fixP
->fx_r_type
= BFD_RELOC_PPC64_ADDR16_DS
;
5550 if (target_big_endian
)
5551 fixP
->fx_where
+= 2;
5553 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5559 /* Use expr_symbol_where to see if this is an expression
5561 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
5562 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5563 _("unresolved expression that must be resolved"));
5565 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5566 _("unsupported relocation against %s"),
5567 S_GET_NAME (fixP
->fx_addsy
));
5575 ppc_elf_validate_fix (fixP
, seg
);
5577 switch (fixP
->fx_r_type
)
5579 case BFD_RELOC_CTOR
:
5586 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
5590 case BFD_RELOC_32_PCREL
:
5591 case BFD_RELOC_PPC_EMB_NADDR32
:
5592 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5599 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
5602 case BFD_RELOC_64_PCREL
:
5603 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5607 case BFD_RELOC_LO16
:
5609 case BFD_RELOC_GPREL16
:
5610 case BFD_RELOC_16_GOT_PCREL
:
5611 case BFD_RELOC_16_GOTOFF
:
5612 case BFD_RELOC_LO16_GOTOFF
:
5613 case BFD_RELOC_HI16_GOTOFF
:
5614 case BFD_RELOC_HI16_S_GOTOFF
:
5615 case BFD_RELOC_16_BASEREL
:
5616 case BFD_RELOC_LO16_BASEREL
:
5617 case BFD_RELOC_HI16_BASEREL
:
5618 case BFD_RELOC_HI16_S_BASEREL
:
5619 case BFD_RELOC_PPC_EMB_NADDR16
:
5620 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5621 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5622 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5623 case BFD_RELOC_PPC_EMB_SDAI16
:
5624 case BFD_RELOC_PPC_EMB_SDA2REL
:
5625 case BFD_RELOC_PPC_EMB_SDA2I16
:
5626 case BFD_RELOC_PPC_EMB_RELSEC16
:
5627 case BFD_RELOC_PPC_EMB_RELST_LO
:
5628 case BFD_RELOC_PPC_EMB_RELST_HI
:
5629 case BFD_RELOC_PPC_EMB_RELST_HA
:
5630 case BFD_RELOC_PPC_EMB_RELSDA
:
5631 case BFD_RELOC_PPC_TOC16
:
5633 case BFD_RELOC_PPC64_TOC16_LO
:
5634 case BFD_RELOC_PPC64_TOC16_HI
:
5635 case BFD_RELOC_PPC64_TOC16_HA
:
5639 if (fixP
->fx_addsy
!= NULL
)
5640 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5641 _("cannot emit PC relative %s relocation against %s"),
5642 bfd_get_reloc_code_name (fixP
->fx_r_type
),
5643 S_GET_NAME (fixP
->fx_addsy
));
5645 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5646 _("cannot emit PC relative %s relocation"),
5647 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5650 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5654 /* This case happens when you write, for example,
5656 where L1 and L2 are defined later. */
5657 case BFD_RELOC_HI16
:
5660 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5664 case BFD_RELOC_HI16_S
:
5667 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5672 case BFD_RELOC_PPC64_HIGHER
:
5675 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5676 PPC_HIGHER (value
), 2);
5679 case BFD_RELOC_PPC64_HIGHER_S
:
5682 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5683 PPC_HIGHERA (value
), 2);
5686 case BFD_RELOC_PPC64_HIGHEST
:
5689 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5690 PPC_HIGHEST (value
), 2);
5693 case BFD_RELOC_PPC64_HIGHEST_S
:
5696 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5697 PPC_HIGHESTA (value
), 2);
5700 case BFD_RELOC_PPC64_ADDR16_DS
:
5701 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
5702 case BFD_RELOC_PPC64_GOT16_DS
:
5703 case BFD_RELOC_PPC64_GOT16_LO_DS
:
5704 case BFD_RELOC_PPC64_PLT16_LO_DS
:
5705 case BFD_RELOC_PPC64_SECTOFF_DS
:
5706 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
5707 case BFD_RELOC_PPC64_TOC16_DS
:
5708 case BFD_RELOC_PPC64_TOC16_LO_DS
:
5709 case BFD_RELOC_PPC64_PLTGOT16_DS
:
5710 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
5714 unsigned char *where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5717 if (target_big_endian
)
5718 val
= bfd_getb16 (where
);
5720 val
= bfd_getl16 (where
);
5721 val
|= (value
& 0xfffc);
5722 if (target_big_endian
)
5723 bfd_putb16 ((bfd_vma
) val
, where
);
5725 bfd_putl16 ((bfd_vma
) val
, where
);
5729 case BFD_RELOC_PPC_TLS
:
5730 case BFD_RELOC_PPC_DTPMOD
:
5731 case BFD_RELOC_PPC_TPREL16
:
5732 case BFD_RELOC_PPC_TPREL16_LO
:
5733 case BFD_RELOC_PPC_TPREL16_HI
:
5734 case BFD_RELOC_PPC_TPREL16_HA
:
5735 case BFD_RELOC_PPC_TPREL
:
5736 case BFD_RELOC_PPC_DTPREL16
:
5737 case BFD_RELOC_PPC_DTPREL16_LO
:
5738 case BFD_RELOC_PPC_DTPREL16_HI
:
5739 case BFD_RELOC_PPC_DTPREL16_HA
:
5740 case BFD_RELOC_PPC_DTPREL
:
5741 case BFD_RELOC_PPC_GOT_TLSGD16
:
5742 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
5743 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
5744 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
5745 case BFD_RELOC_PPC_GOT_TLSLD16
:
5746 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
5747 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
5748 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
5749 case BFD_RELOC_PPC_GOT_TPREL16
:
5750 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
5751 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
5752 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
5753 case BFD_RELOC_PPC_GOT_DTPREL16
:
5754 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
5755 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
5756 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
5757 case BFD_RELOC_PPC64_TPREL16_DS
:
5758 case BFD_RELOC_PPC64_TPREL16_LO_DS
:
5759 case BFD_RELOC_PPC64_TPREL16_HIGHER
:
5760 case BFD_RELOC_PPC64_TPREL16_HIGHERA
:
5761 case BFD_RELOC_PPC64_TPREL16_HIGHEST
:
5762 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
:
5763 case BFD_RELOC_PPC64_DTPREL16_DS
:
5764 case BFD_RELOC_PPC64_DTPREL16_LO_DS
:
5765 case BFD_RELOC_PPC64_DTPREL16_HIGHER
:
5766 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
:
5767 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
:
5768 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
:
5771 /* Because SDA21 modifies the register field, the size is set to 4
5772 bytes, rather than 2, so offset it here appropriately. */
5773 case BFD_RELOC_PPC_EMB_SDA21
:
5777 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
5778 + ((target_big_endian
) ? 2 : 0),
5786 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5790 case BFD_RELOC_24_PLT_PCREL
:
5791 case BFD_RELOC_PPC_LOCAL24PC
:
5792 if (!fixP
->fx_pcrel
&& !fixP
->fx_done
)
5800 /* Fetch the instruction, insert the fully resolved operand
5801 value, and stuff the instruction back again. */
5802 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5803 if (target_big_endian
)
5804 insn
= bfd_getb32 ((unsigned char *) where
);
5806 insn
= bfd_getl32 ((unsigned char *) where
);
5807 if ((value
& 3) != 0)
5808 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5809 _("must branch to an address a multiple of 4"));
5810 if ((offsetT
) value
< -0x40000000
5811 || (offsetT
) value
>= 0x40000000)
5812 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5813 _("@local or @plt branch destination is too far away, %ld bytes"),
5815 insn
= insn
| (value
& 0x03fffffc);
5816 if (target_big_endian
)
5817 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5819 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5823 case BFD_RELOC_VTABLE_INHERIT
:
5826 && !S_IS_DEFINED (fixP
->fx_addsy
)
5827 && !S_IS_WEAK (fixP
->fx_addsy
))
5828 S_SET_WEAK (fixP
->fx_addsy
);
5831 case BFD_RELOC_VTABLE_ENTRY
:
5836 /* Generated by reference to `sym@tocbase'. The sym is
5837 ignored by the linker. */
5838 case BFD_RELOC_PPC64_TOC
:
5844 _("Gas failure, reloc value %d\n"), fixP
->fx_r_type
);
5851 fixP
->fx_addnumber
= value
;
5853 if (fixP
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
5854 fixP
->fx_addnumber
= 0;
5858 fixP
->fx_addnumber
= 0;
5860 /* We want to use the offset within the data segment of the
5861 symbol, not the actual VMA of the symbol. */
5862 fixP
->fx_addnumber
=
5863 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixP
->fx_addsy
));
5869 /* Generate a reloc for a fixup. */
5872 tc_gen_reloc (seg
, fixp
)
5873 asection
*seg ATTRIBUTE_UNUSED
;
5878 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5880 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5881 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5882 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5883 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5884 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
5886 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5887 _("reloc %d not supported by object file format"),
5888 (int) fixp
->fx_r_type
);
5891 reloc
->addend
= fixp
->fx_addnumber
;