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
, "405") == 0
846 || strcmp (arg
, "603") == 0
847 || strcmp (arg
, "604") == 0)
848 ppc_cpu
= PPC_OPCODE_PPC
;
849 else if (strcmp (arg
, "7400") == 0)
850 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
;
851 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
853 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
855 ppc_cpu
= PPC_OPCODE_PPC
;
856 ppc_size
= PPC_OPCODE_64
;
858 else if (strcmp (arg
, "ppc64bridge") == 0)
860 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_64_BRIDGE
;
861 ppc_size
= PPC_OPCODE_64
;
863 /* -mcom means assemble for the common intersection between Power
864 and PowerPC. At present, we just allow the union, rather
865 than the intersection. */
866 else if (strcmp (arg
, "com") == 0)
867 ppc_cpu
= PPC_OPCODE_COMMON
;
868 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
869 else if (strcmp (arg
, "any") == 0)
870 ppc_cpu
= PPC_OPCODE_ANY
;
872 else if (strcmp (arg
, "regnames") == 0)
875 else if (strcmp (arg
, "no-regnames") == 0)
879 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
880 else if (strcmp (arg
, "relocatable") == 0)
882 shlib
= SHILB_MRELOCATABLE
;
883 ppc_flags
|= EF_PPC_RELOCATABLE
;
886 else if (strcmp (arg
, "relocatable-lib") == 0)
888 shlib
= SHILB_MRELOCATABLE
;
889 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
892 /* -memb, set embedded bit */
893 else if (strcmp (arg
, "emb") == 0)
894 ppc_flags
|= EF_PPC_EMB
;
896 /* -mlittle/-mbig set the endianess */
897 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
899 target_big_endian
= 0;
900 set_target_endian
= 1;
903 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
905 target_big_endian
= 1;
906 set_target_endian
= 1;
909 else if (strcmp (arg
, "solaris") == 0)
912 ppc_comment_chars
= ppc_solaris_comment_chars
;
915 else if (strcmp (arg
, "no-solaris") == 0)
918 ppc_comment_chars
= ppc_eabi_comment_chars
;
923 as_bad (_("invalid switch -m%s"), arg
);
929 /* -V: SVR4 argument to print version ID. */
934 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
935 should be emitted or not. FIXME: Not implemented. */
939 /* Solaris takes -s to specify that .stabs go in a .stabs section,
940 rather than .stabs.excl, which is ignored by the linker.
941 FIXME: Not implemented. */
957 md_show_usage (stream
)
963 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
964 -mpwr generate code for IBM POWER (RIOS1)\n\
965 -m601 generate code for Motorola PowerPC 601\n\
966 -mppc, -mppc32, -m403, -m405, -m603, -m604\n\
967 generate code for Motorola PowerPC 603/604\n\
968 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
969 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
970 -mcom generate code Power/PowerPC common instructions\n\
971 -many generate code for any architecture (PWR/PWRX/PPC)\n\
972 -mregnames Allow symbolic names for registers\n\
973 -mno-regnames Do not allow symbolic names for registers\n"));
976 -mrelocatable support for GCC's -mrelocatble option\n\
977 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
978 -memb set PPC_EMB bit in ELF flags\n\
979 -mlittle, -mlittle-endian\n\
980 generate code for a little endian machine\n\
981 -mbig, -mbig-endian generate code for a big endian machine\n\
982 -msolaris generate code for Solaris\n\
983 -mno-solaris do not generate code for Solaris\n\
984 -V print assembler version number\n\
985 -Qy, -Qn ignored\n"));
989 /* Set ppc_cpu if it is not already set. */
994 const char *default_os
= TARGET_OS
;
995 const char *default_cpu
= TARGET_CPU
;
999 if (strncmp (default_os
, "aix", 3) == 0
1000 && default_os
[3] >= '4' && default_os
[3] <= '9')
1001 ppc_cpu
= PPC_OPCODE_COMMON
;
1002 else if (strncmp (default_os
, "aix3", 4) == 0)
1003 ppc_cpu
= PPC_OPCODE_POWER
;
1004 else if (strcmp (default_cpu
, "rs6000") == 0)
1005 ppc_cpu
= PPC_OPCODE_POWER
;
1006 else if (strcmp (default_cpu
, "powerpc") == 0
1007 || strcmp (default_cpu
, "powerpcle") == 0)
1008 ppc_cpu
= PPC_OPCODE_PPC
;
1010 as_fatal (_("Unknown default cpu = %s, os = %s"), default_cpu
, default_os
);
1014 /* Figure out the BFD architecture to use. */
1016 enum bfd_architecture
1019 const char *default_cpu
= TARGET_CPU
;
1022 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1023 return bfd_arch_powerpc
;
1024 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1025 return bfd_arch_rs6000
;
1026 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1028 if (strcmp (default_cpu
, "rs6000") == 0)
1029 return bfd_arch_rs6000
;
1030 else if (strcmp (default_cpu
, "powerpc") == 0
1031 || strcmp (default_cpu
, "powerpcle") == 0)
1032 return bfd_arch_powerpc
;
1035 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1036 return bfd_arch_unknown
;
1042 return (ppc_size
== PPC_OPCODE_64
) ? 620 : 0;
1048 return (ppc_xcoff64
) ? 3 : 2;
1056 return (target_big_endian
? "pe-powerpc" : "pe-powerpcle");
1059 return (ppc_xcoff64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1062 return "xcoff-powermac";
1066 return (target_big_endian
? "elf32-powerpc" : "elf32-powerpcle");
1070 /* This function is called when the assembler starts up. It is called
1071 after the options have been parsed and the output file has been
1077 register const struct powerpc_opcode
*op
;
1078 const struct powerpc_opcode
*op_end
;
1079 const struct powerpc_macro
*macro
;
1080 const struct powerpc_macro
*macro_end
;
1081 boolean dup_insn
= false;
1086 /* Set the ELF flags if desired. */
1087 if (ppc_flags
&& !msolaris
)
1088 bfd_set_private_flags (stdoutput
, ppc_flags
);
1091 /* Insert the opcodes into a hash table. */
1092 ppc_hash
= hash_new ();
1094 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1095 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1097 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1099 if ((op
->flags
& ppc_cpu
) != 0
1100 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1101 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
1102 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0))
1106 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1107 if (retval
!= (const char *) NULL
)
1109 /* Ignore Power duplicates for -m601 */
1110 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1111 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1114 as_bad (_("Internal assembler error for instruction %s"), op
->name
);
1120 /* Insert the macros into a hash table. */
1121 ppc_macro_hash
= hash_new ();
1123 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1124 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1126 if ((macro
->flags
& ppc_cpu
) != 0)
1130 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1131 if (retval
!= (const char *) NULL
)
1133 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1142 /* Tell the main code what the endianness is if it is not overidden by the user. */
1143 if (!set_target_endian
)
1145 set_target_endian
= 1;
1146 target_big_endian
= PPC_BIG_ENDIAN
;
1150 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1152 /* Create dummy symbols to serve as initial csects. This forces the
1153 text csects to precede the data csects. These symbols will not
1155 ppc_text_csects
= symbol_make ("dummy\001");
1156 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1157 ppc_data_csects
= symbol_make ("dummy\001");
1158 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1163 ppc_current_section
= text_section
;
1164 ppc_previous_section
= 0;
1169 /* Insert an operand value into an instruction. */
1171 static unsigned long
1172 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1174 const struct powerpc_operand
*operand
;
1179 if (operand
->bits
!= 32)
1184 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1186 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1187 max
= (1 << operand
->bits
) - 1;
1189 max
= (1 << (operand
->bits
- 1)) - 1;
1190 min
= - (1 << (operand
->bits
- 1));
1192 if (ppc_size
== PPC_OPCODE_32
)
1194 /* Some people write 32 bit hex constants with the sign
1195 extension done by hand. This shouldn't really be
1196 valid, but, to permit this code to assemble on a 64
1197 bit host, we sign extend the 32 bit value. */
1199 && (val
& (offsetT
) 0x80000000) != 0
1200 && (val
& (offsetT
) 0xffffffff) == val
)
1209 max
= (1 << operand
->bits
) - 1;
1213 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1218 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1221 _("operand out of range (%s not between %ld and %ld)");
1224 sprint_value (buf
, test
);
1225 if (file
== (char *) NULL
)
1226 as_bad (err
, buf
, min
, max
);
1228 as_bad_where (file
, line
, err
, buf
, min
, max
);
1232 if (operand
->insert
)
1237 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1238 if (errmsg
!= (const char *) NULL
)
1242 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1250 /* Parse @got, etc. and return the desired relocation. */
1251 static bfd_reloc_code_real_type
1252 ppc_elf_suffix (str_p
, exp_p
)
1259 bfd_reloc_code_real_type reloc
;
1267 struct map_bfd
*ptr
;
1269 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1271 static struct map_bfd mapping
[] = {
1272 MAP ("l", BFD_RELOC_LO16
),
1273 MAP ("h", BFD_RELOC_HI16
),
1274 MAP ("ha", BFD_RELOC_HI16_S
),
1275 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1276 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1277 MAP ("got", BFD_RELOC_16_GOTOFF
),
1278 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1279 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1280 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1281 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1282 MAP ("plt", BFD_RELOC_24_PLT_PCREL
),
1283 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1284 MAP ("copy", BFD_RELOC_PPC_COPY
),
1285 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1286 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1287 MAP ("local", BFD_RELOC_PPC_LOCAL24PC
),
1288 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1289 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1290 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1291 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1292 MAP ("sdarel", BFD_RELOC_GPREL16
),
1293 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1294 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1295 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1296 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1297 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1298 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1299 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1300 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1301 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1302 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1303 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1304 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1305 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1306 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1307 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1308 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1309 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1310 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1311 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1312 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1313 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1315 { (char *)0, 0, BFD_RELOC_UNUSED
}
1319 return BFD_RELOC_UNUSED
;
1321 for (ch
= *str
, str2
= ident
;
1322 (str2
< ident
+ sizeof (ident
) - 1
1323 && (isalnum (ch
) || ch
== '@'));
1326 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1333 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1334 if (ch
== ptr
->string
[0]
1335 && len
== ptr
->length
1336 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1338 if (exp_p
->X_add_number
!= 0
1339 && (ptr
->reloc
== BFD_RELOC_16_GOTOFF
1340 || ptr
->reloc
== BFD_RELOC_LO16_GOTOFF
1341 || ptr
->reloc
== BFD_RELOC_HI16_GOTOFF
1342 || ptr
->reloc
== BFD_RELOC_HI16_S_GOTOFF
))
1343 as_warn (_("identifier+constant@got means identifier@got+constant"));
1345 /* Now check for identifier@suffix+constant */
1346 if (*str
== '-' || *str
== '+')
1348 char *orig_line
= input_line_pointer
;
1349 expressionS new_exp
;
1351 input_line_pointer
= str
;
1352 expression (&new_exp
);
1353 if (new_exp
.X_op
== O_constant
)
1355 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1356 str
= input_line_pointer
;
1359 if (&input_line_pointer
!= str_p
)
1360 input_line_pointer
= orig_line
;
1367 return BFD_RELOC_UNUSED
;
1370 /* Like normal .long/.short/.word, except support @got, etc. */
1371 /* clobbers input_line_pointer, checks */
1374 ppc_elf_cons (nbytes
)
1375 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1378 bfd_reloc_code_real_type reloc
;
1380 if (is_it_end_of_statement ())
1382 demand_empty_rest_of_line ();
1389 if (exp
.X_op
== O_symbol
1390 && *input_line_pointer
== '@'
1391 && (reloc
= ppc_elf_suffix (&input_line_pointer
, &exp
)) != BFD_RELOC_UNUSED
)
1393 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1394 int size
= bfd_get_reloc_size (reloc_howto
);
1397 as_bad (_("%s relocations do not fit in %d bytes\n"), reloc_howto
->name
, nbytes
);
1401 register char *p
= frag_more ((int) nbytes
);
1402 int offset
= nbytes
- size
;
1404 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1408 emit_expr (&exp
, (unsigned int) nbytes
);
1410 while (*input_line_pointer
++ == ',');
1412 input_line_pointer
--; /* Put terminator back into stream. */
1413 demand_empty_rest_of_line ();
1416 /* Solaris pseduo op to change to the .rodata section. */
1421 char *save_line
= input_line_pointer
;
1422 static char section
[] = ".rodata\n";
1424 /* Just pretend this is .section .rodata */
1425 input_line_pointer
= section
;
1426 obj_elf_section (xxx
);
1428 input_line_pointer
= save_line
;
1431 /* Pseudo op to make file scope bss items */
1434 int xxx ATTRIBUTE_UNUSED
;
1436 register char *name
;
1440 register symbolS
*symbolP
;
1447 name
= input_line_pointer
;
1448 c
= get_symbol_end ();
1450 /* just after name is now '\0' */
1451 p
= input_line_pointer
;
1454 if (*input_line_pointer
!= ',')
1456 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1457 ignore_rest_of_line ();
1461 input_line_pointer
++; /* skip ',' */
1462 if ((size
= get_absolute_expression ()) < 0)
1464 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1465 ignore_rest_of_line ();
1469 /* The third argument to .lcomm is the alignment. */
1470 if (*input_line_pointer
!= ',')
1474 ++input_line_pointer
;
1475 align
= get_absolute_expression ();
1478 as_warn (_("ignoring bad alignment"));
1484 symbolP
= symbol_find_or_make (name
);
1487 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1489 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1490 S_GET_NAME (symbolP
));
1491 ignore_rest_of_line ();
1495 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1497 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1498 S_GET_NAME (symbolP
),
1499 (long) S_GET_VALUE (symbolP
),
1502 ignore_rest_of_line ();
1508 old_subsec
= now_subseg
;
1511 /* convert to a power of 2 alignment */
1512 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1515 as_bad (_("Common alignment not a power of 2"));
1516 ignore_rest_of_line ();
1523 record_alignment (bss_section
, align2
);
1524 subseg_set (bss_section
, 0);
1526 frag_align (align2
, 0, 0);
1527 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1528 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1529 symbol_set_frag (symbolP
, frag_now
);
1530 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1533 S_SET_SIZE (symbolP
, size
);
1534 S_SET_SEGMENT (symbolP
, bss_section
);
1535 subseg_set (old_sec
, old_subsec
);
1536 demand_empty_rest_of_line ();
1539 /* Validate any relocations emitted for -mrelocatable, possibly adding
1540 fixups for word relocations in writable segments, so we can adjust
1543 ppc_elf_validate_fix (fixp
, seg
)
1547 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1556 case SHILB_MRELOCATABLE
:
1557 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1558 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1559 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1560 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1561 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1562 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1563 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1564 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1565 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1566 && strcmp (segment_name (seg
), ".got2") != 0
1567 && strcmp (segment_name (seg
), ".dtors") != 0
1568 && strcmp (segment_name (seg
), ".ctors") != 0
1569 && strcmp (segment_name (seg
), ".fixup") != 0
1570 && strcmp (segment_name (seg
), ".stab") != 0
1571 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1572 && strcmp (segment_name (seg
), ".eh_frame") != 0
1573 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1575 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1576 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1578 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1579 _("Relocation cannot be done when using -mrelocatable"));
1585 #endif /* OBJ_ELF */
1590 * Summary of parse_toc_entry().
1592 * in: Input_line_pointer points to the '[' in one of:
1594 * [toc] [tocv] [toc32] [toc64]
1596 * Anything else is an error of one kind or another.
1599 * return value: success or failure
1600 * toc_kind: kind of toc reference
1601 * input_line_pointer:
1602 * success: first char after the ']'
1603 * failure: unchanged
1607 * [toc] - rv == success, toc_kind = default_toc
1608 * [tocv] - rv == success, toc_kind = data_in_toc
1609 * [toc32] - rv == success, toc_kind = must_be_32
1610 * [toc64] - rv == success, toc_kind = must_be_64
1614 enum toc_size_qualifier
1616 default_toc
, /* The toc cell constructed should be the system default size */
1617 data_in_toc
, /* This is a direct reference to a toc cell */
1618 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1619 must_be_64
/* The toc cell constructed must be 64 bits wide */
1623 parse_toc_entry(toc_kind
)
1624 enum toc_size_qualifier
*toc_kind
;
1629 enum toc_size_qualifier t
;
1631 /* save the input_line_pointer */
1632 start
= input_line_pointer
;
1634 /* skip over the '[' , and whitespace */
1635 ++input_line_pointer
;
1638 /* find the spelling of the operand */
1639 toc_spec
= input_line_pointer
;
1640 c
= get_symbol_end ();
1642 if (strcmp(toc_spec
, "toc") == 0)
1646 else if (strcmp(toc_spec
, "tocv") == 0)
1650 else if (strcmp(toc_spec
, "toc32") == 0)
1654 else if (strcmp(toc_spec
, "toc64") == 0)
1660 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1661 *input_line_pointer
= c
; /* put back the delimiting char */
1662 input_line_pointer
= start
; /* reset input_line pointer */
1666 /* now find the ']' */
1667 *input_line_pointer
= c
; /* put back the delimiting char */
1669 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1670 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1674 as_bad (_("syntax error: expected `]', found `%c'"), c
);
1675 input_line_pointer
= start
; /* reset input_line pointer */
1679 *toc_kind
= t
; /* set return value */
1685 /* We need to keep a list of fixups. We can't simply generate them as
1686 we go, because that would require us to first create the frag, and
1687 that would screw up references to ``.''. */
1693 bfd_reloc_code_real_type reloc
;
1696 #define MAX_INSN_FIXUPS (5)
1698 /* This routine is called for each instruction to be assembled. */
1705 const struct powerpc_opcode
*opcode
;
1707 const unsigned char *opindex_ptr
;
1711 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1716 bfd_reloc_code_real_type reloc
;
1719 /* Get the opcode. */
1720 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1725 /* Look up the opcode in the hash table. */
1726 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1727 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1729 const struct powerpc_macro
*macro
;
1731 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1732 if (macro
== (const struct powerpc_macro
*) NULL
)
1733 as_bad (_("Unrecognized opcode: `%s'"), str
);
1735 ppc_macro (s
, macro
);
1740 insn
= opcode
->opcode
;
1743 while (isspace (*str
))
1746 /* PowerPC operands are just expressions. The only real issue is
1747 that a few operand types are optional. All cases which might use
1748 an optional operand separate the operands only with commas (in
1749 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1750 cases never have optional operands). There is never more than
1751 one optional operand for an instruction. So, before we start
1752 seriously parsing the operands, we check to see if we have an
1753 optional operand, and, if we do, we count the number of commas to
1754 see whether the operand should be omitted. */
1756 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1758 const struct powerpc_operand
*operand
;
1760 operand
= &powerpc_operands
[*opindex_ptr
];
1761 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1763 unsigned int opcount
;
1765 /* There is an optional operand. Count the number of
1766 commas in the input line. */
1773 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1780 /* If there are fewer operands in the line then are called
1781 for by the instruction, we want to skip the optional
1783 if (opcount
< strlen (opcode
->operands
))
1790 /* Gather the operands. */
1794 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1796 const struct powerpc_operand
*operand
;
1802 if (next_opindex
== 0)
1803 operand
= &powerpc_operands
[*opindex_ptr
];
1806 operand
= &powerpc_operands
[next_opindex
];
1812 /* If this is a fake operand, then we do not expect anything
1814 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1816 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1817 if (errmsg
!= (const char *) NULL
)
1822 /* If this is an optional operand, and we are skipping it, just
1824 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1827 if (operand
->insert
)
1829 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1830 if (errmsg
!= (const char *) NULL
)
1833 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1834 next_opindex
= *opindex_ptr
+ 1;
1838 /* Gather the operand. */
1839 hold
= input_line_pointer
;
1840 input_line_pointer
= str
;
1843 if (*input_line_pointer
== '[')
1845 /* We are expecting something like the second argument here:
1847 lwz r4,[toc].GS.0.static_int(rtoc)
1848 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1849 The argument following the `]' must be a symbol name, and the
1850 register must be the toc register: 'rtoc' or '2'
1852 The effect is to 0 as the displacement field
1853 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1854 the appropriate variation) reloc against it based on the symbol.
1855 The linker will build the toc, and insert the resolved toc offset.
1858 o The size of the toc entry is currently assumed to be
1859 32 bits. This should not be assumed to be a hard coded
1861 o In an effort to cope with a change from 32 to 64 bits,
1862 there are also toc entries that are specified to be
1863 either 32 or 64 bits:
1864 lwz r4,[toc32].GS.0.static_int(rtoc)
1865 lwz r4,[toc64].GS.0.static_int(rtoc)
1866 These demand toc entries of the specified size, and the
1867 instruction probably requires it.
1871 enum toc_size_qualifier toc_kind
;
1872 bfd_reloc_code_real_type toc_reloc
;
1874 /* go parse off the [tocXX] part */
1875 valid_toc
= parse_toc_entry(&toc_kind
);
1879 /* Note: message has already been issued. */
1880 /* FIXME: what sort of recovery should we do? */
1881 /* demand_rest_of_line(); return; ? */
1884 /* Now get the symbol following the ']' */
1890 /* In this case, we may not have seen the symbol yet, since */
1891 /* it is allowed to appear on a .extern or .globl or just be */
1892 /* a label in the .data section. */
1893 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1896 /* 1. The symbol must be defined and either in the toc */
1897 /* section, or a global. */
1898 /* 2. The reloc generated must have the TOCDEFN flag set in */
1899 /* upper bit mess of the reloc type. */
1900 /* FIXME: It's a little confusing what the tocv qualifier can */
1901 /* be used for. At the very least, I've seen three */
1902 /* uses, only one of which I'm sure I can explain. */
1903 if (ex
.X_op
== O_symbol
)
1905 assert (ex
.X_add_symbol
!= NULL
);
1906 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
1909 as_bad(_("[tocv] symbol is not a toc symbol"));
1913 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1916 /* FIXME: these next two specifically specify 32/64 bit toc */
1917 /* entries. We don't support them today. Is this the */
1918 /* right way to say that? */
1919 toc_reloc
= BFD_RELOC_UNUSED
;
1920 as_bad (_("Unimplemented toc32 expression modifier"));
1923 /* FIXME: see above */
1924 toc_reloc
= BFD_RELOC_UNUSED
;
1925 as_bad (_("Unimplemented toc64 expression modifier"));
1929 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1935 /* We need to generate a fixup for this expression. */
1936 if (fc
>= MAX_INSN_FIXUPS
)
1937 as_fatal (_("too many fixups"));
1939 fixups
[fc
].reloc
= toc_reloc
;
1940 fixups
[fc
].exp
= ex
;
1941 fixups
[fc
].opindex
= *opindex_ptr
;
1944 /* Ok. We've set up the fixup for the instruction. Now make it
1945 look like the constant 0 was found here */
1947 ex
.X_op
= O_constant
;
1948 ex
.X_add_number
= 0;
1949 ex
.X_add_symbol
= NULL
;
1950 ex
.X_op_symbol
= NULL
;
1956 if (! register_name (&ex
))
1958 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1965 str
= input_line_pointer
;
1966 input_line_pointer
= hold
;
1968 if (ex
.X_op
== O_illegal
)
1969 as_bad (_("illegal operand"));
1970 else if (ex
.X_op
== O_absent
)
1971 as_bad (_("missing operand"));
1972 else if (ex
.X_op
== O_register
)
1974 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1977 else if (ex
.X_op
== O_constant
)
1980 /* Allow @HA, @L, @H on constants. */
1981 char *orig_str
= str
;
1983 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1990 case BFD_RELOC_LO16
:
1991 /* X_unsigned is the default, so if the user has done
1992 something which cleared it, we always produce a
1995 && (operand
->flags
& PPC_OPERAND_SIGNED
) == 0)
1996 ex
.X_add_number
&= 0xffff;
1998 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
2003 case BFD_RELOC_HI16
:
2004 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
2007 case BFD_RELOC_HI16_S
:
2008 ex
.X_add_number
= ((((ex
.X_add_number
>> 16) & 0xffff)
2009 + ((ex
.X_add_number
>> 15) & 1))
2014 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2018 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2020 /* For the absoulte forms of branchs, convert the PC relative form back into
2022 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2026 case BFD_RELOC_PPC_B26
:
2027 reloc
= BFD_RELOC_PPC_BA26
;
2029 case BFD_RELOC_PPC_B16
:
2030 reloc
= BFD_RELOC_PPC_BA16
;
2032 case BFD_RELOC_PPC_B16_BRTAKEN
:
2033 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2035 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2036 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2043 /* We need to generate a fixup for this expression. */
2044 if (fc
>= MAX_INSN_FIXUPS
)
2045 as_fatal (_("too many fixups"));
2046 fixups
[fc
].exp
= ex
;
2047 fixups
[fc
].opindex
= 0;
2048 fixups
[fc
].reloc
= reloc
;
2051 #endif /* OBJ_ELF */
2055 /* We need to generate a fixup for this expression. */
2056 if (fc
>= MAX_INSN_FIXUPS
)
2057 as_fatal (_("too many fixups"));
2058 fixups
[fc
].exp
= ex
;
2059 fixups
[fc
].opindex
= *opindex_ptr
;
2060 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2069 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2077 /* The call to expression should have advanced str past any
2080 && (endc
!= ',' || *str
!= '\0'))
2082 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2090 while (isspace (*str
))
2094 as_bad (_("junk at end of line: `%s'"), str
);
2096 /* Write out the instruction. */
2098 md_number_to_chars (f
, insn
, 4);
2100 /* Create any fixups. At this point we do not use a
2101 bfd_reloc_code_real_type, but instead just use the
2102 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2103 handle fixups for any operand type, although that is admittedly
2104 not a very exciting feature. We pick a BFD reloc type in
2106 for (i
= 0; i
< fc
; i
++)
2108 const struct powerpc_operand
*operand
;
2110 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2111 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2113 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2121 size
= bfd_get_reloc_size (reloc_howto
);
2122 offset
= target_big_endian
? (4 - size
) : 0;
2124 if (size
< 1 || size
> 4)
2127 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
2128 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
2131 /* Turn off complaints that the addend is too large for things like
2133 switch (fixups
[i
].reloc
)
2135 case BFD_RELOC_16_GOTOFF
:
2136 case BFD_RELOC_PPC_TOC16
:
2137 case BFD_RELOC_LO16
:
2138 case BFD_RELOC_HI16
:
2139 case BFD_RELOC_HI16_S
:
2140 fixP
->fx_no_overflow
= 1;
2147 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
2149 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2150 ((bfd_reloc_code_real_type
)
2151 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2155 /* Handle a macro. Gather all the operands, transform them as
2156 described by the macro, and call md_assemble recursively. All the
2157 operands are separated by commas; we don't accept parentheses
2158 around operands here. */
2161 ppc_macro (str
, macro
)
2163 const struct powerpc_macro
*macro
;
2174 /* Gather the users operands into the operands array. */
2179 if (count
>= sizeof operands
/ sizeof operands
[0])
2181 operands
[count
++] = s
;
2182 s
= strchr (s
, ',');
2183 if (s
== (char *) NULL
)
2188 if (count
!= macro
->operands
)
2190 as_bad (_("wrong number of operands"));
2194 /* Work out how large the string must be (the size is unbounded
2195 because it includes user input). */
2197 format
= macro
->format
;
2198 while (*format
!= '\0')
2207 arg
= strtol (format
+ 1, &send
, 10);
2208 know (send
!= format
&& arg
>= 0 && arg
< count
);
2209 len
+= strlen (operands
[arg
]);
2214 /* Put the string together. */
2215 complete
= s
= (char *) alloca (len
+ 1);
2216 format
= macro
->format
;
2217 while (*format
!= '\0')
2223 arg
= strtol (format
+ 1, &send
, 10);
2224 strcpy (s
, operands
[arg
]);
2231 /* Assemble the constructed instruction. */
2232 md_assemble (complete
);
2236 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2239 ppc_section_letter (letter
, ptr_msg
)
2246 *ptr_msg
= _("Bad .section directive: want a,w,x,e in string");
2251 ppc_section_word (str
, len
)
2255 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2262 ppc_section_type (str
, len
)
2266 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2273 ppc_section_flags (flags
, attr
, type
)
2278 if (type
== SHT_ORDERED
)
2279 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2281 if (attr
& SHF_EXCLUDE
)
2282 flags
|= SEC_EXCLUDE
;
2286 #endif /* OBJ_ELF */
2289 /* Pseudo-op handling. */
2291 /* The .byte pseudo-op. This is similar to the normal .byte
2292 pseudo-op, but it can also take a single ASCII string. */
2296 int ignore ATTRIBUTE_UNUSED
;
2298 if (*input_line_pointer
!= '\"')
2304 /* Gather characters. A real double quote is doubled. Unusual
2305 characters are not permitted. */
2306 ++input_line_pointer
;
2311 c
= *input_line_pointer
++;
2315 if (*input_line_pointer
!= '\"')
2317 ++input_line_pointer
;
2320 FRAG_APPEND_1_CHAR (c
);
2323 demand_empty_rest_of_line ();
2328 /* XCOFF specific pseudo-op handling. */
2330 /* This is set if we are creating a .stabx symbol, since we don't want
2331 to handle symbol suffixes for such symbols. */
2332 static boolean ppc_stab_symbol
;
2334 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2335 symbols in the .bss segment as though they were local common
2336 symbols, and uses a different smclas. */
2342 asection
*current_seg
= now_seg
;
2343 subsegT current_subseg
= now_subseg
;
2349 symbolS
*lcomm_sym
= NULL
;
2353 name
= input_line_pointer
;
2354 endc
= get_symbol_end ();
2355 end_name
= input_line_pointer
;
2358 if (*input_line_pointer
!= ',')
2360 as_bad (_("missing size"));
2361 ignore_rest_of_line ();
2364 ++input_line_pointer
;
2366 size
= get_absolute_expression ();
2369 as_bad (_("negative size"));
2370 ignore_rest_of_line ();
2376 /* The third argument to .comm is the alignment. */
2377 if (*input_line_pointer
!= ',')
2381 ++input_line_pointer
;
2382 align
= get_absolute_expression ();
2385 as_warn (_("ignoring bad alignment"));
2404 /* The third argument to .lcomm appears to be the real local
2405 common symbol to create. References to the symbol named in
2406 the first argument are turned into references to the third
2408 if (*input_line_pointer
!= ',')
2410 as_bad (_("missing real symbol name"));
2411 ignore_rest_of_line ();
2414 ++input_line_pointer
;
2416 lcomm_name
= input_line_pointer
;
2417 lcomm_endc
= get_symbol_end ();
2419 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2421 *input_line_pointer
= lcomm_endc
;
2425 sym
= symbol_find_or_make (name
);
2428 if (S_IS_DEFINED (sym
)
2429 || S_GET_VALUE (sym
) != 0)
2431 as_bad (_("attempt to redefine symbol"));
2432 ignore_rest_of_line ();
2436 record_alignment (bss_section
, align
);
2439 || ! S_IS_DEFINED (lcomm_sym
))
2448 S_SET_EXTERNAL (sym
);
2452 symbol_get_tc (lcomm_sym
)->output
= 1;
2453 def_sym
= lcomm_sym
;
2457 subseg_set (bss_section
, 1);
2458 frag_align (align
, 0, 0);
2460 symbol_set_frag (def_sym
, frag_now
);
2461 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2462 def_size
, (char *) NULL
);
2464 S_SET_SEGMENT (def_sym
, bss_section
);
2465 symbol_get_tc (def_sym
)->align
= align
;
2469 /* Align the size of lcomm_sym. */
2470 symbol_get_frag (lcomm_sym
)->fr_offset
=
2471 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
2472 &~ ((1 << align
) - 1));
2473 if (align
> symbol_get_tc (lcomm_sym
)->align
)
2474 symbol_get_tc (lcomm_sym
)->align
= align
;
2479 /* Make sym an offset from lcomm_sym. */
2480 S_SET_SEGMENT (sym
, bss_section
);
2481 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
2482 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
2483 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
2486 subseg_set (current_seg
, current_subseg
);
2488 demand_empty_rest_of_line ();
2491 /* The .csect pseudo-op. This switches us into a different
2492 subsegment. The first argument is a symbol whose value is the
2493 start of the .csect. In COFF, csect symbols get special aux
2494 entries defined by the x_csect field of union internal_auxent. The
2495 optional second argument is the alignment (the default is 2). */
2499 int ignore ATTRIBUTE_UNUSED
;
2505 name
= input_line_pointer
;
2506 endc
= get_symbol_end ();
2508 sym
= symbol_find_or_make (name
);
2510 *input_line_pointer
= endc
;
2512 if (S_GET_NAME (sym
)[0] == '\0')
2514 /* An unnamed csect is assumed to be [PR]. */
2515 symbol_get_tc (sym
)->class = XMC_PR
;
2518 ppc_change_csect (sym
);
2520 if (*input_line_pointer
== ',')
2522 ++input_line_pointer
;
2523 symbol_get_tc (sym
)->align
= get_absolute_expression ();
2526 demand_empty_rest_of_line ();
2529 /* Change to a different csect. */
2532 ppc_change_csect (sym
)
2535 if (S_IS_DEFINED (sym
))
2536 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
2544 /* This is a new csect. We need to look at the symbol class to
2545 figure out whether it should go in the text section or the
2548 switch (symbol_get_tc (sym
)->class)
2558 S_SET_SEGMENT (sym
, text_section
);
2559 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
2560 ++ppc_text_subsegment
;
2561 list_ptr
= &ppc_text_csects
;
2570 if (ppc_toc_csect
!= NULL
2571 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
2572 == ppc_data_subsegment
))
2574 S_SET_SEGMENT (sym
, data_section
);
2575 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
2576 ++ppc_data_subsegment
;
2577 list_ptr
= &ppc_data_csects
;
2583 /* We set the obstack chunk size to a small value before
2584 changing subsegments, so that we don't use a lot of memory
2585 space for what may be a small section. */
2586 hold_chunksize
= chunksize
;
2589 subseg_new (segment_name (S_GET_SEGMENT (sym
)),
2590 symbol_get_tc (sym
)->subseg
);
2592 chunksize
= hold_chunksize
;
2595 ppc_after_toc_frag
= frag_now
;
2597 symbol_set_frag (sym
, frag_now
);
2598 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2600 symbol_get_tc (sym
)->align
= (ppc_xcoff64
) ? 3 : 2;
2601 symbol_get_tc (sym
)->output
= 1;
2602 symbol_get_tc (sym
)->within
= sym
;
2604 for (list
= *list_ptr
;
2605 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
2606 list
= symbol_get_tc (list
)->next
)
2608 symbol_get_tc (list
)->next
= sym
;
2610 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2611 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
2615 ppc_current_csect
= sym
;
2618 /* This function handles the .text and .data pseudo-ops. These
2619 pseudo-ops aren't really used by XCOFF; we implement them for the
2620 convenience of people who aren't used to XCOFF. */
2631 else if (type
== 'd')
2636 sym
= symbol_find_or_make (name
);
2638 ppc_change_csect (sym
);
2640 demand_empty_rest_of_line ();
2643 /* This function handles the .section pseudo-op. This is mostly to
2644 give an error, since XCOFF only supports .text, .data and .bss, but
2645 we do permit the user to name the text or data section. */
2648 ppc_named_section (ignore
)
2649 int ignore ATTRIBUTE_UNUSED
;
2652 const char *real_name
;
2656 user_name
= input_line_pointer
;
2657 c
= get_symbol_end ();
2659 if (strcmp (user_name
, ".text") == 0)
2660 real_name
= ".text[PR]";
2661 else if (strcmp (user_name
, ".data") == 0)
2662 real_name
= ".data[RW]";
2665 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2666 *input_line_pointer
= c
;
2667 ignore_rest_of_line ();
2671 *input_line_pointer
= c
;
2673 sym
= symbol_find_or_make (real_name
);
2675 ppc_change_csect (sym
);
2677 demand_empty_rest_of_line ();
2680 /* The .extern pseudo-op. We create an undefined symbol. */
2684 int ignore ATTRIBUTE_UNUSED
;
2689 name
= input_line_pointer
;
2690 endc
= get_symbol_end ();
2692 (void) symbol_find_or_make (name
);
2694 *input_line_pointer
= endc
;
2696 demand_empty_rest_of_line ();
2699 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2703 int ignore ATTRIBUTE_UNUSED
;
2709 name
= input_line_pointer
;
2710 endc
= get_symbol_end ();
2712 sym
= symbol_find_or_make (name
);
2714 *input_line_pointer
= endc
;
2716 symbol_get_tc (sym
)->output
= 1;
2718 demand_empty_rest_of_line ();
2721 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2722 although I don't know why it bothers. */
2726 int ignore ATTRIBUTE_UNUSED
;
2733 name
= input_line_pointer
;
2734 endc
= get_symbol_end ();
2736 sym
= symbol_find_or_make (name
);
2738 *input_line_pointer
= endc
;
2740 if (*input_line_pointer
!= ',')
2742 as_bad (_("missing rename string"));
2743 ignore_rest_of_line ();
2746 ++input_line_pointer
;
2748 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
2750 demand_empty_rest_of_line ();
2753 /* The .stabx pseudo-op. This is similar to a normal .stabs
2754 pseudo-op, but slightly different. A sample is
2755 .stabx "main:F-1",.main,142,0
2756 The first argument is the symbol name to create. The second is the
2757 value, and the third is the storage class. The fourth seems to be
2758 always zero, and I am assuming it is the type. */
2762 int ignore ATTRIBUTE_UNUSED
;
2769 name
= demand_copy_C_string (&len
);
2771 if (*input_line_pointer
!= ',')
2773 as_bad (_("missing value"));
2776 ++input_line_pointer
;
2778 ppc_stab_symbol
= true;
2779 sym
= symbol_make (name
);
2780 ppc_stab_symbol
= false;
2782 symbol_get_tc (sym
)->real_name
= name
;
2784 (void) expression (&exp
);
2791 as_bad (_("illegal .stabx expression; zero assumed"));
2792 exp
.X_add_number
= 0;
2795 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2796 symbol_set_frag (sym
, &zero_address_frag
);
2800 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2801 symbol_set_value_expression (sym
, &exp
);
2805 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2806 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
2811 /* The value is some complex expression. This will probably
2812 fail at some later point, but this is probably the right
2813 thing to do here. */
2814 symbol_set_value_expression (sym
, &exp
);
2818 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2819 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
2821 if (*input_line_pointer
!= ',')
2823 as_bad (_("missing class"));
2826 ++input_line_pointer
;
2828 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2830 if (*input_line_pointer
!= ',')
2832 as_bad (_("missing type"));
2835 ++input_line_pointer
;
2837 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2839 symbol_get_tc (sym
)->output
= 1;
2841 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2842 symbol_get_tc (sym
)->within
= ppc_current_block
;
2844 if (exp
.X_op
!= O_symbol
2845 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2846 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2847 ppc_frob_label (sym
);
2850 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2851 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2852 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
2853 symbol_get_tc (ppc_current_csect
)->within
= sym
;
2856 demand_empty_rest_of_line ();
2859 /* The .function pseudo-op. This takes several arguments. The first
2860 argument seems to be the external name of the symbol. The second
2861 argment seems to be the label for the start of the function. gcc
2862 uses the same name for both. I have no idea what the third and
2863 fourth arguments are meant to be. The optional fifth argument is
2864 an expression for the size of the function. In COFF this symbol
2865 gets an aux entry like that used for a csect. */
2868 ppc_function (ignore
)
2869 int ignore ATTRIBUTE_UNUSED
;
2877 name
= input_line_pointer
;
2878 endc
= get_symbol_end ();
2880 /* Ignore any [PR] suffix. */
2881 name
= ppc_canonicalize_symbol_name (name
);
2882 s
= strchr (name
, '[');
2883 if (s
!= (char *) NULL
2884 && strcmp (s
+ 1, "PR]") == 0)
2887 ext_sym
= symbol_find_or_make (name
);
2889 *input_line_pointer
= endc
;
2891 if (*input_line_pointer
!= ',')
2893 as_bad (_("missing symbol name"));
2894 ignore_rest_of_line ();
2897 ++input_line_pointer
;
2899 name
= input_line_pointer
;
2900 endc
= get_symbol_end ();
2902 lab_sym
= symbol_find_or_make (name
);
2904 *input_line_pointer
= endc
;
2906 if (ext_sym
!= lab_sym
)
2910 exp
.X_op
= O_symbol
;
2911 exp
.X_add_symbol
= lab_sym
;
2912 exp
.X_op_symbol
= NULL
;
2913 exp
.X_add_number
= 0;
2915 symbol_set_value_expression (ext_sym
, &exp
);
2918 if (symbol_get_tc (ext_sym
)->class == -1)
2919 symbol_get_tc (ext_sym
)->class = XMC_PR
;
2920 symbol_get_tc (ext_sym
)->output
= 1;
2922 if (*input_line_pointer
== ',')
2926 /* Ignore the third argument. */
2927 ++input_line_pointer
;
2928 expression (&ignore
);
2929 if (*input_line_pointer
== ',')
2931 /* Ignore the fourth argument. */
2932 ++input_line_pointer
;
2933 expression (&ignore
);
2934 if (*input_line_pointer
== ',')
2936 /* The fifth argument is the function size. */
2937 ++input_line_pointer
;
2938 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
2941 &zero_address_frag
);
2942 pseudo_set (symbol_get_tc (ext_sym
)->size
);
2947 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2948 SF_SET_FUNCTION (ext_sym
);
2949 SF_SET_PROCESS (ext_sym
);
2950 coff_add_linesym (ext_sym
);
2952 demand_empty_rest_of_line ();
2955 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2960 int ignore ATTRIBUTE_UNUSED
;
2964 sym
= symbol_make (".bf");
2965 S_SET_SEGMENT (sym
, text_section
);
2966 symbol_set_frag (sym
, frag_now
);
2967 S_SET_VALUE (sym
, frag_now_fix ());
2968 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2970 coff_line_base
= get_absolute_expression ();
2972 S_SET_NUMBER_AUXILIARY (sym
, 1);
2973 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2975 symbol_get_tc (sym
)->output
= 1;
2977 ppc_frob_label (sym
);
2979 demand_empty_rest_of_line ();
2982 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2983 ".ef", except that the line number is absolute, not relative to the
2984 most recent ".bf" symbol. */
2988 int ignore ATTRIBUTE_UNUSED
;
2992 sym
= symbol_make (".ef");
2993 S_SET_SEGMENT (sym
, text_section
);
2994 symbol_set_frag (sym
, frag_now
);
2995 S_SET_VALUE (sym
, frag_now_fix ());
2996 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2997 S_SET_NUMBER_AUXILIARY (sym
, 1);
2998 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2999 symbol_get_tc (sym
)->output
= 1;
3001 ppc_frob_label (sym
);
3003 demand_empty_rest_of_line ();
3006 /* The .bi and .ei pseudo-ops. These take a string argument and
3007 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3014 static symbolS
*last_biei
;
3021 name
= demand_copy_C_string (&len
);
3023 /* The value of these symbols is actually file offset. Here we set
3024 the value to the index into the line number entries. In
3025 ppc_frob_symbols we set the fix_line field, which will cause BFD
3026 to do the right thing. */
3028 sym
= symbol_make (name
);
3029 /* obj-coff.c currently only handles line numbers correctly in the
3031 S_SET_SEGMENT (sym
, text_section
);
3032 S_SET_VALUE (sym
, coff_n_line_nos
);
3033 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3035 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3036 symbol_get_tc (sym
)->output
= 1;
3038 for (look
= last_biei
? last_biei
: symbol_rootP
;
3039 (look
!= (symbolS
*) NULL
3040 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3041 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3042 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3043 look
= symbol_next (look
))
3045 if (look
!= (symbolS
*) NULL
)
3047 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3048 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3052 demand_empty_rest_of_line ();
3055 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3056 There is one argument, which is a csect symbol. The value of the
3057 .bs symbol is the index of this csect symbol. */
3061 int ignore ATTRIBUTE_UNUSED
;
3068 if (ppc_current_block
!= NULL
)
3069 as_bad (_("nested .bs blocks"));
3071 name
= input_line_pointer
;
3072 endc
= get_symbol_end ();
3074 csect
= symbol_find_or_make (name
);
3076 *input_line_pointer
= endc
;
3078 sym
= symbol_make (".bs");
3079 S_SET_SEGMENT (sym
, now_seg
);
3080 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3081 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3082 symbol_get_tc (sym
)->output
= 1;
3084 symbol_get_tc (sym
)->within
= csect
;
3086 ppc_frob_label (sym
);
3088 ppc_current_block
= sym
;
3090 demand_empty_rest_of_line ();
3093 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3097 int ignore ATTRIBUTE_UNUSED
;
3101 if (ppc_current_block
== NULL
)
3102 as_bad (_(".es without preceding .bs"));
3104 sym
= symbol_make (".es");
3105 S_SET_SEGMENT (sym
, now_seg
);
3106 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3107 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3108 symbol_get_tc (sym
)->output
= 1;
3110 ppc_frob_label (sym
);
3112 ppc_current_block
= NULL
;
3114 demand_empty_rest_of_line ();
3117 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3122 int ignore ATTRIBUTE_UNUSED
;
3126 sym
= symbol_make (".bb");
3127 S_SET_SEGMENT (sym
, text_section
);
3128 symbol_set_frag (sym
, frag_now
);
3129 S_SET_VALUE (sym
, frag_now_fix ());
3130 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3132 S_SET_NUMBER_AUXILIARY (sym
, 1);
3133 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3135 symbol_get_tc (sym
)->output
= 1;
3137 SF_SET_PROCESS (sym
);
3139 ppc_frob_label (sym
);
3141 demand_empty_rest_of_line ();
3144 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3149 int ignore ATTRIBUTE_UNUSED
;
3153 sym
= symbol_make (".eb");
3154 S_SET_SEGMENT (sym
, text_section
);
3155 symbol_set_frag (sym
, frag_now
);
3156 S_SET_VALUE (sym
, frag_now_fix ());
3157 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3158 S_SET_NUMBER_AUXILIARY (sym
, 1);
3159 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3160 symbol_get_tc (sym
)->output
= 1;
3162 SF_SET_PROCESS (sym
);
3164 ppc_frob_label (sym
);
3166 demand_empty_rest_of_line ();
3169 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3174 int ignore ATTRIBUTE_UNUSED
;
3180 name
= demand_copy_C_string (&len
);
3181 sym
= symbol_make (name
);
3182 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3183 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3184 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3185 S_SET_VALUE (sym
, 0);
3186 symbol_get_tc (sym
)->output
= 1;
3188 ppc_frob_label (sym
);
3190 demand_empty_rest_of_line ();
3193 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3197 int ignore ATTRIBUTE_UNUSED
;
3201 sym
= symbol_make (".ec");
3202 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3203 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3204 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3205 S_SET_VALUE (sym
, 0);
3206 symbol_get_tc (sym
)->output
= 1;
3208 ppc_frob_label (sym
);
3210 demand_empty_rest_of_line ();
3213 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3217 int ignore ATTRIBUTE_UNUSED
;
3219 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3220 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3227 subseg
= ppc_data_subsegment
;
3228 ++ppc_data_subsegment
;
3230 subseg_new (segment_name (data_section
), subseg
);
3231 ppc_toc_frag
= frag_now
;
3233 sym
= symbol_find_or_make ("TOC[TC0]");
3234 symbol_set_frag (sym
, frag_now
);
3235 S_SET_SEGMENT (sym
, data_section
);
3236 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3237 symbol_get_tc (sym
)->subseg
= subseg
;
3238 symbol_get_tc (sym
)->output
= 1;
3239 symbol_get_tc (sym
)->within
= sym
;
3241 ppc_toc_csect
= sym
;
3243 for (list
= ppc_data_csects
;
3244 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3245 list
= symbol_get_tc (list
)->next
)
3247 symbol_get_tc (list
)->next
= sym
;
3249 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3250 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3254 ppc_current_csect
= ppc_toc_csect
;
3256 demand_empty_rest_of_line ();
3259 /* The AIX assembler automatically aligns the operands of a .long or
3260 .short pseudo-op, and we want to be compatible. */
3263 ppc_xcoff_cons (log_size
)
3266 frag_align (log_size
, 0, 0);
3267 record_alignment (now_seg
, log_size
);
3268 cons (1 << log_size
);
3273 int dummy ATTRIBUTE_UNUSED
;
3275 discard_rest_of_line();
3276 /* What does aix use this for? */
3281 int dummy ATTRIBUTE_UNUSED
;
3286 (void) expression (&exp
);
3288 if (exp
.X_op
!= O_constant
)
3290 as_bad (_("non-constant byte count"));
3294 byte_count
= exp
.X_add_number
;
3296 if (*input_line_pointer
!= ',')
3298 as_bad (_("missing value"));
3302 ++input_line_pointer
;
3306 #endif /* OBJ_XCOFF */
3308 /* The .tc pseudo-op. This is used when generating either XCOFF or
3309 ELF. This takes two or more arguments.
3311 When generating XCOFF output, the first argument is the name to
3312 give to this location in the toc; this will be a symbol with class
3313 TC. The rest of the arguments are 4 byte values to actually put at
3314 this location in the TOC; often there is just one more argument, a
3315 relocateable symbol reference.
3317 When not generating XCOFF output, the arguments are the same, but
3318 the first argument is simply ignored. */
3322 int ignore ATTRIBUTE_UNUSED
;
3326 /* Define the TOC symbol name. */
3332 if (ppc_toc_csect
== (symbolS
*) NULL
3333 || ppc_toc_csect
!= ppc_current_csect
)
3335 as_bad (_(".tc not in .toc section"));
3336 ignore_rest_of_line ();
3340 name
= input_line_pointer
;
3341 endc
= get_symbol_end ();
3343 sym
= symbol_find_or_make (name
);
3345 *input_line_pointer
= endc
;
3347 if (S_IS_DEFINED (sym
))
3351 label
= symbol_get_tc (ppc_current_csect
)->within
;
3352 if (symbol_get_tc (label
)->class != XMC_TC0
)
3354 as_bad (_(".tc with no label"));
3355 ignore_rest_of_line ();
3359 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3360 symbol_set_frag (label
, symbol_get_frag (sym
));
3361 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3363 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3364 ++input_line_pointer
;
3369 S_SET_SEGMENT (sym
, now_seg
);
3370 symbol_set_frag (sym
, frag_now
);
3371 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3372 symbol_get_tc (sym
)->class = XMC_TC
;
3373 symbol_get_tc (sym
)->output
= 1;
3375 ppc_frob_label (sym
);
3378 #else /* ! defined (OBJ_XCOFF) */
3380 /* Skip the TOC symbol name. */
3381 while (is_part_of_name (*input_line_pointer
)
3382 || *input_line_pointer
== '['
3383 || *input_line_pointer
== ']'
3384 || *input_line_pointer
== '{'
3385 || *input_line_pointer
== '}')
3386 ++input_line_pointer
;
3388 /* Align to a four byte boundary. */
3389 frag_align (2, 0, 0);
3390 record_alignment (now_seg
, 2);
3392 #endif /* ! defined (OBJ_XCOFF) */
3394 if (*input_line_pointer
!= ',')
3395 demand_empty_rest_of_line ();
3398 ++input_line_pointer
;
3399 cons ((ppc_size
== PPC_OPCODE_64
) ? 8 : 4);
3405 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3407 /* Set the current section. */
3409 ppc_set_current_section (new)
3412 ppc_previous_section
= ppc_current_section
;
3413 ppc_current_section
= new;
3416 /* pseudo-op: .previous
3417 behaviour: toggles the current section with the previous section.
3419 warnings: "No previous section"
3422 ppc_previous(ignore
)
3423 int ignore ATTRIBUTE_UNUSED
;
3427 if (ppc_previous_section
== NULL
)
3429 as_warn(_("No previous section to return to. Directive ignored."));
3433 subseg_set(ppc_previous_section
, 0);
3435 ppc_set_current_section(ppc_previous_section
);
3438 /* pseudo-op: .pdata
3439 behaviour: predefined read only data section
3443 initial: .section .pdata "adr3"
3444 a - don't know -- maybe a misprint
3445 d - initialized data
3447 3 - double word aligned (that would be 4 byte boundary)
3450 Tag index tables (also known as the function table) for exception
3451 handling, debugging, etc.
3456 int ignore ATTRIBUTE_UNUSED
;
3458 if (pdata_section
== 0)
3460 pdata_section
= subseg_new (".pdata", 0);
3462 bfd_set_section_flags (stdoutput
, pdata_section
,
3463 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3464 | SEC_READONLY
| SEC_DATA
));
3466 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3470 pdata_section
= subseg_new(".pdata", 0);
3472 ppc_set_current_section(pdata_section
);
3475 /* pseudo-op: .ydata
3476 behaviour: predefined read only data section
3480 initial: .section .ydata "drw3"
3481 a - don't know -- maybe a misprint
3482 d - initialized data
3484 3 - double word aligned (that would be 4 byte boundary)
3486 Tag tables (also known as the scope table) for exception handling,
3491 int ignore ATTRIBUTE_UNUSED
;
3493 if (ydata_section
== 0)
3495 ydata_section
= subseg_new (".ydata", 0);
3496 bfd_set_section_flags (stdoutput
, ydata_section
,
3497 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3498 | SEC_READONLY
| SEC_DATA
));
3500 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3504 ydata_section
= subseg_new (".ydata", 0);
3506 ppc_set_current_section(ydata_section
);
3509 /* pseudo-op: .reldata
3510 behaviour: predefined read write data section
3511 double word aligned (4-byte)
3512 FIXME: relocation is applied to it
3513 FIXME: what's the difference between this and .data?
3516 initial: .section .reldata "drw3"
3517 d - initialized data
3520 3 - double word aligned (that would be 8 byte boundary)
3523 Like .data, but intended to hold data subject to relocation, such as
3524 function descriptors, etc.
3528 int ignore ATTRIBUTE_UNUSED
;
3530 if (reldata_section
== 0)
3532 reldata_section
= subseg_new (".reldata", 0);
3534 bfd_set_section_flags (stdoutput
, reldata_section
,
3535 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3538 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3542 reldata_section
= subseg_new (".reldata", 0);
3544 ppc_set_current_section(reldata_section
);
3547 /* pseudo-op: .rdata
3548 behaviour: predefined read only data section
3552 initial: .section .rdata "dr3"
3553 d - initialized data
3555 3 - double word aligned (that would be 4 byte boundary)
3559 int ignore ATTRIBUTE_UNUSED
;
3561 if (rdata_section
== 0)
3563 rdata_section
= subseg_new (".rdata", 0);
3564 bfd_set_section_flags (stdoutput
, rdata_section
,
3565 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3566 | SEC_READONLY
| SEC_DATA
));
3568 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3572 rdata_section
= subseg_new (".rdata", 0);
3574 ppc_set_current_section(rdata_section
);
3577 /* pseudo-op: .ualong
3578 behaviour: much like .int, with the exception that no alignment is
3580 FIXME: test the alignment statement
3586 int ignore ATTRIBUTE_UNUSED
;
3592 /* pseudo-op: .znop <symbol name>
3593 behaviour: Issue a nop instruction
3594 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3595 the supplied symbol name.
3597 warnings: Missing symbol name
3601 int ignore ATTRIBUTE_UNUSED
;
3604 const struct powerpc_opcode
*opcode
;
3610 /* Strip out the symbol name */
3618 symbol_name
= input_line_pointer
;
3619 c
= get_symbol_end ();
3621 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3622 strcpy (name
, symbol_name
);
3624 sym
= symbol_find_or_make (name
);
3626 *input_line_pointer
= c
;
3630 /* Look up the opcode in the hash table. */
3631 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3633 /* stick in the nop */
3634 insn
= opcode
->opcode
;
3636 /* Write out the instruction. */
3638 md_number_to_chars (f
, insn
, 4);
3640 f
- frag_now
->fr_literal
,
3645 BFD_RELOC_16_GOT_PCREL
);
3658 register char *name
;
3662 register symbolS
*symbolP
;
3665 name
= input_line_pointer
;
3666 c
= get_symbol_end ();
3668 /* just after name is now '\0' */
3669 p
= input_line_pointer
;
3672 if (*input_line_pointer
!= ',')
3674 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3675 ignore_rest_of_line ();
3679 input_line_pointer
++; /* skip ',' */
3680 if ((temp
= get_absolute_expression ()) < 0)
3682 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
3683 ignore_rest_of_line ();
3689 /* The third argument to .comm is the alignment. */
3690 if (*input_line_pointer
!= ',')
3694 ++input_line_pointer
;
3695 align
= get_absolute_expression ();
3698 as_warn (_("ignoring bad alignment"));
3705 symbolP
= symbol_find_or_make (name
);
3708 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3710 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3711 S_GET_NAME (symbolP
));
3712 ignore_rest_of_line ();
3716 if (S_GET_VALUE (symbolP
))
3718 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3719 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3720 S_GET_NAME (symbolP
),
3721 (long) S_GET_VALUE (symbolP
),
3726 S_SET_VALUE (symbolP
, (valueT
) temp
);
3727 S_SET_EXTERNAL (symbolP
);
3730 demand_empty_rest_of_line ();
3734 * implement the .section pseudo op:
3735 * .section name {, "flags"}
3737 * | +--- optional flags: 'b' for bss
3739 * +-- section name 'l' for lib
3743 * 'd' (apparently m88k for data)
3745 * But if the argument is not a quoted string, treat it as a
3746 * subsegment number.
3748 * FIXME: this is a copy of the section processing from obj-coff.c, with
3749 * additions/changes for the moto-pas assembler support. There are three
3752 * FIXME: I just noticed this. This doesn't work at all really. It it
3753 * setting bits that bfd probably neither understands or uses. The
3754 * correct approach (?) will have to incorporate extra fields attached
3755 * to the section to hold the system specific stuff. (krk)
3758 * 'a' - unknown - referred to in documentation, but no definition supplied
3759 * 'c' - section has code
3760 * 'd' - section has initialized data
3761 * 'u' - section has uninitialized data
3762 * 'i' - section contains directives (info)
3763 * 'n' - section can be discarded
3764 * 'R' - remove section at link time
3766 * Section Protection:
3767 * 'r' - section is readable
3768 * 'w' - section is writeable
3769 * 'x' - section is executable
3770 * 's' - section is sharable
3772 * Section Alignment:
3773 * '0' - align to byte boundary
3774 * '1' - align to halfword undary
3775 * '2' - align to word boundary
3776 * '3' - align to doubleword boundary
3777 * '4' - align to quadword boundary
3778 * '5' - align to 32 byte boundary
3779 * '6' - align to 64 byte boundary
3784 ppc_pe_section (ignore
)
3785 int ignore ATTRIBUTE_UNUSED
;
3787 /* Strip out the section name */
3796 section_name
= input_line_pointer
;
3797 c
= get_symbol_end ();
3799 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3800 strcpy (name
, section_name
);
3802 *input_line_pointer
= c
;
3807 flags
= SEC_NO_FLAGS
;
3809 if (strcmp (name
, ".idata$2") == 0)
3813 else if (strcmp (name
, ".idata$3") == 0)
3817 else if (strcmp (name
, ".idata$4") == 0)
3821 else if (strcmp (name
, ".idata$5") == 0)
3825 else if (strcmp (name
, ".idata$6") == 0)
3830 align
= 4; /* default alignment to 16 byte boundary */
3832 if (*input_line_pointer
== ',')
3834 ++input_line_pointer
;
3836 if (*input_line_pointer
!= '"')
3837 exp
= get_absolute_expression ();
3840 ++input_line_pointer
;
3841 while (*input_line_pointer
!= '"'
3842 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3844 switch (*input_line_pointer
)
3846 /* Section Contents */
3847 case 'a': /* unknown */
3848 as_bad (_("Unsupported section attribute -- 'a'"));
3850 case 'c': /* code section */
3853 case 'd': /* section has initialized data */
3856 case 'u': /* section has uninitialized data */
3857 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3861 case 'i': /* section contains directives (info) */
3862 /* FIXME: This is IMAGE_SCN_LNK_INFO
3864 flags
|= SEC_HAS_CONTENTS
;
3866 case 'n': /* section can be discarded */
3869 case 'R': /* Remove section at link time */
3870 flags
|= SEC_NEVER_LOAD
;
3873 /* Section Protection */
3874 case 'r': /* section is readable */
3875 flags
|= IMAGE_SCN_MEM_READ
;
3877 case 'w': /* section is writeable */
3878 flags
|= IMAGE_SCN_MEM_WRITE
;
3880 case 'x': /* section is executable */
3881 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3883 case 's': /* section is sharable */
3884 flags
|= IMAGE_SCN_MEM_SHARED
;
3887 /* Section Alignment */
3888 case '0': /* align to byte boundary */
3889 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3892 case '1': /* align to halfword boundary */
3893 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3896 case '2': /* align to word boundary */
3897 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3900 case '3': /* align to doubleword boundary */
3901 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3904 case '4': /* align to quadword boundary */
3905 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3908 case '5': /* align to 32 byte boundary */
3909 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3912 case '6': /* align to 64 byte boundary */
3913 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3918 as_bad(_("unknown section attribute '%c'"),
3919 *input_line_pointer
);
3922 ++input_line_pointer
;
3924 if (*input_line_pointer
== '"')
3925 ++input_line_pointer
;
3929 sec
= subseg_new (name
, (subsegT
) exp
);
3931 ppc_set_current_section(sec
);
3933 if (flags
!= SEC_NO_FLAGS
)
3935 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3936 as_bad (_("error setting flags for \"%s\": %s"),
3937 bfd_section_name (stdoutput
, sec
),
3938 bfd_errmsg (bfd_get_error ()));
3941 bfd_set_section_alignment(stdoutput
, sec
, align
);
3946 ppc_pe_function (ignore
)
3947 int ignore ATTRIBUTE_UNUSED
;
3953 name
= input_line_pointer
;
3954 endc
= get_symbol_end ();
3956 ext_sym
= symbol_find_or_make (name
);
3958 *input_line_pointer
= endc
;
3960 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3961 SF_SET_FUNCTION (ext_sym
);
3962 SF_SET_PROCESS (ext_sym
);
3963 coff_add_linesym (ext_sym
);
3965 demand_empty_rest_of_line ();
3969 ppc_pe_tocd (ignore
)
3970 int ignore ATTRIBUTE_UNUSED
;
3972 if (tocdata_section
== 0)
3974 tocdata_section
= subseg_new (".tocd", 0);
3975 /* FIXME: section flags won't work */
3976 bfd_set_section_flags (stdoutput
, tocdata_section
,
3977 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3978 | SEC_READONLY
| SEC_DATA
));
3980 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3984 rdata_section
= subseg_new (".tocd", 0);
3987 ppc_set_current_section(tocdata_section
);
3989 demand_empty_rest_of_line ();
3992 /* Don't adjust TOC relocs to use the section symbol. */
3995 ppc_pe_fix_adjustable (fix
)
3998 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4005 /* XCOFF specific symbol and file handling. */
4007 /* Canonicalize the symbol name. We use the to force the suffix, if
4008 any, to use square brackets, and to be in upper case. */
4011 ppc_canonicalize_symbol_name (name
)
4016 if (ppc_stab_symbol
)
4019 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4033 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4037 if (*s
== '\0' || s
[1] != '\0')
4038 as_bad (_("bad symbol suffix"));
4046 /* Set the class of a symbol based on the suffix, if any. This is
4047 called whenever a new symbol is created. */
4050 ppc_symbol_new_hook (sym
)
4053 struct ppc_tc_sy
*tc
;
4056 tc
= symbol_get_tc (sym
);
4060 tc
->real_name
= NULL
;
4066 if (ppc_stab_symbol
)
4069 s
= strchr (S_GET_NAME (sym
), '[');
4070 if (s
== (const char *) NULL
)
4072 /* There is no suffix. */
4081 if (strcmp (s
, "BS]") == 0)
4085 if (strcmp (s
, "DB]") == 0)
4087 else if (strcmp (s
, "DS]") == 0)
4091 if (strcmp (s
, "GL]") == 0)
4095 if (strcmp (s
, "PR]") == 0)
4099 if (strcmp (s
, "RO]") == 0)
4101 else if (strcmp (s
, "RW]") == 0)
4105 if (strcmp (s
, "SV]") == 0)
4109 if (strcmp (s
, "TC]") == 0)
4111 else if (strcmp (s
, "TI]") == 0)
4113 else if (strcmp (s
, "TB]") == 0)
4115 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4116 tc
->class = XMC_TC0
;
4119 if (strcmp (s
, "UA]") == 0)
4121 else if (strcmp (s
, "UC]") == 0)
4125 if (strcmp (s
, "XO]") == 0)
4130 if (tc
->class == -1)
4131 as_bad (_("Unrecognized symbol suffix"));
4134 /* Set the class of a label based on where it is defined. This
4135 handles symbols without suffixes. Also, move the symbol so that it
4136 follows the csect symbol. */
4139 ppc_frob_label (sym
)
4142 if (ppc_current_csect
!= (symbolS
*) NULL
)
4144 if (symbol_get_tc (sym
)->class == -1)
4145 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4147 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4148 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4149 &symbol_rootP
, &symbol_lastP
);
4150 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4154 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4155 seen. It tells ppc_adjust_symtab whether it needs to look through
4158 static boolean ppc_saw_abs
;
4160 /* Change the name of a symbol just before writing it out. Set the
4161 real name if the .rename pseudo-op was used. Otherwise, remove any
4162 class suffix. Return 1 if the symbol should not be included in the
4166 ppc_frob_symbol (sym
)
4169 static symbolS
*ppc_last_function
;
4170 static symbolS
*set_end
;
4172 /* Discard symbols that should not be included in the output symbol
4174 if (! symbol_used_in_reloc_p (sym
)
4175 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4176 || (! S_IS_EXTERNAL (sym
)
4177 && ! symbol_get_tc (sym
)->output
4178 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4181 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4182 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4188 name
= S_GET_NAME (sym
);
4189 s
= strchr (name
, '[');
4190 if (s
!= (char *) NULL
)
4196 snew
= xmalloc (len
+ 1);
4197 memcpy (snew
, name
, len
);
4200 S_SET_NAME (sym
, snew
);
4204 if (set_end
!= (symbolS
*) NULL
)
4206 SA_SET_SYM_ENDNDX (set_end
, sym
);
4210 if (SF_GET_FUNCTION (sym
))
4212 if (ppc_last_function
!= (symbolS
*) NULL
)
4213 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4214 ppc_last_function
= sym
;
4215 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4217 resolve_symbol_value (symbol_get_tc (sym
)->size
, 1);
4218 SA_SET_SYM_FSIZE (sym
,
4219 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4222 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4223 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4225 if (ppc_last_function
== (symbolS
*) NULL
)
4226 as_bad (_(".ef with no preceding .function"));
4229 set_end
= ppc_last_function
;
4230 ppc_last_function
= NULL
;
4232 /* We don't have a C_EFCN symbol, but we need to force the
4233 COFF backend to believe that it has seen one. */
4234 coff_last_function
= NULL
;
4238 if (! S_IS_EXTERNAL (sym
)
4239 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4240 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4241 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4242 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4243 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4244 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4245 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4246 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4247 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4248 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4250 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4251 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4254 union internal_auxent
*a
;
4256 /* Create a csect aux. */
4257 i
= S_GET_NUMBER_AUXILIARY (sym
);
4258 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4259 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4260 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4262 /* This is the TOC table. */
4263 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4264 a
->x_csect
.x_scnlen
.l
= 0;
4265 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4267 else if (symbol_get_tc (sym
)->subseg
!= 0)
4269 /* This is a csect symbol. x_scnlen is the size of the
4271 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4272 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4273 S_GET_SEGMENT (sym
))
4274 - S_GET_VALUE (sym
));
4277 resolve_symbol_value (symbol_get_tc (sym
)->next
, 1);
4278 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4279 - S_GET_VALUE (sym
));
4281 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4283 else if (S_GET_SEGMENT (sym
) == bss_section
)
4285 /* This is a common symbol. */
4286 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4287 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4288 if (S_IS_EXTERNAL (sym
))
4289 symbol_get_tc (sym
)->class = XMC_RW
;
4291 symbol_get_tc (sym
)->class = XMC_BS
;
4293 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4295 /* This is an absolute symbol. The csect will be created by
4296 ppc_adjust_symtab. */
4298 a
->x_csect
.x_smtyp
= XTY_LD
;
4299 if (symbol_get_tc (sym
)->class == -1)
4300 symbol_get_tc (sym
)->class = XMC_XO
;
4302 else if (! S_IS_DEFINED (sym
))
4304 /* This is an external symbol. */
4305 a
->x_csect
.x_scnlen
.l
= 0;
4306 a
->x_csect
.x_smtyp
= XTY_ER
;
4308 else if (symbol_get_tc (sym
)->class == XMC_TC
)
4312 /* This is a TOC definition. x_scnlen is the size of the
4314 next
= symbol_next (sym
);
4315 while (symbol_get_tc (next
)->class == XMC_TC0
)
4316 next
= symbol_next (next
);
4317 if (next
== (symbolS
*) NULL
4318 || symbol_get_tc (next
)->class != XMC_TC
)
4320 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4321 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4323 - S_GET_VALUE (sym
));
4325 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4326 - S_GET_VALUE (sym
));
4330 resolve_symbol_value (next
, 1);
4331 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4332 - S_GET_VALUE (sym
));
4334 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4340 /* This is a normal symbol definition. x_scnlen is the
4341 symbol index of the containing csect. */
4342 if (S_GET_SEGMENT (sym
) == text_section
)
4343 csect
= ppc_text_csects
;
4344 else if (S_GET_SEGMENT (sym
) == data_section
)
4345 csect
= ppc_data_csects
;
4349 /* Skip the initial dummy symbol. */
4350 csect
= symbol_get_tc (csect
)->next
;
4352 if (csect
== (symbolS
*) NULL
)
4354 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4355 a
->x_csect
.x_scnlen
.l
= 0;
4359 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
4361 resolve_symbol_value (symbol_get_tc (csect
)->next
, 1);
4362 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
4363 > S_GET_VALUE (sym
))
4365 csect
= symbol_get_tc (csect
)->next
;
4368 a
->x_csect
.x_scnlen
.p
=
4369 coffsymbol (symbol_get_bfdsym (csect
))->native
;
4370 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
4373 a
->x_csect
.x_smtyp
= XTY_LD
;
4376 a
->x_csect
.x_parmhash
= 0;
4377 a
->x_csect
.x_snhash
= 0;
4378 if (symbol_get_tc (sym
)->class == -1)
4379 a
->x_csect
.x_smclas
= XMC_PR
;
4381 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
4382 a
->x_csect
.x_stab
= 0;
4383 a
->x_csect
.x_snstab
= 0;
4385 /* Don't let the COFF backend resort these symbols. */
4386 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
4388 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4390 /* We want the value to be the symbol index of the referenced
4391 csect symbol. BFD will do that for us if we set the right
4395 coffsymbol (symbol_get_bfdsym
4396 (symbol_get_tc (sym
)->within
))->native
));
4397 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
4399 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4404 /* The value is the offset from the enclosing csect. */
4405 block
= symbol_get_tc (sym
)->within
;
4406 csect
= symbol_get_tc (block
)->within
;
4407 resolve_symbol_value (csect
, 1);
4408 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4410 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4411 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4413 /* We want the value to be a file offset into the line numbers.
4414 BFD will do that for us if we set the right flags. We have
4415 already set the value correctly. */
4416 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
4422 /* Adjust the symbol table. This creates csect symbols for all
4423 absolute symbols. */
4426 ppc_adjust_symtab ()
4433 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4437 union internal_auxent
*a
;
4439 if (S_GET_SEGMENT (sym
) != absolute_section
)
4442 csect
= symbol_create (".abs[XO]", absolute_section
,
4443 S_GET_VALUE (sym
), &zero_address_frag
);
4444 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
4445 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4446 i
= S_GET_NUMBER_AUXILIARY (csect
);
4447 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4448 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
4449 a
->x_csect
.x_scnlen
.l
= 0;
4450 a
->x_csect
.x_smtyp
= XTY_SD
;
4451 a
->x_csect
.x_parmhash
= 0;
4452 a
->x_csect
.x_snhash
= 0;
4453 a
->x_csect
.x_smclas
= XMC_XO
;
4454 a
->x_csect
.x_stab
= 0;
4455 a
->x_csect
.x_snstab
= 0;
4457 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4459 i
= S_GET_NUMBER_AUXILIARY (sym
);
4460 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
4461 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
4462 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
4465 ppc_saw_abs
= false;
4468 /* Set the VMA for a section. This is called on all the sections in
4472 ppc_frob_section (sec
)
4475 static bfd_size_type vma
= 0;
4477 bfd_set_section_vma (stdoutput
, sec
, vma
);
4478 vma
+= bfd_section_size (stdoutput
, sec
);
4481 #endif /* OBJ_XCOFF */
4483 /* Turn a string in input_line_pointer into a floating point constant
4484 of type TYPE, and store the appropriate bytes in *LITP. The number
4485 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4486 returned, or NULL on OK. */
4489 md_atof (type
, litp
, sizep
)
4495 LITTLENUM_TYPE words
[4];
4511 return _("bad call to md_atof");
4514 t
= atof_ieee (input_line_pointer
, type
, words
);
4516 input_line_pointer
= t
;
4520 if (target_big_endian
)
4522 for (i
= 0; i
< prec
; i
++)
4524 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4530 for (i
= prec
- 1; i
>= 0; i
--)
4532 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4540 /* Write a value out to the object file, using the appropriate
4544 md_number_to_chars (buf
, val
, n
)
4549 if (target_big_endian
)
4550 number_to_chars_bigendian (buf
, val
, n
);
4552 number_to_chars_littleendian (buf
, val
, n
);
4555 /* Align a section (I don't know why this is machine dependent). */
4558 md_section_align (seg
, addr
)
4562 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4564 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4567 /* We don't have any form of relaxing. */
4570 md_estimate_size_before_relax (fragp
, seg
)
4571 fragS
*fragp ATTRIBUTE_UNUSED
;
4572 asection
*seg ATTRIBUTE_UNUSED
;
4578 /* Convert a machine dependent frag. We never generate these. */
4581 md_convert_frag (abfd
, sec
, fragp
)
4582 bfd
*abfd ATTRIBUTE_UNUSED
;
4583 asection
*sec ATTRIBUTE_UNUSED
;
4584 fragS
*fragp ATTRIBUTE_UNUSED
;
4589 /* We have no need to default values of symbols. */
4593 md_undefined_symbol (name
)
4594 char *name ATTRIBUTE_UNUSED
;
4599 /* Functions concerning relocs. */
4601 /* The location from which a PC relative jump should be calculated,
4602 given a PC relative reloc. */
4605 md_pcrel_from_section (fixp
, sec
)
4607 segT sec ATTRIBUTE_UNUSED
;
4609 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4614 /* This is called to see whether a fixup should be adjusted to use a
4615 section symbol. We take the opportunity to change a fixup against
4616 a symbol in the TOC subsegment into a reloc against the
4617 corresponding .tc symbol. */
4620 ppc_fix_adjustable (fix
)
4625 resolve_symbol_value (fix
->fx_addsy
, 1);
4626 val
= S_GET_VALUE (fix
->fx_addsy
);
4627 if (ppc_toc_csect
!= (symbolS
*) NULL
4628 && fix
->fx_addsy
!= (symbolS
*) NULL
4629 && fix
->fx_addsy
!= ppc_toc_csect
4630 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4631 && val
>= ppc_toc_frag
->fr_address
4632 && (ppc_after_toc_frag
== (fragS
*) NULL
4633 || val
< ppc_after_toc_frag
->fr_address
))
4637 for (sy
= symbol_next (ppc_toc_csect
);
4638 sy
!= (symbolS
*) NULL
;
4639 sy
= symbol_next (sy
))
4641 if (symbol_get_tc (sy
)->class == XMC_TC0
)
4643 if (symbol_get_tc (sy
)->class != XMC_TC
)
4645 resolve_symbol_value (sy
, 1);
4646 if (val
== S_GET_VALUE (sy
))
4649 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4654 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4655 _("symbol in .toc does not match any .tc"));
4658 /* Possibly adjust the reloc to be against the csect. */
4659 if (fix
->fx_addsy
!= (symbolS
*) NULL
4660 && symbol_get_tc (fix
->fx_addsy
)->subseg
== 0
4661 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC0
4662 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC
4663 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
4664 /* Don't adjust if this is a reloc in the toc section. */
4665 && (S_GET_SEGMENT (fix
->fx_addsy
) != data_section
4666 || ppc_toc_csect
== NULL
4667 || val
< ppc_toc_frag
->fr_address
4668 || (ppc_after_toc_frag
!= NULL
4669 && val
>= ppc_after_toc_frag
->fr_address
)))
4673 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4674 csect
= ppc_text_csects
;
4675 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4676 csect
= ppc_data_csects
;
4680 /* Skip the initial dummy symbol. */
4681 csect
= symbol_get_tc (csect
)->next
;
4683 if (csect
!= (symbolS
*) NULL
)
4685 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
4686 && (symbol_get_frag (symbol_get_tc (csect
)->next
)->fr_address
4689 /* If the csect address equals the symbol value, then we
4690 have to look through the full symbol table to see
4691 whether this is the csect we want. Note that we will
4692 only get here if the csect has zero length. */
4693 if ((symbol_get_frag (csect
)->fr_address
== val
)
4694 && S_GET_VALUE (csect
) == S_GET_VALUE (fix
->fx_addsy
))
4698 for (scan
= symbol_next (csect
);
4700 scan
= symbol_next (scan
))
4702 if (symbol_get_tc (scan
)->subseg
!= 0)
4704 if (scan
== fix
->fx_addsy
)
4708 /* If we found the symbol before the next csect
4709 symbol, then this is the csect we want. */
4710 if (scan
== fix
->fx_addsy
)
4714 csect
= symbol_get_tc (csect
)->next
;
4717 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4718 - symbol_get_frag (csect
)->fr_address
);
4719 fix
->fx_addsy
= csect
;
4723 /* Adjust a reloc against a .lcomm symbol to be against the base
4725 if (fix
->fx_addsy
!= (symbolS
*) NULL
4726 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4727 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4729 resolve_symbol_value (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
, 1);
4731 (S_GET_VALUE (fix
->fx_addsy
)
4732 - S_GET_VALUE (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
));
4733 fix
->fx_addsy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
4739 /* A reloc from one csect to another must be kept. The assembler
4740 will, of course, keep relocs between sections, and it will keep
4741 absolute relocs, but we need to force it to keep PC relative relocs
4742 between two csects in the same section. */
4745 ppc_force_relocation (fix
)
4748 /* At this point fix->fx_addsy should already have been converted to
4749 a csect symbol. If the csect does not include the fragment, then
4750 we need to force the relocation. */
4752 && fix
->fx_addsy
!= NULL
4753 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
4754 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
4755 > fix
->fx_frag
->fr_address
)
4756 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
4757 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
4758 <= fix
->fx_frag
->fr_address
))))
4764 #endif /* OBJ_XCOFF */
4766 /* See whether a symbol is in the TOC section. */
4769 ppc_is_toc_sym (sym
)
4773 return symbol_get_tc (sym
)->class == XMC_TC
;
4775 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4779 /* Apply a fixup to the object code. This is called for all the
4780 fixups we generated by the call to fix_new_exp, above. In the call
4781 above we used a reloc code which was the largest legal reloc code
4782 plus the operand index. Here we undo that to recover the operand
4783 index. At this point all symbol values should be fully resolved,
4784 and we attempt to completely resolve the reloc. If we can not do
4785 that, we determine the correct reloc code and put it back in the
4789 md_apply_fix3 (fixp
, valuep
, seg
)
4798 if (fixp
->fx_addsy
!= NULL
)
4800 /* `*valuep' may contain the value of the symbol on which the reloc
4801 will be based; we have to remove it. */
4802 if (symbol_used_in_reloc_p (fixp
->fx_addsy
)
4803 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
4804 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
4805 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
4806 value
-= S_GET_VALUE (fixp
->fx_addsy
);
4808 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4809 supposed to be? I think this is related to various similar
4810 FIXMEs in tc-i386.c and tc-sparc.c. */
4812 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4819 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4820 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4821 doing this relocation the code in write.c is going to call
4822 bfd_install_relocation, which is also going to use the symbol
4823 value. That means that if the reloc is fully resolved we want to
4824 use *valuep since bfd_install_relocation is not being used.
4825 However, if the reloc is not fully resolved we do not want to use
4826 *valuep, and must use fx_offset instead. However, if the reloc
4827 is PC relative, we do want to use *valuep since it includes the
4828 result of md_pcrel_from. This is confusing. */
4829 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4834 else if (fixp
->fx_pcrel
)
4838 value
= fixp
->fx_offset
;
4839 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4841 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4842 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4845 /* We can't actually support subtracting a symbol. */
4846 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4847 _("expression too complex"));
4853 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4856 const struct powerpc_operand
*operand
;
4860 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4862 operand
= &powerpc_operands
[opindex
];
4865 /* It appears that an instruction like
4867 when LC..1 is not a TOC symbol does not generate a reloc. It
4868 uses the offset of LC..1 within its csect. However, .long
4869 LC..1 will generate a reloc. I can't find any documentation
4870 on how these cases are to be distinguished, so this is a wild
4871 guess. These cases are generated by gcc -mminimal-toc. */
4872 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4873 && operand
->bits
== 16
4874 && operand
->shift
== 0
4875 && operand
->insert
== NULL
4876 && fixp
->fx_addsy
!= NULL
4877 && symbol_get_tc (fixp
->fx_addsy
)->subseg
!= 0
4878 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC
4879 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC0
4880 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4882 value
= fixp
->fx_offset
;
4887 /* Fetch the instruction, insert the fully resolved operand
4888 value, and stuff the instruction back again. */
4889 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4890 if (target_big_endian
)
4891 insn
= bfd_getb32 ((unsigned char *) where
);
4893 insn
= bfd_getl32 ((unsigned char *) where
);
4894 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4895 fixp
->fx_file
, fixp
->fx_line
);
4896 if (target_big_endian
)
4897 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4899 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4903 /* Nothing else to do here. */
4907 /* Determine a BFD reloc value based on the operand information.
4908 We are only prepared to turn a few of the operands into
4910 FIXME: We need to handle the DS field at the very least.
4911 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4912 there should be a new field in the operand table. */
4913 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4914 && operand
->bits
== 26
4915 && operand
->shift
== 0)
4916 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4917 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4918 && operand
->bits
== 16
4919 && operand
->shift
== 0)
4920 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4921 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4922 && operand
->bits
== 26
4923 && operand
->shift
== 0)
4924 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4925 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4926 && operand
->bits
== 16
4927 && operand
->shift
== 0)
4928 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4929 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4930 && operand
->bits
== 16
4931 && operand
->shift
== 0
4932 && fixp
->fx_addsy
!= NULL
4933 && ppc_is_toc_sym (fixp
->fx_addsy
))
4936 if (target_big_endian
)
4937 fixp
->fx_where
+= 2;
4938 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4945 /* Use expr_symbol_where to see if this is an expression
4947 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
4948 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4949 _("unresolved expression that must be resolved"));
4951 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4952 _("unsupported relocation type"));
4960 ppc_elf_validate_fix (fixp
, seg
);
4962 switch (fixp
->fx_r_type
)
4965 case BFD_RELOC_CTOR
:
4967 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4971 case BFD_RELOC_32_PCREL
:
4972 case BFD_RELOC_32_BASEREL
:
4973 case BFD_RELOC_PPC_EMB_NADDR32
:
4974 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4980 fixp
->fx_r_type
= BFD_RELOC_64_PCREL
;
4982 case BFD_RELOC_64_PCREL
:
4983 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4986 case BFD_RELOC_LO16
:
4988 case BFD_RELOC_GPREL16
:
4989 case BFD_RELOC_16_GOT_PCREL
:
4990 case BFD_RELOC_16_GOTOFF
:
4991 case BFD_RELOC_LO16_GOTOFF
:
4992 case BFD_RELOC_HI16_GOTOFF
:
4993 case BFD_RELOC_HI16_S_GOTOFF
:
4994 case BFD_RELOC_LO16_BASEREL
:
4995 case BFD_RELOC_HI16_BASEREL
:
4996 case BFD_RELOC_HI16_S_BASEREL
:
4997 case BFD_RELOC_PPC_EMB_NADDR16
:
4998 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
4999 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5000 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5001 case BFD_RELOC_PPC_EMB_SDAI16
:
5002 case BFD_RELOC_PPC_EMB_SDA2REL
:
5003 case BFD_RELOC_PPC_EMB_SDA2I16
:
5004 case BFD_RELOC_PPC_EMB_RELSEC16
:
5005 case BFD_RELOC_PPC_EMB_RELST_LO
:
5006 case BFD_RELOC_PPC_EMB_RELST_HI
:
5007 case BFD_RELOC_PPC_EMB_RELST_HA
:
5008 case BFD_RELOC_PPC_EMB_RELSDA
:
5009 case BFD_RELOC_PPC_TOC16
:
5012 if (fixp
->fx_addsy
!= NULL
)
5013 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5014 _("cannot emit PC relative %s relocation against %s"),
5015 bfd_get_reloc_code_name (fixp
->fx_r_type
),
5016 S_GET_NAME (fixp
->fx_addsy
));
5018 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5019 _("cannot emit PC relative %s relocation"),
5020 bfd_get_reloc_code_name (fixp
->fx_r_type
));
5023 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5027 /* This case happens when you write, for example,
5029 where L1 and L2 are defined later. */
5030 case BFD_RELOC_HI16
:
5033 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5036 case BFD_RELOC_HI16_S
:
5039 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5040 (value
+ 0x8000) >> 16, 2);
5043 /* Because SDA21 modifies the register field, the size is set to 4
5044 bytes, rather than 2, so offset it here appropriately */
5045 case BFD_RELOC_PPC_EMB_SDA21
:
5049 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
5050 + ((target_big_endian
) ? 2 : 0),
5058 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5062 case BFD_RELOC_24_PLT_PCREL
:
5063 case BFD_RELOC_PPC_LOCAL24PC
:
5064 if (!fixp
->fx_pcrel
&& !fixp
->fx_done
)
5072 /* Fetch the instruction, insert the fully resolved operand
5073 value, and stuff the instruction back again. */
5074 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5075 if (target_big_endian
)
5076 insn
= bfd_getb32 ((unsigned char *) where
);
5078 insn
= bfd_getl32 ((unsigned char *) where
);
5079 if ((value
& 3) != 0)
5080 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5081 _("must branch to an address a multiple of 4"));
5082 if ((offsetT
) value
< -0x40000000
5083 || (offsetT
) value
>= 0x40000000)
5084 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5085 _("@local or @plt branch destination is too far away, %ld bytes"),
5087 insn
= insn
| (value
& 0x03fffffc);
5088 if (target_big_endian
)
5089 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5091 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5095 case BFD_RELOC_VTABLE_INHERIT
:
5098 && !S_IS_DEFINED (fixp
->fx_addsy
)
5099 && !S_IS_WEAK (fixp
->fx_addsy
))
5100 S_SET_WEAK (fixp
->fx_addsy
);
5103 case BFD_RELOC_VTABLE_ENTRY
:
5109 _("Gas failure, reloc value %d\n"), fixp
->fx_r_type
);
5116 fixp
->fx_addnumber
= value
;
5118 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
5119 fixp
->fx_addnumber
= 0;
5123 fixp
->fx_addnumber
= 0;
5125 /* We want to use the offset within the data segment of the
5126 symbol, not the actual VMA of the symbol. */
5127 fixp
->fx_addnumber
=
5128 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
5136 /* Generate a reloc for a fixup. */
5139 tc_gen_reloc (seg
, fixp
)
5140 asection
*seg ATTRIBUTE_UNUSED
;
5145 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5147 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5148 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5149 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5150 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5151 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
5153 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5154 _("reloc %d not supported by object file format"), (int)fixp
->fx_r_type
);
5157 reloc
->addend
= fixp
->fx_addnumber
;