1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #include "opcode/ppc.h"
32 #include "dwarf2dbg.h"
39 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
41 /* Tell the main code what the endianness is. */
42 extern int target_big_endian
;
44 /* Whether or not, we've set target_big_endian. */
45 static int set_target_endian
= 0;
47 /* Whether to use user friendly register names. */
48 #ifndef TARGET_REG_NAMES_P
50 #define TARGET_REG_NAMES_P true
52 #define TARGET_REG_NAMES_P false
56 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
58 static boolean register_name
PARAMS ((expressionS
*));
59 static void ppc_set_cpu
PARAMS ((void));
60 static unsigned long ppc_insert_operand
61 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
62 offsetT val
, char *file
, unsigned int line
));
63 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
64 static void ppc_byte
PARAMS ((int));
65 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
66 static void ppc_tc
PARAMS ((int));
69 static void ppc_comm
PARAMS ((int));
70 static void ppc_bb
PARAMS ((int));
71 static void ppc_bc
PARAMS ((int));
72 static void ppc_bf
PARAMS ((int));
73 static void ppc_biei
PARAMS ((int));
74 static void ppc_bs
PARAMS ((int));
75 static void ppc_eb
PARAMS ((int));
76 static void ppc_ec
PARAMS ((int));
77 static void ppc_ef
PARAMS ((int));
78 static void ppc_es
PARAMS ((int));
79 static void ppc_csect
PARAMS ((int));
80 static void ppc_change_csect
PARAMS ((symbolS
*));
81 static void ppc_function
PARAMS ((int));
82 static void ppc_extern
PARAMS ((int));
83 static void ppc_lglobl
PARAMS ((int));
84 static void ppc_section
PARAMS ((int));
85 static void ppc_named_section
PARAMS ((int));
86 static void ppc_stabx
PARAMS ((int));
87 static void ppc_rename
PARAMS ((int));
88 static void ppc_toc
PARAMS ((int));
89 static void ppc_xcoff_cons
PARAMS ((int));
90 static void ppc_machine
PARAMS ((int));
91 static void ppc_vbyte
PARAMS ((int));
95 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
96 static void ppc_elf_cons
PARAMS ((int));
97 static void ppc_elf_rdata
PARAMS ((int));
98 static void ppc_elf_lcomm
PARAMS ((int));
99 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
103 static void ppc_set_current_section
PARAMS ((segT
));
104 static void ppc_previous
PARAMS ((int));
105 static void ppc_pdata
PARAMS ((int));
106 static void ppc_ydata
PARAMS ((int));
107 static void ppc_reldata
PARAMS ((int));
108 static void ppc_rdata
PARAMS ((int));
109 static void ppc_ualong
PARAMS ((int));
110 static void ppc_znop
PARAMS ((int));
111 static void ppc_pe_comm
PARAMS ((int));
112 static void ppc_pe_section
PARAMS ((int));
113 static void ppc_pe_function
PARAMS ((int));
114 static void ppc_pe_tocd
PARAMS ((int));
117 /* Generic assembler global variables which must be defined by all
121 /* This string holds the chars that always start a comment. If the
122 pre-processor is disabled, these aren't very useful. The macro
123 tc_comment_chars points to this. We use this, rather than the
124 usual comment_chars, so that we can switch for Solaris conventions. */
125 static const char ppc_solaris_comment_chars
[] = "#!";
126 static const char ppc_eabi_comment_chars
[] = "#";
128 #ifdef TARGET_SOLARIS_COMMENT
129 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
131 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
134 const char comment_chars
[] = "#";
137 /* Characters which start a comment at the beginning of a line. */
138 const char line_comment_chars
[] = "#";
140 /* Characters which may be used to separate multiple commands on a
142 const char line_separator_chars
[] = ";";
144 /* Characters which are used to indicate an exponent in a floating
146 const char EXP_CHARS
[] = "eE";
148 /* Characters which mean that a number is a floating point constant,
150 const char FLT_CHARS
[] = "dD";
152 /* The target specific pseudo-ops which we support. */
154 const pseudo_typeS md_pseudo_table
[] =
156 /* Pseudo-ops which must be overridden. */
157 { "byte", ppc_byte
, 0 },
160 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
161 legitimately belong in the obj-*.c file. However, XCOFF is based
162 on COFF, and is only implemented for the RS/6000. We just use
163 obj-coff.c, and add what we need here. */
164 { "comm", ppc_comm
, 0 },
165 { "lcomm", ppc_comm
, 1 },
169 { "bi", ppc_biei
, 0 },
171 { "csect", ppc_csect
, 0 },
172 { "data", ppc_section
, 'd' },
176 { "ei", ppc_biei
, 1 },
178 { "extern", ppc_extern
, 0 },
179 { "function", ppc_function
, 0 },
180 { "lglobl", ppc_lglobl
, 0 },
181 { "rename", ppc_rename
, 0 },
182 { "section", ppc_named_section
, 0 },
183 { "stabx", ppc_stabx
, 0 },
184 { "text", ppc_section
, 't' },
185 { "toc", ppc_toc
, 0 },
186 { "long", ppc_xcoff_cons
, 2 },
187 { "llong", ppc_xcoff_cons
, 3 },
188 { "word", ppc_xcoff_cons
, 1 },
189 { "short", ppc_xcoff_cons
, 1 },
190 { "vbyte", ppc_vbyte
, 0 },
191 { "machine", ppc_machine
, 0 },
195 { "long", ppc_elf_cons
, 4 },
196 { "word", ppc_elf_cons
, 2 },
197 { "short", ppc_elf_cons
, 2 },
198 { "rdata", ppc_elf_rdata
, 0 },
199 { "rodata", ppc_elf_rdata
, 0 },
200 { "lcomm", ppc_elf_lcomm
, 0 },
201 { "file", dwarf2_directive_file
, 0 },
202 { "loc", dwarf2_directive_loc
, 0 },
206 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
207 { "previous", ppc_previous
, 0 },
208 { "pdata", ppc_pdata
, 0 },
209 { "ydata", ppc_ydata
, 0 },
210 { "reldata", ppc_reldata
, 0 },
211 { "rdata", ppc_rdata
, 0 },
212 { "ualong", ppc_ualong
, 0 },
213 { "znop", ppc_znop
, 0 },
214 { "comm", ppc_pe_comm
, 0 },
215 { "lcomm", ppc_pe_comm
, 1 },
216 { "section", ppc_pe_section
, 0 },
217 { "function", ppc_pe_function
,0 },
218 { "tocd", ppc_pe_tocd
, 0 },
221 /* This pseudo-op is used even when not generating XCOFF output. */
228 /* Predefined register names if -mregnames (or default for Windows NT). */
229 /* In general, there are lots of them, in an attempt to be compatible */
230 /* with a number of other Windows NT assemblers. */
232 /* Structure to hold information about predefined registers. */
239 /* List of registers that are pre-defined:
241 Each general register has predefined names of the form:
242 1. r<reg_num> which has the value <reg_num>.
243 2. r.<reg_num> which has the value <reg_num>.
245 Each floating point register has predefined names of the form:
246 1. f<reg_num> which has the value <reg_num>.
247 2. f.<reg_num> which has the value <reg_num>.
249 Each vector unit register has predefined names of the form:
250 1. v<reg_num> which has the value <reg_num>.
251 2. v.<reg_num> which has the value <reg_num>.
253 Each condition register has predefined names of the form:
254 1. cr<reg_num> which has the value <reg_num>.
255 2. cr.<reg_num> which has the value <reg_num>.
257 There are individual registers as well:
258 sp or r.sp has the value 1
259 rtoc or r.toc has the value 2
260 fpscr has the value 0
266 dsisr has the value 18
268 sdr1 has the value 25
269 srr0 has the value 26
270 srr1 has the value 27
272 The table is sorted. Suitable for searching by a binary search. */
274 static const struct pd_reg pre_defined_registers
[] =
276 { "cr.0", 0 }, /* Condition Registers */
296 { "dar", 19 }, /* Data Access Register */
297 { "dec", 22 }, /* Decrementer */
298 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
300 { "f.0", 0 }, /* Floating point registers */
368 { "lr", 8 }, /* Link Register */
372 { "r.0", 0 }, /* General Purpose Registers */
405 { "r.sp", 1 }, /* Stack Pointer */
407 { "r.toc", 2 }, /* Pointer to the table of contents */
409 { "r0", 0 }, /* More general purpose registers */
442 { "rtoc", 2 }, /* Table of contents */
444 { "sdr1", 25 }, /* Storage Description Register 1 */
448 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
449 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
451 { "v.0", 0 }, /* Vector registers */
521 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
523 /* Given NAME, find the register number associated with that name, return
524 the integer value associated with the given name or -1 on failure. */
526 static int reg_name_search
527 PARAMS ((const struct pd_reg
*, int, const char * name
));
530 reg_name_search (regs
, regcount
, name
)
531 const struct pd_reg
*regs
;
535 int middle
, low
, high
;
543 middle
= (low
+ high
) / 2;
544 cmp
= strcasecmp (name
, regs
[middle
].name
);
550 return regs
[middle
].value
;
558 * Summary of register_name().
560 * in: Input_line_pointer points to 1st char of operand.
562 * out: A expressionS.
563 * The operand may have been a register: in this case, X_op == O_register,
564 * X_add_number is set to the register number, and truth is returned.
565 * Input_line_pointer->(next non-blank) char after operand, or is in its
570 register_name (expressionP
)
571 expressionS
*expressionP
;
578 /* Find the spelling of the operand */
579 start
= name
= input_line_pointer
;
580 if (name
[0] == '%' && isalpha (name
[1]))
581 name
= ++input_line_pointer
;
583 else if (!reg_names_p
|| !isalpha (name
[0]))
586 c
= get_symbol_end ();
587 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
589 /* look to see if it's in the register table */
592 expressionP
->X_op
= O_register
;
593 expressionP
->X_add_number
= reg_number
;
595 /* make the rest nice */
596 expressionP
->X_add_symbol
= NULL
;
597 expressionP
->X_op_symbol
= NULL
;
598 *input_line_pointer
= c
; /* put back the delimiting char */
603 /* reset the line as if we had not done anything */
604 *input_line_pointer
= c
; /* put back the delimiting char */
605 input_line_pointer
= start
; /* reset input_line pointer */
610 /* This function is called for each symbol seen in an expression. It
611 handles the special parsing which PowerPC assemblers are supposed
612 to use for condition codes. */
614 /* Whether to do the special parsing. */
615 static boolean cr_operand
;
617 /* Names to recognize in a condition code. This table is sorted. */
618 static const struct pd_reg cr_names
[] =
635 /* Parsing function. This returns non-zero if it recognized an
639 ppc_parse_name (name
, expr
)
648 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
653 expr
->X_op
= O_constant
;
654 expr
->X_add_number
= val
;
659 /* Local variables. */
661 /* The type of processor we are assembling for. This is one or more
662 of the PPC_OPCODE flags defined in opcode/ppc.h. */
663 static int ppc_cpu
= 0;
665 /* The size of the processor we are assembling for. This is either
666 PPC_OPCODE_32 or PPC_OPCODE_64. */
667 static unsigned long ppc_size
= PPC_OPCODE_32
;
669 /* Whether to target xcoff64 */
670 static int ppc_xcoff64
= 0;
672 /* Opcode hash table. */
673 static struct hash_control
*ppc_hash
;
675 /* Macro hash table. */
676 static struct hash_control
*ppc_macro_hash
;
679 /* What type of shared library support to use */
680 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
682 /* Flags to set in the elf header */
683 static flagword ppc_flags
= 0;
685 /* Whether this is Solaris or not. */
686 #ifdef TARGET_SOLARIS_COMMENT
687 #define SOLARIS_P true
689 #define SOLARIS_P false
692 static boolean msolaris
= SOLARIS_P
;
697 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
698 using a bunch of different sections. These assembler sections,
699 however, are all encompassed within the .text or .data sections of
700 the final output file. We handle this by using different
701 subsegments within these main segments. */
703 /* Next subsegment to allocate within the .text segment. */
704 static subsegT ppc_text_subsegment
= 2;
706 /* Linked list of csects in the text section. */
707 static symbolS
*ppc_text_csects
;
709 /* Next subsegment to allocate within the .data segment. */
710 static subsegT ppc_data_subsegment
= 2;
712 /* Linked list of csects in the data section. */
713 static symbolS
*ppc_data_csects
;
715 /* The current csect. */
716 static symbolS
*ppc_current_csect
;
718 /* The RS/6000 assembler uses a TOC which holds addresses of functions
719 and variables. Symbols are put in the TOC with the .tc pseudo-op.
720 A special relocation is used when accessing TOC entries. We handle
721 the TOC as a subsegment within the .data segment. We set it up if
722 we see a .toc pseudo-op, and save the csect symbol here. */
723 static symbolS
*ppc_toc_csect
;
725 /* The first frag in the TOC subsegment. */
726 static fragS
*ppc_toc_frag
;
728 /* The first frag in the first subsegment after the TOC in the .data
729 segment. NULL if there are no subsegments after the TOC. */
730 static fragS
*ppc_after_toc_frag
;
732 /* The current static block. */
733 static symbolS
*ppc_current_block
;
735 /* The COFF debugging section; set by md_begin. This is not the
736 .debug section, but is instead the secret BFD section which will
737 cause BFD to set the section number of a symbol to N_DEBUG. */
738 static asection
*ppc_coff_debug_section
;
740 #endif /* OBJ_XCOFF */
744 /* Various sections that we need for PE coff support. */
745 static segT ydata_section
;
746 static segT pdata_section
;
747 static segT reldata_section
;
748 static segT rdata_section
;
749 static segT tocdata_section
;
751 /* The current section and the previous section. See ppc_previous. */
752 static segT ppc_previous_section
;
753 static segT ppc_current_section
;
758 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
762 CONST
char *md_shortopts
= "b:l:usm:K:VQ:";
764 CONST
char *md_shortopts
= "um:";
766 struct option md_longopts
[] = {
767 {NULL
, no_argument
, NULL
, 0}
769 size_t md_longopts_size
= sizeof (md_longopts
);
772 md_parse_option (c
, arg
)
779 /* -u means that any undefined symbols should be treated as
780 external, which is the default for gas anyhow. */
785 /* Solaris as takes -le (presumably for little endian). For completeness
786 sake, recognize -be also. */
787 if (strcmp (arg
, "e") == 0)
789 target_big_endian
= 0;
790 set_target_endian
= 1;
798 if (strcmp (arg
, "e") == 0)
800 target_big_endian
= 1;
801 set_target_endian
= 1;
809 /* Recognize -K PIC */
810 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
813 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
821 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
823 if (strcmp (arg
, "64") == 0)
825 else if (strcmp (arg
, "32") == 0)
832 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
834 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
835 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
836 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
837 else if (strcmp (arg
, "pwr") == 0)
838 ppc_cpu
= PPC_OPCODE_POWER
;
839 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
840 instructions that are holdovers from the Power. */
841 else if (strcmp (arg
, "601") == 0)
842 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
843 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
844 Motorola PowerPC 603/604. */
845 else if (strcmp (arg
, "ppc") == 0
846 || strcmp (arg
, "ppc32") == 0
847 || strcmp (arg
, "403") == 0
848 || strcmp (arg
, "405") == 0
849 || strcmp (arg
, "603") == 0
850 || strcmp (arg
, "604") == 0)
851 ppc_cpu
= PPC_OPCODE_PPC
;
852 else if (strcmp (arg
, "7400") == 0)
853 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
;
854 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
856 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
858 ppc_cpu
= PPC_OPCODE_PPC
;
859 ppc_size
= PPC_OPCODE_64
;
861 else if (strcmp (arg
, "ppc64bridge") == 0)
863 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_64_BRIDGE
;
864 ppc_size
= PPC_OPCODE_64
;
866 /* -mcom means assemble for the common intersection between Power
867 and PowerPC. At present, we just allow the union, rather
868 than the intersection. */
869 else if (strcmp (arg
, "com") == 0)
870 ppc_cpu
= PPC_OPCODE_COMMON
;
871 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
872 else if (strcmp (arg
, "any") == 0)
873 ppc_cpu
= PPC_OPCODE_ANY
;
875 else if (strcmp (arg
, "regnames") == 0)
878 else if (strcmp (arg
, "no-regnames") == 0)
882 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
883 else if (strcmp (arg
, "relocatable") == 0)
885 shlib
= SHLIB_MRELOCATABLE
;
886 ppc_flags
|= EF_PPC_RELOCATABLE
;
889 else if (strcmp (arg
, "relocatable-lib") == 0)
891 shlib
= SHLIB_MRELOCATABLE
;
892 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
895 /* -memb, set embedded bit */
896 else if (strcmp (arg
, "emb") == 0)
897 ppc_flags
|= EF_PPC_EMB
;
899 /* -mlittle/-mbig set the endianess */
900 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
902 target_big_endian
= 0;
903 set_target_endian
= 1;
906 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
908 target_big_endian
= 1;
909 set_target_endian
= 1;
912 else if (strcmp (arg
, "solaris") == 0)
915 ppc_comment_chars
= ppc_solaris_comment_chars
;
918 else if (strcmp (arg
, "no-solaris") == 0)
921 ppc_comment_chars
= ppc_eabi_comment_chars
;
926 as_bad (_("invalid switch -m%s"), arg
);
932 /* -V: SVR4 argument to print version ID. */
937 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
938 should be emitted or not. FIXME: Not implemented. */
942 /* Solaris takes -s to specify that .stabs go in a .stabs section,
943 rather than .stabs.excl, which is ignored by the linker.
944 FIXME: Not implemented. */
960 md_show_usage (stream
)
963 fprintf (stream
, _("\
966 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
967 -mpwr generate code for IBM POWER (RIOS1)\n\
968 -m601 generate code for Motorola PowerPC 601\n\
969 -mppc, -mppc32, -m403, -m405, -m603, -m604\n\
970 generate code for Motorola PowerPC 603/604\n\
971 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
972 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
973 -mcom generate code Power/PowerPC common instructions\n\
974 -many generate code for any architecture (PWR/PWRX/PPC)\n\
975 -mregnames Allow symbolic names for registers\n\
976 -mno-regnames Do not allow symbolic names for registers\n"));
978 fprintf (stream
, _("\
979 -mrelocatable support for GCC's -mrelocatble option\n\
980 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
981 -memb set PPC_EMB bit in ELF flags\n\
982 -mlittle, -mlittle-endian\n\
983 generate code for a little endian machine\n\
984 -mbig, -mbig-endian generate code for a big endian machine\n\
985 -msolaris generate code for Solaris\n\
986 -mno-solaris do not generate code for Solaris\n\
987 -V print assembler version number\n\
988 -Qy, -Qn ignored\n"));
992 /* Set ppc_cpu if it is not already set. */
997 const char *default_os
= TARGET_OS
;
998 const char *default_cpu
= TARGET_CPU
;
1002 if (strncmp (default_os
, "aix", 3) == 0
1003 && default_os
[3] >= '4' && default_os
[3] <= '9')
1004 ppc_cpu
= PPC_OPCODE_COMMON
;
1005 else if (strncmp (default_os
, "aix3", 4) == 0)
1006 ppc_cpu
= PPC_OPCODE_POWER
;
1007 else if (strcmp (default_cpu
, "rs6000") == 0)
1008 ppc_cpu
= PPC_OPCODE_POWER
;
1009 else if (strcmp (default_cpu
, "powerpc") == 0
1010 || strcmp (default_cpu
, "powerpcle") == 0)
1011 ppc_cpu
= PPC_OPCODE_PPC
;
1013 as_fatal (_("Unknown default cpu = %s, os = %s"), default_cpu
, default_os
);
1017 /* Figure out the BFD architecture to use. */
1019 enum bfd_architecture
1022 const char *default_cpu
= TARGET_CPU
;
1025 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1026 return bfd_arch_powerpc
;
1027 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1028 return bfd_arch_rs6000
;
1029 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1031 if (strcmp (default_cpu
, "rs6000") == 0)
1032 return bfd_arch_rs6000
;
1033 else if (strcmp (default_cpu
, "powerpc") == 0
1034 || strcmp (default_cpu
, "powerpcle") == 0)
1035 return bfd_arch_powerpc
;
1038 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1039 return bfd_arch_unknown
;
1045 return (ppc_size
== PPC_OPCODE_64
) ? 620 : 0;
1051 return (ppc_xcoff64
) ? 3 : 2;
1059 return (target_big_endian
? "pe-powerpc" : "pe-powerpcle");
1062 return (ppc_xcoff64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1065 return "xcoff-powermac";
1069 return (target_big_endian
? "elf32-powerpc" : "elf32-powerpcle");
1073 /* This function is called when the assembler starts up. It is called
1074 after the options have been parsed and the output file has been
1080 register const struct powerpc_opcode
*op
;
1081 const struct powerpc_opcode
*op_end
;
1082 const struct powerpc_macro
*macro
;
1083 const struct powerpc_macro
*macro_end
;
1084 boolean dup_insn
= false;
1089 /* Set the ELF flags if desired. */
1090 if (ppc_flags
&& !msolaris
)
1091 bfd_set_private_flags (stdoutput
, ppc_flags
);
1094 /* Insert the opcodes into a hash table. */
1095 ppc_hash
= hash_new ();
1097 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1098 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1100 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1102 if ((op
->flags
& ppc_cpu
) != 0
1103 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1104 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
1105 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0))
1109 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1110 if (retval
!= (const char *) NULL
)
1112 /* Ignore Power duplicates for -m601 */
1113 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1114 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1117 as_bad (_("Internal assembler error for instruction %s"), op
->name
);
1123 /* Insert the macros into a hash table. */
1124 ppc_macro_hash
= hash_new ();
1126 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1127 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1129 if ((macro
->flags
& ppc_cpu
) != 0)
1133 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1134 if (retval
!= (const char *) NULL
)
1136 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1145 /* Tell the main code what the endianness is if it is not overidden by the user. */
1146 if (!set_target_endian
)
1148 set_target_endian
= 1;
1149 target_big_endian
= PPC_BIG_ENDIAN
;
1153 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1155 /* Create dummy symbols to serve as initial csects. This forces the
1156 text csects to precede the data csects. These symbols will not
1158 ppc_text_csects
= symbol_make ("dummy\001");
1159 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1160 ppc_data_csects
= symbol_make ("dummy\001");
1161 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1166 ppc_current_section
= text_section
;
1167 ppc_previous_section
= 0;
1172 /* Insert an operand value into an instruction. */
1174 static unsigned long
1175 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1177 const struct powerpc_operand
*operand
;
1182 if (operand
->bits
!= 32)
1187 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1189 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1190 max
= (1 << operand
->bits
) - 1;
1192 max
= (1 << (operand
->bits
- 1)) - 1;
1193 min
= - (1 << (operand
->bits
- 1));
1195 if (ppc_size
== PPC_OPCODE_32
)
1197 /* Some people write 32 bit hex constants with the sign
1198 extension done by hand. This shouldn't really be
1199 valid, but, to permit this code to assemble on a 64
1200 bit host, we sign extend the 32 bit value. */
1202 && (val
& (offsetT
) 0x80000000) != 0
1203 && (val
& (offsetT
) 0xffffffff) == val
)
1212 max
= (1 << operand
->bits
) - 1;
1216 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1221 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1224 _("operand out of range (%s not between %ld and %ld)");
1227 sprint_value (buf
, test
);
1228 if (file
== (char *) NULL
)
1229 as_bad (err
, buf
, min
, max
);
1231 as_bad_where (file
, line
, err
, buf
, min
, max
);
1235 if (operand
->insert
)
1240 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1241 if (errmsg
!= (const char *) NULL
)
1245 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1253 /* Parse @got, etc. and return the desired relocation. */
1254 static bfd_reloc_code_real_type
1255 ppc_elf_suffix (str_p
, exp_p
)
1262 bfd_reloc_code_real_type reloc
;
1270 struct map_bfd
*ptr
;
1272 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1274 static struct map_bfd mapping
[] = {
1275 MAP ("l", BFD_RELOC_LO16
),
1276 MAP ("h", BFD_RELOC_HI16
),
1277 MAP ("ha", BFD_RELOC_HI16_S
),
1278 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1279 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1280 MAP ("got", BFD_RELOC_16_GOTOFF
),
1281 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1282 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1283 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1284 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1285 MAP ("plt", BFD_RELOC_24_PLT_PCREL
),
1286 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1287 MAP ("copy", BFD_RELOC_PPC_COPY
),
1288 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1289 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1290 MAP ("local", BFD_RELOC_PPC_LOCAL24PC
),
1291 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1292 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1293 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1294 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1295 MAP ("sdarel", BFD_RELOC_GPREL16
),
1296 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1297 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1298 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1299 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1300 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1301 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1302 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1303 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1304 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1305 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1306 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1307 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1308 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1309 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1310 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1311 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1312 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1313 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1314 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1315 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1316 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1318 { (char *)0, 0, BFD_RELOC_UNUSED
}
1322 return BFD_RELOC_UNUSED
;
1324 for (ch
= *str
, str2
= ident
;
1325 (str2
< ident
+ sizeof (ident
) - 1
1326 && (isalnum (ch
) || ch
== '@'));
1329 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1336 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1337 if (ch
== ptr
->string
[0]
1338 && len
== ptr
->length
1339 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1341 if (exp_p
->X_add_number
!= 0
1342 && (ptr
->reloc
== BFD_RELOC_16_GOTOFF
1343 || ptr
->reloc
== BFD_RELOC_LO16_GOTOFF
1344 || ptr
->reloc
== BFD_RELOC_HI16_GOTOFF
1345 || ptr
->reloc
== BFD_RELOC_HI16_S_GOTOFF
))
1346 as_warn (_("identifier+constant@got means identifier@got+constant"));
1348 /* Now check for identifier@suffix+constant */
1349 if (*str
== '-' || *str
== '+')
1351 char *orig_line
= input_line_pointer
;
1352 expressionS new_exp
;
1354 input_line_pointer
= str
;
1355 expression (&new_exp
);
1356 if (new_exp
.X_op
== O_constant
)
1358 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1359 str
= input_line_pointer
;
1362 if (&input_line_pointer
!= str_p
)
1363 input_line_pointer
= orig_line
;
1370 return BFD_RELOC_UNUSED
;
1373 /* Like normal .long/.short/.word, except support @got, etc. */
1374 /* clobbers input_line_pointer, checks */
1377 ppc_elf_cons (nbytes
)
1378 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1381 bfd_reloc_code_real_type reloc
;
1383 if (is_it_end_of_statement ())
1385 demand_empty_rest_of_line ();
1392 if (exp
.X_op
== O_symbol
1393 && *input_line_pointer
== '@'
1394 && (reloc
= ppc_elf_suffix (&input_line_pointer
, &exp
)) != BFD_RELOC_UNUSED
)
1396 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1397 int size
= bfd_get_reloc_size (reloc_howto
);
1400 as_bad (_("%s relocations do not fit in %d bytes\n"), reloc_howto
->name
, nbytes
);
1404 register char *p
= frag_more ((int) nbytes
);
1405 int offset
= nbytes
- size
;
1407 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1411 emit_expr (&exp
, (unsigned int) nbytes
);
1413 while (*input_line_pointer
++ == ',');
1415 input_line_pointer
--; /* Put terminator back into stream. */
1416 demand_empty_rest_of_line ();
1419 /* Solaris pseduo op to change to the .rodata section. */
1424 char *save_line
= input_line_pointer
;
1425 static char section
[] = ".rodata\n";
1427 /* Just pretend this is .section .rodata */
1428 input_line_pointer
= section
;
1429 obj_elf_section (xxx
);
1431 input_line_pointer
= save_line
;
1434 /* Pseudo op to make file scope bss items */
1437 int xxx ATTRIBUTE_UNUSED
;
1439 register char *name
;
1443 register symbolS
*symbolP
;
1450 name
= input_line_pointer
;
1451 c
= get_symbol_end ();
1453 /* just after name is now '\0' */
1454 p
= input_line_pointer
;
1457 if (*input_line_pointer
!= ',')
1459 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1460 ignore_rest_of_line ();
1464 input_line_pointer
++; /* skip ',' */
1465 if ((size
= get_absolute_expression ()) < 0)
1467 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1468 ignore_rest_of_line ();
1472 /* The third argument to .lcomm is the alignment. */
1473 if (*input_line_pointer
!= ',')
1477 ++input_line_pointer
;
1478 align
= get_absolute_expression ();
1481 as_warn (_("ignoring bad alignment"));
1487 symbolP
= symbol_find_or_make (name
);
1490 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1492 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1493 S_GET_NAME (symbolP
));
1494 ignore_rest_of_line ();
1498 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1500 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1501 S_GET_NAME (symbolP
),
1502 (long) S_GET_VALUE (symbolP
),
1505 ignore_rest_of_line ();
1511 old_subsec
= now_subseg
;
1514 /* convert to a power of 2 alignment */
1515 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1518 as_bad (_("Common alignment not a power of 2"));
1519 ignore_rest_of_line ();
1526 record_alignment (bss_section
, align2
);
1527 subseg_set (bss_section
, 0);
1529 frag_align (align2
, 0, 0);
1530 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1531 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1532 symbol_set_frag (symbolP
, frag_now
);
1533 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1536 S_SET_SIZE (symbolP
, size
);
1537 S_SET_SEGMENT (symbolP
, bss_section
);
1538 subseg_set (old_sec
, old_subsec
);
1539 demand_empty_rest_of_line ();
1542 /* Validate any relocations emitted for -mrelocatable, possibly adding
1543 fixups for word relocations in writable segments, so we can adjust
1546 ppc_elf_validate_fix (fixp
, seg
)
1550 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1559 case SHLIB_MRELOCATABLE
:
1560 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1561 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1562 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1563 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1564 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1565 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1566 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1567 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1568 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1569 && strcmp (segment_name (seg
), ".got2") != 0
1570 && strcmp (segment_name (seg
), ".dtors") != 0
1571 && strcmp (segment_name (seg
), ".ctors") != 0
1572 && strcmp (segment_name (seg
), ".fixup") != 0
1573 && strcmp (segment_name (seg
), ".stab") != 0
1574 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1575 && strcmp (segment_name (seg
), ".eh_frame") != 0
1576 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1578 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1579 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1581 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1582 _("Relocation cannot be done when using -mrelocatable"));
1588 #endif /* OBJ_ELF */
1593 * Summary of parse_toc_entry().
1595 * in: Input_line_pointer points to the '[' in one of:
1597 * [toc] [tocv] [toc32] [toc64]
1599 * Anything else is an error of one kind or another.
1602 * return value: success or failure
1603 * toc_kind: kind of toc reference
1604 * input_line_pointer:
1605 * success: first char after the ']'
1606 * failure: unchanged
1610 * [toc] - rv == success, toc_kind = default_toc
1611 * [tocv] - rv == success, toc_kind = data_in_toc
1612 * [toc32] - rv == success, toc_kind = must_be_32
1613 * [toc64] - rv == success, toc_kind = must_be_64
1617 enum toc_size_qualifier
1619 default_toc
, /* The toc cell constructed should be the system default size */
1620 data_in_toc
, /* This is a direct reference to a toc cell */
1621 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1622 must_be_64
/* The toc cell constructed must be 64 bits wide */
1626 parse_toc_entry(toc_kind
)
1627 enum toc_size_qualifier
*toc_kind
;
1632 enum toc_size_qualifier t
;
1634 /* save the input_line_pointer */
1635 start
= input_line_pointer
;
1637 /* skip over the '[' , and whitespace */
1638 ++input_line_pointer
;
1641 /* find the spelling of the operand */
1642 toc_spec
= input_line_pointer
;
1643 c
= get_symbol_end ();
1645 if (strcmp(toc_spec
, "toc") == 0)
1649 else if (strcmp(toc_spec
, "tocv") == 0)
1653 else if (strcmp(toc_spec
, "toc32") == 0)
1657 else if (strcmp(toc_spec
, "toc64") == 0)
1663 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1664 *input_line_pointer
= c
; /* put back the delimiting char */
1665 input_line_pointer
= start
; /* reset input_line pointer */
1669 /* now find the ']' */
1670 *input_line_pointer
= c
; /* put back the delimiting char */
1672 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1673 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1677 as_bad (_("syntax error: expected `]', found `%c'"), c
);
1678 input_line_pointer
= start
; /* reset input_line pointer */
1682 *toc_kind
= t
; /* set return value */
1688 /* We need to keep a list of fixups. We can't simply generate them as
1689 we go, because that would require us to first create the frag, and
1690 that would screw up references to ``.''. */
1696 bfd_reloc_code_real_type reloc
;
1699 #define MAX_INSN_FIXUPS (5)
1701 /* This routine is called for each instruction to be assembled. */
1708 const struct powerpc_opcode
*opcode
;
1710 const unsigned char *opindex_ptr
;
1714 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1719 bfd_reloc_code_real_type reloc
;
1722 /* Get the opcode. */
1723 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1728 /* Look up the opcode in the hash table. */
1729 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1730 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1732 const struct powerpc_macro
*macro
;
1734 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1735 if (macro
== (const struct powerpc_macro
*) NULL
)
1736 as_bad (_("Unrecognized opcode: `%s'"), str
);
1738 ppc_macro (s
, macro
);
1743 insn
= opcode
->opcode
;
1746 while (isspace (*str
))
1749 /* PowerPC operands are just expressions. The only real issue is
1750 that a few operand types are optional. All cases which might use
1751 an optional operand separate the operands only with commas (in
1752 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1753 cases never have optional operands). There is never more than
1754 one optional operand for an instruction. So, before we start
1755 seriously parsing the operands, we check to see if we have an
1756 optional operand, and, if we do, we count the number of commas to
1757 see whether the operand should be omitted. */
1759 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1761 const struct powerpc_operand
*operand
;
1763 operand
= &powerpc_operands
[*opindex_ptr
];
1764 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1766 unsigned int opcount
;
1768 /* There is an optional operand. Count the number of
1769 commas in the input line. */
1776 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1783 /* If there are fewer operands in the line then are called
1784 for by the instruction, we want to skip the optional
1786 if (opcount
< strlen (opcode
->operands
))
1793 /* Gather the operands. */
1797 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1799 const struct powerpc_operand
*operand
;
1805 if (next_opindex
== 0)
1806 operand
= &powerpc_operands
[*opindex_ptr
];
1809 operand
= &powerpc_operands
[next_opindex
];
1815 /* If this is a fake operand, then we do not expect anything
1817 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1819 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1820 if (errmsg
!= (const char *) NULL
)
1825 /* If this is an optional operand, and we are skipping it, just
1827 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1830 if (operand
->insert
)
1832 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1833 if (errmsg
!= (const char *) NULL
)
1836 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1837 next_opindex
= *opindex_ptr
+ 1;
1841 /* Gather the operand. */
1842 hold
= input_line_pointer
;
1843 input_line_pointer
= str
;
1846 if (*input_line_pointer
== '[')
1848 /* We are expecting something like the second argument here:
1850 lwz r4,[toc].GS.0.static_int(rtoc)
1851 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1852 The argument following the `]' must be a symbol name, and the
1853 register must be the toc register: 'rtoc' or '2'
1855 The effect is to 0 as the displacement field
1856 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1857 the appropriate variation) reloc against it based on the symbol.
1858 The linker will build the toc, and insert the resolved toc offset.
1861 o The size of the toc entry is currently assumed to be
1862 32 bits. This should not be assumed to be a hard coded
1864 o In an effort to cope with a change from 32 to 64 bits,
1865 there are also toc entries that are specified to be
1866 either 32 or 64 bits:
1867 lwz r4,[toc32].GS.0.static_int(rtoc)
1868 lwz r4,[toc64].GS.0.static_int(rtoc)
1869 These demand toc entries of the specified size, and the
1870 instruction probably requires it.
1874 enum toc_size_qualifier toc_kind
;
1875 bfd_reloc_code_real_type toc_reloc
;
1877 /* go parse off the [tocXX] part */
1878 valid_toc
= parse_toc_entry(&toc_kind
);
1882 /* Note: message has already been issued. */
1883 /* FIXME: what sort of recovery should we do? */
1884 /* demand_rest_of_line(); return; ? */
1887 /* Now get the symbol following the ']' */
1893 /* In this case, we may not have seen the symbol yet, since */
1894 /* it is allowed to appear on a .extern or .globl or just be */
1895 /* a label in the .data section. */
1896 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1899 /* 1. The symbol must be defined and either in the toc */
1900 /* section, or a global. */
1901 /* 2. The reloc generated must have the TOCDEFN flag set in */
1902 /* upper bit mess of the reloc type. */
1903 /* FIXME: It's a little confusing what the tocv qualifier can */
1904 /* be used for. At the very least, I've seen three */
1905 /* uses, only one of which I'm sure I can explain. */
1906 if (ex
.X_op
== O_symbol
)
1908 assert (ex
.X_add_symbol
!= NULL
);
1909 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
1912 as_bad(_("[tocv] symbol is not a toc symbol"));
1916 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1919 /* FIXME: these next two specifically specify 32/64 bit toc */
1920 /* entries. We don't support them today. Is this the */
1921 /* right way to say that? */
1922 toc_reloc
= BFD_RELOC_UNUSED
;
1923 as_bad (_("Unimplemented toc32 expression modifier"));
1926 /* FIXME: see above */
1927 toc_reloc
= BFD_RELOC_UNUSED
;
1928 as_bad (_("Unimplemented toc64 expression modifier"));
1932 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1938 /* We need to generate a fixup for this expression. */
1939 if (fc
>= MAX_INSN_FIXUPS
)
1940 as_fatal (_("too many fixups"));
1942 fixups
[fc
].reloc
= toc_reloc
;
1943 fixups
[fc
].exp
= ex
;
1944 fixups
[fc
].opindex
= *opindex_ptr
;
1947 /* Ok. We've set up the fixup for the instruction. Now make it
1948 look like the constant 0 was found here */
1950 ex
.X_op
= O_constant
;
1951 ex
.X_add_number
= 0;
1952 ex
.X_add_symbol
= NULL
;
1953 ex
.X_op_symbol
= NULL
;
1959 if (! register_name (&ex
))
1961 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1968 str
= input_line_pointer
;
1969 input_line_pointer
= hold
;
1971 if (ex
.X_op
== O_illegal
)
1972 as_bad (_("illegal operand"));
1973 else if (ex
.X_op
== O_absent
)
1974 as_bad (_("missing operand"));
1975 else if (ex
.X_op
== O_register
)
1977 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1980 else if (ex
.X_op
== O_constant
)
1983 /* Allow @HA, @L, @H on constants. */
1984 char *orig_str
= str
;
1986 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1993 case BFD_RELOC_LO16
:
1994 /* X_unsigned is the default, so if the user has done
1995 something which cleared it, we always produce a
1998 && (operand
->flags
& PPC_OPERAND_SIGNED
) == 0)
1999 ex
.X_add_number
&= 0xffff;
2001 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
2006 case BFD_RELOC_HI16
:
2007 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
2010 case BFD_RELOC_HI16_S
:
2011 ex
.X_add_number
= ((((ex
.X_add_number
>> 16) & 0xffff)
2012 + ((ex
.X_add_number
>> 15) & 1))
2017 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2021 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2023 /* For the absoulte forms of branchs, convert the PC relative form back into
2025 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2029 case BFD_RELOC_PPC_B26
:
2030 reloc
= BFD_RELOC_PPC_BA26
;
2032 case BFD_RELOC_PPC_B16
:
2033 reloc
= BFD_RELOC_PPC_BA16
;
2035 case BFD_RELOC_PPC_B16_BRTAKEN
:
2036 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2038 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2039 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2046 /* We need to generate a fixup for this expression. */
2047 if (fc
>= MAX_INSN_FIXUPS
)
2048 as_fatal (_("too many fixups"));
2049 fixups
[fc
].exp
= ex
;
2050 fixups
[fc
].opindex
= 0;
2051 fixups
[fc
].reloc
= reloc
;
2054 #endif /* OBJ_ELF */
2058 /* We need to generate a fixup for this expression. */
2059 if (fc
>= MAX_INSN_FIXUPS
)
2060 as_fatal (_("too many fixups"));
2061 fixups
[fc
].exp
= ex
;
2062 fixups
[fc
].opindex
= *opindex_ptr
;
2063 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2072 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2080 /* The call to expression should have advanced str past any
2083 && (endc
!= ',' || *str
!= '\0'))
2085 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2093 while (isspace (*str
))
2097 as_bad (_("junk at end of line: `%s'"), str
);
2099 /* Write out the instruction. */
2101 md_number_to_chars (f
, insn
, 4);
2104 dwarf2_emit_insn (4);
2107 /* Create any fixups. At this point we do not use a
2108 bfd_reloc_code_real_type, but instead just use the
2109 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2110 handle fixups for any operand type, although that is admittedly
2111 not a very exciting feature. We pick a BFD reloc type in
2113 for (i
= 0; i
< fc
; i
++)
2115 const struct powerpc_operand
*operand
;
2117 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2118 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2120 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2128 size
= bfd_get_reloc_size (reloc_howto
);
2129 offset
= target_big_endian
? (4 - size
) : 0;
2131 if (size
< 1 || size
> 4)
2134 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
2135 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
2138 /* Turn off complaints that the addend is too large for things like
2140 switch (fixups
[i
].reloc
)
2142 case BFD_RELOC_16_GOTOFF
:
2143 case BFD_RELOC_PPC_TOC16
:
2144 case BFD_RELOC_LO16
:
2145 case BFD_RELOC_HI16
:
2146 case BFD_RELOC_HI16_S
:
2147 fixP
->fx_no_overflow
= 1;
2154 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
2156 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2157 ((bfd_reloc_code_real_type
)
2158 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2162 /* Handle a macro. Gather all the operands, transform them as
2163 described by the macro, and call md_assemble recursively. All the
2164 operands are separated by commas; we don't accept parentheses
2165 around operands here. */
2168 ppc_macro (str
, macro
)
2170 const struct powerpc_macro
*macro
;
2181 /* Gather the users operands into the operands array. */
2186 if (count
>= sizeof operands
/ sizeof operands
[0])
2188 operands
[count
++] = s
;
2189 s
= strchr (s
, ',');
2190 if (s
== (char *) NULL
)
2195 if (count
!= macro
->operands
)
2197 as_bad (_("wrong number of operands"));
2201 /* Work out how large the string must be (the size is unbounded
2202 because it includes user input). */
2204 format
= macro
->format
;
2205 while (*format
!= '\0')
2214 arg
= strtol (format
+ 1, &send
, 10);
2215 know (send
!= format
&& arg
>= 0 && arg
< count
);
2216 len
+= strlen (operands
[arg
]);
2221 /* Put the string together. */
2222 complete
= s
= (char *) alloca (len
+ 1);
2223 format
= macro
->format
;
2224 while (*format
!= '\0')
2230 arg
= strtol (format
+ 1, &send
, 10);
2231 strcpy (s
, operands
[arg
]);
2238 /* Assemble the constructed instruction. */
2239 md_assemble (complete
);
2243 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2246 ppc_section_letter (letter
, ptr_msg
)
2253 *ptr_msg
= _("Bad .section directive: want a,w,x,e in string");
2258 ppc_section_word (str
, len
)
2262 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2269 ppc_section_type (str
, len
)
2273 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2280 ppc_section_flags (flags
, attr
, type
)
2285 if (type
== SHT_ORDERED
)
2286 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2288 if (attr
& SHF_EXCLUDE
)
2289 flags
|= SEC_EXCLUDE
;
2293 #endif /* OBJ_ELF */
2296 /* Pseudo-op handling. */
2298 /* The .byte pseudo-op. This is similar to the normal .byte
2299 pseudo-op, but it can also take a single ASCII string. */
2303 int ignore ATTRIBUTE_UNUSED
;
2305 if (*input_line_pointer
!= '\"')
2311 /* Gather characters. A real double quote is doubled. Unusual
2312 characters are not permitted. */
2313 ++input_line_pointer
;
2318 c
= *input_line_pointer
++;
2322 if (*input_line_pointer
!= '\"')
2324 ++input_line_pointer
;
2327 FRAG_APPEND_1_CHAR (c
);
2330 demand_empty_rest_of_line ();
2335 /* XCOFF specific pseudo-op handling. */
2337 /* This is set if we are creating a .stabx symbol, since we don't want
2338 to handle symbol suffixes for such symbols. */
2339 static boolean ppc_stab_symbol
;
2341 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2342 symbols in the .bss segment as though they were local common
2343 symbols, and uses a different smclas. */
2349 asection
*current_seg
= now_seg
;
2350 subsegT current_subseg
= now_subseg
;
2356 symbolS
*lcomm_sym
= NULL
;
2360 name
= input_line_pointer
;
2361 endc
= get_symbol_end ();
2362 end_name
= input_line_pointer
;
2365 if (*input_line_pointer
!= ',')
2367 as_bad (_("missing size"));
2368 ignore_rest_of_line ();
2371 ++input_line_pointer
;
2373 size
= get_absolute_expression ();
2376 as_bad (_("negative size"));
2377 ignore_rest_of_line ();
2383 /* The third argument to .comm is the alignment. */
2384 if (*input_line_pointer
!= ',')
2388 ++input_line_pointer
;
2389 align
= get_absolute_expression ();
2392 as_warn (_("ignoring bad alignment"));
2411 /* The third argument to .lcomm appears to be the real local
2412 common symbol to create. References to the symbol named in
2413 the first argument are turned into references to the third
2415 if (*input_line_pointer
!= ',')
2417 as_bad (_("missing real symbol name"));
2418 ignore_rest_of_line ();
2421 ++input_line_pointer
;
2423 lcomm_name
= input_line_pointer
;
2424 lcomm_endc
= get_symbol_end ();
2426 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2428 *input_line_pointer
= lcomm_endc
;
2432 sym
= symbol_find_or_make (name
);
2435 if (S_IS_DEFINED (sym
)
2436 || S_GET_VALUE (sym
) != 0)
2438 as_bad (_("attempt to redefine symbol"));
2439 ignore_rest_of_line ();
2443 record_alignment (bss_section
, align
);
2446 || ! S_IS_DEFINED (lcomm_sym
))
2455 S_SET_EXTERNAL (sym
);
2459 symbol_get_tc (lcomm_sym
)->output
= 1;
2460 def_sym
= lcomm_sym
;
2464 subseg_set (bss_section
, 1);
2465 frag_align (align
, 0, 0);
2467 symbol_set_frag (def_sym
, frag_now
);
2468 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2469 def_size
, (char *) NULL
);
2471 S_SET_SEGMENT (def_sym
, bss_section
);
2472 symbol_get_tc (def_sym
)->align
= align
;
2476 /* Align the size of lcomm_sym. */
2477 symbol_get_frag (lcomm_sym
)->fr_offset
=
2478 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
2479 &~ ((1 << align
) - 1));
2480 if (align
> symbol_get_tc (lcomm_sym
)->align
)
2481 symbol_get_tc (lcomm_sym
)->align
= align
;
2486 /* Make sym an offset from lcomm_sym. */
2487 S_SET_SEGMENT (sym
, bss_section
);
2488 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
2489 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
2490 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
2493 subseg_set (current_seg
, current_subseg
);
2495 demand_empty_rest_of_line ();
2498 /* The .csect pseudo-op. This switches us into a different
2499 subsegment. The first argument is a symbol whose value is the
2500 start of the .csect. In COFF, csect symbols get special aux
2501 entries defined by the x_csect field of union internal_auxent. The
2502 optional second argument is the alignment (the default is 2). */
2506 int ignore ATTRIBUTE_UNUSED
;
2512 name
= input_line_pointer
;
2513 endc
= get_symbol_end ();
2515 sym
= symbol_find_or_make (name
);
2517 *input_line_pointer
= endc
;
2519 if (S_GET_NAME (sym
)[0] == '\0')
2521 /* An unnamed csect is assumed to be [PR]. */
2522 symbol_get_tc (sym
)->class = XMC_PR
;
2525 ppc_change_csect (sym
);
2527 if (*input_line_pointer
== ',')
2529 ++input_line_pointer
;
2530 symbol_get_tc (sym
)->align
= get_absolute_expression ();
2533 demand_empty_rest_of_line ();
2536 /* Change to a different csect. */
2539 ppc_change_csect (sym
)
2542 if (S_IS_DEFINED (sym
))
2543 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
2551 /* This is a new csect. We need to look at the symbol class to
2552 figure out whether it should go in the text section or the
2555 switch (symbol_get_tc (sym
)->class)
2565 S_SET_SEGMENT (sym
, text_section
);
2566 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
2567 ++ppc_text_subsegment
;
2568 list_ptr
= &ppc_text_csects
;
2577 if (ppc_toc_csect
!= NULL
2578 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
2579 == ppc_data_subsegment
))
2581 S_SET_SEGMENT (sym
, data_section
);
2582 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
2583 ++ppc_data_subsegment
;
2584 list_ptr
= &ppc_data_csects
;
2590 /* We set the obstack chunk size to a small value before
2591 changing subsegments, so that we don't use a lot of memory
2592 space for what may be a small section. */
2593 hold_chunksize
= chunksize
;
2596 subseg_new (segment_name (S_GET_SEGMENT (sym
)),
2597 symbol_get_tc (sym
)->subseg
);
2599 chunksize
= hold_chunksize
;
2602 ppc_after_toc_frag
= frag_now
;
2604 symbol_set_frag (sym
, frag_now
);
2605 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2607 symbol_get_tc (sym
)->align
= (ppc_xcoff64
) ? 3 : 2;
2608 symbol_get_tc (sym
)->output
= 1;
2609 symbol_get_tc (sym
)->within
= sym
;
2611 for (list
= *list_ptr
;
2612 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
2613 list
= symbol_get_tc (list
)->next
)
2615 symbol_get_tc (list
)->next
= sym
;
2617 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2618 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
2622 ppc_current_csect
= sym
;
2625 /* This function handles the .text and .data pseudo-ops. These
2626 pseudo-ops aren't really used by XCOFF; we implement them for the
2627 convenience of people who aren't used to XCOFF. */
2638 else if (type
== 'd')
2643 sym
= symbol_find_or_make (name
);
2645 ppc_change_csect (sym
);
2647 demand_empty_rest_of_line ();
2650 /* This function handles the .section pseudo-op. This is mostly to
2651 give an error, since XCOFF only supports .text, .data and .bss, but
2652 we do permit the user to name the text or data section. */
2655 ppc_named_section (ignore
)
2656 int ignore ATTRIBUTE_UNUSED
;
2659 const char *real_name
;
2663 user_name
= input_line_pointer
;
2664 c
= get_symbol_end ();
2666 if (strcmp (user_name
, ".text") == 0)
2667 real_name
= ".text[PR]";
2668 else if (strcmp (user_name
, ".data") == 0)
2669 real_name
= ".data[RW]";
2672 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2673 *input_line_pointer
= c
;
2674 ignore_rest_of_line ();
2678 *input_line_pointer
= c
;
2680 sym
= symbol_find_or_make (real_name
);
2682 ppc_change_csect (sym
);
2684 demand_empty_rest_of_line ();
2687 /* The .extern pseudo-op. We create an undefined symbol. */
2691 int ignore ATTRIBUTE_UNUSED
;
2696 name
= input_line_pointer
;
2697 endc
= get_symbol_end ();
2699 (void) symbol_find_or_make (name
);
2701 *input_line_pointer
= endc
;
2703 demand_empty_rest_of_line ();
2706 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2710 int ignore ATTRIBUTE_UNUSED
;
2716 name
= input_line_pointer
;
2717 endc
= get_symbol_end ();
2719 sym
= symbol_find_or_make (name
);
2721 *input_line_pointer
= endc
;
2723 symbol_get_tc (sym
)->output
= 1;
2725 demand_empty_rest_of_line ();
2728 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2729 although I don't know why it bothers. */
2733 int ignore ATTRIBUTE_UNUSED
;
2740 name
= input_line_pointer
;
2741 endc
= get_symbol_end ();
2743 sym
= symbol_find_or_make (name
);
2745 *input_line_pointer
= endc
;
2747 if (*input_line_pointer
!= ',')
2749 as_bad (_("missing rename string"));
2750 ignore_rest_of_line ();
2753 ++input_line_pointer
;
2755 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
2757 demand_empty_rest_of_line ();
2760 /* The .stabx pseudo-op. This is similar to a normal .stabs
2761 pseudo-op, but slightly different. A sample is
2762 .stabx "main:F-1",.main,142,0
2763 The first argument is the symbol name to create. The second is the
2764 value, and the third is the storage class. The fourth seems to be
2765 always zero, and I am assuming it is the type. */
2769 int ignore ATTRIBUTE_UNUSED
;
2776 name
= demand_copy_C_string (&len
);
2778 if (*input_line_pointer
!= ',')
2780 as_bad (_("missing value"));
2783 ++input_line_pointer
;
2785 ppc_stab_symbol
= true;
2786 sym
= symbol_make (name
);
2787 ppc_stab_symbol
= false;
2789 symbol_get_tc (sym
)->real_name
= name
;
2791 (void) expression (&exp
);
2798 as_bad (_("illegal .stabx expression; zero assumed"));
2799 exp
.X_add_number
= 0;
2802 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2803 symbol_set_frag (sym
, &zero_address_frag
);
2807 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2808 symbol_set_value_expression (sym
, &exp
);
2812 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2813 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
2818 /* The value is some complex expression. This will probably
2819 fail at some later point, but this is probably the right
2820 thing to do here. */
2821 symbol_set_value_expression (sym
, &exp
);
2825 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2826 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
2828 if (*input_line_pointer
!= ',')
2830 as_bad (_("missing class"));
2833 ++input_line_pointer
;
2835 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2837 if (*input_line_pointer
!= ',')
2839 as_bad (_("missing type"));
2842 ++input_line_pointer
;
2844 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2846 symbol_get_tc (sym
)->output
= 1;
2848 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
2850 symbol_get_tc (sym
)->within
= ppc_current_block
;
2856 .stabx "z",arrays_,133,0
2859 .comm arrays_,13768,3
2861 resolve_symbol_value will copy the exp's "within" into sym's when the
2862 offset is 0. Since this seems to be corner case problem,
2863 only do the correction for storage class C_STSYM. A better solution
2864 would be to have the tc field updated in ppc_symbol_new_hook.
2868 if (exp
.X_op
== O_symbol
) {
2869 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
2873 if (exp
.X_op
!= O_symbol
2874 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2875 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2876 ppc_frob_label (sym
);
2879 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2880 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2881 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
2882 symbol_get_tc (ppc_current_csect
)->within
= sym
;
2885 demand_empty_rest_of_line ();
2888 /* The .function pseudo-op. This takes several arguments. The first
2889 argument seems to be the external name of the symbol. The second
2890 argment seems to be the label for the start of the function. gcc
2891 uses the same name for both. I have no idea what the third and
2892 fourth arguments are meant to be. The optional fifth argument is
2893 an expression for the size of the function. In COFF this symbol
2894 gets an aux entry like that used for a csect. */
2897 ppc_function (ignore
)
2898 int ignore ATTRIBUTE_UNUSED
;
2906 name
= input_line_pointer
;
2907 endc
= get_symbol_end ();
2909 /* Ignore any [PR] suffix. */
2910 name
= ppc_canonicalize_symbol_name (name
);
2911 s
= strchr (name
, '[');
2912 if (s
!= (char *) NULL
2913 && strcmp (s
+ 1, "PR]") == 0)
2916 ext_sym
= symbol_find_or_make (name
);
2918 *input_line_pointer
= endc
;
2920 if (*input_line_pointer
!= ',')
2922 as_bad (_("missing symbol name"));
2923 ignore_rest_of_line ();
2926 ++input_line_pointer
;
2928 name
= input_line_pointer
;
2929 endc
= get_symbol_end ();
2931 lab_sym
= symbol_find_or_make (name
);
2933 *input_line_pointer
= endc
;
2935 if (ext_sym
!= lab_sym
)
2939 exp
.X_op
= O_symbol
;
2940 exp
.X_add_symbol
= lab_sym
;
2941 exp
.X_op_symbol
= NULL
;
2942 exp
.X_add_number
= 0;
2944 symbol_set_value_expression (ext_sym
, &exp
);
2947 if (symbol_get_tc (ext_sym
)->class == -1)
2948 symbol_get_tc (ext_sym
)->class = XMC_PR
;
2949 symbol_get_tc (ext_sym
)->output
= 1;
2951 if (*input_line_pointer
== ',')
2955 /* Ignore the third argument. */
2956 ++input_line_pointer
;
2957 expression (&ignore
);
2958 if (*input_line_pointer
== ',')
2960 /* Ignore the fourth argument. */
2961 ++input_line_pointer
;
2962 expression (&ignore
);
2963 if (*input_line_pointer
== ',')
2965 /* The fifth argument is the function size. */
2966 ++input_line_pointer
;
2967 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
2970 &zero_address_frag
);
2971 pseudo_set (symbol_get_tc (ext_sym
)->size
);
2976 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2977 SF_SET_FUNCTION (ext_sym
);
2978 SF_SET_PROCESS (ext_sym
);
2979 coff_add_linesym (ext_sym
);
2981 demand_empty_rest_of_line ();
2984 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2989 int ignore ATTRIBUTE_UNUSED
;
2993 sym
= symbol_make (".bf");
2994 S_SET_SEGMENT (sym
, text_section
);
2995 symbol_set_frag (sym
, frag_now
);
2996 S_SET_VALUE (sym
, frag_now_fix ());
2997 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2999 coff_line_base
= get_absolute_expression ();
3001 S_SET_NUMBER_AUXILIARY (sym
, 1);
3002 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3004 symbol_get_tc (sym
)->output
= 1;
3006 ppc_frob_label (sym
);
3008 demand_empty_rest_of_line ();
3011 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3012 ".ef", except that the line number is absolute, not relative to the
3013 most recent ".bf" symbol. */
3017 int ignore ATTRIBUTE_UNUSED
;
3021 sym
= symbol_make (".ef");
3022 S_SET_SEGMENT (sym
, text_section
);
3023 symbol_set_frag (sym
, frag_now
);
3024 S_SET_VALUE (sym
, frag_now_fix ());
3025 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3026 S_SET_NUMBER_AUXILIARY (sym
, 1);
3027 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3028 symbol_get_tc (sym
)->output
= 1;
3030 ppc_frob_label (sym
);
3032 demand_empty_rest_of_line ();
3035 /* The .bi and .ei pseudo-ops. These take a string argument and
3036 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3043 static symbolS
*last_biei
;
3050 name
= demand_copy_C_string (&len
);
3052 /* The value of these symbols is actually file offset. Here we set
3053 the value to the index into the line number entries. In
3054 ppc_frob_symbols we set the fix_line field, which will cause BFD
3055 to do the right thing. */
3057 sym
= symbol_make (name
);
3058 /* obj-coff.c currently only handles line numbers correctly in the
3060 S_SET_SEGMENT (sym
, text_section
);
3061 S_SET_VALUE (sym
, coff_n_line_nos
);
3062 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3064 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3065 symbol_get_tc (sym
)->output
= 1;
3067 for (look
= last_biei
? last_biei
: symbol_rootP
;
3068 (look
!= (symbolS
*) NULL
3069 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3070 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3071 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3072 look
= symbol_next (look
))
3074 if (look
!= (symbolS
*) NULL
)
3076 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3077 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3081 demand_empty_rest_of_line ();
3084 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3085 There is one argument, which is a csect symbol. The value of the
3086 .bs symbol is the index of this csect symbol. */
3090 int ignore ATTRIBUTE_UNUSED
;
3097 if (ppc_current_block
!= NULL
)
3098 as_bad (_("nested .bs blocks"));
3100 name
= input_line_pointer
;
3101 endc
= get_symbol_end ();
3103 csect
= symbol_find_or_make (name
);
3105 *input_line_pointer
= endc
;
3107 sym
= symbol_make (".bs");
3108 S_SET_SEGMENT (sym
, now_seg
);
3109 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3110 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3111 symbol_get_tc (sym
)->output
= 1;
3113 symbol_get_tc (sym
)->within
= csect
;
3115 ppc_frob_label (sym
);
3117 ppc_current_block
= sym
;
3119 demand_empty_rest_of_line ();
3122 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3126 int ignore ATTRIBUTE_UNUSED
;
3130 if (ppc_current_block
== NULL
)
3131 as_bad (_(".es without preceding .bs"));
3133 sym
= symbol_make (".es");
3134 S_SET_SEGMENT (sym
, now_seg
);
3135 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3136 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3137 symbol_get_tc (sym
)->output
= 1;
3139 ppc_frob_label (sym
);
3141 ppc_current_block
= NULL
;
3143 demand_empty_rest_of_line ();
3146 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3151 int ignore ATTRIBUTE_UNUSED
;
3155 sym
= symbol_make (".bb");
3156 S_SET_SEGMENT (sym
, text_section
);
3157 symbol_set_frag (sym
, frag_now
);
3158 S_SET_VALUE (sym
, frag_now_fix ());
3159 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3161 S_SET_NUMBER_AUXILIARY (sym
, 1);
3162 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3164 symbol_get_tc (sym
)->output
= 1;
3166 SF_SET_PROCESS (sym
);
3168 ppc_frob_label (sym
);
3170 demand_empty_rest_of_line ();
3173 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3178 int ignore ATTRIBUTE_UNUSED
;
3182 sym
= symbol_make (".eb");
3183 S_SET_SEGMENT (sym
, text_section
);
3184 symbol_set_frag (sym
, frag_now
);
3185 S_SET_VALUE (sym
, frag_now_fix ());
3186 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3187 S_SET_NUMBER_AUXILIARY (sym
, 1);
3188 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3189 symbol_get_tc (sym
)->output
= 1;
3191 SF_SET_PROCESS (sym
);
3193 ppc_frob_label (sym
);
3195 demand_empty_rest_of_line ();
3198 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3203 int ignore ATTRIBUTE_UNUSED
;
3209 name
= demand_copy_C_string (&len
);
3210 sym
= symbol_make (name
);
3211 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3212 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3213 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3214 S_SET_VALUE (sym
, 0);
3215 symbol_get_tc (sym
)->output
= 1;
3217 ppc_frob_label (sym
);
3219 demand_empty_rest_of_line ();
3222 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3226 int ignore ATTRIBUTE_UNUSED
;
3230 sym
= symbol_make (".ec");
3231 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3232 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3233 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3234 S_SET_VALUE (sym
, 0);
3235 symbol_get_tc (sym
)->output
= 1;
3237 ppc_frob_label (sym
);
3239 demand_empty_rest_of_line ();
3242 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3246 int ignore ATTRIBUTE_UNUSED
;
3248 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3249 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3256 subseg
= ppc_data_subsegment
;
3257 ++ppc_data_subsegment
;
3259 subseg_new (segment_name (data_section
), subseg
);
3260 ppc_toc_frag
= frag_now
;
3262 sym
= symbol_find_or_make ("TOC[TC0]");
3263 symbol_set_frag (sym
, frag_now
);
3264 S_SET_SEGMENT (sym
, data_section
);
3265 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3266 symbol_get_tc (sym
)->subseg
= subseg
;
3267 symbol_get_tc (sym
)->output
= 1;
3268 symbol_get_tc (sym
)->within
= sym
;
3270 ppc_toc_csect
= sym
;
3272 for (list
= ppc_data_csects
;
3273 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3274 list
= symbol_get_tc (list
)->next
)
3276 symbol_get_tc (list
)->next
= sym
;
3278 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3279 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3283 ppc_current_csect
= ppc_toc_csect
;
3285 demand_empty_rest_of_line ();
3288 /* The AIX assembler automatically aligns the operands of a .long or
3289 .short pseudo-op, and we want to be compatible. */
3292 ppc_xcoff_cons (log_size
)
3295 frag_align (log_size
, 0, 0);
3296 record_alignment (now_seg
, log_size
);
3297 cons (1 << log_size
);
3302 int dummy ATTRIBUTE_UNUSED
;
3304 discard_rest_of_line();
3305 /* What does aix use this for? */
3310 int dummy ATTRIBUTE_UNUSED
;
3315 (void) expression (&exp
);
3317 if (exp
.X_op
!= O_constant
)
3319 as_bad (_("non-constant byte count"));
3323 byte_count
= exp
.X_add_number
;
3325 if (*input_line_pointer
!= ',')
3327 as_bad (_("missing value"));
3331 ++input_line_pointer
;
3335 #endif /* OBJ_XCOFF */
3337 /* The .tc pseudo-op. This is used when generating either XCOFF or
3338 ELF. This takes two or more arguments.
3340 When generating XCOFF output, the first argument is the name to
3341 give to this location in the toc; this will be a symbol with class
3342 TC. The rest of the arguments are 4 byte values to actually put at
3343 this location in the TOC; often there is just one more argument, a
3344 relocateable symbol reference.
3346 When not generating XCOFF output, the arguments are the same, but
3347 the first argument is simply ignored. */
3351 int ignore ATTRIBUTE_UNUSED
;
3355 /* Define the TOC symbol name. */
3361 if (ppc_toc_csect
== (symbolS
*) NULL
3362 || ppc_toc_csect
!= ppc_current_csect
)
3364 as_bad (_(".tc not in .toc section"));
3365 ignore_rest_of_line ();
3369 name
= input_line_pointer
;
3370 endc
= get_symbol_end ();
3372 sym
= symbol_find_or_make (name
);
3374 *input_line_pointer
= endc
;
3376 if (S_IS_DEFINED (sym
))
3380 label
= symbol_get_tc (ppc_current_csect
)->within
;
3381 if (symbol_get_tc (label
)->class != XMC_TC0
)
3383 as_bad (_(".tc with no label"));
3384 ignore_rest_of_line ();
3388 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3389 symbol_set_frag (label
, symbol_get_frag (sym
));
3390 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3392 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3393 ++input_line_pointer
;
3398 S_SET_SEGMENT (sym
, now_seg
);
3399 symbol_set_frag (sym
, frag_now
);
3400 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3401 symbol_get_tc (sym
)->class = XMC_TC
;
3402 symbol_get_tc (sym
)->output
= 1;
3404 ppc_frob_label (sym
);
3407 #else /* ! defined (OBJ_XCOFF) */
3409 /* Skip the TOC symbol name. */
3410 while (is_part_of_name (*input_line_pointer
)
3411 || *input_line_pointer
== '['
3412 || *input_line_pointer
== ']'
3413 || *input_line_pointer
== '{'
3414 || *input_line_pointer
== '}')
3415 ++input_line_pointer
;
3417 /* Align to a four byte boundary. */
3418 frag_align (2, 0, 0);
3419 record_alignment (now_seg
, 2);
3421 #endif /* ! defined (OBJ_XCOFF) */
3423 if (*input_line_pointer
!= ',')
3424 demand_empty_rest_of_line ();
3427 ++input_line_pointer
;
3428 cons ((ppc_size
== PPC_OPCODE_64
) ? 8 : 4);
3434 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3436 /* Set the current section. */
3438 ppc_set_current_section (new)
3441 ppc_previous_section
= ppc_current_section
;
3442 ppc_current_section
= new;
3445 /* pseudo-op: .previous
3446 behaviour: toggles the current section with the previous section.
3448 warnings: "No previous section"
3451 ppc_previous(ignore
)
3452 int ignore ATTRIBUTE_UNUSED
;
3456 if (ppc_previous_section
== NULL
)
3458 as_warn(_("No previous section to return to. Directive ignored."));
3462 subseg_set(ppc_previous_section
, 0);
3464 ppc_set_current_section(ppc_previous_section
);
3467 /* pseudo-op: .pdata
3468 behaviour: predefined read only data section
3472 initial: .section .pdata "adr3"
3473 a - don't know -- maybe a misprint
3474 d - initialized data
3476 3 - double word aligned (that would be 4 byte boundary)
3479 Tag index tables (also known as the function table) for exception
3480 handling, debugging, etc.
3485 int ignore ATTRIBUTE_UNUSED
;
3487 if (pdata_section
== 0)
3489 pdata_section
= subseg_new (".pdata", 0);
3491 bfd_set_section_flags (stdoutput
, pdata_section
,
3492 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3493 | SEC_READONLY
| SEC_DATA
));
3495 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3499 pdata_section
= subseg_new(".pdata", 0);
3501 ppc_set_current_section(pdata_section
);
3504 /* pseudo-op: .ydata
3505 behaviour: predefined read only data section
3509 initial: .section .ydata "drw3"
3510 a - don't know -- maybe a misprint
3511 d - initialized data
3513 3 - double word aligned (that would be 4 byte boundary)
3515 Tag tables (also known as the scope table) for exception handling,
3520 int ignore ATTRIBUTE_UNUSED
;
3522 if (ydata_section
== 0)
3524 ydata_section
= subseg_new (".ydata", 0);
3525 bfd_set_section_flags (stdoutput
, ydata_section
,
3526 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3527 | SEC_READONLY
| SEC_DATA
));
3529 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3533 ydata_section
= subseg_new (".ydata", 0);
3535 ppc_set_current_section(ydata_section
);
3538 /* pseudo-op: .reldata
3539 behaviour: predefined read write data section
3540 double word aligned (4-byte)
3541 FIXME: relocation is applied to it
3542 FIXME: what's the difference between this and .data?
3545 initial: .section .reldata "drw3"
3546 d - initialized data
3549 3 - double word aligned (that would be 8 byte boundary)
3552 Like .data, but intended to hold data subject to relocation, such as
3553 function descriptors, etc.
3557 int ignore ATTRIBUTE_UNUSED
;
3559 if (reldata_section
== 0)
3561 reldata_section
= subseg_new (".reldata", 0);
3563 bfd_set_section_flags (stdoutput
, reldata_section
,
3564 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3567 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3571 reldata_section
= subseg_new (".reldata", 0);
3573 ppc_set_current_section(reldata_section
);
3576 /* pseudo-op: .rdata
3577 behaviour: predefined read only data section
3581 initial: .section .rdata "dr3"
3582 d - initialized data
3584 3 - double word aligned (that would be 4 byte boundary)
3588 int ignore ATTRIBUTE_UNUSED
;
3590 if (rdata_section
== 0)
3592 rdata_section
= subseg_new (".rdata", 0);
3593 bfd_set_section_flags (stdoutput
, rdata_section
,
3594 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3595 | SEC_READONLY
| SEC_DATA
));
3597 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3601 rdata_section
= subseg_new (".rdata", 0);
3603 ppc_set_current_section(rdata_section
);
3606 /* pseudo-op: .ualong
3607 behaviour: much like .int, with the exception that no alignment is
3609 FIXME: test the alignment statement
3615 int ignore ATTRIBUTE_UNUSED
;
3621 /* pseudo-op: .znop <symbol name>
3622 behaviour: Issue a nop instruction
3623 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3624 the supplied symbol name.
3626 warnings: Missing symbol name
3630 int ignore ATTRIBUTE_UNUSED
;
3633 const struct powerpc_opcode
*opcode
;
3639 /* Strip out the symbol name */
3647 symbol_name
= input_line_pointer
;
3648 c
= get_symbol_end ();
3650 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3651 strcpy (name
, symbol_name
);
3653 sym
= symbol_find_or_make (name
);
3655 *input_line_pointer
= c
;
3659 /* Look up the opcode in the hash table. */
3660 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3662 /* stick in the nop */
3663 insn
= opcode
->opcode
;
3665 /* Write out the instruction. */
3667 md_number_to_chars (f
, insn
, 4);
3669 f
- frag_now
->fr_literal
,
3674 BFD_RELOC_16_GOT_PCREL
);
3687 register char *name
;
3691 register symbolS
*symbolP
;
3694 name
= input_line_pointer
;
3695 c
= get_symbol_end ();
3697 /* just after name is now '\0' */
3698 p
= input_line_pointer
;
3701 if (*input_line_pointer
!= ',')
3703 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3704 ignore_rest_of_line ();
3708 input_line_pointer
++; /* skip ',' */
3709 if ((temp
= get_absolute_expression ()) < 0)
3711 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
3712 ignore_rest_of_line ();
3718 /* The third argument to .comm is the alignment. */
3719 if (*input_line_pointer
!= ',')
3723 ++input_line_pointer
;
3724 align
= get_absolute_expression ();
3727 as_warn (_("ignoring bad alignment"));
3734 symbolP
= symbol_find_or_make (name
);
3737 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3739 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3740 S_GET_NAME (symbolP
));
3741 ignore_rest_of_line ();
3745 if (S_GET_VALUE (symbolP
))
3747 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3748 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3749 S_GET_NAME (symbolP
),
3750 (long) S_GET_VALUE (symbolP
),
3755 S_SET_VALUE (symbolP
, (valueT
) temp
);
3756 S_SET_EXTERNAL (symbolP
);
3759 demand_empty_rest_of_line ();
3763 * implement the .section pseudo op:
3764 * .section name {, "flags"}
3766 * | +--- optional flags: 'b' for bss
3768 * +-- section name 'l' for lib
3772 * 'd' (apparently m88k for data)
3774 * But if the argument is not a quoted string, treat it as a
3775 * subsegment number.
3777 * FIXME: this is a copy of the section processing from obj-coff.c, with
3778 * additions/changes for the moto-pas assembler support. There are three
3781 * FIXME: I just noticed this. This doesn't work at all really. It it
3782 * setting bits that bfd probably neither understands or uses. The
3783 * correct approach (?) will have to incorporate extra fields attached
3784 * to the section to hold the system specific stuff. (krk)
3787 * 'a' - unknown - referred to in documentation, but no definition supplied
3788 * 'c' - section has code
3789 * 'd' - section has initialized data
3790 * 'u' - section has uninitialized data
3791 * 'i' - section contains directives (info)
3792 * 'n' - section can be discarded
3793 * 'R' - remove section at link time
3795 * Section Protection:
3796 * 'r' - section is readable
3797 * 'w' - section is writeable
3798 * 'x' - section is executable
3799 * 's' - section is sharable
3801 * Section Alignment:
3802 * '0' - align to byte boundary
3803 * '1' - align to halfword undary
3804 * '2' - align to word boundary
3805 * '3' - align to doubleword boundary
3806 * '4' - align to quadword boundary
3807 * '5' - align to 32 byte boundary
3808 * '6' - align to 64 byte boundary
3813 ppc_pe_section (ignore
)
3814 int ignore ATTRIBUTE_UNUSED
;
3816 /* Strip out the section name */
3825 section_name
= input_line_pointer
;
3826 c
= get_symbol_end ();
3828 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3829 strcpy (name
, section_name
);
3831 *input_line_pointer
= c
;
3836 flags
= SEC_NO_FLAGS
;
3838 if (strcmp (name
, ".idata$2") == 0)
3842 else if (strcmp (name
, ".idata$3") == 0)
3846 else if (strcmp (name
, ".idata$4") == 0)
3850 else if (strcmp (name
, ".idata$5") == 0)
3854 else if (strcmp (name
, ".idata$6") == 0)
3859 align
= 4; /* default alignment to 16 byte boundary */
3861 if (*input_line_pointer
== ',')
3863 ++input_line_pointer
;
3865 if (*input_line_pointer
!= '"')
3866 exp
= get_absolute_expression ();
3869 ++input_line_pointer
;
3870 while (*input_line_pointer
!= '"'
3871 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3873 switch (*input_line_pointer
)
3875 /* Section Contents */
3876 case 'a': /* unknown */
3877 as_bad (_("Unsupported section attribute -- 'a'"));
3879 case 'c': /* code section */
3882 case 'd': /* section has initialized data */
3885 case 'u': /* section has uninitialized data */
3886 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3890 case 'i': /* section contains directives (info) */
3891 /* FIXME: This is IMAGE_SCN_LNK_INFO
3893 flags
|= SEC_HAS_CONTENTS
;
3895 case 'n': /* section can be discarded */
3898 case 'R': /* Remove section at link time */
3899 flags
|= SEC_NEVER_LOAD
;
3902 /* Section Protection */
3903 case 'r': /* section is readable */
3904 flags
|= IMAGE_SCN_MEM_READ
;
3906 case 'w': /* section is writeable */
3907 flags
|= IMAGE_SCN_MEM_WRITE
;
3909 case 'x': /* section is executable */
3910 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3912 case 's': /* section is sharable */
3913 flags
|= IMAGE_SCN_MEM_SHARED
;
3916 /* Section Alignment */
3917 case '0': /* align to byte boundary */
3918 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3921 case '1': /* align to halfword boundary */
3922 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3925 case '2': /* align to word boundary */
3926 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3929 case '3': /* align to doubleword boundary */
3930 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3933 case '4': /* align to quadword boundary */
3934 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3937 case '5': /* align to 32 byte boundary */
3938 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3941 case '6': /* align to 64 byte boundary */
3942 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3947 as_bad(_("unknown section attribute '%c'"),
3948 *input_line_pointer
);
3951 ++input_line_pointer
;
3953 if (*input_line_pointer
== '"')
3954 ++input_line_pointer
;
3958 sec
= subseg_new (name
, (subsegT
) exp
);
3960 ppc_set_current_section(sec
);
3962 if (flags
!= SEC_NO_FLAGS
)
3964 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3965 as_bad (_("error setting flags for \"%s\": %s"),
3966 bfd_section_name (stdoutput
, sec
),
3967 bfd_errmsg (bfd_get_error ()));
3970 bfd_set_section_alignment(stdoutput
, sec
, align
);
3975 ppc_pe_function (ignore
)
3976 int ignore ATTRIBUTE_UNUSED
;
3982 name
= input_line_pointer
;
3983 endc
= get_symbol_end ();
3985 ext_sym
= symbol_find_or_make (name
);
3987 *input_line_pointer
= endc
;
3989 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3990 SF_SET_FUNCTION (ext_sym
);
3991 SF_SET_PROCESS (ext_sym
);
3992 coff_add_linesym (ext_sym
);
3994 demand_empty_rest_of_line ();
3998 ppc_pe_tocd (ignore
)
3999 int ignore ATTRIBUTE_UNUSED
;
4001 if (tocdata_section
== 0)
4003 tocdata_section
= subseg_new (".tocd", 0);
4004 /* FIXME: section flags won't work */
4005 bfd_set_section_flags (stdoutput
, tocdata_section
,
4006 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4007 | SEC_READONLY
| SEC_DATA
));
4009 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4013 rdata_section
= subseg_new (".tocd", 0);
4016 ppc_set_current_section(tocdata_section
);
4018 demand_empty_rest_of_line ();
4021 /* Don't adjust TOC relocs to use the section symbol. */
4024 ppc_pe_fix_adjustable (fix
)
4027 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4034 /* XCOFF specific symbol and file handling. */
4036 /* Canonicalize the symbol name. We use the to force the suffix, if
4037 any, to use square brackets, and to be in upper case. */
4040 ppc_canonicalize_symbol_name (name
)
4045 if (ppc_stab_symbol
)
4048 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4062 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4066 if (*s
== '\0' || s
[1] != '\0')
4067 as_bad (_("bad symbol suffix"));
4075 /* Set the class of a symbol based on the suffix, if any. This is
4076 called whenever a new symbol is created. */
4079 ppc_symbol_new_hook (sym
)
4082 struct ppc_tc_sy
*tc
;
4085 tc
= symbol_get_tc (sym
);
4089 tc
->real_name
= NULL
;
4095 if (ppc_stab_symbol
)
4098 s
= strchr (S_GET_NAME (sym
), '[');
4099 if (s
== (const char *) NULL
)
4101 /* There is no suffix. */
4110 if (strcmp (s
, "BS]") == 0)
4114 if (strcmp (s
, "DB]") == 0)
4116 else if (strcmp (s
, "DS]") == 0)
4120 if (strcmp (s
, "GL]") == 0)
4124 if (strcmp (s
, "PR]") == 0)
4128 if (strcmp (s
, "RO]") == 0)
4130 else if (strcmp (s
, "RW]") == 0)
4134 if (strcmp (s
, "SV]") == 0)
4138 if (strcmp (s
, "TC]") == 0)
4140 else if (strcmp (s
, "TI]") == 0)
4142 else if (strcmp (s
, "TB]") == 0)
4144 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4145 tc
->class = XMC_TC0
;
4148 if (strcmp (s
, "UA]") == 0)
4150 else if (strcmp (s
, "UC]") == 0)
4154 if (strcmp (s
, "XO]") == 0)
4159 if (tc
->class == -1)
4160 as_bad (_("Unrecognized symbol suffix"));
4163 /* Set the class of a label based on where it is defined. This
4164 handles symbols without suffixes. Also, move the symbol so that it
4165 follows the csect symbol. */
4168 ppc_frob_label (sym
)
4171 if (ppc_current_csect
!= (symbolS
*) NULL
)
4173 if (symbol_get_tc (sym
)->class == -1)
4174 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4176 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4177 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4178 &symbol_rootP
, &symbol_lastP
);
4179 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4183 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4184 seen. It tells ppc_adjust_symtab whether it needs to look through
4187 static boolean ppc_saw_abs
;
4189 /* Change the name of a symbol just before writing it out. Set the
4190 real name if the .rename pseudo-op was used. Otherwise, remove any
4191 class suffix. Return 1 if the symbol should not be included in the
4195 ppc_frob_symbol (sym
)
4198 static symbolS
*ppc_last_function
;
4199 static symbolS
*set_end
;
4201 /* Discard symbols that should not be included in the output symbol
4203 if (! symbol_used_in_reloc_p (sym
)
4204 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4205 || (! S_IS_EXTERNAL (sym
)
4206 && ! symbol_get_tc (sym
)->output
4207 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4210 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4211 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4217 name
= S_GET_NAME (sym
);
4218 s
= strchr (name
, '[');
4219 if (s
!= (char *) NULL
)
4225 snew
= xmalloc (len
+ 1);
4226 memcpy (snew
, name
, len
);
4229 S_SET_NAME (sym
, snew
);
4233 if (set_end
!= (symbolS
*) NULL
)
4235 SA_SET_SYM_ENDNDX (set_end
, sym
);
4239 if (SF_GET_FUNCTION (sym
))
4241 if (ppc_last_function
!= (symbolS
*) NULL
)
4242 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4243 ppc_last_function
= sym
;
4244 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4246 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4247 SA_SET_SYM_FSIZE (sym
,
4248 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4251 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4252 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4254 if (ppc_last_function
== (symbolS
*) NULL
)
4255 as_bad (_(".ef with no preceding .function"));
4258 set_end
= ppc_last_function
;
4259 ppc_last_function
= NULL
;
4261 /* We don't have a C_EFCN symbol, but we need to force the
4262 COFF backend to believe that it has seen one. */
4263 coff_last_function
= NULL
;
4267 if (! S_IS_EXTERNAL (sym
)
4268 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4269 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4270 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4271 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4272 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4273 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4274 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4275 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4276 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4277 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4279 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4280 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4283 union internal_auxent
*a
;
4285 /* Create a csect aux. */
4286 i
= S_GET_NUMBER_AUXILIARY (sym
);
4287 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4288 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4289 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4291 /* This is the TOC table. */
4292 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4293 a
->x_csect
.x_scnlen
.l
= 0;
4294 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4296 else if (symbol_get_tc (sym
)->subseg
!= 0)
4298 /* This is a csect symbol. x_scnlen is the size of the
4300 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4301 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4302 S_GET_SEGMENT (sym
))
4303 - S_GET_VALUE (sym
));
4306 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4307 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4308 - S_GET_VALUE (sym
));
4310 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4312 else if (S_GET_SEGMENT (sym
) == bss_section
)
4314 /* This is a common symbol. */
4315 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4316 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4317 if (S_IS_EXTERNAL (sym
))
4318 symbol_get_tc (sym
)->class = XMC_RW
;
4320 symbol_get_tc (sym
)->class = XMC_BS
;
4322 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4324 /* This is an absolute symbol. The csect will be created by
4325 ppc_adjust_symtab. */
4327 a
->x_csect
.x_smtyp
= XTY_LD
;
4328 if (symbol_get_tc (sym
)->class == -1)
4329 symbol_get_tc (sym
)->class = XMC_XO
;
4331 else if (! S_IS_DEFINED (sym
))
4333 /* This is an external symbol. */
4334 a
->x_csect
.x_scnlen
.l
= 0;
4335 a
->x_csect
.x_smtyp
= XTY_ER
;
4337 else if (symbol_get_tc (sym
)->class == XMC_TC
)
4341 /* This is a TOC definition. x_scnlen is the size of the
4343 next
= symbol_next (sym
);
4344 while (symbol_get_tc (next
)->class == XMC_TC0
)
4345 next
= symbol_next (next
);
4346 if (next
== (symbolS
*) NULL
4347 || symbol_get_tc (next
)->class != XMC_TC
)
4349 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4350 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4352 - S_GET_VALUE (sym
));
4354 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4355 - S_GET_VALUE (sym
));
4359 resolve_symbol_value (next
);
4360 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4361 - S_GET_VALUE (sym
));
4363 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4369 /* This is a normal symbol definition. x_scnlen is the
4370 symbol index of the containing csect. */
4371 if (S_GET_SEGMENT (sym
) == text_section
)
4372 csect
= ppc_text_csects
;
4373 else if (S_GET_SEGMENT (sym
) == data_section
)
4374 csect
= ppc_data_csects
;
4378 /* Skip the initial dummy symbol. */
4379 csect
= symbol_get_tc (csect
)->next
;
4381 if (csect
== (symbolS
*) NULL
)
4383 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4384 a
->x_csect
.x_scnlen
.l
= 0;
4388 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
4390 resolve_symbol_value (symbol_get_tc (csect
)->next
);
4391 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
4392 > S_GET_VALUE (sym
))
4394 csect
= symbol_get_tc (csect
)->next
;
4397 a
->x_csect
.x_scnlen
.p
=
4398 coffsymbol (symbol_get_bfdsym (csect
))->native
;
4399 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
4402 a
->x_csect
.x_smtyp
= XTY_LD
;
4405 a
->x_csect
.x_parmhash
= 0;
4406 a
->x_csect
.x_snhash
= 0;
4407 if (symbol_get_tc (sym
)->class == -1)
4408 a
->x_csect
.x_smclas
= XMC_PR
;
4410 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
4411 a
->x_csect
.x_stab
= 0;
4412 a
->x_csect
.x_snstab
= 0;
4414 /* Don't let the COFF backend resort these symbols. */
4415 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
4417 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4419 /* We want the value to be the symbol index of the referenced
4420 csect symbol. BFD will do that for us if we set the right
4424 coffsymbol (symbol_get_bfdsym
4425 (symbol_get_tc (sym
)->within
))->native
));
4426 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
4428 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4433 /* The value is the offset from the enclosing csect. */
4434 block
= symbol_get_tc (sym
)->within
;
4435 csect
= symbol_get_tc (block
)->within
;
4436 resolve_symbol_value (csect
);
4437 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4439 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4440 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4442 /* We want the value to be a file offset into the line numbers.
4443 BFD will do that for us if we set the right flags. We have
4444 already set the value correctly. */
4445 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
4451 /* Adjust the symbol table. This creates csect symbols for all
4452 absolute symbols. */
4455 ppc_adjust_symtab ()
4462 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4466 union internal_auxent
*a
;
4468 if (S_GET_SEGMENT (sym
) != absolute_section
)
4471 csect
= symbol_create (".abs[XO]", absolute_section
,
4472 S_GET_VALUE (sym
), &zero_address_frag
);
4473 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
4474 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4475 i
= S_GET_NUMBER_AUXILIARY (csect
);
4476 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4477 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
4478 a
->x_csect
.x_scnlen
.l
= 0;
4479 a
->x_csect
.x_smtyp
= XTY_SD
;
4480 a
->x_csect
.x_parmhash
= 0;
4481 a
->x_csect
.x_snhash
= 0;
4482 a
->x_csect
.x_smclas
= XMC_XO
;
4483 a
->x_csect
.x_stab
= 0;
4484 a
->x_csect
.x_snstab
= 0;
4486 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4488 i
= S_GET_NUMBER_AUXILIARY (sym
);
4489 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
4490 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
4491 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
4494 ppc_saw_abs
= false;
4497 /* Set the VMA for a section. This is called on all the sections in
4501 ppc_frob_section (sec
)
4504 static bfd_size_type vma
= 0;
4506 bfd_set_section_vma (stdoutput
, sec
, vma
);
4507 vma
+= bfd_section_size (stdoutput
, sec
);
4510 #endif /* OBJ_XCOFF */
4512 /* Turn a string in input_line_pointer into a floating point constant
4513 of type TYPE, and store the appropriate bytes in *LITP. The number
4514 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4515 returned, or NULL on OK. */
4518 md_atof (type
, litp
, sizep
)
4524 LITTLENUM_TYPE words
[4];
4540 return _("bad call to md_atof");
4543 t
= atof_ieee (input_line_pointer
, type
, words
);
4545 input_line_pointer
= t
;
4549 if (target_big_endian
)
4551 for (i
= 0; i
< prec
; i
++)
4553 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4559 for (i
= prec
- 1; i
>= 0; i
--)
4561 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4569 /* Write a value out to the object file, using the appropriate
4573 md_number_to_chars (buf
, val
, n
)
4578 if (target_big_endian
)
4579 number_to_chars_bigendian (buf
, val
, n
);
4581 number_to_chars_littleendian (buf
, val
, n
);
4584 /* Align a section (I don't know why this is machine dependent). */
4587 md_section_align (seg
, addr
)
4591 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4593 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4596 /* We don't have any form of relaxing. */
4599 md_estimate_size_before_relax (fragp
, seg
)
4600 fragS
*fragp ATTRIBUTE_UNUSED
;
4601 asection
*seg ATTRIBUTE_UNUSED
;
4607 /* Convert a machine dependent frag. We never generate these. */
4610 md_convert_frag (abfd
, sec
, fragp
)
4611 bfd
*abfd ATTRIBUTE_UNUSED
;
4612 asection
*sec ATTRIBUTE_UNUSED
;
4613 fragS
*fragp ATTRIBUTE_UNUSED
;
4618 /* We have no need to default values of symbols. */
4621 md_undefined_symbol (name
)
4622 char *name ATTRIBUTE_UNUSED
;
4627 /* Functions concerning relocs. */
4629 /* The location from which a PC relative jump should be calculated,
4630 given a PC relative reloc. */
4633 md_pcrel_from_section (fixp
, sec
)
4635 segT sec ATTRIBUTE_UNUSED
;
4637 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4642 /* This is called to see whether a fixup should be adjusted to use a
4643 section symbol. We take the opportunity to change a fixup against
4644 a symbol in the TOC subsegment into a reloc against the
4645 corresponding .tc symbol. */
4648 ppc_fix_adjustable (fix
)
4653 resolve_symbol_value (fix
->fx_addsy
);
4654 val
= S_GET_VALUE (fix
->fx_addsy
);
4655 if (ppc_toc_csect
!= (symbolS
*) NULL
4656 && fix
->fx_addsy
!= (symbolS
*) NULL
4657 && fix
->fx_addsy
!= ppc_toc_csect
4658 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4659 && val
>= ppc_toc_frag
->fr_address
4660 && (ppc_after_toc_frag
== (fragS
*) NULL
4661 || val
< ppc_after_toc_frag
->fr_address
))
4665 for (sy
= symbol_next (ppc_toc_csect
);
4666 sy
!= (symbolS
*) NULL
;
4667 sy
= symbol_next (sy
))
4669 if (symbol_get_tc (sy
)->class == XMC_TC0
)
4671 if (symbol_get_tc (sy
)->class != XMC_TC
)
4673 resolve_symbol_value (sy
);
4674 if (val
== S_GET_VALUE (sy
))
4677 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4682 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4683 _("symbol in .toc does not match any .tc"));
4686 /* Possibly adjust the reloc to be against the csect. */
4687 if (fix
->fx_addsy
!= (symbolS
*) NULL
4688 && symbol_get_tc (fix
->fx_addsy
)->subseg
== 0
4689 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC0
4690 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC
4691 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
4692 /* Don't adjust if this is a reloc in the toc section. */
4693 && (S_GET_SEGMENT (fix
->fx_addsy
) != data_section
4694 || ppc_toc_csect
== NULL
4695 || val
< ppc_toc_frag
->fr_address
4696 || (ppc_after_toc_frag
!= NULL
4697 && val
>= ppc_after_toc_frag
->fr_address
)))
4701 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4702 csect
= ppc_text_csects
;
4703 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4704 csect
= ppc_data_csects
;
4708 /* Skip the initial dummy symbol. */
4709 csect
= symbol_get_tc (csect
)->next
;
4711 if (csect
!= (symbolS
*) NULL
)
4713 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
4714 && (symbol_get_frag (symbol_get_tc (csect
)->next
)->fr_address
4717 /* If the csect address equals the symbol value, then we
4718 have to look through the full symbol table to see
4719 whether this is the csect we want. Note that we will
4720 only get here if the csect has zero length. */
4721 if ((symbol_get_frag (csect
)->fr_address
== val
)
4722 && S_GET_VALUE (csect
) == S_GET_VALUE (fix
->fx_addsy
))
4726 for (scan
= symbol_next (csect
);
4728 scan
= symbol_next (scan
))
4730 if (symbol_get_tc (scan
)->subseg
!= 0)
4732 if (scan
== fix
->fx_addsy
)
4736 /* If we found the symbol before the next csect
4737 symbol, then this is the csect we want. */
4738 if (scan
== fix
->fx_addsy
)
4742 csect
= symbol_get_tc (csect
)->next
;
4745 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4746 - symbol_get_frag (csect
)->fr_address
);
4747 fix
->fx_addsy
= csect
;
4751 /* Adjust a reloc against a .lcomm symbol to be against the base
4753 if (fix
->fx_addsy
!= (symbolS
*) NULL
4754 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4755 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4757 resolve_symbol_value (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
);
4759 (S_GET_VALUE (fix
->fx_addsy
)
4760 - S_GET_VALUE (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
));
4761 fix
->fx_addsy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
4767 /* A reloc from one csect to another must be kept. The assembler
4768 will, of course, keep relocs between sections, and it will keep
4769 absolute relocs, but we need to force it to keep PC relative relocs
4770 between two csects in the same section. */
4773 ppc_force_relocation (fix
)
4776 /* At this point fix->fx_addsy should already have been converted to
4777 a csect symbol. If the csect does not include the fragment, then
4778 we need to force the relocation. */
4780 && fix
->fx_addsy
!= NULL
4781 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
4782 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
4783 > fix
->fx_frag
->fr_address
)
4784 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
4785 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
4786 <= fix
->fx_frag
->fr_address
))))
4792 #endif /* OBJ_XCOFF */
4794 /* See whether a symbol is in the TOC section. */
4797 ppc_is_toc_sym (sym
)
4801 return symbol_get_tc (sym
)->class == XMC_TC
;
4803 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4807 /* Apply a fixup to the object code. This is called for all the
4808 fixups we generated by the call to fix_new_exp, above. In the call
4809 above we used a reloc code which was the largest legal reloc code
4810 plus the operand index. Here we undo that to recover the operand
4811 index. At this point all symbol values should be fully resolved,
4812 and we attempt to completely resolve the reloc. If we can not do
4813 that, we determine the correct reloc code and put it back in the
4817 md_apply_fix3 (fixp
, valuep
, seg
)
4826 if (fixp
->fx_addsy
!= NULL
)
4828 /* `*valuep' may contain the value of the symbol on which the reloc
4829 will be based; we have to remove it. */
4830 if (symbol_used_in_reloc_p (fixp
->fx_addsy
)
4831 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
4832 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
4833 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
4834 value
-= S_GET_VALUE (fixp
->fx_addsy
);
4836 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4837 supposed to be? I think this is related to various similar
4838 FIXMEs in tc-i386.c and tc-sparc.c. */
4840 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4847 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4848 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4849 doing this relocation the code in write.c is going to call
4850 bfd_install_relocation, which is also going to use the symbol
4851 value. That means that if the reloc is fully resolved we want to
4852 use *valuep since bfd_install_relocation is not being used.
4853 However, if the reloc is not fully resolved we do not want to use
4854 *valuep, and must use fx_offset instead. However, if the reloc
4855 is PC relative, we do want to use *valuep since it includes the
4856 result of md_pcrel_from. This is confusing. */
4857 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4862 else if (fixp
->fx_pcrel
)
4866 value
= fixp
->fx_offset
;
4867 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4869 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4870 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4873 /* We can't actually support subtracting a symbol. */
4874 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4875 _("expression too complex"));
4881 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4884 const struct powerpc_operand
*operand
;
4888 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4890 operand
= &powerpc_operands
[opindex
];
4893 /* It appears that an instruction like
4895 when LC..1 is not a TOC symbol does not generate a reloc. It
4896 uses the offset of LC..1 within its csect. However, .long
4897 LC..1 will generate a reloc. I can't find any documentation
4898 on how these cases are to be distinguished, so this is a wild
4899 guess. These cases are generated by gcc -mminimal-toc. */
4900 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4901 && operand
->bits
== 16
4902 && operand
->shift
== 0
4903 && operand
->insert
== NULL
4904 && fixp
->fx_addsy
!= NULL
4905 && symbol_get_tc (fixp
->fx_addsy
)->subseg
!= 0
4906 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC
4907 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC0
4908 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4910 value
= fixp
->fx_offset
;
4915 /* Fetch the instruction, insert the fully resolved operand
4916 value, and stuff the instruction back again. */
4917 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4918 if (target_big_endian
)
4919 insn
= bfd_getb32 ((unsigned char *) where
);
4921 insn
= bfd_getl32 ((unsigned char *) where
);
4922 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4923 fixp
->fx_file
, fixp
->fx_line
);
4924 if (target_big_endian
)
4925 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4927 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4931 /* Nothing else to do here. */
4935 /* Determine a BFD reloc value based on the operand information.
4936 We are only prepared to turn a few of the operands into
4938 FIXME: We need to handle the DS field at the very least.
4939 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4940 there should be a new field in the operand table. */
4941 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4942 && operand
->bits
== 26
4943 && operand
->shift
== 0)
4944 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4945 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4946 && operand
->bits
== 16
4947 && operand
->shift
== 0)
4948 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4949 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4950 && operand
->bits
== 26
4951 && operand
->shift
== 0)
4952 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4953 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4954 && operand
->bits
== 16
4955 && operand
->shift
== 0)
4956 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4957 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4958 && operand
->bits
== 16
4959 && operand
->shift
== 0
4960 && fixp
->fx_addsy
!= NULL
4961 && ppc_is_toc_sym (fixp
->fx_addsy
))
4964 if (target_big_endian
)
4965 fixp
->fx_where
+= 2;
4966 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4973 /* Use expr_symbol_where to see if this is an expression
4975 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
4976 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4977 _("unresolved expression that must be resolved"));
4979 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4980 _("unsupported relocation type"));
4988 ppc_elf_validate_fix (fixp
, seg
);
4990 switch (fixp
->fx_r_type
)
4993 case BFD_RELOC_CTOR
:
4995 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4999 case BFD_RELOC_32_PCREL
:
5000 case BFD_RELOC_32_BASEREL
:
5001 case BFD_RELOC_PPC_EMB_NADDR32
:
5002 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5008 fixp
->fx_r_type
= BFD_RELOC_64_PCREL
;
5010 case BFD_RELOC_64_PCREL
:
5011 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5014 case BFD_RELOC_LO16
:
5016 case BFD_RELOC_GPREL16
:
5017 case BFD_RELOC_16_GOT_PCREL
:
5018 case BFD_RELOC_16_GOTOFF
:
5019 case BFD_RELOC_LO16_GOTOFF
:
5020 case BFD_RELOC_HI16_GOTOFF
:
5021 case BFD_RELOC_HI16_S_GOTOFF
:
5022 case BFD_RELOC_LO16_BASEREL
:
5023 case BFD_RELOC_HI16_BASEREL
:
5024 case BFD_RELOC_HI16_S_BASEREL
:
5025 case BFD_RELOC_PPC_EMB_NADDR16
:
5026 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5027 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5028 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5029 case BFD_RELOC_PPC_EMB_SDAI16
:
5030 case BFD_RELOC_PPC_EMB_SDA2REL
:
5031 case BFD_RELOC_PPC_EMB_SDA2I16
:
5032 case BFD_RELOC_PPC_EMB_RELSEC16
:
5033 case BFD_RELOC_PPC_EMB_RELST_LO
:
5034 case BFD_RELOC_PPC_EMB_RELST_HI
:
5035 case BFD_RELOC_PPC_EMB_RELST_HA
:
5036 case BFD_RELOC_PPC_EMB_RELSDA
:
5037 case BFD_RELOC_PPC_TOC16
:
5040 if (fixp
->fx_addsy
!= NULL
)
5041 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5042 _("cannot emit PC relative %s relocation against %s"),
5043 bfd_get_reloc_code_name (fixp
->fx_r_type
),
5044 S_GET_NAME (fixp
->fx_addsy
));
5046 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5047 _("cannot emit PC relative %s relocation"),
5048 bfd_get_reloc_code_name (fixp
->fx_r_type
));
5051 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5055 /* This case happens when you write, for example,
5057 where L1 and L2 are defined later. */
5058 case BFD_RELOC_HI16
:
5061 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5064 case BFD_RELOC_HI16_S
:
5067 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5068 (value
+ 0x8000) >> 16, 2);
5071 /* Because SDA21 modifies the register field, the size is set to 4
5072 bytes, rather than 2, so offset it here appropriately */
5073 case BFD_RELOC_PPC_EMB_SDA21
:
5077 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
5078 + ((target_big_endian
) ? 2 : 0),
5086 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5090 case BFD_RELOC_24_PLT_PCREL
:
5091 case BFD_RELOC_PPC_LOCAL24PC
:
5092 if (!fixp
->fx_pcrel
&& !fixp
->fx_done
)
5100 /* Fetch the instruction, insert the fully resolved operand
5101 value, and stuff the instruction back again. */
5102 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5103 if (target_big_endian
)
5104 insn
= bfd_getb32 ((unsigned char *) where
);
5106 insn
= bfd_getl32 ((unsigned char *) where
);
5107 if ((value
& 3) != 0)
5108 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5109 _("must branch to an address a multiple of 4"));
5110 if ((offsetT
) value
< -0x40000000
5111 || (offsetT
) value
>= 0x40000000)
5112 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5113 _("@local or @plt branch destination is too far away, %ld bytes"),
5115 insn
= insn
| (value
& 0x03fffffc);
5116 if (target_big_endian
)
5117 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5119 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5123 case BFD_RELOC_VTABLE_INHERIT
:
5126 && !S_IS_DEFINED (fixp
->fx_addsy
)
5127 && !S_IS_WEAK (fixp
->fx_addsy
))
5128 S_SET_WEAK (fixp
->fx_addsy
);
5131 case BFD_RELOC_VTABLE_ENTRY
:
5137 _("Gas failure, reloc value %d\n"), fixp
->fx_r_type
);
5144 fixp
->fx_addnumber
= value
;
5146 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
5147 fixp
->fx_addnumber
= 0;
5151 fixp
->fx_addnumber
= 0;
5153 /* We want to use the offset within the data segment of the
5154 symbol, not the actual VMA of the symbol. */
5155 fixp
->fx_addnumber
=
5156 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
5164 /* Generate a reloc for a fixup. */
5167 tc_gen_reloc (seg
, fixp
)
5168 asection
*seg ATTRIBUTE_UNUSED
;
5173 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5175 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5176 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5177 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5178 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5179 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
5181 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5182 _("reloc %d not supported by object file format"), (int)fixp
->fx_r_type
);
5185 reloc
->addend
= fixp
->fx_addnumber
;