1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000
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
28 #include "opcode/ppc.h"
38 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
40 /* Tell the main code what the endianness is. */
41 extern int target_big_endian
;
43 /* Whether or not, we've set target_big_endian. */
44 static int set_target_endian
= 0;
46 /* Whether to use user friendly register names. */
47 #ifndef TARGET_REG_NAMES_P
49 #define TARGET_REG_NAMES_P true
51 #define TARGET_REG_NAMES_P false
55 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
57 static boolean register_name
PARAMS ((expressionS
*));
58 static void ppc_set_cpu
PARAMS ((void));
59 static unsigned long ppc_insert_operand
60 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
61 offsetT val
, char *file
, unsigned int line
));
62 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
63 static void ppc_byte
PARAMS ((int));
64 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
65 static void ppc_tc
PARAMS ((int));
68 static void ppc_comm
PARAMS ((int));
69 static void ppc_bb
PARAMS ((int));
70 static void ppc_bc
PARAMS ((int));
71 static void ppc_bf
PARAMS ((int));
72 static void ppc_biei
PARAMS ((int));
73 static void ppc_bs
PARAMS ((int));
74 static void ppc_eb
PARAMS ((int));
75 static void ppc_ec
PARAMS ((int));
76 static void ppc_ef
PARAMS ((int));
77 static void ppc_es
PARAMS ((int));
78 static void ppc_csect
PARAMS ((int));
79 static void ppc_change_csect
PARAMS ((symbolS
*));
80 static void ppc_function
PARAMS ((int));
81 static void ppc_extern
PARAMS ((int));
82 static void ppc_lglobl
PARAMS ((int));
83 static void ppc_section
PARAMS ((int));
84 static void ppc_named_section
PARAMS ((int));
85 static void ppc_stabx
PARAMS ((int));
86 static void ppc_rename
PARAMS ((int));
87 static void ppc_toc
PARAMS ((int));
88 static void ppc_xcoff_cons
PARAMS ((int));
89 static void ppc_machine
PARAMS ((int));
90 static void ppc_vbyte
PARAMS ((int));
94 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
95 static void ppc_elf_cons
PARAMS ((int));
96 static void ppc_elf_rdata
PARAMS ((int));
97 static void ppc_elf_lcomm
PARAMS ((int));
98 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
102 static void ppc_set_current_section
PARAMS ((segT
));
103 static void ppc_previous
PARAMS ((int));
104 static void ppc_pdata
PARAMS ((int));
105 static void ppc_ydata
PARAMS ((int));
106 static void ppc_reldata
PARAMS ((int));
107 static void ppc_rdata
PARAMS ((int));
108 static void ppc_ualong
PARAMS ((int));
109 static void ppc_znop
PARAMS ((int));
110 static void ppc_pe_comm
PARAMS ((int));
111 static void ppc_pe_section
PARAMS ((int));
112 static void ppc_pe_function
PARAMS ((int));
113 static void ppc_pe_tocd
PARAMS ((int));
116 /* Generic assembler global variables which must be defined by all
120 /* This string holds the chars that always start a comment. If the
121 pre-processor is disabled, these aren't very useful. The macro
122 tc_comment_chars points to this. We use this, rather than the
123 usual comment_chars, so that we can switch for Solaris conventions. */
124 static const char ppc_solaris_comment_chars
[] = "#!";
125 static const char ppc_eabi_comment_chars
[] = "#";
127 #ifdef TARGET_SOLARIS_COMMENT
128 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
130 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
133 const char comment_chars
[] = "#";
136 /* Characters which start a comment at the beginning of a line. */
137 const char line_comment_chars
[] = "#";
139 /* Characters which may be used to separate multiple commands on a
141 const char line_separator_chars
[] = ";";
143 /* Characters which are used to indicate an exponent in a floating
145 const char EXP_CHARS
[] = "eE";
147 /* Characters which mean that a number is a floating point constant,
149 const char FLT_CHARS
[] = "dD";
151 /* The target specific pseudo-ops which we support. */
153 const pseudo_typeS md_pseudo_table
[] =
155 /* Pseudo-ops which must be overridden. */
156 { "byte", ppc_byte
, 0 },
159 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
160 legitimately belong in the obj-*.c file. However, XCOFF is based
161 on COFF, and is only implemented for the RS/6000. We just use
162 obj-coff.c, and add what we need here. */
163 { "comm", ppc_comm
, 0 },
164 { "lcomm", ppc_comm
, 1 },
168 { "bi", ppc_biei
, 0 },
170 { "csect", ppc_csect
, 0 },
171 { "data", ppc_section
, 'd' },
175 { "ei", ppc_biei
, 1 },
177 { "extern", ppc_extern
, 0 },
178 { "function", ppc_function
, 0 },
179 { "lglobl", ppc_lglobl
, 0 },
180 { "rename", ppc_rename
, 0 },
181 { "section", ppc_named_section
, 0 },
182 { "stabx", ppc_stabx
, 0 },
183 { "text", ppc_section
, 't' },
184 { "toc", ppc_toc
, 0 },
185 { "long", ppc_xcoff_cons
, 2 },
186 { "llong", ppc_xcoff_cons
, 3 },
187 { "word", ppc_xcoff_cons
, 1 },
188 { "short", ppc_xcoff_cons
, 1 },
189 { "vbyte", ppc_vbyte
, 0 },
190 { "machine", ppc_machine
, 0 },
194 { "long", ppc_elf_cons
, 4 },
195 { "word", ppc_elf_cons
, 2 },
196 { "short", ppc_elf_cons
, 2 },
197 { "rdata", ppc_elf_rdata
, 0 },
198 { "rodata", ppc_elf_rdata
, 0 },
199 { "lcomm", ppc_elf_lcomm
, 0 },
203 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
204 { "previous", ppc_previous
, 0 },
205 { "pdata", ppc_pdata
, 0 },
206 { "ydata", ppc_ydata
, 0 },
207 { "reldata", ppc_reldata
, 0 },
208 { "rdata", ppc_rdata
, 0 },
209 { "ualong", ppc_ualong
, 0 },
210 { "znop", ppc_znop
, 0 },
211 { "comm", ppc_pe_comm
, 0 },
212 { "lcomm", ppc_pe_comm
, 1 },
213 { "section", ppc_pe_section
, 0 },
214 { "function", ppc_pe_function
,0 },
215 { "tocd", ppc_pe_tocd
, 0 },
218 /* This pseudo-op is used even when not generating XCOFF output. */
225 /* Predefined register names if -mregnames (or default for Windows NT). */
226 /* In general, there are lots of them, in an attempt to be compatible */
227 /* with a number of other Windows NT assemblers. */
229 /* Structure to hold information about predefined registers. */
236 /* List of registers that are pre-defined:
238 Each general register has predefined names of the form:
239 1. r<reg_num> which has the value <reg_num>.
240 2. r.<reg_num> which has the value <reg_num>.
242 Each floating point register has predefined names of the form:
243 1. f<reg_num> which has the value <reg_num>.
244 2. f.<reg_num> which has the value <reg_num>.
246 Each vector unit register has predefined names of the form:
247 1. v<reg_num> which has the value <reg_num>.
248 2. v.<reg_num> which has the value <reg_num>.
250 Each condition register has predefined names of the form:
251 1. cr<reg_num> which has the value <reg_num>.
252 2. cr.<reg_num> which has the value <reg_num>.
254 There are individual registers as well:
255 sp or r.sp has the value 1
256 rtoc or r.toc has the value 2
257 fpscr has the value 0
263 dsisr has the value 18
265 sdr1 has the value 25
266 srr0 has the value 26
267 srr1 has the value 27
269 The table is sorted. Suitable for searching by a binary search. */
271 static const struct pd_reg pre_defined_registers
[] =
273 { "cr.0", 0 }, /* Condition Registers */
293 { "dar", 19 }, /* Data Access Register */
294 { "dec", 22 }, /* Decrementer */
295 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
297 { "f.0", 0 }, /* Floating point registers */
365 { "lr", 8 }, /* Link Register */
369 { "r.0", 0 }, /* General Purpose Registers */
402 { "r.sp", 1 }, /* Stack Pointer */
404 { "r.toc", 2 }, /* Pointer to the table of contents */
406 { "r0", 0 }, /* More general purpose registers */
439 { "rtoc", 2 }, /* Table of contents */
441 { "sdr1", 25 }, /* Storage Description Register 1 */
445 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
446 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
448 { "v.0", 0 }, /* Vector registers */
518 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
520 /* Given NAME, find the register number associated with that name, return
521 the integer value associated with the given name or -1 on failure. */
523 static int reg_name_search
524 PARAMS ((const struct pd_reg
*, int, const char * name
));
527 reg_name_search (regs
, regcount
, name
)
528 const struct pd_reg
*regs
;
532 int middle
, low
, high
;
540 middle
= (low
+ high
) / 2;
541 cmp
= strcasecmp (name
, regs
[middle
].name
);
547 return regs
[middle
].value
;
555 * Summary of register_name().
557 * in: Input_line_pointer points to 1st char of operand.
559 * out: A expressionS.
560 * The operand may have been a register: in this case, X_op == O_register,
561 * X_add_number is set to the register number, and truth is returned.
562 * Input_line_pointer->(next non-blank) char after operand, or is in its
567 register_name (expressionP
)
568 expressionS
*expressionP
;
575 /* Find the spelling of the operand */
576 start
= name
= input_line_pointer
;
577 if (name
[0] == '%' && isalpha (name
[1]))
578 name
= ++input_line_pointer
;
580 else if (!reg_names_p
|| !isalpha (name
[0]))
583 c
= get_symbol_end ();
584 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
586 /* look to see if it's in the register table */
589 expressionP
->X_op
= O_register
;
590 expressionP
->X_add_number
= reg_number
;
592 /* make the rest nice */
593 expressionP
->X_add_symbol
= NULL
;
594 expressionP
->X_op_symbol
= NULL
;
595 *input_line_pointer
= c
; /* put back the delimiting char */
600 /* reset the line as if we had not done anything */
601 *input_line_pointer
= c
; /* put back the delimiting char */
602 input_line_pointer
= start
; /* reset input_line pointer */
607 /* This function is called for each symbol seen in an expression. It
608 handles the special parsing which PowerPC assemblers are supposed
609 to use for condition codes. */
611 /* Whether to do the special parsing. */
612 static boolean cr_operand
;
614 /* Names to recognize in a condition code. This table is sorted. */
615 static const struct pd_reg cr_names
[] =
632 /* Parsing function. This returns non-zero if it recognized an
636 ppc_parse_name (name
, expr
)
645 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
650 expr
->X_op
= O_constant
;
651 expr
->X_add_number
= val
;
656 /* Local variables. */
658 /* The type of processor we are assembling for. This is one or more
659 of the PPC_OPCODE flags defined in opcode/ppc.h. */
660 static int ppc_cpu
= 0;
662 /* The size of the processor we are assembling for. This is either
663 PPC_OPCODE_32 or PPC_OPCODE_64. */
664 static unsigned long ppc_size
= PPC_OPCODE_32
;
666 /* Whether to target xcoff64 */
667 static int ppc_xcoff64
= 0;
669 /* Opcode hash table. */
670 static struct hash_control
*ppc_hash
;
672 /* Macro hash table. */
673 static struct hash_control
*ppc_macro_hash
;
676 /* What type of shared library support to use */
677 static enum { SHLIB_NONE
, SHLIB_PIC
, SHILB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
679 /* Flags to set in the elf header */
680 static flagword ppc_flags
= 0;
682 /* Whether this is Solaris or not. */
683 #ifdef TARGET_SOLARIS_COMMENT
684 #define SOLARIS_P true
686 #define SOLARIS_P false
689 static boolean msolaris
= SOLARIS_P
;
694 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
695 using a bunch of different sections. These assembler sections,
696 however, are all encompassed within the .text or .data sections of
697 the final output file. We handle this by using different
698 subsegments within these main segments. */
700 /* Next subsegment to allocate within the .text segment. */
701 static subsegT ppc_text_subsegment
= 2;
703 /* Linked list of csects in the text section. */
704 static symbolS
*ppc_text_csects
;
706 /* Next subsegment to allocate within the .data segment. */
707 static subsegT ppc_data_subsegment
= 2;
709 /* Linked list of csects in the data section. */
710 static symbolS
*ppc_data_csects
;
712 /* The current csect. */
713 static symbolS
*ppc_current_csect
;
715 /* The RS/6000 assembler uses a TOC which holds addresses of functions
716 and variables. Symbols are put in the TOC with the .tc pseudo-op.
717 A special relocation is used when accessing TOC entries. We handle
718 the TOC as a subsegment within the .data segment. We set it up if
719 we see a .toc pseudo-op, and save the csect symbol here. */
720 static symbolS
*ppc_toc_csect
;
722 /* The first frag in the TOC subsegment. */
723 static fragS
*ppc_toc_frag
;
725 /* The first frag in the first subsegment after the TOC in the .data
726 segment. NULL if there are no subsegments after the TOC. */
727 static fragS
*ppc_after_toc_frag
;
729 /* The current static block. */
730 static symbolS
*ppc_current_block
;
732 /* The COFF debugging section; set by md_begin. This is not the
733 .debug section, but is instead the secret BFD section which will
734 cause BFD to set the section number of a symbol to N_DEBUG. */
735 static asection
*ppc_coff_debug_section
;
737 #endif /* OBJ_XCOFF */
741 /* Various sections that we need for PE coff support. */
742 static segT ydata_section
;
743 static segT pdata_section
;
744 static segT reldata_section
;
745 static segT rdata_section
;
746 static segT tocdata_section
;
748 /* The current section and the previous section. See ppc_previous. */
749 static segT ppc_previous_section
;
750 static segT ppc_current_section
;
755 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
759 CONST
char *md_shortopts
= "b:l:usm:K:VQ:";
761 CONST
char *md_shortopts
= "um:";
763 struct option md_longopts
[] = {
764 {NULL
, no_argument
, NULL
, 0}
766 size_t md_longopts_size
= sizeof(md_longopts
);
769 md_parse_option (c
, arg
)
776 /* -u means that any undefined symbols should be treated as
777 external, which is the default for gas anyhow. */
782 /* Solaris as takes -le (presumably for little endian). For completeness
783 sake, recognize -be also. */
784 if (strcmp (arg
, "e") == 0)
786 target_big_endian
= 0;
787 set_target_endian
= 1;
795 if (strcmp (arg
, "e") == 0)
797 target_big_endian
= 1;
798 set_target_endian
= 1;
806 /* Recognize -K PIC */
807 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
810 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
818 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
820 if (strcmp (arg
, "64") == 0)
822 else if (strcmp (arg
, "32") == 0)
829 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
831 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
832 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
833 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
834 else if (strcmp (arg
, "pwr") == 0)
835 ppc_cpu
= PPC_OPCODE_POWER
;
836 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
837 instructions that are holdovers from the Power. */
838 else if (strcmp (arg
, "601") == 0)
839 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
840 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
841 Motorola PowerPC 603/604. */
842 else if (strcmp (arg
, "ppc") == 0
843 || strcmp (arg
, "ppc32") == 0
844 || strcmp (arg
, "403") == 0
845 || strcmp (arg
, "603") == 0
846 || strcmp (arg
, "604") == 0)
847 ppc_cpu
= PPC_OPCODE_PPC
;
848 else if (strcmp (arg
, "7400") == 0)
849 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
;
850 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
852 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
854 ppc_cpu
= PPC_OPCODE_PPC
;
855 ppc_size
= PPC_OPCODE_64
;
857 else if (strcmp (arg
, "ppc64bridge") == 0)
859 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_64_BRIDGE
;
860 ppc_size
= PPC_OPCODE_64
;
862 /* -mcom means assemble for the common intersection between Power
863 and PowerPC. At present, we just allow the union, rather
864 than the intersection. */
865 else if (strcmp (arg
, "com") == 0)
866 ppc_cpu
= PPC_OPCODE_COMMON
;
867 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
868 else if (strcmp (arg
, "any") == 0)
869 ppc_cpu
= PPC_OPCODE_ANY
;
871 else if (strcmp (arg
, "regnames") == 0)
874 else if (strcmp (arg
, "no-regnames") == 0)
878 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
879 else if (strcmp (arg
, "relocatable") == 0)
881 shlib
= SHILB_MRELOCATABLE
;
882 ppc_flags
|= EF_PPC_RELOCATABLE
;
885 else if (strcmp (arg
, "relocatable-lib") == 0)
887 shlib
= SHILB_MRELOCATABLE
;
888 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
891 /* -memb, set embedded bit */
892 else if (strcmp (arg
, "emb") == 0)
893 ppc_flags
|= EF_PPC_EMB
;
895 /* -mlittle/-mbig set the endianess */
896 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
898 target_big_endian
= 0;
899 set_target_endian
= 1;
902 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
904 target_big_endian
= 1;
905 set_target_endian
= 1;
908 else if (strcmp (arg
, "solaris") == 0)
911 ppc_comment_chars
= ppc_solaris_comment_chars
;
914 else if (strcmp (arg
, "no-solaris") == 0)
917 ppc_comment_chars
= ppc_eabi_comment_chars
;
922 as_bad (_("invalid switch -m%s"), arg
);
928 /* -V: SVR4 argument to print version ID. */
933 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
934 should be emitted or not. FIXME: Not implemented. */
938 /* Solaris takes -s to specify that .stabs go in a .stabs section,
939 rather than .stabs.excl, which is ignored by the linker.
940 FIXME: Not implemented. */
956 md_show_usage (stream
)
962 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
963 -mpwr generate code for IBM POWER (RIOS1)\n\
964 -m601 generate code for Motorola PowerPC 601\n\
965 -mppc, -mppc32, -m403, -m603, -m604\n\
966 generate code for Motorola PowerPC 603/604\n\
967 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
968 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
969 -mcom generate code Power/PowerPC common instructions\n\
970 -many generate code for any architecture (PWR/PWRX/PPC)\n\
971 -mregnames Allow symbolic names for registers\n\
972 -mno-regnames Do not allow symbolic names for registers\n"));
975 -mrelocatable support for GCC's -mrelocatble option\n\
976 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
977 -memb set PPC_EMB bit in ELF flags\n\
978 -mlittle, -mlittle-endian\n\
979 generate code for a little endian machine\n\
980 -mbig, -mbig-endian generate code for a big endian machine\n\
981 -msolaris generate code for Solaris\n\
982 -mno-solaris do not generate code for Solaris\n\
983 -V print assembler version number\n\
984 -Qy, -Qn ignored\n"));
988 /* Set ppc_cpu if it is not already set. */
993 const char *default_os
= TARGET_OS
;
994 const char *default_cpu
= TARGET_CPU
;
998 if (strncmp (default_os
, "aix", 3) == 0
999 && default_os
[3] >= '4' && default_os
[3] <= '9')
1000 ppc_cpu
= PPC_OPCODE_COMMON
;
1001 else if (strncmp (default_os
, "aix3", 4) == 0)
1002 ppc_cpu
= PPC_OPCODE_POWER
;
1003 else if (strcmp (default_cpu
, "rs6000") == 0)
1004 ppc_cpu
= PPC_OPCODE_POWER
;
1005 else if (strcmp (default_cpu
, "powerpc") == 0
1006 || strcmp (default_cpu
, "powerpcle") == 0)
1007 ppc_cpu
= PPC_OPCODE_PPC
;
1009 as_fatal (_("Unknown default cpu = %s, os = %s"), default_cpu
, default_os
);
1013 /* Figure out the BFD architecture to use. */
1015 enum bfd_architecture
1018 const char *default_cpu
= TARGET_CPU
;
1021 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1022 return bfd_arch_powerpc
;
1023 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1024 return bfd_arch_rs6000
;
1025 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1027 if (strcmp (default_cpu
, "rs6000") == 0)
1028 return bfd_arch_rs6000
;
1029 else if (strcmp (default_cpu
, "powerpc") == 0
1030 || strcmp (default_cpu
, "powerpcle") == 0)
1031 return bfd_arch_powerpc
;
1034 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1035 return bfd_arch_unknown
;
1041 return (ppc_size
== PPC_OPCODE_64
) ? 620 : 0;
1047 return (ppc_xcoff64
) ? 3 : 2;
1055 return (target_big_endian
? "pe-powerpc" : "pe-powerpcle");
1058 return (ppc_xcoff64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1061 return "xcoff-powermac";
1065 return (target_big_endian
? "elf32-powerpc" : "elf32-powerpcle");
1069 /* This function is called when the assembler starts up. It is called
1070 after the options have been parsed and the output file has been
1076 register const struct powerpc_opcode
*op
;
1077 const struct powerpc_opcode
*op_end
;
1078 const struct powerpc_macro
*macro
;
1079 const struct powerpc_macro
*macro_end
;
1080 boolean dup_insn
= false;
1085 /* Set the ELF flags if desired. */
1086 if (ppc_flags
&& !msolaris
)
1087 bfd_set_private_flags (stdoutput
, ppc_flags
);
1090 /* Insert the opcodes into a hash table. */
1091 ppc_hash
= hash_new ();
1093 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1094 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1096 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1098 if ((op
->flags
& ppc_cpu
) != 0
1099 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1100 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
1101 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0))
1105 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1106 if (retval
!= (const char *) NULL
)
1108 /* Ignore Power duplicates for -m601 */
1109 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1110 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1113 as_bad (_("Internal assembler error for instruction %s"), op
->name
);
1119 /* Insert the macros into a hash table. */
1120 ppc_macro_hash
= hash_new ();
1122 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1123 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1125 if ((macro
->flags
& ppc_cpu
) != 0)
1129 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1130 if (retval
!= (const char *) NULL
)
1132 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1141 /* Tell the main code what the endianness is if it is not overidden by the user. */
1142 if (!set_target_endian
)
1144 set_target_endian
= 1;
1145 target_big_endian
= PPC_BIG_ENDIAN
;
1149 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1151 /* Create dummy symbols to serve as initial csects. This forces the
1152 text csects to precede the data csects. These symbols will not
1154 ppc_text_csects
= symbol_make ("dummy\001");
1155 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1156 ppc_data_csects
= symbol_make ("dummy\001");
1157 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1162 ppc_current_section
= text_section
;
1163 ppc_previous_section
= 0;
1168 /* Insert an operand value into an instruction. */
1170 static unsigned long
1171 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1173 const struct powerpc_operand
*operand
;
1178 if (operand
->bits
!= 32)
1183 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1185 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1186 max
= (1 << operand
->bits
) - 1;
1188 max
= (1 << (operand
->bits
- 1)) - 1;
1189 min
= - (1 << (operand
->bits
- 1));
1191 if (ppc_size
== PPC_OPCODE_32
)
1193 /* Some people write 32 bit hex constants with the sign
1194 extension done by hand. This shouldn't really be
1195 valid, but, to permit this code to assemble on a 64
1196 bit host, we sign extend the 32 bit value. */
1198 && (val
& (offsetT
) 0x80000000) != 0
1199 && (val
& (offsetT
) 0xffffffff) == val
)
1208 max
= (1 << operand
->bits
) - 1;
1212 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1217 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1220 _("operand out of range (%s not between %ld and %ld)");
1223 sprint_value (buf
, test
);
1224 if (file
== (char *) NULL
)
1225 as_bad (err
, buf
, min
, max
);
1227 as_bad_where (file
, line
, err
, buf
, min
, max
);
1231 if (operand
->insert
)
1236 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1237 if (errmsg
!= (const char *) NULL
)
1241 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1249 /* Parse @got, etc. and return the desired relocation. */
1250 static bfd_reloc_code_real_type
1251 ppc_elf_suffix (str_p
, exp_p
)
1258 bfd_reloc_code_real_type reloc
;
1266 struct map_bfd
*ptr
;
1268 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1270 static struct map_bfd mapping
[] = {
1271 MAP ("l", BFD_RELOC_LO16
),
1272 MAP ("h", BFD_RELOC_HI16
),
1273 MAP ("ha", BFD_RELOC_HI16_S
),
1274 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1275 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1276 MAP ("got", BFD_RELOC_16_GOTOFF
),
1277 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1278 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1279 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1280 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1281 MAP ("plt", BFD_RELOC_24_PLT_PCREL
),
1282 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1283 MAP ("copy", BFD_RELOC_PPC_COPY
),
1284 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1285 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1286 MAP ("local", BFD_RELOC_PPC_LOCAL24PC
),
1287 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1288 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1289 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1290 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1291 MAP ("sdarel", BFD_RELOC_GPREL16
),
1292 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1293 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1294 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1295 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1296 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1297 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1298 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1299 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1300 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1301 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1302 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1303 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1304 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1305 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1306 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1307 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1308 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1309 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1310 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1311 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1312 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1314 { (char *)0, 0, BFD_RELOC_UNUSED
}
1318 return BFD_RELOC_UNUSED
;
1320 for (ch
= *str
, str2
= ident
;
1321 (str2
< ident
+ sizeof (ident
) - 1
1322 && (isalnum (ch
) || ch
== '@'));
1325 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1332 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1333 if (ch
== ptr
->string
[0]
1334 && len
== ptr
->length
1335 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1337 if (exp_p
->X_add_number
!= 0
1338 && (ptr
->reloc
== BFD_RELOC_16_GOTOFF
1339 || ptr
->reloc
== BFD_RELOC_LO16_GOTOFF
1340 || ptr
->reloc
== BFD_RELOC_HI16_GOTOFF
1341 || ptr
->reloc
== BFD_RELOC_HI16_S_GOTOFF
))
1342 as_warn (_("identifier+constant@got means identifier@got+constant"));
1344 /* Now check for identifier@suffix+constant */
1345 if (*str
== '-' || *str
== '+')
1347 char *orig_line
= input_line_pointer
;
1348 expressionS new_exp
;
1350 input_line_pointer
= str
;
1351 expression (&new_exp
);
1352 if (new_exp
.X_op
== O_constant
)
1354 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1355 str
= input_line_pointer
;
1358 if (&input_line_pointer
!= str_p
)
1359 input_line_pointer
= orig_line
;
1366 return BFD_RELOC_UNUSED
;
1369 /* Like normal .long/.short/.word, except support @got, etc. */
1370 /* clobbers input_line_pointer, checks */
1373 ppc_elf_cons (nbytes
)
1374 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1377 bfd_reloc_code_real_type reloc
;
1379 if (is_it_end_of_statement ())
1381 demand_empty_rest_of_line ();
1388 if (exp
.X_op
== O_symbol
1389 && *input_line_pointer
== '@'
1390 && (reloc
= ppc_elf_suffix (&input_line_pointer
, &exp
)) != BFD_RELOC_UNUSED
)
1392 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1393 int size
= bfd_get_reloc_size (reloc_howto
);
1396 as_bad (_("%s relocations do not fit in %d bytes\n"), reloc_howto
->name
, nbytes
);
1400 register char *p
= frag_more ((int) nbytes
);
1401 int offset
= nbytes
- size
;
1403 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1407 emit_expr (&exp
, (unsigned int) nbytes
);
1409 while (*input_line_pointer
++ == ',');
1411 input_line_pointer
--; /* Put terminator back into stream. */
1412 demand_empty_rest_of_line ();
1415 /* Solaris pseduo op to change to the .rodata section. */
1420 char *save_line
= input_line_pointer
;
1421 static char section
[] = ".rodata\n";
1423 /* Just pretend this is .section .rodata */
1424 input_line_pointer
= section
;
1425 obj_elf_section (xxx
);
1427 input_line_pointer
= save_line
;
1430 /* Pseudo op to make file scope bss items */
1433 int xxx ATTRIBUTE_UNUSED
;
1435 register char *name
;
1439 register symbolS
*symbolP
;
1446 name
= input_line_pointer
;
1447 c
= get_symbol_end ();
1449 /* just after name is now '\0' */
1450 p
= input_line_pointer
;
1453 if (*input_line_pointer
!= ',')
1455 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1456 ignore_rest_of_line ();
1460 input_line_pointer
++; /* skip ',' */
1461 if ((size
= get_absolute_expression ()) < 0)
1463 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1464 ignore_rest_of_line ();
1468 /* The third argument to .lcomm is the alignment. */
1469 if (*input_line_pointer
!= ',')
1473 ++input_line_pointer
;
1474 align
= get_absolute_expression ();
1477 as_warn (_("ignoring bad alignment"));
1483 symbolP
= symbol_find_or_make (name
);
1486 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1488 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1489 S_GET_NAME (symbolP
));
1490 ignore_rest_of_line ();
1494 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1496 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1497 S_GET_NAME (symbolP
),
1498 (long) S_GET_VALUE (symbolP
),
1501 ignore_rest_of_line ();
1507 old_subsec
= now_subseg
;
1510 /* convert to a power of 2 alignment */
1511 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1514 as_bad (_("Common alignment not a power of 2"));
1515 ignore_rest_of_line ();
1522 record_alignment (bss_section
, align2
);
1523 subseg_set (bss_section
, 0);
1525 frag_align (align2
, 0, 0);
1526 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1527 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1528 symbol_set_frag (symbolP
, frag_now
);
1529 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1532 S_SET_SIZE (symbolP
, size
);
1533 S_SET_SEGMENT (symbolP
, bss_section
);
1534 subseg_set (old_sec
, old_subsec
);
1535 demand_empty_rest_of_line ();
1538 /* Validate any relocations emitted for -mrelocatable, possibly adding
1539 fixups for word relocations in writable segments, so we can adjust
1542 ppc_elf_validate_fix (fixp
, seg
)
1546 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1555 case SHILB_MRELOCATABLE
:
1556 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1557 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1558 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1559 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1560 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1561 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1562 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1563 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1564 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1565 && strcmp (segment_name (seg
), ".got2") != 0
1566 && strcmp (segment_name (seg
), ".dtors") != 0
1567 && strcmp (segment_name (seg
), ".ctors") != 0
1568 && strcmp (segment_name (seg
), ".fixup") != 0
1569 && strcmp (segment_name (seg
), ".stab") != 0
1570 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1571 && strcmp (segment_name (seg
), ".eh_frame") != 0
1572 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1574 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1575 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1577 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1578 _("Relocation cannot be done when using -mrelocatable"));
1584 #endif /* OBJ_ELF */
1589 * Summary of parse_toc_entry().
1591 * in: Input_line_pointer points to the '[' in one of:
1593 * [toc] [tocv] [toc32] [toc64]
1595 * Anything else is an error of one kind or another.
1598 * return value: success or failure
1599 * toc_kind: kind of toc reference
1600 * input_line_pointer:
1601 * success: first char after the ']'
1602 * failure: unchanged
1606 * [toc] - rv == success, toc_kind = default_toc
1607 * [tocv] - rv == success, toc_kind = data_in_toc
1608 * [toc32] - rv == success, toc_kind = must_be_32
1609 * [toc64] - rv == success, toc_kind = must_be_64
1613 enum toc_size_qualifier
1615 default_toc
, /* The toc cell constructed should be the system default size */
1616 data_in_toc
, /* This is a direct reference to a toc cell */
1617 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1618 must_be_64
/* The toc cell constructed must be 64 bits wide */
1622 parse_toc_entry(toc_kind
)
1623 enum toc_size_qualifier
*toc_kind
;
1628 enum toc_size_qualifier t
;
1630 /* save the input_line_pointer */
1631 start
= input_line_pointer
;
1633 /* skip over the '[' , and whitespace */
1634 ++input_line_pointer
;
1637 /* find the spelling of the operand */
1638 toc_spec
= input_line_pointer
;
1639 c
= get_symbol_end ();
1641 if (strcmp(toc_spec
, "toc") == 0)
1645 else if (strcmp(toc_spec
, "tocv") == 0)
1649 else if (strcmp(toc_spec
, "toc32") == 0)
1653 else if (strcmp(toc_spec
, "toc64") == 0)
1659 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1660 *input_line_pointer
= c
; /* put back the delimiting char */
1661 input_line_pointer
= start
; /* reset input_line pointer */
1665 /* now find the ']' */
1666 *input_line_pointer
= c
; /* put back the delimiting char */
1668 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1669 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1673 as_bad (_("syntax error: expected `]', found `%c'"), c
);
1674 input_line_pointer
= start
; /* reset input_line pointer */
1678 *toc_kind
= t
; /* set return value */
1684 /* We need to keep a list of fixups. We can't simply generate them as
1685 we go, because that would require us to first create the frag, and
1686 that would screw up references to ``.''. */
1692 bfd_reloc_code_real_type reloc
;
1695 #define MAX_INSN_FIXUPS (5)
1697 /* This routine is called for each instruction to be assembled. */
1704 const struct powerpc_opcode
*opcode
;
1706 const unsigned char *opindex_ptr
;
1710 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1715 bfd_reloc_code_real_type reloc
;
1718 /* Get the opcode. */
1719 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1724 /* Look up the opcode in the hash table. */
1725 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1726 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1728 const struct powerpc_macro
*macro
;
1730 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1731 if (macro
== (const struct powerpc_macro
*) NULL
)
1732 as_bad (_("Unrecognized opcode: `%s'"), str
);
1734 ppc_macro (s
, macro
);
1739 insn
= opcode
->opcode
;
1742 while (isspace (*str
))
1745 /* PowerPC operands are just expressions. The only real issue is
1746 that a few operand types are optional. All cases which might use
1747 an optional operand separate the operands only with commas (in
1748 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1749 cases never have optional operands). There is never more than
1750 one optional operand for an instruction. So, before we start
1751 seriously parsing the operands, we check to see if we have an
1752 optional operand, and, if we do, we count the number of commas to
1753 see whether the operand should be omitted. */
1755 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1757 const struct powerpc_operand
*operand
;
1759 operand
= &powerpc_operands
[*opindex_ptr
];
1760 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1762 unsigned int opcount
;
1764 /* There is an optional operand. Count the number of
1765 commas in the input line. */
1772 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1779 /* If there are fewer operands in the line then are called
1780 for by the instruction, we want to skip the optional
1782 if (opcount
< strlen (opcode
->operands
))
1789 /* Gather the operands. */
1793 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1795 const struct powerpc_operand
*operand
;
1801 if (next_opindex
== 0)
1802 operand
= &powerpc_operands
[*opindex_ptr
];
1805 operand
= &powerpc_operands
[next_opindex
];
1811 /* If this is a fake operand, then we do not expect anything
1813 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1815 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1816 if (errmsg
!= (const char *) NULL
)
1821 /* If this is an optional operand, and we are skipping it, just
1823 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1826 if (operand
->insert
)
1828 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1829 if (errmsg
!= (const char *) NULL
)
1832 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1833 next_opindex
= *opindex_ptr
+ 1;
1837 /* Gather the operand. */
1838 hold
= input_line_pointer
;
1839 input_line_pointer
= str
;
1842 if (*input_line_pointer
== '[')
1844 /* We are expecting something like the second argument here:
1846 lwz r4,[toc].GS.0.static_int(rtoc)
1847 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1848 The argument following the `]' must be a symbol name, and the
1849 register must be the toc register: 'rtoc' or '2'
1851 The effect is to 0 as the displacement field
1852 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1853 the appropriate variation) reloc against it based on the symbol.
1854 The linker will build the toc, and insert the resolved toc offset.
1857 o The size of the toc entry is currently assumed to be
1858 32 bits. This should not be assumed to be a hard coded
1860 o In an effort to cope with a change from 32 to 64 bits,
1861 there are also toc entries that are specified to be
1862 either 32 or 64 bits:
1863 lwz r4,[toc32].GS.0.static_int(rtoc)
1864 lwz r4,[toc64].GS.0.static_int(rtoc)
1865 These demand toc entries of the specified size, and the
1866 instruction probably requires it.
1870 enum toc_size_qualifier toc_kind
;
1871 bfd_reloc_code_real_type toc_reloc
;
1873 /* go parse off the [tocXX] part */
1874 valid_toc
= parse_toc_entry(&toc_kind
);
1878 /* Note: message has already been issued. */
1879 /* FIXME: what sort of recovery should we do? */
1880 /* demand_rest_of_line(); return; ? */
1883 /* Now get the symbol following the ']' */
1889 /* In this case, we may not have seen the symbol yet, since */
1890 /* it is allowed to appear on a .extern or .globl or just be */
1891 /* a label in the .data section. */
1892 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1895 /* 1. The symbol must be defined and either in the toc */
1896 /* section, or a global. */
1897 /* 2. The reloc generated must have the TOCDEFN flag set in */
1898 /* upper bit mess of the reloc type. */
1899 /* FIXME: It's a little confusing what the tocv qualifier can */
1900 /* be used for. At the very least, I've seen three */
1901 /* uses, only one of which I'm sure I can explain. */
1902 if (ex
.X_op
== O_symbol
)
1904 assert (ex
.X_add_symbol
!= NULL
);
1905 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
1908 as_bad(_("[tocv] symbol is not a toc symbol"));
1912 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1915 /* FIXME: these next two specifically specify 32/64 bit toc */
1916 /* entries. We don't support them today. Is this the */
1917 /* right way to say that? */
1918 toc_reloc
= BFD_RELOC_UNUSED
;
1919 as_bad (_("Unimplemented toc32 expression modifier"));
1922 /* FIXME: see above */
1923 toc_reloc
= BFD_RELOC_UNUSED
;
1924 as_bad (_("Unimplemented toc64 expression modifier"));
1928 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1934 /* We need to generate a fixup for this expression. */
1935 if (fc
>= MAX_INSN_FIXUPS
)
1936 as_fatal (_("too many fixups"));
1938 fixups
[fc
].reloc
= toc_reloc
;
1939 fixups
[fc
].exp
= ex
;
1940 fixups
[fc
].opindex
= *opindex_ptr
;
1943 /* Ok. We've set up the fixup for the instruction. Now make it
1944 look like the constant 0 was found here */
1946 ex
.X_op
= O_constant
;
1947 ex
.X_add_number
= 0;
1948 ex
.X_add_symbol
= NULL
;
1949 ex
.X_op_symbol
= NULL
;
1955 if (! register_name (&ex
))
1957 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1964 str
= input_line_pointer
;
1965 input_line_pointer
= hold
;
1967 if (ex
.X_op
== O_illegal
)
1968 as_bad (_("illegal operand"));
1969 else if (ex
.X_op
== O_absent
)
1970 as_bad (_("missing operand"));
1971 else if (ex
.X_op
== O_register
)
1973 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1976 else if (ex
.X_op
== O_constant
)
1979 /* Allow @HA, @L, @H on constants. */
1980 char *orig_str
= str
;
1982 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1989 case BFD_RELOC_LO16
:
1990 /* X_unsigned is the default, so if the user has done
1991 something which cleared it, we always produce a
1994 && (operand
->flags
& PPC_OPERAND_SIGNED
) == 0)
1995 ex
.X_add_number
&= 0xffff;
1997 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
2002 case BFD_RELOC_HI16
:
2003 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
2006 case BFD_RELOC_HI16_S
:
2007 ex
.X_add_number
= ((((ex
.X_add_number
>> 16) & 0xffff)
2008 + ((ex
.X_add_number
>> 15) & 1))
2013 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2017 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2019 /* For the absoulte forms of branchs, convert the PC relative form back into
2021 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2025 case BFD_RELOC_PPC_B26
:
2026 reloc
= BFD_RELOC_PPC_BA26
;
2028 case BFD_RELOC_PPC_B16
:
2029 reloc
= BFD_RELOC_PPC_BA16
;
2031 case BFD_RELOC_PPC_B16_BRTAKEN
:
2032 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2034 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2035 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2042 /* We need to generate a fixup for this expression. */
2043 if (fc
>= MAX_INSN_FIXUPS
)
2044 as_fatal (_("too many fixups"));
2045 fixups
[fc
].exp
= ex
;
2046 fixups
[fc
].opindex
= 0;
2047 fixups
[fc
].reloc
= reloc
;
2050 #endif /* OBJ_ELF */
2054 /* We need to generate a fixup for this expression. */
2055 if (fc
>= MAX_INSN_FIXUPS
)
2056 as_fatal (_("too many fixups"));
2057 fixups
[fc
].exp
= ex
;
2058 fixups
[fc
].opindex
= *opindex_ptr
;
2059 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2068 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2076 /* The call to expression should have advanced str past any
2079 && (endc
!= ',' || *str
!= '\0'))
2081 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2089 while (isspace (*str
))
2093 as_bad (_("junk at end of line: `%s'"), str
);
2095 /* Write out the instruction. */
2097 md_number_to_chars (f
, insn
, 4);
2099 /* Create any fixups. At this point we do not use a
2100 bfd_reloc_code_real_type, but instead just use the
2101 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2102 handle fixups for any operand type, although that is admittedly
2103 not a very exciting feature. We pick a BFD reloc type in
2105 for (i
= 0; i
< fc
; i
++)
2107 const struct powerpc_operand
*operand
;
2109 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2110 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2112 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2120 size
= bfd_get_reloc_size (reloc_howto
);
2121 offset
= target_big_endian
? (4 - size
) : 0;
2123 if (size
< 1 || size
> 4)
2126 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
2127 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
2130 /* Turn off complaints that the addend is too large for things like
2132 switch (fixups
[i
].reloc
)
2134 case BFD_RELOC_16_GOTOFF
:
2135 case BFD_RELOC_PPC_TOC16
:
2136 case BFD_RELOC_LO16
:
2137 case BFD_RELOC_HI16
:
2138 case BFD_RELOC_HI16_S
:
2139 fixP
->fx_no_overflow
= 1;
2146 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
2148 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2149 ((bfd_reloc_code_real_type
)
2150 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2154 /* Handle a macro. Gather all the operands, transform them as
2155 described by the macro, and call md_assemble recursively. All the
2156 operands are separated by commas; we don't accept parentheses
2157 around operands here. */
2160 ppc_macro (str
, macro
)
2162 const struct powerpc_macro
*macro
;
2173 /* Gather the users operands into the operands array. */
2178 if (count
>= sizeof operands
/ sizeof operands
[0])
2180 operands
[count
++] = s
;
2181 s
= strchr (s
, ',');
2182 if (s
== (char *) NULL
)
2187 if (count
!= macro
->operands
)
2189 as_bad (_("wrong number of operands"));
2193 /* Work out how large the string must be (the size is unbounded
2194 because it includes user input). */
2196 format
= macro
->format
;
2197 while (*format
!= '\0')
2206 arg
= strtol (format
+ 1, &send
, 10);
2207 know (send
!= format
&& arg
>= 0 && arg
< count
);
2208 len
+= strlen (operands
[arg
]);
2213 /* Put the string together. */
2214 complete
= s
= (char *) alloca (len
+ 1);
2215 format
= macro
->format
;
2216 while (*format
!= '\0')
2222 arg
= strtol (format
+ 1, &send
, 10);
2223 strcpy (s
, operands
[arg
]);
2230 /* Assemble the constructed instruction. */
2231 md_assemble (complete
);
2235 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2238 ppc_section_letter (letter
, ptr_msg
)
2245 *ptr_msg
= _("Bad .section directive: want a,w,x,e in string");
2250 ppc_section_word (str
, len
)
2254 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2261 ppc_section_type (str
, len
)
2265 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2272 ppc_section_flags (flags
, attr
, type
)
2277 if (type
== SHT_ORDERED
)
2278 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2280 if (attr
& SHF_EXCLUDE
)
2281 flags
|= SEC_EXCLUDE
;
2285 #endif /* OBJ_ELF */
2288 /* Pseudo-op handling. */
2290 /* The .byte pseudo-op. This is similar to the normal .byte
2291 pseudo-op, but it can also take a single ASCII string. */
2295 int ignore ATTRIBUTE_UNUSED
;
2297 if (*input_line_pointer
!= '\"')
2303 /* Gather characters. A real double quote is doubled. Unusual
2304 characters are not permitted. */
2305 ++input_line_pointer
;
2310 c
= *input_line_pointer
++;
2314 if (*input_line_pointer
!= '\"')
2316 ++input_line_pointer
;
2319 FRAG_APPEND_1_CHAR (c
);
2322 demand_empty_rest_of_line ();
2327 /* XCOFF specific pseudo-op handling. */
2329 /* This is set if we are creating a .stabx symbol, since we don't want
2330 to handle symbol suffixes for such symbols. */
2331 static boolean ppc_stab_symbol
;
2333 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2334 symbols in the .bss segment as though they were local common
2335 symbols, and uses a different smclas. */
2341 asection
*current_seg
= now_seg
;
2342 subsegT current_subseg
= now_subseg
;
2348 symbolS
*lcomm_sym
= NULL
;
2352 name
= input_line_pointer
;
2353 endc
= get_symbol_end ();
2354 end_name
= input_line_pointer
;
2357 if (*input_line_pointer
!= ',')
2359 as_bad (_("missing size"));
2360 ignore_rest_of_line ();
2363 ++input_line_pointer
;
2365 size
= get_absolute_expression ();
2368 as_bad (_("negative size"));
2369 ignore_rest_of_line ();
2375 /* The third argument to .comm is the alignment. */
2376 if (*input_line_pointer
!= ',')
2380 ++input_line_pointer
;
2381 align
= get_absolute_expression ();
2384 as_warn (_("ignoring bad alignment"));
2403 /* The third argument to .lcomm appears to be the real local
2404 common symbol to create. References to the symbol named in
2405 the first argument are turned into references to the third
2407 if (*input_line_pointer
!= ',')
2409 as_bad (_("missing real symbol name"));
2410 ignore_rest_of_line ();
2413 ++input_line_pointer
;
2415 lcomm_name
= input_line_pointer
;
2416 lcomm_endc
= get_symbol_end ();
2418 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2420 *input_line_pointer
= lcomm_endc
;
2424 sym
= symbol_find_or_make (name
);
2427 if (S_IS_DEFINED (sym
)
2428 || S_GET_VALUE (sym
) != 0)
2430 as_bad (_("attempt to redefine symbol"));
2431 ignore_rest_of_line ();
2435 record_alignment (bss_section
, align
);
2438 || ! S_IS_DEFINED (lcomm_sym
))
2447 S_SET_EXTERNAL (sym
);
2451 symbol_get_tc (lcomm_sym
)->output
= 1;
2452 def_sym
= lcomm_sym
;
2456 subseg_set (bss_section
, 1);
2457 frag_align (align
, 0, 0);
2459 symbol_set_frag (def_sym
, frag_now
);
2460 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2461 def_size
, (char *) NULL
);
2463 S_SET_SEGMENT (def_sym
, bss_section
);
2464 symbol_get_tc (def_sym
)->align
= align
;
2468 /* Align the size of lcomm_sym. */
2469 symbol_get_frag (lcomm_sym
)->fr_offset
=
2470 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
2471 &~ ((1 << align
) - 1));
2472 if (align
> symbol_get_tc (lcomm_sym
)->align
)
2473 symbol_get_tc (lcomm_sym
)->align
= align
;
2478 /* Make sym an offset from lcomm_sym. */
2479 S_SET_SEGMENT (sym
, bss_section
);
2480 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
2481 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
2482 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
2485 subseg_set (current_seg
, current_subseg
);
2487 demand_empty_rest_of_line ();
2490 /* The .csect pseudo-op. This switches us into a different
2491 subsegment. The first argument is a symbol whose value is the
2492 start of the .csect. In COFF, csect symbols get special aux
2493 entries defined by the x_csect field of union internal_auxent. The
2494 optional second argument is the alignment (the default is 2). */
2504 name
= input_line_pointer
;
2505 endc
= get_symbol_end ();
2507 sym
= symbol_find_or_make (name
);
2509 *input_line_pointer
= endc
;
2511 if (S_GET_NAME (sym
)[0] == '\0')
2513 /* An unnamed csect is assumed to be [PR]. */
2514 symbol_get_tc (sym
)->class = XMC_PR
;
2517 ppc_change_csect (sym
);
2519 if (*input_line_pointer
== ',')
2521 ++input_line_pointer
;
2522 symbol_get_tc (sym
)->align
= get_absolute_expression ();
2525 demand_empty_rest_of_line ();
2528 /* Change to a different csect. */
2531 ppc_change_csect (sym
)
2534 if (S_IS_DEFINED (sym
))
2535 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
2543 /* This is a new csect. We need to look at the symbol class to
2544 figure out whether it should go in the text section or the
2547 switch (symbol_get_tc (sym
)->class)
2557 S_SET_SEGMENT (sym
, text_section
);
2558 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
2559 ++ppc_text_subsegment
;
2560 list_ptr
= &ppc_text_csects
;
2569 if (ppc_toc_csect
!= NULL
2570 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
2571 == ppc_data_subsegment
))
2573 S_SET_SEGMENT (sym
, data_section
);
2574 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
2575 ++ppc_data_subsegment
;
2576 list_ptr
= &ppc_data_csects
;
2582 /* We set the obstack chunk size to a small value before
2583 changing subsegments, so that we don't use a lot of memory
2584 space for what may be a small section. */
2585 hold_chunksize
= chunksize
;
2588 subseg_new (segment_name (S_GET_SEGMENT (sym
)),
2589 symbol_get_tc (sym
)->subseg
);
2591 chunksize
= hold_chunksize
;
2594 ppc_after_toc_frag
= frag_now
;
2596 symbol_set_frag (sym
, frag_now
);
2597 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2599 symbol_get_tc (sym
)->align
= (ppc_xcoff64
) ? 3 : 2;
2600 symbol_get_tc (sym
)->output
= 1;
2601 symbol_get_tc (sym
)->within
= sym
;
2603 for (list
= *list_ptr
;
2604 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
2605 list
= symbol_get_tc (list
)->next
)
2607 symbol_get_tc (list
)->next
= sym
;
2609 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2610 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
2614 ppc_current_csect
= sym
;
2617 /* This function handles the .text and .data pseudo-ops. These
2618 pseudo-ops aren't really used by XCOFF; we implement them for the
2619 convenience of people who aren't used to XCOFF. */
2630 else if (type
== 'd')
2635 sym
= symbol_find_or_make (name
);
2637 ppc_change_csect (sym
);
2639 demand_empty_rest_of_line ();
2642 /* This function handles the .section pseudo-op. This is mostly to
2643 give an error, since XCOFF only supports .text, .data and .bss, but
2644 we do permit the user to name the text or data section. */
2647 ppc_named_section (ignore
)
2651 const char *real_name
;
2655 user_name
= input_line_pointer
;
2656 c
= get_symbol_end ();
2658 if (strcmp (user_name
, ".text") == 0)
2659 real_name
= ".text[PR]";
2660 else if (strcmp (user_name
, ".data") == 0)
2661 real_name
= ".data[RW]";
2664 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2665 *input_line_pointer
= c
;
2666 ignore_rest_of_line ();
2670 *input_line_pointer
= c
;
2672 sym
= symbol_find_or_make (real_name
);
2674 ppc_change_csect (sym
);
2676 demand_empty_rest_of_line ();
2679 /* The .extern pseudo-op. We create an undefined symbol. */
2688 name
= input_line_pointer
;
2689 endc
= get_symbol_end ();
2691 (void) symbol_find_or_make (name
);
2693 *input_line_pointer
= endc
;
2695 demand_empty_rest_of_line ();
2698 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2708 name
= input_line_pointer
;
2709 endc
= get_symbol_end ();
2711 sym
= symbol_find_or_make (name
);
2713 *input_line_pointer
= endc
;
2715 symbol_get_tc (sym
)->output
= 1;
2717 demand_empty_rest_of_line ();
2720 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2721 although I don't know why it bothers. */
2732 name
= input_line_pointer
;
2733 endc
= get_symbol_end ();
2735 sym
= symbol_find_or_make (name
);
2737 *input_line_pointer
= endc
;
2739 if (*input_line_pointer
!= ',')
2741 as_bad (_("missing rename string"));
2742 ignore_rest_of_line ();
2745 ++input_line_pointer
;
2747 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
2749 demand_empty_rest_of_line ();
2752 /* The .stabx pseudo-op. This is similar to a normal .stabs
2753 pseudo-op, but slightly different. A sample is
2754 .stabx "main:F-1",.main,142,0
2755 The first argument is the symbol name to create. The second is the
2756 value, and the third is the storage class. The fourth seems to be
2757 always zero, and I am assuming it is the type. */
2768 name
= demand_copy_C_string (&len
);
2770 if (*input_line_pointer
!= ',')
2772 as_bad (_("missing value"));
2775 ++input_line_pointer
;
2777 ppc_stab_symbol
= true;
2778 sym
= symbol_make (name
);
2779 ppc_stab_symbol
= false;
2781 symbol_get_tc (sym
)->real_name
= name
;
2783 (void) expression (&exp
);
2790 as_bad (_("illegal .stabx expression; zero assumed"));
2791 exp
.X_add_number
= 0;
2794 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2795 symbol_set_frag (sym
, &zero_address_frag
);
2799 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2800 symbol_set_value_expression (sym
, &exp
);
2804 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2805 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
2810 /* The value is some complex expression. This will probably
2811 fail at some later point, but this is probably the right
2812 thing to do here. */
2813 symbol_set_value_expression (sym
, &exp
);
2817 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2818 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
2820 if (*input_line_pointer
!= ',')
2822 as_bad (_("missing class"));
2825 ++input_line_pointer
;
2827 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2829 if (*input_line_pointer
!= ',')
2831 as_bad (_("missing type"));
2834 ++input_line_pointer
;
2836 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2838 symbol_get_tc (sym
)->output
= 1;
2840 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2841 symbol_get_tc (sym
)->within
= ppc_current_block
;
2843 if (exp
.X_op
!= O_symbol
2844 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2845 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2846 ppc_frob_label (sym
);
2849 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2850 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2851 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
2852 symbol_get_tc (ppc_current_csect
)->within
= sym
;
2855 demand_empty_rest_of_line ();
2858 /* The .function pseudo-op. This takes several arguments. The first
2859 argument seems to be the external name of the symbol. The second
2860 argment seems to be the label for the start of the function. gcc
2861 uses the same name for both. I have no idea what the third and
2862 fourth arguments are meant to be. The optional fifth argument is
2863 an expression for the size of the function. In COFF this symbol
2864 gets an aux entry like that used for a csect. */
2867 ppc_function (ignore
)
2876 name
= input_line_pointer
;
2877 endc
= get_symbol_end ();
2879 /* Ignore any [PR] suffix. */
2880 name
= ppc_canonicalize_symbol_name (name
);
2881 s
= strchr (name
, '[');
2882 if (s
!= (char *) NULL
2883 && strcmp (s
+ 1, "PR]") == 0)
2886 ext_sym
= symbol_find_or_make (name
);
2888 *input_line_pointer
= endc
;
2890 if (*input_line_pointer
!= ',')
2892 as_bad (_("missing symbol name"));
2893 ignore_rest_of_line ();
2896 ++input_line_pointer
;
2898 name
= input_line_pointer
;
2899 endc
= get_symbol_end ();
2901 lab_sym
= symbol_find_or_make (name
);
2903 *input_line_pointer
= endc
;
2905 if (ext_sym
!= lab_sym
)
2909 exp
.X_op
= O_symbol
;
2910 exp
.X_add_symbol
= lab_sym
;
2911 exp
.X_op_symbol
= NULL
;
2912 exp
.X_add_number
= 0;
2914 symbol_set_value_expression (ext_sym
, &exp
);
2917 if (symbol_get_tc (ext_sym
)->class == -1)
2918 symbol_get_tc (ext_sym
)->class = XMC_PR
;
2919 symbol_get_tc (ext_sym
)->output
= 1;
2921 if (*input_line_pointer
== ',')
2925 /* Ignore the third argument. */
2926 ++input_line_pointer
;
2927 expression (&ignore
);
2928 if (*input_line_pointer
== ',')
2930 /* Ignore the fourth argument. */
2931 ++input_line_pointer
;
2932 expression (&ignore
);
2933 if (*input_line_pointer
== ',')
2935 /* The fifth argument is the function size. */
2936 ++input_line_pointer
;
2937 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
2940 &zero_address_frag
);
2941 pseudo_set (symbol_get_tc (ext_sym
)->size
);
2946 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2947 SF_SET_FUNCTION (ext_sym
);
2948 SF_SET_PROCESS (ext_sym
);
2949 coff_add_linesym (ext_sym
);
2951 demand_empty_rest_of_line ();
2954 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2963 sym
= symbol_make (".bf");
2964 S_SET_SEGMENT (sym
, text_section
);
2965 symbol_set_frag (sym
, frag_now
);
2966 S_SET_VALUE (sym
, frag_now_fix ());
2967 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2969 coff_line_base
= get_absolute_expression ();
2971 S_SET_NUMBER_AUXILIARY (sym
, 1);
2972 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2974 symbol_get_tc (sym
)->output
= 1;
2976 ppc_frob_label (sym
);
2978 demand_empty_rest_of_line ();
2981 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2982 ".ef", except that the line number is absolute, not relative to the
2983 most recent ".bf" symbol. */
2991 sym
= symbol_make (".ef");
2992 S_SET_SEGMENT (sym
, text_section
);
2993 symbol_set_frag (sym
, frag_now
);
2994 S_SET_VALUE (sym
, frag_now_fix ());
2995 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2996 S_SET_NUMBER_AUXILIARY (sym
, 1);
2997 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2998 symbol_get_tc (sym
)->output
= 1;
3000 ppc_frob_label (sym
);
3002 demand_empty_rest_of_line ();
3005 /* The .bi and .ei pseudo-ops. These take a string argument and
3006 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3013 static symbolS
*last_biei
;
3020 name
= demand_copy_C_string (&len
);
3022 /* The value of these symbols is actually file offset. Here we set
3023 the value to the index into the line number entries. In
3024 ppc_frob_symbols we set the fix_line field, which will cause BFD
3025 to do the right thing. */
3027 sym
= symbol_make (name
);
3028 /* obj-coff.c currently only handles line numbers correctly in the
3030 S_SET_SEGMENT (sym
, text_section
);
3031 S_SET_VALUE (sym
, coff_n_line_nos
);
3032 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3034 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3035 symbol_get_tc (sym
)->output
= 1;
3037 for (look
= last_biei
? last_biei
: symbol_rootP
;
3038 (look
!= (symbolS
*) NULL
3039 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3040 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3041 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3042 look
= symbol_next (look
))
3044 if (look
!= (symbolS
*) NULL
)
3046 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3047 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3051 demand_empty_rest_of_line ();
3054 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3055 There is one argument, which is a csect symbol. The value of the
3056 .bs symbol is the index of this csect symbol. */
3067 if (ppc_current_block
!= NULL
)
3068 as_bad (_("nested .bs blocks"));
3070 name
= input_line_pointer
;
3071 endc
= get_symbol_end ();
3073 csect
= symbol_find_or_make (name
);
3075 *input_line_pointer
= endc
;
3077 sym
= symbol_make (".bs");
3078 S_SET_SEGMENT (sym
, now_seg
);
3079 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3080 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3081 symbol_get_tc (sym
)->output
= 1;
3083 symbol_get_tc (sym
)->within
= csect
;
3085 ppc_frob_label (sym
);
3087 ppc_current_block
= sym
;
3089 demand_empty_rest_of_line ();
3092 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3100 if (ppc_current_block
== NULL
)
3101 as_bad (_(".es without preceding .bs"));
3103 sym
= symbol_make (".es");
3104 S_SET_SEGMENT (sym
, now_seg
);
3105 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3106 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3107 symbol_get_tc (sym
)->output
= 1;
3109 ppc_frob_label (sym
);
3111 ppc_current_block
= NULL
;
3113 demand_empty_rest_of_line ();
3116 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3125 sym
= symbol_make (".bb");
3126 S_SET_SEGMENT (sym
, text_section
);
3127 symbol_set_frag (sym
, frag_now
);
3128 S_SET_VALUE (sym
, frag_now_fix ());
3129 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3131 S_SET_NUMBER_AUXILIARY (sym
, 1);
3132 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3134 symbol_get_tc (sym
)->output
= 1;
3136 SF_SET_PROCESS (sym
);
3138 ppc_frob_label (sym
);
3140 demand_empty_rest_of_line ();
3143 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3152 sym
= symbol_make (".eb");
3153 S_SET_SEGMENT (sym
, text_section
);
3154 symbol_set_frag (sym
, frag_now
);
3155 S_SET_VALUE (sym
, frag_now_fix ());
3156 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3157 S_SET_NUMBER_AUXILIARY (sym
, 1);
3158 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3159 symbol_get_tc (sym
)->output
= 1;
3161 SF_SET_PROCESS (sym
);
3163 ppc_frob_label (sym
);
3165 demand_empty_rest_of_line ();
3168 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3179 name
= demand_copy_C_string (&len
);
3180 sym
= symbol_make (name
);
3181 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3182 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3183 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3184 S_SET_VALUE (sym
, 0);
3185 symbol_get_tc (sym
)->output
= 1;
3187 ppc_frob_label (sym
);
3189 demand_empty_rest_of_line ();
3192 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3200 sym
= symbol_make (".ec");
3201 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3202 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3203 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3204 S_SET_VALUE (sym
, 0);
3205 symbol_get_tc (sym
)->output
= 1;
3207 ppc_frob_label (sym
);
3209 demand_empty_rest_of_line ();
3212 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3218 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3219 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3226 subseg
= ppc_data_subsegment
;
3227 ++ppc_data_subsegment
;
3229 subseg_new (segment_name (data_section
), subseg
);
3230 ppc_toc_frag
= frag_now
;
3232 sym
= symbol_find_or_make ("TOC[TC0]");
3233 symbol_set_frag (sym
, frag_now
);
3234 S_SET_SEGMENT (sym
, data_section
);
3235 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3236 symbol_get_tc (sym
)->subseg
= subseg
;
3237 symbol_get_tc (sym
)->output
= 1;
3238 symbol_get_tc (sym
)->within
= sym
;
3240 ppc_toc_csect
= sym
;
3242 for (list
= ppc_data_csects
;
3243 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3244 list
= symbol_get_tc (list
)->next
)
3246 symbol_get_tc (list
)->next
= sym
;
3248 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3249 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3253 ppc_current_csect
= ppc_toc_csect
;
3255 demand_empty_rest_of_line ();
3258 /* The AIX assembler automatically aligns the operands of a .long or
3259 .short pseudo-op, and we want to be compatible. */
3262 ppc_xcoff_cons (log_size
)
3265 frag_align (log_size
, 0, 0);
3266 record_alignment (now_seg
, log_size
);
3267 cons (1 << log_size
);
3274 discard_rest_of_line();
3275 /* What does aix use this for? */
3285 (void) expression (&exp
);
3287 if (exp
.X_op
!= O_constant
)
3289 as_bad (_("non-constant byte count"));
3293 byte_count
= exp
.X_add_number
;
3295 if (*input_line_pointer
!= ',')
3297 as_bad (_("missing value"));
3301 ++input_line_pointer
;
3305 #endif /* OBJ_XCOFF */
3307 /* The .tc pseudo-op. This is used when generating either XCOFF or
3308 ELF. This takes two or more arguments.
3310 When generating XCOFF output, the first argument is the name to
3311 give to this location in the toc; this will be a symbol with class
3312 TC. The rest of the arguments are 4 byte values to actually put at
3313 this location in the TOC; often there is just one more argument, a
3314 relocateable symbol reference.
3316 When not generating XCOFF output, the arguments are the same, but
3317 the first argument is simply ignored. */
3321 int ignore ATTRIBUTE_UNUSED
;
3325 /* Define the TOC symbol name. */
3331 if (ppc_toc_csect
== (symbolS
*) NULL
3332 || ppc_toc_csect
!= ppc_current_csect
)
3334 as_bad (_(".tc not in .toc section"));
3335 ignore_rest_of_line ();
3339 name
= input_line_pointer
;
3340 endc
= get_symbol_end ();
3342 sym
= symbol_find_or_make (name
);
3344 *input_line_pointer
= endc
;
3346 if (S_IS_DEFINED (sym
))
3350 label
= symbol_get_tc (ppc_current_csect
)->within
;
3351 if (symbol_get_tc (label
)->class != XMC_TC0
)
3353 as_bad (_(".tc with no label"));
3354 ignore_rest_of_line ();
3358 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3359 symbol_set_frag (label
, symbol_get_frag (sym
));
3360 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3362 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3363 ++input_line_pointer
;
3368 S_SET_SEGMENT (sym
, now_seg
);
3369 symbol_set_frag (sym
, frag_now
);
3370 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3371 symbol_get_tc (sym
)->class = XMC_TC
;
3372 symbol_get_tc (sym
)->output
= 1;
3374 ppc_frob_label (sym
);
3377 #else /* ! defined (OBJ_XCOFF) */
3379 /* Skip the TOC symbol name. */
3380 while (is_part_of_name (*input_line_pointer
)
3381 || *input_line_pointer
== '['
3382 || *input_line_pointer
== ']'
3383 || *input_line_pointer
== '{'
3384 || *input_line_pointer
== '}')
3385 ++input_line_pointer
;
3387 /* Align to a four byte boundary. */
3388 frag_align (2, 0, 0);
3389 record_alignment (now_seg
, 2);
3391 #endif /* ! defined (OBJ_XCOFF) */
3393 if (*input_line_pointer
!= ',')
3394 demand_empty_rest_of_line ();
3397 ++input_line_pointer
;
3398 cons ((ppc_size
== PPC_OPCODE_64
) ? 8 : 4);
3404 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3406 /* Set the current section. */
3408 ppc_set_current_section (new)
3411 ppc_previous_section
= ppc_current_section
;
3412 ppc_current_section
= new;
3415 /* pseudo-op: .previous
3416 behaviour: toggles the current section with the previous section.
3418 warnings: "No previous section"
3421 ppc_previous(ignore
)
3426 if (ppc_previous_section
== NULL
)
3428 as_warn(_("No previous section to return to. Directive ignored."));
3432 subseg_set(ppc_previous_section
, 0);
3434 ppc_set_current_section(ppc_previous_section
);
3437 /* pseudo-op: .pdata
3438 behaviour: predefined read only data section
3442 initial: .section .pdata "adr3"
3443 a - don't know -- maybe a misprint
3444 d - initialized data
3446 3 - double word aligned (that would be 4 byte boundary)
3449 Tag index tables (also known as the function table) for exception
3450 handling, debugging, etc.
3457 if (pdata_section
== 0)
3459 pdata_section
= subseg_new (".pdata", 0);
3461 bfd_set_section_flags (stdoutput
, pdata_section
,
3462 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3463 | SEC_READONLY
| SEC_DATA
));
3465 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3469 pdata_section
= subseg_new(".pdata", 0);
3471 ppc_set_current_section(pdata_section
);
3474 /* pseudo-op: .ydata
3475 behaviour: predefined read only data section
3479 initial: .section .ydata "drw3"
3480 a - don't know -- maybe a misprint
3481 d - initialized data
3483 3 - double word aligned (that would be 4 byte boundary)
3485 Tag tables (also known as the scope table) for exception handling,
3492 if (ydata_section
== 0)
3494 ydata_section
= subseg_new (".ydata", 0);
3495 bfd_set_section_flags (stdoutput
, ydata_section
,
3496 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3497 | SEC_READONLY
| SEC_DATA
));
3499 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3503 ydata_section
= subseg_new (".ydata", 0);
3505 ppc_set_current_section(ydata_section
);
3508 /* pseudo-op: .reldata
3509 behaviour: predefined read write data section
3510 double word aligned (4-byte)
3511 FIXME: relocation is applied to it
3512 FIXME: what's the difference between this and .data?
3515 initial: .section .reldata "drw3"
3516 d - initialized data
3519 3 - double word aligned (that would be 8 byte boundary)
3522 Like .data, but intended to hold data subject to relocation, such as
3523 function descriptors, etc.
3529 if (reldata_section
== 0)
3531 reldata_section
= subseg_new (".reldata", 0);
3533 bfd_set_section_flags (stdoutput
, reldata_section
,
3534 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3537 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3541 reldata_section
= subseg_new (".reldata", 0);
3543 ppc_set_current_section(reldata_section
);
3546 /* pseudo-op: .rdata
3547 behaviour: predefined read only data section
3551 initial: .section .rdata "dr3"
3552 d - initialized data
3554 3 - double word aligned (that would be 4 byte boundary)
3560 if (rdata_section
== 0)
3562 rdata_section
= subseg_new (".rdata", 0);
3563 bfd_set_section_flags (stdoutput
, rdata_section
,
3564 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3565 | SEC_READONLY
| SEC_DATA
));
3567 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3571 rdata_section
= subseg_new (".rdata", 0);
3573 ppc_set_current_section(rdata_section
);
3576 /* pseudo-op: .ualong
3577 behaviour: much like .int, with the exception that no alignment is
3579 FIXME: test the alignment statement
3591 /* pseudo-op: .znop <symbol name>
3592 behaviour: Issue a nop instruction
3593 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3594 the supplied symbol name.
3596 warnings: Missing symbol name
3603 const struct powerpc_opcode
*opcode
;
3609 /* Strip out the symbol name */
3617 symbol_name
= input_line_pointer
;
3618 c
= get_symbol_end ();
3620 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3621 strcpy (name
, symbol_name
);
3623 sym
= symbol_find_or_make (name
);
3625 *input_line_pointer
= c
;
3629 /* Look up the opcode in the hash table. */
3630 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3632 /* stick in the nop */
3633 insn
= opcode
->opcode
;
3635 /* Write out the instruction. */
3637 md_number_to_chars (f
, insn
, 4);
3639 f
- frag_now
->fr_literal
,
3644 BFD_RELOC_16_GOT_PCREL
);
3657 register char *name
;
3661 register symbolS
*symbolP
;
3664 name
= input_line_pointer
;
3665 c
= get_symbol_end ();
3667 /* just after name is now '\0' */
3668 p
= input_line_pointer
;
3671 if (*input_line_pointer
!= ',')
3673 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3674 ignore_rest_of_line ();
3678 input_line_pointer
++; /* skip ',' */
3679 if ((temp
= get_absolute_expression ()) < 0)
3681 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
3682 ignore_rest_of_line ();
3688 /* The third argument to .comm is the alignment. */
3689 if (*input_line_pointer
!= ',')
3693 ++input_line_pointer
;
3694 align
= get_absolute_expression ();
3697 as_warn (_("ignoring bad alignment"));
3704 symbolP
= symbol_find_or_make (name
);
3707 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3709 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3710 S_GET_NAME (symbolP
));
3711 ignore_rest_of_line ();
3715 if (S_GET_VALUE (symbolP
))
3717 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3718 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3719 S_GET_NAME (symbolP
),
3720 (long) S_GET_VALUE (symbolP
),
3725 S_SET_VALUE (symbolP
, (valueT
) temp
);
3726 S_SET_EXTERNAL (symbolP
);
3729 demand_empty_rest_of_line ();
3733 * implement the .section pseudo op:
3734 * .section name {, "flags"}
3736 * | +--- optional flags: 'b' for bss
3738 * +-- section name 'l' for lib
3742 * 'd' (apparently m88k for data)
3744 * But if the argument is not a quoted string, treat it as a
3745 * subsegment number.
3747 * FIXME: this is a copy of the section processing from obj-coff.c, with
3748 * additions/changes for the moto-pas assembler support. There are three
3751 * FIXME: I just noticed this. This doesn't work at all really. It it
3752 * setting bits that bfd probably neither understands or uses. The
3753 * correct approach (?) will have to incorporate extra fields attached
3754 * to the section to hold the system specific stuff. (krk)
3757 * 'a' - unknown - referred to in documentation, but no definition supplied
3758 * 'c' - section has code
3759 * 'd' - section has initialized data
3760 * 'u' - section has uninitialized data
3761 * 'i' - section contains directives (info)
3762 * 'n' - section can be discarded
3763 * 'R' - remove section at link time
3765 * Section Protection:
3766 * 'r' - section is readable
3767 * 'w' - section is writeable
3768 * 'x' - section is executable
3769 * 's' - section is sharable
3771 * Section Alignment:
3772 * '0' - align to byte boundary
3773 * '1' - align to halfword undary
3774 * '2' - align to word boundary
3775 * '3' - align to doubleword boundary
3776 * '4' - align to quadword boundary
3777 * '5' - align to 32 byte boundary
3778 * '6' - align to 64 byte boundary
3783 ppc_pe_section (ignore
)
3786 /* Strip out the section name */
3795 section_name
= input_line_pointer
;
3796 c
= get_symbol_end ();
3798 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3799 strcpy (name
, section_name
);
3801 *input_line_pointer
= c
;
3806 flags
= SEC_NO_FLAGS
;
3808 if (strcmp (name
, ".idata$2") == 0)
3812 else if (strcmp (name
, ".idata$3") == 0)
3816 else if (strcmp (name
, ".idata$4") == 0)
3820 else if (strcmp (name
, ".idata$5") == 0)
3824 else if (strcmp (name
, ".idata$6") == 0)
3829 align
= 4; /* default alignment to 16 byte boundary */
3831 if (*input_line_pointer
== ',')
3833 ++input_line_pointer
;
3835 if (*input_line_pointer
!= '"')
3836 exp
= get_absolute_expression ();
3839 ++input_line_pointer
;
3840 while (*input_line_pointer
!= '"'
3841 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3843 switch (*input_line_pointer
)
3845 /* Section Contents */
3846 case 'a': /* unknown */
3847 as_bad (_("Unsupported section attribute -- 'a'"));
3849 case 'c': /* code section */
3852 case 'd': /* section has initialized data */
3855 case 'u': /* section has uninitialized data */
3856 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3860 case 'i': /* section contains directives (info) */
3861 /* FIXME: This is IMAGE_SCN_LNK_INFO
3863 flags
|= SEC_HAS_CONTENTS
;
3865 case 'n': /* section can be discarded */
3868 case 'R': /* Remove section at link time */
3869 flags
|= SEC_NEVER_LOAD
;
3872 /* Section Protection */
3873 case 'r': /* section is readable */
3874 flags
|= IMAGE_SCN_MEM_READ
;
3876 case 'w': /* section is writeable */
3877 flags
|= IMAGE_SCN_MEM_WRITE
;
3879 case 'x': /* section is executable */
3880 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3882 case 's': /* section is sharable */
3883 flags
|= IMAGE_SCN_MEM_SHARED
;
3886 /* Section Alignment */
3887 case '0': /* align to byte boundary */
3888 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3891 case '1': /* align to halfword boundary */
3892 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3895 case '2': /* align to word boundary */
3896 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3899 case '3': /* align to doubleword boundary */
3900 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3903 case '4': /* align to quadword boundary */
3904 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3907 case '5': /* align to 32 byte boundary */
3908 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3911 case '6': /* align to 64 byte boundary */
3912 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3917 as_bad(_("unknown section attribute '%c'"),
3918 *input_line_pointer
);
3921 ++input_line_pointer
;
3923 if (*input_line_pointer
== '"')
3924 ++input_line_pointer
;
3928 sec
= subseg_new (name
, (subsegT
) exp
);
3930 ppc_set_current_section(sec
);
3932 if (flags
!= SEC_NO_FLAGS
)
3934 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3935 as_bad (_("error setting flags for \"%s\": %s"),
3936 bfd_section_name (stdoutput
, sec
),
3937 bfd_errmsg (bfd_get_error ()));
3940 bfd_set_section_alignment(stdoutput
, sec
, align
);
3945 ppc_pe_function (ignore
)
3952 name
= input_line_pointer
;
3953 endc
= get_symbol_end ();
3955 ext_sym
= symbol_find_or_make (name
);
3957 *input_line_pointer
= endc
;
3959 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3960 SF_SET_FUNCTION (ext_sym
);
3961 SF_SET_PROCESS (ext_sym
);
3962 coff_add_linesym (ext_sym
);
3964 demand_empty_rest_of_line ();
3968 ppc_pe_tocd (ignore
)
3971 if (tocdata_section
== 0)
3973 tocdata_section
= subseg_new (".tocd", 0);
3974 /* FIXME: section flags won't work */
3975 bfd_set_section_flags (stdoutput
, tocdata_section
,
3976 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3977 | SEC_READONLY
| SEC_DATA
));
3979 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3983 rdata_section
= subseg_new (".tocd", 0);
3986 ppc_set_current_section(tocdata_section
);
3988 demand_empty_rest_of_line ();
3991 /* Don't adjust TOC relocs to use the section symbol. */
3994 ppc_pe_fix_adjustable (fix
)
3997 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4004 /* XCOFF specific symbol and file handling. */
4006 /* Canonicalize the symbol name. We use the to force the suffix, if
4007 any, to use square brackets, and to be in upper case. */
4010 ppc_canonicalize_symbol_name (name
)
4015 if (ppc_stab_symbol
)
4018 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4032 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4036 if (*s
== '\0' || s
[1] != '\0')
4037 as_bad (_("bad symbol suffix"));
4045 /* Set the class of a symbol based on the suffix, if any. This is
4046 called whenever a new symbol is created. */
4049 ppc_symbol_new_hook (sym
)
4052 struct ppc_tc_sy
*tc
;
4055 tc
= symbol_get_tc (sym
);
4059 tc
->real_name
= NULL
;
4065 if (ppc_stab_symbol
)
4068 s
= strchr (S_GET_NAME (sym
), '[');
4069 if (s
== (const char *) NULL
)
4071 /* There is no suffix. */
4080 if (strcmp (s
, "BS]") == 0)
4084 if (strcmp (s
, "DB]") == 0)
4086 else if (strcmp (s
, "DS]") == 0)
4090 if (strcmp (s
, "GL]") == 0)
4094 if (strcmp (s
, "PR]") == 0)
4098 if (strcmp (s
, "RO]") == 0)
4100 else if (strcmp (s
, "RW]") == 0)
4104 if (strcmp (s
, "SV]") == 0)
4108 if (strcmp (s
, "TC]") == 0)
4110 else if (strcmp (s
, "TI]") == 0)
4112 else if (strcmp (s
, "TB]") == 0)
4114 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4115 tc
->class = XMC_TC0
;
4118 if (strcmp (s
, "UA]") == 0)
4120 else if (strcmp (s
, "UC]") == 0)
4124 if (strcmp (s
, "XO]") == 0)
4129 if (tc
->class == -1)
4130 as_bad (_("Unrecognized symbol suffix"));
4133 /* Set the class of a label based on where it is defined. This
4134 handles symbols without suffixes. Also, move the symbol so that it
4135 follows the csect symbol. */
4138 ppc_frob_label (sym
)
4141 if (ppc_current_csect
!= (symbolS
*) NULL
)
4143 if (symbol_get_tc (sym
)->class == -1)
4144 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4146 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4147 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4148 &symbol_rootP
, &symbol_lastP
);
4149 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4153 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4154 seen. It tells ppc_adjust_symtab whether it needs to look through
4157 static boolean ppc_saw_abs
;
4159 /* Change the name of a symbol just before writing it out. Set the
4160 real name if the .rename pseudo-op was used. Otherwise, remove any
4161 class suffix. Return 1 if the symbol should not be included in the
4165 ppc_frob_symbol (sym
)
4168 static symbolS
*ppc_last_function
;
4169 static symbolS
*set_end
;
4171 /* Discard symbols that should not be included in the output symbol
4173 if (! symbol_used_in_reloc_p (sym
)
4174 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4175 || (! S_IS_EXTERNAL (sym
)
4176 && ! symbol_get_tc (sym
)->output
4177 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4180 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4181 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4187 name
= S_GET_NAME (sym
);
4188 s
= strchr (name
, '[');
4189 if (s
!= (char *) NULL
)
4195 snew
= xmalloc (len
+ 1);
4196 memcpy (snew
, name
, len
);
4199 S_SET_NAME (sym
, snew
);
4203 if (set_end
!= (symbolS
*) NULL
)
4205 SA_SET_SYM_ENDNDX (set_end
, sym
);
4209 if (SF_GET_FUNCTION (sym
))
4211 if (ppc_last_function
!= (symbolS
*) NULL
)
4212 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4213 ppc_last_function
= sym
;
4214 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4216 resolve_symbol_value (symbol_get_tc (sym
)->size
, 1);
4217 SA_SET_SYM_FSIZE (sym
,
4218 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4221 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4222 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4224 if (ppc_last_function
== (symbolS
*) NULL
)
4225 as_bad (_(".ef with no preceding .function"));
4228 set_end
= ppc_last_function
;
4229 ppc_last_function
= NULL
;
4231 /* We don't have a C_EFCN symbol, but we need to force the
4232 COFF backend to believe that it has seen one. */
4233 coff_last_function
= NULL
;
4237 if (! S_IS_EXTERNAL (sym
)
4238 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4239 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4240 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4241 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4242 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4243 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4244 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4245 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4246 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4247 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4249 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4250 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4253 union internal_auxent
*a
;
4255 /* Create a csect aux. */
4256 i
= S_GET_NUMBER_AUXILIARY (sym
);
4257 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4258 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4259 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4261 /* This is the TOC table. */
4262 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4263 a
->x_csect
.x_scnlen
.l
= 0;
4264 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4266 else if (symbol_get_tc (sym
)->subseg
!= 0)
4268 /* This is a csect symbol. x_scnlen is the size of the
4270 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4271 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4272 S_GET_SEGMENT (sym
))
4273 - S_GET_VALUE (sym
));
4276 resolve_symbol_value (symbol_get_tc (sym
)->next
, 1);
4277 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4278 - S_GET_VALUE (sym
));
4280 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4282 else if (S_GET_SEGMENT (sym
) == bss_section
)
4284 /* This is a common symbol. */
4285 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4286 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4287 if (S_IS_EXTERNAL (sym
))
4288 symbol_get_tc (sym
)->class = XMC_RW
;
4290 symbol_get_tc (sym
)->class = XMC_BS
;
4292 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4294 /* This is an absolute symbol. The csect will be created by
4295 ppc_adjust_symtab. */
4297 a
->x_csect
.x_smtyp
= XTY_LD
;
4298 if (symbol_get_tc (sym
)->class == -1)
4299 symbol_get_tc (sym
)->class = XMC_XO
;
4301 else if (! S_IS_DEFINED (sym
))
4303 /* This is an external symbol. */
4304 a
->x_csect
.x_scnlen
.l
= 0;
4305 a
->x_csect
.x_smtyp
= XTY_ER
;
4307 else if (symbol_get_tc (sym
)->class == XMC_TC
)
4311 /* This is a TOC definition. x_scnlen is the size of the
4313 next
= symbol_next (sym
);
4314 while (symbol_get_tc (next
)->class == XMC_TC0
)
4315 next
= symbol_next (next
);
4316 if (next
== (symbolS
*) NULL
4317 || symbol_get_tc (next
)->class != XMC_TC
)
4319 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4320 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4322 - S_GET_VALUE (sym
));
4324 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4325 - S_GET_VALUE (sym
));
4329 resolve_symbol_value (next
, 1);
4330 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4331 - S_GET_VALUE (sym
));
4333 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4339 /* This is a normal symbol definition. x_scnlen is the
4340 symbol index of the containing csect. */
4341 if (S_GET_SEGMENT (sym
) == text_section
)
4342 csect
= ppc_text_csects
;
4343 else if (S_GET_SEGMENT (sym
) == data_section
)
4344 csect
= ppc_data_csects
;
4348 /* Skip the initial dummy symbol. */
4349 csect
= symbol_get_tc (csect
)->next
;
4351 if (csect
== (symbolS
*) NULL
)
4353 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4354 a
->x_csect
.x_scnlen
.l
= 0;
4358 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
4360 resolve_symbol_value (symbol_get_tc (csect
)->next
, 1);
4361 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
4362 > S_GET_VALUE (sym
))
4364 csect
= symbol_get_tc (csect
)->next
;
4367 a
->x_csect
.x_scnlen
.p
=
4368 coffsymbol (symbol_get_bfdsym (csect
))->native
;
4369 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
4372 a
->x_csect
.x_smtyp
= XTY_LD
;
4375 a
->x_csect
.x_parmhash
= 0;
4376 a
->x_csect
.x_snhash
= 0;
4377 if (symbol_get_tc (sym
)->class == -1)
4378 a
->x_csect
.x_smclas
= XMC_PR
;
4380 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
4381 a
->x_csect
.x_stab
= 0;
4382 a
->x_csect
.x_snstab
= 0;
4384 /* Don't let the COFF backend resort these symbols. */
4385 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
4387 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4389 /* We want the value to be the symbol index of the referenced
4390 csect symbol. BFD will do that for us if we set the right
4394 coffsymbol (symbol_get_bfdsym
4395 (symbol_get_tc (sym
)->within
))->native
));
4396 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
4398 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4403 /* The value is the offset from the enclosing csect. */
4404 block
= symbol_get_tc (sym
)->within
;
4405 csect
= symbol_get_tc (block
)->within
;
4406 resolve_symbol_value (csect
, 1);
4407 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4409 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4410 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4412 /* We want the value to be a file offset into the line numbers.
4413 BFD will do that for us if we set the right flags. We have
4414 already set the value correctly. */
4415 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
4421 /* Adjust the symbol table. This creates csect symbols for all
4422 absolute symbols. */
4425 ppc_adjust_symtab ()
4432 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4436 union internal_auxent
*a
;
4438 if (S_GET_SEGMENT (sym
) != absolute_section
)
4441 csect
= symbol_create (".abs[XO]", absolute_section
,
4442 S_GET_VALUE (sym
), &zero_address_frag
);
4443 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
4444 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4445 i
= S_GET_NUMBER_AUXILIARY (csect
);
4446 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4447 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
4448 a
->x_csect
.x_scnlen
.l
= 0;
4449 a
->x_csect
.x_smtyp
= XTY_SD
;
4450 a
->x_csect
.x_parmhash
= 0;
4451 a
->x_csect
.x_snhash
= 0;
4452 a
->x_csect
.x_smclas
= XMC_XO
;
4453 a
->x_csect
.x_stab
= 0;
4454 a
->x_csect
.x_snstab
= 0;
4456 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4458 i
= S_GET_NUMBER_AUXILIARY (sym
);
4459 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
4460 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
4461 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
4464 ppc_saw_abs
= false;
4467 /* Set the VMA for a section. This is called on all the sections in
4471 ppc_frob_section (sec
)
4474 static bfd_size_type vma
= 0;
4476 bfd_set_section_vma (stdoutput
, sec
, vma
);
4477 vma
+= bfd_section_size (stdoutput
, sec
);
4480 #endif /* OBJ_XCOFF */
4482 /* Turn a string in input_line_pointer into a floating point constant
4483 of type type, and store the appropriate bytes in *litp. The number
4484 of LITTLENUMS emitted is stored in *sizep . An error message is
4485 returned, or NULL on OK. */
4488 md_atof (type
, litp
, sizep
)
4494 LITTLENUM_TYPE words
[4];
4510 return _("bad call to md_atof");
4513 t
= atof_ieee (input_line_pointer
, type
, words
);
4515 input_line_pointer
= t
;
4519 if (target_big_endian
)
4521 for (i
= 0; i
< prec
; i
++)
4523 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4529 for (i
= prec
- 1; i
>= 0; i
--)
4531 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4539 /* Write a value out to the object file, using the appropriate
4543 md_number_to_chars (buf
, val
, n
)
4548 if (target_big_endian
)
4549 number_to_chars_bigendian (buf
, val
, n
);
4551 number_to_chars_littleendian (buf
, val
, n
);
4554 /* Align a section (I don't know why this is machine dependent). */
4557 md_section_align (seg
, addr
)
4561 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4563 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4566 /* We don't have any form of relaxing. */
4569 md_estimate_size_before_relax (fragp
, seg
)
4570 fragS
*fragp ATTRIBUTE_UNUSED
;
4571 asection
*seg ATTRIBUTE_UNUSED
;
4577 /* Convert a machine dependent frag. We never generate these. */
4580 md_convert_frag (abfd
, sec
, fragp
)
4581 bfd
*abfd ATTRIBUTE_UNUSED
;
4582 asection
*sec ATTRIBUTE_UNUSED
;
4583 fragS
*fragp ATTRIBUTE_UNUSED
;
4588 /* We have no need to default values of symbols. */
4592 md_undefined_symbol (name
)
4593 char *name ATTRIBUTE_UNUSED
;
4598 /* Functions concerning relocs. */
4600 /* The location from which a PC relative jump should be calculated,
4601 given a PC relative reloc. */
4604 md_pcrel_from_section (fixp
, sec
)
4606 segT sec ATTRIBUTE_UNUSED
;
4608 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4613 /* This is called to see whether a fixup should be adjusted to use a
4614 section symbol. We take the opportunity to change a fixup against
4615 a symbol in the TOC subsegment into a reloc against the
4616 corresponding .tc symbol. */
4619 ppc_fix_adjustable (fix
)
4624 resolve_symbol_value (fix
->fx_addsy
, 1);
4625 val
= S_GET_VALUE (fix
->fx_addsy
);
4626 if (ppc_toc_csect
!= (symbolS
*) NULL
4627 && fix
->fx_addsy
!= (symbolS
*) NULL
4628 && fix
->fx_addsy
!= ppc_toc_csect
4629 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4630 && val
>= ppc_toc_frag
->fr_address
4631 && (ppc_after_toc_frag
== (fragS
*) NULL
4632 || val
< ppc_after_toc_frag
->fr_address
))
4636 for (sy
= symbol_next (ppc_toc_csect
);
4637 sy
!= (symbolS
*) NULL
;
4638 sy
= symbol_next (sy
))
4640 if (symbol_get_tc (sy
)->class == XMC_TC0
)
4642 if (symbol_get_tc (sy
)->class != XMC_TC
)
4644 resolve_symbol_value (sy
, 1);
4645 if (val
== S_GET_VALUE (sy
))
4648 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4653 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4654 _("symbol in .toc does not match any .tc"));
4657 /* Possibly adjust the reloc to be against the csect. */
4658 if (fix
->fx_addsy
!= (symbolS
*) NULL
4659 && symbol_get_tc (fix
->fx_addsy
)->subseg
== 0
4660 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC0
4661 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC
4662 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
4663 /* Don't adjust if this is a reloc in the toc section. */
4664 && (S_GET_SEGMENT (fix
->fx_addsy
) != data_section
4665 || ppc_toc_csect
== NULL
4666 || val
< ppc_toc_frag
->fr_address
4667 || (ppc_after_toc_frag
!= NULL
4668 && val
>= ppc_after_toc_frag
->fr_address
)))
4672 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4673 csect
= ppc_text_csects
;
4674 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4675 csect
= ppc_data_csects
;
4679 /* Skip the initial dummy symbol. */
4680 csect
= symbol_get_tc (csect
)->next
;
4682 if (csect
!= (symbolS
*) NULL
)
4684 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
4685 && (symbol_get_frag (symbol_get_tc (csect
)->next
)->fr_address
4688 /* If the csect address equals the symbol value, then we
4689 have to look through the full symbol table to see
4690 whether this is the csect we want. Note that we will
4691 only get here if the csect has zero length. */
4692 if ((symbol_get_frag (csect
)->fr_address
== val
)
4693 && S_GET_VALUE (csect
) == S_GET_VALUE (fix
->fx_addsy
))
4697 for (scan
= symbol_next (csect
);
4699 scan
= symbol_next (scan
))
4701 if (symbol_get_tc (scan
)->subseg
!= 0)
4703 if (scan
== fix
->fx_addsy
)
4707 /* If we found the symbol before the next csect
4708 symbol, then this is the csect we want. */
4709 if (scan
== fix
->fx_addsy
)
4713 csect
= symbol_get_tc (csect
)->next
;
4716 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4717 - symbol_get_frag (csect
)->fr_address
);
4718 fix
->fx_addsy
= csect
;
4722 /* Adjust a reloc against a .lcomm symbol to be against the base
4724 if (fix
->fx_addsy
!= (symbolS
*) NULL
4725 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4726 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4728 resolve_symbol_value (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
, 1);
4730 (S_GET_VALUE (fix
->fx_addsy
)
4731 - S_GET_VALUE (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
));
4732 fix
->fx_addsy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
4738 /* A reloc from one csect to another must be kept. The assembler
4739 will, of course, keep relocs between sections, and it will keep
4740 absolute relocs, but we need to force it to keep PC relative relocs
4741 between two csects in the same section. */
4744 ppc_force_relocation (fix
)
4747 /* At this point fix->fx_addsy should already have been converted to
4748 a csect symbol. If the csect does not include the fragment, then
4749 we need to force the relocation. */
4751 && fix
->fx_addsy
!= NULL
4752 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
4753 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
4754 > fix
->fx_frag
->fr_address
)
4755 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
4756 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
4757 <= fix
->fx_frag
->fr_address
))))
4763 #endif /* OBJ_XCOFF */
4765 /* See whether a symbol is in the TOC section. */
4768 ppc_is_toc_sym (sym
)
4772 return symbol_get_tc (sym
)->class == XMC_TC
;
4774 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4778 /* Apply a fixup to the object code. This is called for all the
4779 fixups we generated by the call to fix_new_exp, above. In the call
4780 above we used a reloc code which was the largest legal reloc code
4781 plus the operand index. Here we undo that to recover the operand
4782 index. At this point all symbol values should be fully resolved,
4783 and we attempt to completely resolve the reloc. If we can not do
4784 that, we determine the correct reloc code and put it back in the
4788 md_apply_fix3 (fixp
, valuep
, seg
)
4797 if (fixp
->fx_addsy
!= NULL
)
4799 /* `*valuep' may contain the value of the symbol on which the reloc
4800 will be based; we have to remove it. */
4801 if (symbol_used_in_reloc_p (fixp
->fx_addsy
)
4802 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
4803 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
4804 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
4805 value
-= S_GET_VALUE (fixp
->fx_addsy
);
4807 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4808 supposed to be? I think this is related to various similar
4809 FIXMEs in tc-i386.c and tc-sparc.c. */
4811 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4818 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4819 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4820 doing this relocation the code in write.c is going to call
4821 bfd_install_relocation, which is also going to use the symbol
4822 value. That means that if the reloc is fully resolved we want to
4823 use *valuep since bfd_install_relocation is not being used.
4824 However, if the reloc is not fully resolved we do not want to use
4825 *valuep, and must use fx_offset instead. However, if the reloc
4826 is PC relative, we do want to use *valuep since it includes the
4827 result of md_pcrel_from. This is confusing. */
4828 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4833 else if (fixp
->fx_pcrel
)
4837 value
= fixp
->fx_offset
;
4838 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4840 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4841 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4844 /* We can't actually support subtracting a symbol. */
4845 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4846 _("expression too complex"));
4852 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4855 const struct powerpc_operand
*operand
;
4859 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4861 operand
= &powerpc_operands
[opindex
];
4864 /* It appears that an instruction like
4866 when LC..1 is not a TOC symbol does not generate a reloc. It
4867 uses the offset of LC..1 within its csect. However, .long
4868 LC..1 will generate a reloc. I can't find any documentation
4869 on how these cases are to be distinguished, so this is a wild
4870 guess. These cases are generated by gcc -mminimal-toc. */
4871 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4872 && operand
->bits
== 16
4873 && operand
->shift
== 0
4874 && operand
->insert
== NULL
4875 && fixp
->fx_addsy
!= NULL
4876 && symbol_get_tc (fixp
->fx_addsy
)->subseg
!= 0
4877 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC
4878 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC0
4879 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4881 value
= fixp
->fx_offset
;
4886 /* Fetch the instruction, insert the fully resolved operand
4887 value, and stuff the instruction back again. */
4888 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4889 if (target_big_endian
)
4890 insn
= bfd_getb32 ((unsigned char *) where
);
4892 insn
= bfd_getl32 ((unsigned char *) where
);
4893 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4894 fixp
->fx_file
, fixp
->fx_line
);
4895 if (target_big_endian
)
4896 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4898 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4902 /* Nothing else to do here. */
4906 /* Determine a BFD reloc value based on the operand information.
4907 We are only prepared to turn a few of the operands into
4909 FIXME: We need to handle the DS field at the very least.
4910 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4911 there should be a new field in the operand table. */
4912 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4913 && operand
->bits
== 26
4914 && operand
->shift
== 0)
4915 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4916 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4917 && operand
->bits
== 16
4918 && operand
->shift
== 0)
4919 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4920 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4921 && operand
->bits
== 26
4922 && operand
->shift
== 0)
4923 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4924 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4925 && operand
->bits
== 16
4926 && operand
->shift
== 0)
4927 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4928 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4929 && operand
->bits
== 16
4930 && operand
->shift
== 0
4931 && fixp
->fx_addsy
!= NULL
4932 && ppc_is_toc_sym (fixp
->fx_addsy
))
4935 if (target_big_endian
)
4936 fixp
->fx_where
+= 2;
4937 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4944 /* Use expr_symbol_where to see if this is an expression
4946 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
4947 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4948 _("unresolved expression that must be resolved"));
4950 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4951 _("unsupported relocation type"));
4959 ppc_elf_validate_fix (fixp
, seg
);
4961 switch (fixp
->fx_r_type
)
4964 case BFD_RELOC_CTOR
:
4966 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4970 case BFD_RELOC_32_PCREL
:
4971 case BFD_RELOC_32_BASEREL
:
4972 case BFD_RELOC_PPC_EMB_NADDR32
:
4973 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4979 fixp
->fx_r_type
= BFD_RELOC_64_PCREL
;
4981 case BFD_RELOC_64_PCREL
:
4982 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4985 case BFD_RELOC_LO16
:
4987 case BFD_RELOC_GPREL16
:
4988 case BFD_RELOC_16_GOT_PCREL
:
4989 case BFD_RELOC_16_GOTOFF
:
4990 case BFD_RELOC_LO16_GOTOFF
:
4991 case BFD_RELOC_HI16_GOTOFF
:
4992 case BFD_RELOC_HI16_S_GOTOFF
:
4993 case BFD_RELOC_LO16_BASEREL
:
4994 case BFD_RELOC_HI16_BASEREL
:
4995 case BFD_RELOC_HI16_S_BASEREL
:
4996 case BFD_RELOC_PPC_EMB_NADDR16
:
4997 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
4998 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
4999 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5000 case BFD_RELOC_PPC_EMB_SDAI16
:
5001 case BFD_RELOC_PPC_EMB_SDA2REL
:
5002 case BFD_RELOC_PPC_EMB_SDA2I16
:
5003 case BFD_RELOC_PPC_EMB_RELSEC16
:
5004 case BFD_RELOC_PPC_EMB_RELST_LO
:
5005 case BFD_RELOC_PPC_EMB_RELST_HI
:
5006 case BFD_RELOC_PPC_EMB_RELST_HA
:
5007 case BFD_RELOC_PPC_EMB_RELSDA
:
5008 case BFD_RELOC_PPC_TOC16
:
5011 if (fixp
->fx_addsy
!= NULL
)
5012 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5013 _("cannot emit PC relative %s relocation against %s"),
5014 bfd_get_reloc_code_name (fixp
->fx_r_type
),
5015 S_GET_NAME (fixp
->fx_addsy
));
5017 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5018 _("cannot emit PC relative %s relocation"),
5019 bfd_get_reloc_code_name (fixp
->fx_r_type
));
5022 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5026 /* This case happens when you write, for example,
5028 where L1 and L2 are defined later. */
5029 case BFD_RELOC_HI16
:
5032 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5035 case BFD_RELOC_HI16_S
:
5038 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5039 (value
+ 0x8000) >> 16, 2);
5042 /* Because SDA21 modifies the register field, the size is set to 4
5043 bytes, rather than 2, so offset it here appropriately */
5044 case BFD_RELOC_PPC_EMB_SDA21
:
5048 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
5049 + ((target_big_endian
) ? 2 : 0),
5057 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5061 case BFD_RELOC_24_PLT_PCREL
:
5062 case BFD_RELOC_PPC_LOCAL24PC
:
5063 if (!fixp
->fx_pcrel
&& !fixp
->fx_done
)
5071 /* Fetch the instruction, insert the fully resolved operand
5072 value, and stuff the instruction back again. */
5073 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5074 if (target_big_endian
)
5075 insn
= bfd_getb32 ((unsigned char *) where
);
5077 insn
= bfd_getl32 ((unsigned char *) where
);
5078 if ((value
& 3) != 0)
5079 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5080 _("must branch to an address a multiple of 4"));
5081 if ((offsetT
) value
< -0x40000000
5082 || (offsetT
) value
>= 0x40000000)
5083 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5084 _("@local or @plt branch destination is too far away, %ld bytes"),
5086 insn
= insn
| (value
& 0x03fffffc);
5087 if (target_big_endian
)
5088 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5090 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5094 case BFD_RELOC_VTABLE_INHERIT
:
5097 && !S_IS_DEFINED (fixp
->fx_addsy
)
5098 && !S_IS_WEAK (fixp
->fx_addsy
))
5099 S_SET_WEAK (fixp
->fx_addsy
);
5102 case BFD_RELOC_VTABLE_ENTRY
:
5108 _("Gas failure, reloc value %d\n"), fixp
->fx_r_type
);
5115 fixp
->fx_addnumber
= value
;
5117 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
5118 fixp
->fx_addnumber
= 0;
5122 fixp
->fx_addnumber
= 0;
5124 /* We want to use the offset within the data segment of the
5125 symbol, not the actual VMA of the symbol. */
5126 fixp
->fx_addnumber
=
5127 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
5135 /* Generate a reloc for a fixup. */
5138 tc_gen_reloc (seg
, fixp
)
5139 asection
*seg ATTRIBUTE_UNUSED
;
5144 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5146 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5147 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5148 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5149 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5150 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
5152 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5153 _("reloc %d not supported by object file format"), (int)fixp
->fx_r_type
);
5156 reloc
->addend
= fixp
->fx_addnumber
;