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 /* Put back the delimiting char. */
590 *input_line_pointer
= c
;
592 /* Look to see if it's in the register table. */
595 expressionP
->X_op
= O_register
;
596 expressionP
->X_add_number
= reg_number
;
598 /* Make the rest nice. */
599 expressionP
->X_add_symbol
= NULL
;
600 expressionP
->X_op_symbol
= NULL
;
604 /* Reset the line as if we had not done anything. */
605 input_line_pointer
= start
;
609 /* This function is called for each symbol seen in an expression. It
610 handles the special parsing which PowerPC assemblers are supposed
611 to use for condition codes. */
613 /* Whether to do the special parsing. */
614 static boolean cr_operand
;
616 /* Names to recognize in a condition code. This table is sorted. */
617 static const struct pd_reg cr_names
[] =
634 /* Parsing function. This returns non-zero if it recognized an
638 ppc_parse_name (name
, expr
)
647 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
652 expr
->X_op
= O_constant
;
653 expr
->X_add_number
= val
;
658 /* Local variables. */
660 /* The type of processor we are assembling for. This is one or more
661 of the PPC_OPCODE flags defined in opcode/ppc.h. */
662 static int ppc_cpu
= 0;
664 /* The size of the processor we are assembling for. This is either
665 PPC_OPCODE_32 or PPC_OPCODE_64. */
666 static unsigned long ppc_size
= PPC_OPCODE_32
;
668 /* Whether to target xcoff64. */
669 static int ppc_xcoff64
= 0;
671 /* Opcode hash table. */
672 static struct hash_control
*ppc_hash
;
674 /* Macro hash table. */
675 static struct hash_control
*ppc_macro_hash
;
678 /* What type of shared library support to use. */
679 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
681 /* Flags to set in the elf header. */
682 static flagword ppc_flags
= 0;
684 /* Whether this is Solaris or not. */
685 #ifdef TARGET_SOLARIS_COMMENT
686 #define SOLARIS_P true
688 #define SOLARIS_P false
691 static boolean msolaris
= SOLARIS_P
;
696 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
697 using a bunch of different sections. These assembler sections,
698 however, are all encompassed within the .text or .data sections of
699 the final output file. We handle this by using different
700 subsegments within these main segments. */
702 /* Next subsegment to allocate within the .text segment. */
703 static subsegT ppc_text_subsegment
= 2;
705 /* Linked list of csects in the text section. */
706 static symbolS
*ppc_text_csects
;
708 /* Next subsegment to allocate within the .data segment. */
709 static subsegT ppc_data_subsegment
= 2;
711 /* Linked list of csects in the data section. */
712 static symbolS
*ppc_data_csects
;
714 /* The current csect. */
715 static symbolS
*ppc_current_csect
;
717 /* The RS/6000 assembler uses a TOC which holds addresses of functions
718 and variables. Symbols are put in the TOC with the .tc pseudo-op.
719 A special relocation is used when accessing TOC entries. We handle
720 the TOC as a subsegment within the .data segment. We set it up if
721 we see a .toc pseudo-op, and save the csect symbol here. */
722 static symbolS
*ppc_toc_csect
;
724 /* The first frag in the TOC subsegment. */
725 static fragS
*ppc_toc_frag
;
727 /* The first frag in the first subsegment after the TOC in the .data
728 segment. NULL if there are no subsegments after the TOC. */
729 static fragS
*ppc_after_toc_frag
;
731 /* The current static block. */
732 static symbolS
*ppc_current_block
;
734 /* The COFF debugging section; set by md_begin. This is not the
735 .debug section, but is instead the secret BFD section which will
736 cause BFD to set the section number of a symbol to N_DEBUG. */
737 static asection
*ppc_coff_debug_section
;
739 #endif /* OBJ_XCOFF */
743 /* Various sections that we need for PE coff support. */
744 static segT ydata_section
;
745 static segT pdata_section
;
746 static segT reldata_section
;
747 static segT rdata_section
;
748 static segT tocdata_section
;
750 /* The current section and the previous section. See ppc_previous. */
751 static segT ppc_previous_section
;
752 static segT ppc_current_section
;
757 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
761 CONST
char *md_shortopts
= "b:l:usm:K:VQ:";
763 CONST
char *md_shortopts
= "um:";
765 struct option md_longopts
[] = {
766 {NULL
, no_argument
, NULL
, 0}
768 size_t md_longopts_size
= sizeof (md_longopts
);
771 md_parse_option (c
, arg
)
778 /* -u means that any undefined symbols should be treated as
779 external, which is the default for gas anyhow. */
784 /* Solaris as takes -le (presumably for little endian). For completeness
785 sake, recognize -be also. */
786 if (strcmp (arg
, "e") == 0)
788 target_big_endian
= 0;
789 set_target_endian
= 1;
797 if (strcmp (arg
, "e") == 0)
799 target_big_endian
= 1;
800 set_target_endian
= 1;
808 /* Recognize -K PIC. */
809 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
812 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
820 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
822 if (strcmp (arg
, "64") == 0)
824 else if (strcmp (arg
, "32") == 0)
831 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
833 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
834 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
835 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
836 else if (strcmp (arg
, "pwr") == 0)
837 ppc_cpu
= PPC_OPCODE_POWER
;
838 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
839 instructions that are holdovers from the Power. */
840 else if (strcmp (arg
, "601") == 0)
841 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
842 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
843 Motorola PowerPC 603/604. */
844 else if (strcmp (arg
, "ppc") == 0
845 || strcmp (arg
, "ppc32") == 0
846 || strcmp (arg
, "403") == 0
847 || strcmp (arg
, "405") == 0
848 || strcmp (arg
, "603") == 0
849 || strcmp (arg
, "604") == 0)
850 ppc_cpu
= PPC_OPCODE_PPC
;
851 else if (strcmp (arg
, "7400") == 0)
852 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
;
853 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
855 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
857 ppc_cpu
= PPC_OPCODE_PPC
;
858 ppc_size
= PPC_OPCODE_64
;
860 else if (strcmp (arg
, "ppc64bridge") == 0)
862 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_64_BRIDGE
;
863 ppc_size
= PPC_OPCODE_64
;
865 /* -mcom means assemble for the common intersection between Power
866 and PowerPC. At present, we just allow the union, rather
867 than the intersection. */
868 else if (strcmp (arg
, "com") == 0)
869 ppc_cpu
= PPC_OPCODE_COMMON
;
870 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
871 else if (strcmp (arg
, "any") == 0)
872 ppc_cpu
= PPC_OPCODE_ANY
;
874 else if (strcmp (arg
, "regnames") == 0)
877 else if (strcmp (arg
, "no-regnames") == 0)
881 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
882 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
901 || strcmp (arg
, "little-endian") == 0)
903 target_big_endian
= 0;
904 set_target_endian
= 1;
907 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
909 target_big_endian
= 1;
910 set_target_endian
= 1;
913 else if (strcmp (arg
, "solaris") == 0)
916 ppc_comment_chars
= ppc_solaris_comment_chars
;
919 else if (strcmp (arg
, "no-solaris") == 0)
922 ppc_comment_chars
= ppc_eabi_comment_chars
;
927 as_bad (_("invalid switch -m%s"), arg
);
933 /* -V: SVR4 argument to print version ID. */
938 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
939 should be emitted or not. FIXME: Not implemented. */
943 /* Solaris takes -s to specify that .stabs go in a .stabs section,
944 rather than .stabs.excl, which is ignored by the linker.
945 FIXME: Not implemented. */
961 md_show_usage (stream
)
964 fprintf (stream
, _("\
967 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
968 -mpwr generate code for IBM POWER (RIOS1)\n\
969 -m601 generate code for Motorola PowerPC 601\n\
970 -mppc, -mppc32, -m403, -m405, -m603, -m604\n\
971 generate code for Motorola PowerPC 603/604\n\
972 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
973 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
974 -mcom generate code Power/PowerPC common instructions\n\
975 -many generate code for any architecture (PWR/PWRX/PPC)\n\
976 -mregnames Allow symbolic names for registers\n\
977 -mno-regnames Do not allow symbolic names for registers\n"));
979 fprintf (stream
, _("\
980 -mrelocatable support for GCC's -mrelocatble option\n\
981 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
982 -memb set PPC_EMB bit in ELF flags\n\
983 -mlittle, -mlittle-endian\n\
984 generate code for a little endian machine\n\
985 -mbig, -mbig-endian generate code for a big endian machine\n\
986 -msolaris generate code for Solaris\n\
987 -mno-solaris do not generate code for Solaris\n\
988 -V print assembler version number\n\
989 -Qy, -Qn ignored\n"));
993 /* Set ppc_cpu if it is not already set. */
998 const char *default_os
= TARGET_OS
;
999 const char *default_cpu
= TARGET_CPU
;
1003 if (strncmp (default_os
, "aix", 3) == 0
1004 && default_os
[3] >= '4' && default_os
[3] <= '9')
1005 ppc_cpu
= PPC_OPCODE_COMMON
;
1006 else if (strncmp (default_os
, "aix3", 4) == 0)
1007 ppc_cpu
= PPC_OPCODE_POWER
;
1008 else if (strcmp (default_cpu
, "rs6000") == 0)
1009 ppc_cpu
= PPC_OPCODE_POWER
;
1010 else if (strcmp (default_cpu
, "powerpc") == 0
1011 || strcmp (default_cpu
, "powerpcle") == 0)
1012 ppc_cpu
= PPC_OPCODE_PPC
;
1014 as_fatal (_("Unknown default cpu = %s, os = %s"),
1015 default_cpu
, default_os
);
1019 /* Figure out the BFD architecture to use. */
1021 enum bfd_architecture
1024 const char *default_cpu
= TARGET_CPU
;
1027 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1028 return bfd_arch_powerpc
;
1029 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1030 return bfd_arch_rs6000
;
1031 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1033 if (strcmp (default_cpu
, "rs6000") == 0)
1034 return bfd_arch_rs6000
;
1035 else if (strcmp (default_cpu
, "powerpc") == 0
1036 || strcmp (default_cpu
, "powerpcle") == 0)
1037 return bfd_arch_powerpc
;
1040 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1041 return bfd_arch_unknown
;
1047 return ppc_size
== PPC_OPCODE_64
? 620 : 0;
1053 return ppc_xcoff64
? 3 : 2;
1057 ppc_target_format ()
1061 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1064 return ppc_xcoff64
? "aixcoff64-rs6000" : "aixcoff-rs6000";
1067 return "xcoff-powermac";
1071 return target_big_endian
? "elf32-powerpc" : "elf32-powerpcle";
1075 /* This function is called when the assembler starts up. It is called
1076 after the options have been parsed and the output file has been
1082 register const struct powerpc_opcode
*op
;
1083 const struct powerpc_opcode
*op_end
;
1084 const struct powerpc_macro
*macro
;
1085 const struct powerpc_macro
*macro_end
;
1086 boolean dup_insn
= false;
1091 /* Set the ELF flags if desired. */
1092 if (ppc_flags
&& !msolaris
)
1093 bfd_set_private_flags (stdoutput
, ppc_flags
);
1096 /* Insert the opcodes into a hash table. */
1097 ppc_hash
= hash_new ();
1099 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1100 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1102 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1104 if ((op
->flags
& ppc_cpu
) != 0
1105 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1106 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
1107 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0))
1111 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1112 if (retval
!= (const char *) NULL
)
1114 /* Ignore Power duplicates for -m601. */
1115 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1116 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1119 as_bad (_("Internal assembler error for instruction %s"),
1126 /* Insert the macros into a hash table. */
1127 ppc_macro_hash
= hash_new ();
1129 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1130 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1132 if ((macro
->flags
& ppc_cpu
) != 0)
1136 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1137 if (retval
!= (const char *) NULL
)
1139 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1148 /* Tell the main code what the endianness is if it is not overidden
1150 if (!set_target_endian
)
1152 set_target_endian
= 1;
1153 target_big_endian
= PPC_BIG_ENDIAN
;
1157 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1159 /* Create dummy symbols to serve as initial csects. This forces the
1160 text csects to precede the data csects. These symbols will not
1162 ppc_text_csects
= symbol_make ("dummy\001");
1163 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1164 ppc_data_csects
= symbol_make ("dummy\001");
1165 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1170 ppc_current_section
= text_section
;
1171 ppc_previous_section
= 0;
1176 /* Insert an operand value into an instruction. */
1178 static unsigned long
1179 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1181 const struct powerpc_operand
*operand
;
1186 if (operand
->bits
!= 32)
1191 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1193 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1194 max
= (1 << operand
->bits
) - 1;
1196 max
= (1 << (operand
->bits
- 1)) - 1;
1197 min
= - (1 << (operand
->bits
- 1));
1199 if (ppc_size
== PPC_OPCODE_32
)
1201 /* Some people write 32 bit hex constants with the sign
1202 extension done by hand. This shouldn't really be
1203 valid, but, to permit this code to assemble on a 64
1204 bit host, we sign extend the 32 bit value. */
1206 && (val
& (offsetT
) 0x80000000) != 0
1207 && (val
& (offsetT
) 0xffffffff) == val
)
1216 max
= (1 << operand
->bits
) - 1;
1220 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1225 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1228 _("operand out of range (%s not between %ld and %ld)");
1231 sprint_value (buf
, test
);
1232 if (file
== (char *) NULL
)
1233 as_bad (err
, buf
, min
, max
);
1235 as_bad_where (file
, line
, err
, buf
, min
, max
);
1239 if (operand
->insert
)
1244 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1245 if (errmsg
!= (const char *) NULL
)
1249 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1257 /* Parse @got, etc. and return the desired relocation. */
1258 static bfd_reloc_code_real_type
1259 ppc_elf_suffix (str_p
, exp_p
)
1266 bfd_reloc_code_real_type reloc
;
1274 struct map_bfd
*ptr
;
1276 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1278 static struct map_bfd mapping
[] = {
1279 MAP ("l", BFD_RELOC_LO16
),
1280 MAP ("h", BFD_RELOC_HI16
),
1281 MAP ("ha", BFD_RELOC_HI16_S
),
1282 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1283 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1284 MAP ("got", BFD_RELOC_16_GOTOFF
),
1285 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1286 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1287 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1288 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1289 MAP ("plt", BFD_RELOC_24_PLT_PCREL
),
1290 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1291 MAP ("copy", BFD_RELOC_PPC_COPY
),
1292 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1293 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1294 MAP ("local", BFD_RELOC_PPC_LOCAL24PC
),
1295 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1296 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1297 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1298 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1299 MAP ("sdarel", BFD_RELOC_GPREL16
),
1300 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1301 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1302 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1303 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1304 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1305 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1306 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1307 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1308 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1309 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1310 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1311 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1312 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1313 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1314 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1315 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1316 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1317 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1318 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1319 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1320 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1322 { (char *) 0, 0, BFD_RELOC_UNUSED
}
1326 return BFD_RELOC_UNUSED
;
1328 for (ch
= *str
, str2
= ident
;
1329 (str2
< ident
+ sizeof (ident
) - 1
1330 && (isalnum (ch
) || ch
== '@'));
1333 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1340 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1341 if (ch
== ptr
->string
[0]
1342 && len
== ptr
->length
1343 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1345 if (exp_p
->X_add_number
!= 0
1346 && (ptr
->reloc
== BFD_RELOC_16_GOTOFF
1347 || ptr
->reloc
== BFD_RELOC_LO16_GOTOFF
1348 || ptr
->reloc
== BFD_RELOC_HI16_GOTOFF
1349 || ptr
->reloc
== BFD_RELOC_HI16_S_GOTOFF
))
1350 as_warn (_("identifier+constant@got means identifier@got+constant"));
1352 /* Now check for identifier@suffix+constant. */
1353 if (*str
== '-' || *str
== '+')
1355 char *orig_line
= input_line_pointer
;
1356 expressionS new_exp
;
1358 input_line_pointer
= str
;
1359 expression (&new_exp
);
1360 if (new_exp
.X_op
== O_constant
)
1362 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1363 str
= input_line_pointer
;
1366 if (&input_line_pointer
!= str_p
)
1367 input_line_pointer
= orig_line
;
1374 return BFD_RELOC_UNUSED
;
1377 /* Like normal .long/.short/.word, except support @got, etc.
1378 Clobbers input_line_pointer, checks end-of-line. */
1380 ppc_elf_cons (nbytes
)
1381 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1384 bfd_reloc_code_real_type reloc
;
1386 if (is_it_end_of_statement ())
1388 demand_empty_rest_of_line ();
1395 if (exp
.X_op
== O_symbol
1396 && *input_line_pointer
== '@'
1397 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1398 &exp
)) != BFD_RELOC_UNUSED
)
1400 reloc_howto_type
*reloc_howto
;
1403 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1404 size
= bfd_get_reloc_size (reloc_howto
);
1407 as_bad (_("%s relocations do not fit in %d bytes\n"),
1408 reloc_howto
->name
, nbytes
);
1412 register char *p
= frag_more ((int) nbytes
);
1413 int offset
= nbytes
- size
;
1415 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1420 emit_expr (&exp
, (unsigned int) nbytes
);
1422 while (*input_line_pointer
++ == ',');
1424 /* Put terminator back into stream. */
1425 input_line_pointer
--;
1426 demand_empty_rest_of_line ();
1429 /* Solaris pseduo op to change to the .rodata section. */
1434 char *save_line
= input_line_pointer
;
1435 static char section
[] = ".rodata\n";
1437 /* Just pretend this is .section .rodata */
1438 input_line_pointer
= section
;
1439 obj_elf_section (xxx
);
1441 input_line_pointer
= save_line
;
1444 /* Pseudo op to make file scope bss items. */
1447 int xxx ATTRIBUTE_UNUSED
;
1449 register char *name
;
1453 register symbolS
*symbolP
;
1460 name
= input_line_pointer
;
1461 c
= get_symbol_end ();
1463 /* just after name is now '\0'. */
1464 p
= input_line_pointer
;
1467 if (*input_line_pointer
!= ',')
1469 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1470 ignore_rest_of_line ();
1474 input_line_pointer
++; /* skip ',' */
1475 if ((size
= get_absolute_expression ()) < 0)
1477 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1478 ignore_rest_of_line ();
1482 /* The third argument to .lcomm is the alignment. */
1483 if (*input_line_pointer
!= ',')
1487 ++input_line_pointer
;
1488 align
= get_absolute_expression ();
1491 as_warn (_("ignoring bad alignment"));
1497 symbolP
= symbol_find_or_make (name
);
1500 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1502 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1503 S_GET_NAME (symbolP
));
1504 ignore_rest_of_line ();
1508 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1510 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1511 S_GET_NAME (symbolP
),
1512 (long) S_GET_VALUE (symbolP
),
1515 ignore_rest_of_line ();
1521 old_subsec
= now_subseg
;
1524 /* Convert to a power of 2 alignment. */
1525 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1528 as_bad (_("Common alignment not a power of 2"));
1529 ignore_rest_of_line ();
1536 record_alignment (bss_section
, align2
);
1537 subseg_set (bss_section
, 0);
1539 frag_align (align2
, 0, 0);
1540 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1541 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1542 symbol_set_frag (symbolP
, frag_now
);
1543 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1546 S_SET_SIZE (symbolP
, size
);
1547 S_SET_SEGMENT (symbolP
, bss_section
);
1548 subseg_set (old_sec
, old_subsec
);
1549 demand_empty_rest_of_line ();
1552 /* Validate any relocations emitted for -mrelocatable, possibly adding
1553 fixups for word relocations in writable segments, so we can adjust
1556 ppc_elf_validate_fix (fixp
, seg
)
1560 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1569 case SHLIB_MRELOCATABLE
:
1570 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1571 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1572 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1573 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1574 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1575 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1576 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1577 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1578 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1579 && (seg
->flags
& SEC_LOAD
) != 0
1580 && strcmp (segment_name (seg
), ".got2") != 0
1581 && strcmp (segment_name (seg
), ".dtors") != 0
1582 && strcmp (segment_name (seg
), ".ctors") != 0
1583 && strcmp (segment_name (seg
), ".fixup") != 0
1584 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1585 && strcmp (segment_name (seg
), ".eh_frame") != 0
1586 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1588 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1589 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1591 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1592 _("Relocation cannot be done when using -mrelocatable"));
1598 #endif /* OBJ_ELF */
1603 * Summary of parse_toc_entry.
1605 * in: Input_line_pointer points to the '[' in one of:
1607 * [toc] [tocv] [toc32] [toc64]
1609 * Anything else is an error of one kind or another.
1612 * return value: success or failure
1613 * toc_kind: kind of toc reference
1614 * input_line_pointer:
1615 * success: first char after the ']'
1616 * failure: unchanged
1620 * [toc] - rv == success, toc_kind = default_toc
1621 * [tocv] - rv == success, toc_kind = data_in_toc
1622 * [toc32] - rv == success, toc_kind = must_be_32
1623 * [toc64] - rv == success, toc_kind = must_be_64
1627 enum toc_size_qualifier
1629 default_toc
, /* The toc cell constructed should be the system default size */
1630 data_in_toc
, /* This is a direct reference to a toc cell */
1631 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1632 must_be_64
/* The toc cell constructed must be 64 bits wide */
1636 parse_toc_entry (toc_kind
)
1637 enum toc_size_qualifier
*toc_kind
;
1642 enum toc_size_qualifier t
;
1644 /* Save the input_line_pointer. */
1645 start
= input_line_pointer
;
1647 /* Skip over the '[' , and whitespace. */
1648 ++input_line_pointer
;
1651 /* Find the spelling of the operand. */
1652 toc_spec
= input_line_pointer
;
1653 c
= get_symbol_end ();
1655 if (strcmp (toc_spec
, "toc") == 0)
1659 else if (strcmp (toc_spec
, "tocv") == 0)
1663 else if (strcmp (toc_spec
, "toc32") == 0)
1667 else if (strcmp (toc_spec
, "toc64") == 0)
1673 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1674 *input_line_pointer
= c
;
1675 input_line_pointer
= start
;
1679 /* Now find the ']'. */
1680 *input_line_pointer
= c
;
1682 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1683 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1687 as_bad (_("syntax error: expected `]', found `%c'"), c
);
1688 input_line_pointer
= start
;
1698 /* We need to keep a list of fixups. We can't simply generate them as
1699 we go, because that would require us to first create the frag, and
1700 that would screw up references to ``.''. */
1706 bfd_reloc_code_real_type reloc
;
1709 #define MAX_INSN_FIXUPS (5)
1711 /* This routine is called for each instruction to be assembled. */
1718 const struct powerpc_opcode
*opcode
;
1720 const unsigned char *opindex_ptr
;
1724 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1729 bfd_reloc_code_real_type reloc
;
1732 /* Get the opcode. */
1733 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1738 /* Look up the opcode in the hash table. */
1739 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1740 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1742 const struct powerpc_macro
*macro
;
1744 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1745 if (macro
== (const struct powerpc_macro
*) NULL
)
1746 as_bad (_("Unrecognized opcode: `%s'"), str
);
1748 ppc_macro (s
, macro
);
1753 insn
= opcode
->opcode
;
1756 while (isspace (*str
))
1759 /* PowerPC operands are just expressions. The only real issue is
1760 that a few operand types are optional. All cases which might use
1761 an optional operand separate the operands only with commas (in
1762 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1763 cases never have optional operands). There is never more than
1764 one optional operand for an instruction. So, before we start
1765 seriously parsing the operands, we check to see if we have an
1766 optional operand, and, if we do, we count the number of commas to
1767 see whether the operand should be omitted. */
1769 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1771 const struct powerpc_operand
*operand
;
1773 operand
= &powerpc_operands
[*opindex_ptr
];
1774 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1776 unsigned int opcount
;
1778 /* There is an optional operand. Count the number of
1779 commas in the input line. */
1786 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1793 /* If there are fewer operands in the line then are called
1794 for by the instruction, we want to skip the optional
1796 if (opcount
< strlen (opcode
->operands
))
1803 /* Gather the operands. */
1807 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1809 const struct powerpc_operand
*operand
;
1815 if (next_opindex
== 0)
1816 operand
= &powerpc_operands
[*opindex_ptr
];
1819 operand
= &powerpc_operands
[next_opindex
];
1825 /* If this is a fake operand, then we do not expect anything
1827 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1829 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1830 if (errmsg
!= (const char *) NULL
)
1835 /* If this is an optional operand, and we are skipping it, just
1837 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1840 if (operand
->insert
)
1842 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1843 if (errmsg
!= (const char *) NULL
)
1846 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1847 next_opindex
= *opindex_ptr
+ 1;
1851 /* Gather the operand. */
1852 hold
= input_line_pointer
;
1853 input_line_pointer
= str
;
1856 if (*input_line_pointer
== '[')
1858 /* We are expecting something like the second argument here:
1860 * lwz r4,[toc].GS.0.static_int(rtoc)
1861 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1862 * The argument following the `]' must be a symbol name, and the
1863 * register must be the toc register: 'rtoc' or '2'
1865 * The effect is to 0 as the displacement field
1866 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1867 * the appropriate variation) reloc against it based on the symbol.
1868 * The linker will build the toc, and insert the resolved toc offset.
1871 * o The size of the toc entry is currently assumed to be
1872 * 32 bits. This should not be assumed to be a hard coded
1874 * o In an effort to cope with a change from 32 to 64 bits,
1875 * there are also toc entries that are specified to be
1876 * either 32 or 64 bits:
1877 * lwz r4,[toc32].GS.0.static_int(rtoc)
1878 * lwz r4,[toc64].GS.0.static_int(rtoc)
1879 * These demand toc entries of the specified size, and the
1880 * instruction probably requires it.
1884 enum toc_size_qualifier toc_kind
;
1885 bfd_reloc_code_real_type toc_reloc
;
1887 /* Go parse off the [tocXX] part. */
1888 valid_toc
= parse_toc_entry (&toc_kind
);
1892 /* Note: message has already been issued.
1893 FIXME: what sort of recovery should we do?
1894 demand_rest_of_line (); return; ? */
1897 /* Now get the symbol following the ']'. */
1903 /* In this case, we may not have seen the symbol yet,
1904 since it is allowed to appear on a .extern or .globl
1905 or just be a label in the .data section. */
1906 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1909 /* 1. The symbol must be defined and either in the toc
1910 section, or a global.
1911 2. The reloc generated must have the TOCDEFN flag set
1912 in upper bit mess of the reloc type.
1913 FIXME: It's a little confusing what the tocv
1914 qualifier can be used for. At the very least, I've
1915 seen three uses, only one of which I'm sure I can
1917 if (ex
.X_op
== O_symbol
)
1919 assert (ex
.X_add_symbol
!= NULL
);
1920 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
1923 as_bad (_("[tocv] symbol is not a toc symbol"));
1927 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1930 /* FIXME: these next two specifically specify 32/64 bit
1931 toc entries. We don't support them today. Is this
1932 the right way to say that? */
1933 toc_reloc
= BFD_RELOC_UNUSED
;
1934 as_bad (_("Unimplemented toc32 expression modifier"));
1937 /* FIXME: see above. */
1938 toc_reloc
= BFD_RELOC_UNUSED
;
1939 as_bad (_("Unimplemented toc64 expression modifier"));
1943 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1949 /* We need to generate a fixup for this expression. */
1950 if (fc
>= MAX_INSN_FIXUPS
)
1951 as_fatal (_("too many fixups"));
1953 fixups
[fc
].reloc
= toc_reloc
;
1954 fixups
[fc
].exp
= ex
;
1955 fixups
[fc
].opindex
= *opindex_ptr
;
1958 /* Ok. We've set up the fixup for the instruction. Now make it
1959 look like the constant 0 was found here. */
1961 ex
.X_op
= O_constant
;
1962 ex
.X_add_number
= 0;
1963 ex
.X_add_symbol
= NULL
;
1964 ex
.X_op_symbol
= NULL
;
1970 if (! register_name (&ex
))
1972 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1979 str
= input_line_pointer
;
1980 input_line_pointer
= hold
;
1982 if (ex
.X_op
== O_illegal
)
1983 as_bad (_("illegal operand"));
1984 else if (ex
.X_op
== O_absent
)
1985 as_bad (_("missing operand"));
1986 else if (ex
.X_op
== O_register
)
1988 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1991 else if (ex
.X_op
== O_constant
)
1994 /* Allow @HA, @L, @H on constants. */
1995 char *orig_str
= str
;
1997 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2004 case BFD_RELOC_LO16
:
2005 /* X_unsigned is the default, so if the user has done
2006 something which cleared it, we always produce a
2009 && (operand
->flags
& PPC_OPERAND_SIGNED
) == 0)
2010 ex
.X_add_number
&= 0xffff;
2012 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
2017 case BFD_RELOC_HI16
:
2018 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
2021 case BFD_RELOC_HI16_S
:
2022 ex
.X_add_number
= ((((ex
.X_add_number
>> 16) & 0xffff)
2023 + ((ex
.X_add_number
>> 15) & 1))
2028 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2032 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2034 /* For the absolute forms of branches, convert the PC
2035 relative form back into the absolute. */
2036 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2040 case BFD_RELOC_PPC_B26
:
2041 reloc
= BFD_RELOC_PPC_BA26
;
2043 case BFD_RELOC_PPC_B16
:
2044 reloc
= BFD_RELOC_PPC_BA16
;
2046 case BFD_RELOC_PPC_B16_BRTAKEN
:
2047 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2049 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2050 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2057 /* We need to generate a fixup for this expression. */
2058 if (fc
>= MAX_INSN_FIXUPS
)
2059 as_fatal (_("too many fixups"));
2060 fixups
[fc
].exp
= ex
;
2061 fixups
[fc
].opindex
= 0;
2062 fixups
[fc
].reloc
= reloc
;
2065 #endif /* OBJ_ELF */
2069 /* We need to generate a fixup for this expression. */
2070 if (fc
>= MAX_INSN_FIXUPS
)
2071 as_fatal (_("too many fixups"));
2072 fixups
[fc
].exp
= ex
;
2073 fixups
[fc
].opindex
= *opindex_ptr
;
2074 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2083 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2091 /* The call to expression should have advanced str past any
2094 && (endc
!= ',' || *str
!= '\0'))
2096 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2104 while (isspace (*str
))
2108 as_bad (_("junk at end of line: `%s'"), str
);
2110 /* Write out the instruction. */
2112 md_number_to_chars (f
, insn
, 4);
2115 dwarf2_emit_insn (4);
2118 /* Create any fixups. At this point we do not use a
2119 bfd_reloc_code_real_type, but instead just use the
2120 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2121 handle fixups for any operand type, although that is admittedly
2122 not a very exciting feature. We pick a BFD reloc type in
2124 for (i
= 0; i
< fc
; i
++)
2126 const struct powerpc_operand
*operand
;
2128 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2129 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2131 reloc_howto_type
*reloc_howto
;
2136 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2140 size
= bfd_get_reloc_size (reloc_howto
);
2141 offset
= target_big_endian
? (4 - size
) : 0;
2143 if (size
< 1 || size
> 4)
2146 fixP
= fix_new_exp (frag_now
,
2147 f
- frag_now
->fr_literal
+ offset
,
2150 reloc_howto
->pc_relative
,
2153 /* Turn off complaints that the addend is too large for things like
2155 switch (fixups
[i
].reloc
)
2157 case BFD_RELOC_16_GOTOFF
:
2158 case BFD_RELOC_PPC_TOC16
:
2159 case BFD_RELOC_LO16
:
2160 case BFD_RELOC_HI16
:
2161 case BFD_RELOC_HI16_S
:
2162 fixP
->fx_no_overflow
= 1;
2169 fix_new_exp (frag_now
,
2170 f
- frag_now
->fr_literal
,
2173 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2174 ((bfd_reloc_code_real_type
)
2175 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2179 /* Handle a macro. Gather all the operands, transform them as
2180 described by the macro, and call md_assemble recursively. All the
2181 operands are separated by commas; we don't accept parentheses
2182 around operands here. */
2185 ppc_macro (str
, macro
)
2187 const struct powerpc_macro
*macro
;
2198 /* Gather the users operands into the operands array. */
2203 if (count
>= sizeof operands
/ sizeof operands
[0])
2205 operands
[count
++] = s
;
2206 s
= strchr (s
, ',');
2207 if (s
== (char *) NULL
)
2212 if (count
!= macro
->operands
)
2214 as_bad (_("wrong number of operands"));
2218 /* Work out how large the string must be (the size is unbounded
2219 because it includes user input). */
2221 format
= macro
->format
;
2222 while (*format
!= '\0')
2231 arg
= strtol (format
+ 1, &send
, 10);
2232 know (send
!= format
&& arg
>= 0 && arg
< count
);
2233 len
+= strlen (operands
[arg
]);
2238 /* Put the string together. */
2239 complete
= s
= (char *) alloca (len
+ 1);
2240 format
= macro
->format
;
2241 while (*format
!= '\0')
2247 arg
= strtol (format
+ 1, &send
, 10);
2248 strcpy (s
, operands
[arg
]);
2255 /* Assemble the constructed instruction. */
2256 md_assemble (complete
);
2260 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2263 ppc_section_letter (letter
, ptr_msg
)
2270 *ptr_msg
= _("Bad .section directive: want a,w,x,e in string");
2275 ppc_section_word (str
, len
)
2279 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2286 ppc_section_type (str
, len
)
2290 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2297 ppc_section_flags (flags
, attr
, type
)
2302 if (type
== SHT_ORDERED
)
2303 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2305 if (attr
& SHF_EXCLUDE
)
2306 flags
|= SEC_EXCLUDE
;
2310 #endif /* OBJ_ELF */
2313 /* Pseudo-op handling. */
2315 /* The .byte pseudo-op. This is similar to the normal .byte
2316 pseudo-op, but it can also take a single ASCII string. */
2320 int ignore ATTRIBUTE_UNUSED
;
2322 if (*input_line_pointer
!= '\"')
2328 /* Gather characters. A real double quote is doubled. Unusual
2329 characters are not permitted. */
2330 ++input_line_pointer
;
2335 c
= *input_line_pointer
++;
2339 if (*input_line_pointer
!= '\"')
2341 ++input_line_pointer
;
2344 FRAG_APPEND_1_CHAR (c
);
2347 demand_empty_rest_of_line ();
2352 /* XCOFF specific pseudo-op handling. */
2354 /* This is set if we are creating a .stabx symbol, since we don't want
2355 to handle symbol suffixes for such symbols. */
2356 static boolean ppc_stab_symbol
;
2358 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2359 symbols in the .bss segment as though they were local common
2360 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2361 aligns .comm and .lcomm to 4 bytes. */
2367 asection
*current_seg
= now_seg
;
2368 subsegT current_subseg
= now_subseg
;
2374 symbolS
*lcomm_sym
= NULL
;
2378 name
= input_line_pointer
;
2379 endc
= get_symbol_end ();
2380 end_name
= input_line_pointer
;
2383 if (*input_line_pointer
!= ',')
2385 as_bad (_("missing size"));
2386 ignore_rest_of_line ();
2389 ++input_line_pointer
;
2391 size
= get_absolute_expression ();
2394 as_bad (_("negative size"));
2395 ignore_rest_of_line ();
2401 /* The third argument to .comm is the alignment. */
2402 if (*input_line_pointer
!= ',')
2406 ++input_line_pointer
;
2407 align
= get_absolute_expression ();
2410 as_warn (_("ignoring bad alignment"));
2425 /* The third argument to .lcomm appears to be the real local
2426 common symbol to create. References to the symbol named in
2427 the first argument are turned into references to the third
2429 if (*input_line_pointer
!= ',')
2431 as_bad (_("missing real symbol name"));
2432 ignore_rest_of_line ();
2435 ++input_line_pointer
;
2437 lcomm_name
= input_line_pointer
;
2438 lcomm_endc
= get_symbol_end ();
2440 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2442 *input_line_pointer
= lcomm_endc
;
2446 sym
= symbol_find_or_make (name
);
2449 if (S_IS_DEFINED (sym
)
2450 || S_GET_VALUE (sym
) != 0)
2452 as_bad (_("attempt to redefine symbol"));
2453 ignore_rest_of_line ();
2457 record_alignment (bss_section
, align
);
2460 || ! S_IS_DEFINED (lcomm_sym
))
2469 S_SET_EXTERNAL (sym
);
2473 symbol_get_tc (lcomm_sym
)->output
= 1;
2474 def_sym
= lcomm_sym
;
2478 subseg_set (bss_section
, 1);
2479 frag_align (align
, 0, 0);
2481 symbol_set_frag (def_sym
, frag_now
);
2482 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2483 def_size
, (char *) NULL
);
2485 S_SET_SEGMENT (def_sym
, bss_section
);
2486 symbol_get_tc (def_sym
)->align
= align
;
2490 /* Align the size of lcomm_sym. */
2491 symbol_get_frag (lcomm_sym
)->fr_offset
=
2492 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
2493 &~ ((1 << align
) - 1));
2494 if (align
> symbol_get_tc (lcomm_sym
)->align
)
2495 symbol_get_tc (lcomm_sym
)->align
= align
;
2500 /* Make sym an offset from lcomm_sym. */
2501 S_SET_SEGMENT (sym
, bss_section
);
2502 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
2503 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
2504 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
2507 subseg_set (current_seg
, current_subseg
);
2509 demand_empty_rest_of_line ();
2512 /* The .csect pseudo-op. This switches us into a different
2513 subsegment. The first argument is a symbol whose value is the
2514 start of the .csect. In COFF, csect symbols get special aux
2515 entries defined by the x_csect field of union internal_auxent. The
2516 optional second argument is the alignment (the default is 2). */
2520 int ignore ATTRIBUTE_UNUSED
;
2526 name
= input_line_pointer
;
2527 endc
= get_symbol_end ();
2529 sym
= symbol_find_or_make (name
);
2531 *input_line_pointer
= endc
;
2533 if (S_GET_NAME (sym
)[0] == '\0')
2535 /* An unnamed csect is assumed to be [PR]. */
2536 symbol_get_tc (sym
)->class = XMC_PR
;
2539 ppc_change_csect (sym
);
2541 if (*input_line_pointer
== ',')
2543 ++input_line_pointer
;
2544 symbol_get_tc (sym
)->align
= get_absolute_expression ();
2547 demand_empty_rest_of_line ();
2550 /* Change to a different csect. */
2553 ppc_change_csect (sym
)
2556 if (S_IS_DEFINED (sym
))
2557 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
2565 /* This is a new csect. We need to look at the symbol class to
2566 figure out whether it should go in the text section or the
2569 switch (symbol_get_tc (sym
)->class)
2579 S_SET_SEGMENT (sym
, text_section
);
2580 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
2581 ++ppc_text_subsegment
;
2582 list_ptr
= &ppc_text_csects
;
2591 if (ppc_toc_csect
!= NULL
2592 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
2593 == ppc_data_subsegment
))
2595 S_SET_SEGMENT (sym
, data_section
);
2596 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
2597 ++ppc_data_subsegment
;
2598 list_ptr
= &ppc_data_csects
;
2604 /* We set the obstack chunk size to a small value before
2605 changing subsegments, so that we don't use a lot of memory
2606 space for what may be a small section. */
2607 hold_chunksize
= chunksize
;
2610 subseg_new (segment_name (S_GET_SEGMENT (sym
)),
2611 symbol_get_tc (sym
)->subseg
);
2613 chunksize
= hold_chunksize
;
2616 ppc_after_toc_frag
= frag_now
;
2618 symbol_set_frag (sym
, frag_now
);
2619 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2621 symbol_get_tc (sym
)->align
= (ppc_xcoff64
) ? 3 : 2;
2622 symbol_get_tc (sym
)->output
= 1;
2623 symbol_get_tc (sym
)->within
= sym
;
2625 for (list
= *list_ptr
;
2626 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
2627 list
= symbol_get_tc (list
)->next
)
2629 symbol_get_tc (list
)->next
= sym
;
2631 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2632 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
2636 ppc_current_csect
= sym
;
2639 /* This function handles the .text and .data pseudo-ops. These
2640 pseudo-ops aren't really used by XCOFF; we implement them for the
2641 convenience of people who aren't used to XCOFF. */
2652 else if (type
== 'd')
2657 sym
= symbol_find_or_make (name
);
2659 ppc_change_csect (sym
);
2661 demand_empty_rest_of_line ();
2664 /* This function handles the .section pseudo-op. This is mostly to
2665 give an error, since XCOFF only supports .text, .data and .bss, but
2666 we do permit the user to name the text or data section. */
2669 ppc_named_section (ignore
)
2670 int ignore ATTRIBUTE_UNUSED
;
2673 const char *real_name
;
2677 user_name
= input_line_pointer
;
2678 c
= get_symbol_end ();
2680 if (strcmp (user_name
, ".text") == 0)
2681 real_name
= ".text[PR]";
2682 else if (strcmp (user_name
, ".data") == 0)
2683 real_name
= ".data[RW]";
2686 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2687 *input_line_pointer
= c
;
2688 ignore_rest_of_line ();
2692 *input_line_pointer
= c
;
2694 sym
= symbol_find_or_make (real_name
);
2696 ppc_change_csect (sym
);
2698 demand_empty_rest_of_line ();
2701 /* The .extern pseudo-op. We create an undefined symbol. */
2705 int ignore ATTRIBUTE_UNUSED
;
2710 name
= input_line_pointer
;
2711 endc
= get_symbol_end ();
2713 (void) symbol_find_or_make (name
);
2715 *input_line_pointer
= endc
;
2717 demand_empty_rest_of_line ();
2720 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2724 int ignore ATTRIBUTE_UNUSED
;
2730 name
= input_line_pointer
;
2731 endc
= get_symbol_end ();
2733 sym
= symbol_find_or_make (name
);
2735 *input_line_pointer
= endc
;
2737 symbol_get_tc (sym
)->output
= 1;
2739 demand_empty_rest_of_line ();
2742 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2743 although I don't know why it bothers. */
2747 int ignore ATTRIBUTE_UNUSED
;
2754 name
= input_line_pointer
;
2755 endc
= get_symbol_end ();
2757 sym
= symbol_find_or_make (name
);
2759 *input_line_pointer
= endc
;
2761 if (*input_line_pointer
!= ',')
2763 as_bad (_("missing rename string"));
2764 ignore_rest_of_line ();
2767 ++input_line_pointer
;
2769 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
2771 demand_empty_rest_of_line ();
2774 /* The .stabx pseudo-op. This is similar to a normal .stabs
2775 pseudo-op, but slightly different. A sample is
2776 .stabx "main:F-1",.main,142,0
2777 The first argument is the symbol name to create. The second is the
2778 value, and the third is the storage class. The fourth seems to be
2779 always zero, and I am assuming it is the type. */
2783 int ignore ATTRIBUTE_UNUSED
;
2790 name
= demand_copy_C_string (&len
);
2792 if (*input_line_pointer
!= ',')
2794 as_bad (_("missing value"));
2797 ++input_line_pointer
;
2799 ppc_stab_symbol
= true;
2800 sym
= symbol_make (name
);
2801 ppc_stab_symbol
= false;
2803 symbol_get_tc (sym
)->real_name
= name
;
2805 (void) expression (&exp
);
2812 as_bad (_("illegal .stabx expression; zero assumed"));
2813 exp
.X_add_number
= 0;
2816 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2817 symbol_set_frag (sym
, &zero_address_frag
);
2821 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2822 symbol_set_value_expression (sym
, &exp
);
2826 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2827 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
2832 /* The value is some complex expression. This will probably
2833 fail at some later point, but this is probably the right
2834 thing to do here. */
2835 symbol_set_value_expression (sym
, &exp
);
2839 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2840 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
2842 if (*input_line_pointer
!= ',')
2844 as_bad (_("missing class"));
2847 ++input_line_pointer
;
2849 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2851 if (*input_line_pointer
!= ',')
2853 as_bad (_("missing type"));
2856 ++input_line_pointer
;
2858 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2860 symbol_get_tc (sym
)->output
= 1;
2862 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
2864 symbol_get_tc (sym
)->within
= ppc_current_block
;
2869 .stabx "z",arrays_,133,0
2872 .comm arrays_,13768,3
2874 resolve_symbol_value will copy the exp's "within" into sym's when the
2875 offset is 0. Since this seems to be corner case problem,
2876 only do the correction for storage class C_STSYM. A better solution
2877 would be to have the tc field updated in ppc_symbol_new_hook. */
2879 if (exp
.X_op
== O_symbol
)
2881 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
2885 if (exp
.X_op
!= O_symbol
2886 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2887 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2888 ppc_frob_label (sym
);
2891 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2892 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2893 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
2894 symbol_get_tc (ppc_current_csect
)->within
= sym
;
2897 demand_empty_rest_of_line ();
2900 /* The .function pseudo-op. This takes several arguments. The first
2901 argument seems to be the external name of the symbol. The second
2902 argment seems to be the label for the start of the function. gcc
2903 uses the same name for both. I have no idea what the third and
2904 fourth arguments are meant to be. The optional fifth argument is
2905 an expression for the size of the function. In COFF this symbol
2906 gets an aux entry like that used for a csect. */
2909 ppc_function (ignore
)
2910 int ignore ATTRIBUTE_UNUSED
;
2918 name
= input_line_pointer
;
2919 endc
= get_symbol_end ();
2921 /* Ignore any [PR] suffix. */
2922 name
= ppc_canonicalize_symbol_name (name
);
2923 s
= strchr (name
, '[');
2924 if (s
!= (char *) NULL
2925 && strcmp (s
+ 1, "PR]") == 0)
2928 ext_sym
= symbol_find_or_make (name
);
2930 *input_line_pointer
= endc
;
2932 if (*input_line_pointer
!= ',')
2934 as_bad (_("missing symbol name"));
2935 ignore_rest_of_line ();
2938 ++input_line_pointer
;
2940 name
= input_line_pointer
;
2941 endc
= get_symbol_end ();
2943 lab_sym
= symbol_find_or_make (name
);
2945 *input_line_pointer
= endc
;
2947 if (ext_sym
!= lab_sym
)
2951 exp
.X_op
= O_symbol
;
2952 exp
.X_add_symbol
= lab_sym
;
2953 exp
.X_op_symbol
= NULL
;
2954 exp
.X_add_number
= 0;
2956 symbol_set_value_expression (ext_sym
, &exp
);
2959 if (symbol_get_tc (ext_sym
)->class == -1)
2960 symbol_get_tc (ext_sym
)->class = XMC_PR
;
2961 symbol_get_tc (ext_sym
)->output
= 1;
2963 if (*input_line_pointer
== ',')
2967 /* Ignore the third argument. */
2968 ++input_line_pointer
;
2969 expression (&ignore
);
2970 if (*input_line_pointer
== ',')
2972 /* Ignore the fourth argument. */
2973 ++input_line_pointer
;
2974 expression (&ignore
);
2975 if (*input_line_pointer
== ',')
2977 /* The fifth argument is the function size. */
2978 ++input_line_pointer
;
2979 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
2982 &zero_address_frag
);
2983 pseudo_set (symbol_get_tc (ext_sym
)->size
);
2988 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2989 SF_SET_FUNCTION (ext_sym
);
2990 SF_SET_PROCESS (ext_sym
);
2991 coff_add_linesym (ext_sym
);
2993 demand_empty_rest_of_line ();
2996 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3001 int ignore ATTRIBUTE_UNUSED
;
3005 sym
= symbol_make (".bf");
3006 S_SET_SEGMENT (sym
, text_section
);
3007 symbol_set_frag (sym
, frag_now
);
3008 S_SET_VALUE (sym
, frag_now_fix ());
3009 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3011 coff_line_base
= get_absolute_expression ();
3013 S_SET_NUMBER_AUXILIARY (sym
, 1);
3014 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3016 symbol_get_tc (sym
)->output
= 1;
3018 ppc_frob_label (sym
);
3020 demand_empty_rest_of_line ();
3023 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3024 ".ef", except that the line number is absolute, not relative to the
3025 most recent ".bf" symbol. */
3029 int ignore ATTRIBUTE_UNUSED
;
3033 sym
= symbol_make (".ef");
3034 S_SET_SEGMENT (sym
, text_section
);
3035 symbol_set_frag (sym
, frag_now
);
3036 S_SET_VALUE (sym
, frag_now_fix ());
3037 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3038 S_SET_NUMBER_AUXILIARY (sym
, 1);
3039 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3040 symbol_get_tc (sym
)->output
= 1;
3042 ppc_frob_label (sym
);
3044 demand_empty_rest_of_line ();
3047 /* The .bi and .ei pseudo-ops. These take a string argument and
3048 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3055 static symbolS
*last_biei
;
3062 name
= demand_copy_C_string (&len
);
3064 /* The value of these symbols is actually file offset. Here we set
3065 the value to the index into the line number entries. In
3066 ppc_frob_symbols we set the fix_line field, which will cause BFD
3067 to do the right thing. */
3069 sym
= symbol_make (name
);
3070 /* obj-coff.c currently only handles line numbers correctly in the
3072 S_SET_SEGMENT (sym
, text_section
);
3073 S_SET_VALUE (sym
, coff_n_line_nos
);
3074 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3076 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3077 symbol_get_tc (sym
)->output
= 1;
3079 for (look
= last_biei
? last_biei
: symbol_rootP
;
3080 (look
!= (symbolS
*) NULL
3081 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3082 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3083 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3084 look
= symbol_next (look
))
3086 if (look
!= (symbolS
*) NULL
)
3088 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3089 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3093 demand_empty_rest_of_line ();
3096 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3097 There is one argument, which is a csect symbol. The value of the
3098 .bs symbol is the index of this csect symbol. */
3102 int ignore ATTRIBUTE_UNUSED
;
3109 if (ppc_current_block
!= NULL
)
3110 as_bad (_("nested .bs blocks"));
3112 name
= input_line_pointer
;
3113 endc
= get_symbol_end ();
3115 csect
= symbol_find_or_make (name
);
3117 *input_line_pointer
= endc
;
3119 sym
= symbol_make (".bs");
3120 S_SET_SEGMENT (sym
, now_seg
);
3121 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3122 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3123 symbol_get_tc (sym
)->output
= 1;
3125 symbol_get_tc (sym
)->within
= csect
;
3127 ppc_frob_label (sym
);
3129 ppc_current_block
= sym
;
3131 demand_empty_rest_of_line ();
3134 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3138 int ignore ATTRIBUTE_UNUSED
;
3142 if (ppc_current_block
== NULL
)
3143 as_bad (_(".es without preceding .bs"));
3145 sym
= symbol_make (".es");
3146 S_SET_SEGMENT (sym
, now_seg
);
3147 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3148 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3149 symbol_get_tc (sym
)->output
= 1;
3151 ppc_frob_label (sym
);
3153 ppc_current_block
= NULL
;
3155 demand_empty_rest_of_line ();
3158 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3163 int ignore ATTRIBUTE_UNUSED
;
3167 sym
= symbol_make (".bb");
3168 S_SET_SEGMENT (sym
, text_section
);
3169 symbol_set_frag (sym
, frag_now
);
3170 S_SET_VALUE (sym
, frag_now_fix ());
3171 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3173 S_SET_NUMBER_AUXILIARY (sym
, 1);
3174 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3176 symbol_get_tc (sym
)->output
= 1;
3178 SF_SET_PROCESS (sym
);
3180 ppc_frob_label (sym
);
3182 demand_empty_rest_of_line ();
3185 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3190 int ignore ATTRIBUTE_UNUSED
;
3194 sym
= symbol_make (".eb");
3195 S_SET_SEGMENT (sym
, text_section
);
3196 symbol_set_frag (sym
, frag_now
);
3197 S_SET_VALUE (sym
, frag_now_fix ());
3198 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3199 S_SET_NUMBER_AUXILIARY (sym
, 1);
3200 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3201 symbol_get_tc (sym
)->output
= 1;
3203 SF_SET_PROCESS (sym
);
3205 ppc_frob_label (sym
);
3207 demand_empty_rest_of_line ();
3210 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3215 int ignore ATTRIBUTE_UNUSED
;
3221 name
= demand_copy_C_string (&len
);
3222 sym
= symbol_make (name
);
3223 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3224 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3225 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3226 S_SET_VALUE (sym
, 0);
3227 symbol_get_tc (sym
)->output
= 1;
3229 ppc_frob_label (sym
);
3231 demand_empty_rest_of_line ();
3234 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3238 int ignore ATTRIBUTE_UNUSED
;
3242 sym
= symbol_make (".ec");
3243 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3244 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3245 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3246 S_SET_VALUE (sym
, 0);
3247 symbol_get_tc (sym
)->output
= 1;
3249 ppc_frob_label (sym
);
3251 demand_empty_rest_of_line ();
3254 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3258 int ignore ATTRIBUTE_UNUSED
;
3260 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3261 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3268 subseg
= ppc_data_subsegment
;
3269 ++ppc_data_subsegment
;
3271 subseg_new (segment_name (data_section
), subseg
);
3272 ppc_toc_frag
= frag_now
;
3274 sym
= symbol_find_or_make ("TOC[TC0]");
3275 symbol_set_frag (sym
, frag_now
);
3276 S_SET_SEGMENT (sym
, data_section
);
3277 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3278 symbol_get_tc (sym
)->subseg
= subseg
;
3279 symbol_get_tc (sym
)->output
= 1;
3280 symbol_get_tc (sym
)->within
= sym
;
3282 ppc_toc_csect
= sym
;
3284 for (list
= ppc_data_csects
;
3285 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3286 list
= symbol_get_tc (list
)->next
)
3288 symbol_get_tc (list
)->next
= sym
;
3290 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3291 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3295 ppc_current_csect
= ppc_toc_csect
;
3297 demand_empty_rest_of_line ();
3300 /* The AIX assembler automatically aligns the operands of a .long or
3301 .short pseudo-op, and we want to be compatible. */
3304 ppc_xcoff_cons (log_size
)
3307 frag_align (log_size
, 0, 0);
3308 record_alignment (now_seg
, log_size
);
3309 cons (1 << log_size
);
3314 int dummy ATTRIBUTE_UNUSED
;
3316 discard_rest_of_line();
3317 /* What does aix use this for? */
3322 int dummy ATTRIBUTE_UNUSED
;
3327 (void) expression (&exp
);
3329 if (exp
.X_op
!= O_constant
)
3331 as_bad (_("non-constant byte count"));
3335 byte_count
= exp
.X_add_number
;
3337 if (*input_line_pointer
!= ',')
3339 as_bad (_("missing value"));
3343 ++input_line_pointer
;
3347 #endif /* OBJ_XCOFF */
3349 /* The .tc pseudo-op. This is used when generating either XCOFF or
3350 ELF. This takes two or more arguments.
3352 When generating XCOFF output, the first argument is the name to
3353 give to this location in the toc; this will be a symbol with class
3354 TC. The rest of the arguments are 4 byte values to actually put at
3355 this location in the TOC; often there is just one more argument, a
3356 relocateable symbol reference.
3358 When not generating XCOFF output, the arguments are the same, but
3359 the first argument is simply ignored. */
3363 int ignore ATTRIBUTE_UNUSED
;
3367 /* Define the TOC symbol name. */
3373 if (ppc_toc_csect
== (symbolS
*) NULL
3374 || ppc_toc_csect
!= ppc_current_csect
)
3376 as_bad (_(".tc not in .toc section"));
3377 ignore_rest_of_line ();
3381 name
= input_line_pointer
;
3382 endc
= get_symbol_end ();
3384 sym
= symbol_find_or_make (name
);
3386 *input_line_pointer
= endc
;
3388 if (S_IS_DEFINED (sym
))
3392 label
= symbol_get_tc (ppc_current_csect
)->within
;
3393 if (symbol_get_tc (label
)->class != XMC_TC0
)
3395 as_bad (_(".tc with no label"));
3396 ignore_rest_of_line ();
3400 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3401 symbol_set_frag (label
, symbol_get_frag (sym
));
3402 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3404 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3405 ++input_line_pointer
;
3410 S_SET_SEGMENT (sym
, now_seg
);
3411 symbol_set_frag (sym
, frag_now
);
3412 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3413 symbol_get_tc (sym
)->class = XMC_TC
;
3414 symbol_get_tc (sym
)->output
= 1;
3416 ppc_frob_label (sym
);
3419 #else /* ! defined (OBJ_XCOFF) */
3421 /* Skip the TOC symbol name. */
3422 while (is_part_of_name (*input_line_pointer
)
3423 || *input_line_pointer
== '['
3424 || *input_line_pointer
== ']'
3425 || *input_line_pointer
== '{'
3426 || *input_line_pointer
== '}')
3427 ++input_line_pointer
;
3429 /* Align to a four byte boundary. */
3430 frag_align (2, 0, 0);
3431 record_alignment (now_seg
, 2);
3433 #endif /* ! defined (OBJ_XCOFF) */
3435 if (*input_line_pointer
!= ',')
3436 demand_empty_rest_of_line ();
3439 ++input_line_pointer
;
3440 cons ((ppc_size
== PPC_OPCODE_64
) ? 8 : 4);
3446 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
3448 /* Set the current section. */
3450 ppc_set_current_section (new)
3453 ppc_previous_section
= ppc_current_section
;
3454 ppc_current_section
= new;
3457 /* pseudo-op: .previous
3458 behaviour: toggles the current section with the previous section.
3460 warnings: "No previous section" */
3463 ppc_previous (ignore
)
3464 int ignore ATTRIBUTE_UNUSED
;
3468 if (ppc_previous_section
== NULL
)
3470 as_warn (_("No previous section to return to. Directive ignored."));
3474 subseg_set (ppc_previous_section
, 0);
3476 ppc_set_current_section (ppc_previous_section
);
3479 /* pseudo-op: .pdata
3480 behaviour: predefined read only data section
3484 initial: .section .pdata "adr3"
3485 a - don't know -- maybe a misprint
3486 d - initialized data
3488 3 - double word aligned (that would be 4 byte boundary)
3491 Tag index tables (also known as the function table) for exception
3492 handling, debugging, etc. */
3496 int ignore ATTRIBUTE_UNUSED
;
3498 if (pdata_section
== 0)
3500 pdata_section
= subseg_new (".pdata", 0);
3502 bfd_set_section_flags (stdoutput
, pdata_section
,
3503 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3504 | SEC_READONLY
| SEC_DATA
));
3506 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3510 pdata_section
= subseg_new (".pdata", 0);
3512 ppc_set_current_section (pdata_section
);
3515 /* pseudo-op: .ydata
3516 behaviour: predefined read only data section
3520 initial: .section .ydata "drw3"
3521 a - don't know -- maybe a misprint
3522 d - initialized data
3524 3 - double word aligned (that would be 4 byte boundary)
3526 Tag tables (also known as the scope table) for exception handling,
3531 int ignore ATTRIBUTE_UNUSED
;
3533 if (ydata_section
== 0)
3535 ydata_section
= subseg_new (".ydata", 0);
3536 bfd_set_section_flags (stdoutput
, ydata_section
,
3537 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3538 | SEC_READONLY
| SEC_DATA
));
3540 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3544 ydata_section
= subseg_new (".ydata", 0);
3546 ppc_set_current_section (ydata_section
);
3549 /* pseudo-op: .reldata
3550 behaviour: predefined read write data section
3551 double word aligned (4-byte)
3552 FIXME: relocation is applied to it
3553 FIXME: what's the difference between this and .data?
3556 initial: .section .reldata "drw3"
3557 d - initialized data
3560 3 - double word aligned (that would be 8 byte boundary)
3563 Like .data, but intended to hold data subject to relocation, such as
3564 function descriptors, etc. */
3567 ppc_reldata (ignore
)
3568 int ignore ATTRIBUTE_UNUSED
;
3570 if (reldata_section
== 0)
3572 reldata_section
= subseg_new (".reldata", 0);
3574 bfd_set_section_flags (stdoutput
, reldata_section
,
3575 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3578 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3582 reldata_section
= subseg_new (".reldata", 0);
3584 ppc_set_current_section (reldata_section
);
3587 /* pseudo-op: .rdata
3588 behaviour: predefined read only data section
3592 initial: .section .rdata "dr3"
3593 d - initialized data
3595 3 - double word aligned (that would be 4 byte boundary) */
3599 int ignore ATTRIBUTE_UNUSED
;
3601 if (rdata_section
== 0)
3603 rdata_section
= subseg_new (".rdata", 0);
3604 bfd_set_section_flags (stdoutput
, rdata_section
,
3605 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3606 | SEC_READONLY
| SEC_DATA
));
3608 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3612 rdata_section
= subseg_new (".rdata", 0);
3614 ppc_set_current_section (rdata_section
);
3617 /* pseudo-op: .ualong
3618 behaviour: much like .int, with the exception that no alignment is
3620 FIXME: test the alignment statement
3626 int ignore ATTRIBUTE_UNUSED
;
3632 /* pseudo-op: .znop <symbol name>
3633 behaviour: Issue a nop instruction
3634 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3635 the supplied symbol name.
3637 warnings: Missing symbol name */
3641 int ignore ATTRIBUTE_UNUSED
;
3644 const struct powerpc_opcode
*opcode
;
3655 /* Strip out the symbol name. */
3656 symbol_name
= input_line_pointer
;
3657 c
= get_symbol_end ();
3659 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3660 strcpy (name
, symbol_name
);
3662 sym
= symbol_find_or_make (name
);
3664 *input_line_pointer
= c
;
3668 /* Look up the opcode in the hash table. */
3669 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3671 /* Stick in the nop. */
3672 insn
= opcode
->opcode
;
3674 /* Write out the instruction. */
3676 md_number_to_chars (f
, insn
, 4);
3678 f
- frag_now
->fr_literal
,
3683 BFD_RELOC_16_GOT_PCREL
);
3696 register char *name
;
3700 register symbolS
*symbolP
;
3703 name
= input_line_pointer
;
3704 c
= get_symbol_end ();
3706 /* just after name is now '\0'. */
3707 p
= input_line_pointer
;
3710 if (*input_line_pointer
!= ',')
3712 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3713 ignore_rest_of_line ();
3717 input_line_pointer
++; /* skip ',' */
3718 if ((temp
= get_absolute_expression ()) < 0)
3720 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
3721 ignore_rest_of_line ();
3727 /* The third argument to .comm is the alignment. */
3728 if (*input_line_pointer
!= ',')
3732 ++input_line_pointer
;
3733 align
= get_absolute_expression ();
3736 as_warn (_("ignoring bad alignment"));
3743 symbolP
= symbol_find_or_make (name
);
3746 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3748 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3749 S_GET_NAME (symbolP
));
3750 ignore_rest_of_line ();
3754 if (S_GET_VALUE (symbolP
))
3756 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3757 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3758 S_GET_NAME (symbolP
),
3759 (long) S_GET_VALUE (symbolP
),
3764 S_SET_VALUE (symbolP
, (valueT
) temp
);
3765 S_SET_EXTERNAL (symbolP
);
3768 demand_empty_rest_of_line ();
3772 * implement the .section pseudo op:
3773 * .section name {, "flags"}
3775 * | +--- optional flags: 'b' for bss
3777 * +-- section name 'l' for lib
3781 * 'd' (apparently m88k for data)
3783 * But if the argument is not a quoted string, treat it as a
3784 * subsegment number.
3786 * FIXME: this is a copy of the section processing from obj-coff.c, with
3787 * additions/changes for the moto-pas assembler support. There are three
3790 * FIXME: I just noticed this. This doesn't work at all really. It it
3791 * setting bits that bfd probably neither understands or uses. The
3792 * correct approach (?) will have to incorporate extra fields attached
3793 * to the section to hold the system specific stuff. (krk)
3796 * 'a' - unknown - referred to in documentation, but no definition supplied
3797 * 'c' - section has code
3798 * 'd' - section has initialized data
3799 * 'u' - section has uninitialized data
3800 * 'i' - section contains directives (info)
3801 * 'n' - section can be discarded
3802 * 'R' - remove section at link time
3804 * Section Protection:
3805 * 'r' - section is readable
3806 * 'w' - section is writeable
3807 * 'x' - section is executable
3808 * 's' - section is sharable
3810 * Section Alignment:
3811 * '0' - align to byte boundary
3812 * '1' - align to halfword undary
3813 * '2' - align to word boundary
3814 * '3' - align to doubleword boundary
3815 * '4' - align to quadword boundary
3816 * '5' - align to 32 byte boundary
3817 * '6' - align to 64 byte boundary
3822 ppc_pe_section (ignore
)
3823 int ignore ATTRIBUTE_UNUSED
;
3825 /* Strip out the section name. */
3834 section_name
= input_line_pointer
;
3835 c
= get_symbol_end ();
3837 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3838 strcpy (name
, section_name
);
3840 *input_line_pointer
= c
;
3845 flags
= SEC_NO_FLAGS
;
3847 if (strcmp (name
, ".idata$2") == 0)
3851 else if (strcmp (name
, ".idata$3") == 0)
3855 else if (strcmp (name
, ".idata$4") == 0)
3859 else if (strcmp (name
, ".idata$5") == 0)
3863 else if (strcmp (name
, ".idata$6") == 0)
3868 /* Default alignment to 16 byte boundary. */
3871 if (*input_line_pointer
== ',')
3873 ++input_line_pointer
;
3875 if (*input_line_pointer
!= '"')
3876 exp
= get_absolute_expression ();
3879 ++input_line_pointer
;
3880 while (*input_line_pointer
!= '"'
3881 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3883 switch (*input_line_pointer
)
3885 /* Section Contents */
3886 case 'a': /* unknown */
3887 as_bad (_("Unsupported section attribute -- 'a'"));
3889 case 'c': /* code section */
3892 case 'd': /* section has initialized data */
3895 case 'u': /* section has uninitialized data */
3896 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3900 case 'i': /* section contains directives (info) */
3901 /* FIXME: This is IMAGE_SCN_LNK_INFO
3903 flags
|= SEC_HAS_CONTENTS
;
3905 case 'n': /* section can be discarded */
3908 case 'R': /* Remove section at link time */
3909 flags
|= SEC_NEVER_LOAD
;
3912 /* Section Protection */
3913 case 'r': /* section is readable */
3914 flags
|= IMAGE_SCN_MEM_READ
;
3916 case 'w': /* section is writeable */
3917 flags
|= IMAGE_SCN_MEM_WRITE
;
3919 case 'x': /* section is executable */
3920 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3922 case 's': /* section is sharable */
3923 flags
|= IMAGE_SCN_MEM_SHARED
;
3926 /* Section Alignment */
3927 case '0': /* align to byte boundary */
3928 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3931 case '1': /* align to halfword boundary */
3932 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3935 case '2': /* align to word boundary */
3936 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3939 case '3': /* align to doubleword boundary */
3940 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3943 case '4': /* align to quadword boundary */
3944 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3947 case '5': /* align to 32 byte boundary */
3948 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3951 case '6': /* align to 64 byte boundary */
3952 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3957 as_bad (_("unknown section attribute '%c'"),
3958 *input_line_pointer
);
3961 ++input_line_pointer
;
3963 if (*input_line_pointer
== '"')
3964 ++input_line_pointer
;
3968 sec
= subseg_new (name
, (subsegT
) exp
);
3970 ppc_set_current_section (sec
);
3972 if (flags
!= SEC_NO_FLAGS
)
3974 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3975 as_bad (_("error setting flags for \"%s\": %s"),
3976 bfd_section_name (stdoutput
, sec
),
3977 bfd_errmsg (bfd_get_error ()));
3980 bfd_set_section_alignment (stdoutput
, sec
, align
);
3985 ppc_pe_function (ignore
)
3986 int ignore ATTRIBUTE_UNUSED
;
3992 name
= input_line_pointer
;
3993 endc
= get_symbol_end ();
3995 ext_sym
= symbol_find_or_make (name
);
3997 *input_line_pointer
= endc
;
3999 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4000 SF_SET_FUNCTION (ext_sym
);
4001 SF_SET_PROCESS (ext_sym
);
4002 coff_add_linesym (ext_sym
);
4004 demand_empty_rest_of_line ();
4008 ppc_pe_tocd (ignore
)
4009 int ignore ATTRIBUTE_UNUSED
;
4011 if (tocdata_section
== 0)
4013 tocdata_section
= subseg_new (".tocd", 0);
4014 /* FIXME: section flags won't work. */
4015 bfd_set_section_flags (stdoutput
, tocdata_section
,
4016 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4017 | SEC_READONLY
| SEC_DATA
));
4019 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4023 rdata_section
= subseg_new (".tocd", 0);
4026 ppc_set_current_section (tocdata_section
);
4028 demand_empty_rest_of_line ();
4031 /* Don't adjust TOC relocs to use the section symbol. */
4034 ppc_pe_fix_adjustable (fix
)
4037 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4044 /* XCOFF specific symbol and file handling. */
4046 /* Canonicalize the symbol name. We use the to force the suffix, if
4047 any, to use square brackets, and to be in upper case. */
4050 ppc_canonicalize_symbol_name (name
)
4055 if (ppc_stab_symbol
)
4058 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4072 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4076 if (*s
== '\0' || s
[1] != '\0')
4077 as_bad (_("bad symbol suffix"));
4085 /* Set the class of a symbol based on the suffix, if any. This is
4086 called whenever a new symbol is created. */
4089 ppc_symbol_new_hook (sym
)
4092 struct ppc_tc_sy
*tc
;
4095 tc
= symbol_get_tc (sym
);
4099 tc
->real_name
= NULL
;
4105 if (ppc_stab_symbol
)
4108 s
= strchr (S_GET_NAME (sym
), '[');
4109 if (s
== (const char *) NULL
)
4111 /* There is no suffix. */
4120 if (strcmp (s
, "BS]") == 0)
4124 if (strcmp (s
, "DB]") == 0)
4126 else if (strcmp (s
, "DS]") == 0)
4130 if (strcmp (s
, "GL]") == 0)
4134 if (strcmp (s
, "PR]") == 0)
4138 if (strcmp (s
, "RO]") == 0)
4140 else if (strcmp (s
, "RW]") == 0)
4144 if (strcmp (s
, "SV]") == 0)
4148 if (strcmp (s
, "TC]") == 0)
4150 else if (strcmp (s
, "TI]") == 0)
4152 else if (strcmp (s
, "TB]") == 0)
4154 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4155 tc
->class = XMC_TC0
;
4158 if (strcmp (s
, "UA]") == 0)
4160 else if (strcmp (s
, "UC]") == 0)
4164 if (strcmp (s
, "XO]") == 0)
4169 if (tc
->class == -1)
4170 as_bad (_("Unrecognized symbol suffix"));
4173 /* Set the class of a label based on where it is defined. This
4174 handles symbols without suffixes. Also, move the symbol so that it
4175 follows the csect symbol. */
4178 ppc_frob_label (sym
)
4181 if (ppc_current_csect
!= (symbolS
*) NULL
)
4183 if (symbol_get_tc (sym
)->class == -1)
4184 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4186 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4187 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4188 &symbol_rootP
, &symbol_lastP
);
4189 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4193 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4194 seen. It tells ppc_adjust_symtab whether it needs to look through
4197 static boolean ppc_saw_abs
;
4199 /* Change the name of a symbol just before writing it out. Set the
4200 real name if the .rename pseudo-op was used. Otherwise, remove any
4201 class suffix. Return 1 if the symbol should not be included in the
4205 ppc_frob_symbol (sym
)
4208 static symbolS
*ppc_last_function
;
4209 static symbolS
*set_end
;
4211 /* Discard symbols that should not be included in the output symbol
4213 if (! symbol_used_in_reloc_p (sym
)
4214 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4215 || (! S_IS_EXTERNAL (sym
)
4216 && ! symbol_get_tc (sym
)->output
4217 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4220 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4221 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4227 name
= S_GET_NAME (sym
);
4228 s
= strchr (name
, '[');
4229 if (s
!= (char *) NULL
)
4235 snew
= xmalloc (len
+ 1);
4236 memcpy (snew
, name
, len
);
4239 S_SET_NAME (sym
, snew
);
4243 if (set_end
!= (symbolS
*) NULL
)
4245 SA_SET_SYM_ENDNDX (set_end
, sym
);
4249 if (SF_GET_FUNCTION (sym
))
4251 if (ppc_last_function
!= (symbolS
*) NULL
)
4252 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4253 ppc_last_function
= sym
;
4254 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4256 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4257 SA_SET_SYM_FSIZE (sym
,
4258 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4261 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4262 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4264 if (ppc_last_function
== (symbolS
*) NULL
)
4265 as_bad (_(".ef with no preceding .function"));
4268 set_end
= ppc_last_function
;
4269 ppc_last_function
= NULL
;
4271 /* We don't have a C_EFCN symbol, but we need to force the
4272 COFF backend to believe that it has seen one. */
4273 coff_last_function
= NULL
;
4277 if (! S_IS_EXTERNAL (sym
)
4278 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4279 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4280 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4281 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4282 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4283 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4284 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4285 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4286 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4287 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4289 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4290 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4293 union internal_auxent
*a
;
4295 /* Create a csect aux. */
4296 i
= S_GET_NUMBER_AUXILIARY (sym
);
4297 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4298 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4299 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4301 /* This is the TOC table. */
4302 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4303 a
->x_csect
.x_scnlen
.l
= 0;
4304 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4306 else if (symbol_get_tc (sym
)->subseg
!= 0)
4308 /* This is a csect symbol. x_scnlen is the size of the
4310 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4311 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4312 S_GET_SEGMENT (sym
))
4313 - S_GET_VALUE (sym
));
4316 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4317 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4318 - S_GET_VALUE (sym
));
4320 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4322 else if (S_GET_SEGMENT (sym
) == bss_section
)
4324 /* This is a common symbol. */
4325 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4326 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4327 if (S_IS_EXTERNAL (sym
))
4328 symbol_get_tc (sym
)->class = XMC_RW
;
4330 symbol_get_tc (sym
)->class = XMC_BS
;
4332 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4334 /* This is an absolute symbol. The csect will be created by
4335 ppc_adjust_symtab. */
4337 a
->x_csect
.x_smtyp
= XTY_LD
;
4338 if (symbol_get_tc (sym
)->class == -1)
4339 symbol_get_tc (sym
)->class = XMC_XO
;
4341 else if (! S_IS_DEFINED (sym
))
4343 /* This is an external symbol. */
4344 a
->x_csect
.x_scnlen
.l
= 0;
4345 a
->x_csect
.x_smtyp
= XTY_ER
;
4347 else if (symbol_get_tc (sym
)->class == XMC_TC
)
4351 /* This is a TOC definition. x_scnlen is the size of the
4353 next
= symbol_next (sym
);
4354 while (symbol_get_tc (next
)->class == XMC_TC0
)
4355 next
= symbol_next (next
);
4356 if (next
== (symbolS
*) NULL
4357 || symbol_get_tc (next
)->class != XMC_TC
)
4359 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4360 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4362 - S_GET_VALUE (sym
));
4364 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4365 - S_GET_VALUE (sym
));
4369 resolve_symbol_value (next
);
4370 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4371 - S_GET_VALUE (sym
));
4373 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4379 /* This is a normal symbol definition. x_scnlen is the
4380 symbol index of the containing csect. */
4381 if (S_GET_SEGMENT (sym
) == text_section
)
4382 csect
= ppc_text_csects
;
4383 else if (S_GET_SEGMENT (sym
) == data_section
)
4384 csect
= ppc_data_csects
;
4388 /* Skip the initial dummy symbol. */
4389 csect
= symbol_get_tc (csect
)->next
;
4391 if (csect
== (symbolS
*) NULL
)
4393 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4394 a
->x_csect
.x_scnlen
.l
= 0;
4398 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
4400 resolve_symbol_value (symbol_get_tc (csect
)->next
);
4401 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
4402 > S_GET_VALUE (sym
))
4404 csect
= symbol_get_tc (csect
)->next
;
4407 a
->x_csect
.x_scnlen
.p
=
4408 coffsymbol (symbol_get_bfdsym (csect
))->native
;
4409 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
4412 a
->x_csect
.x_smtyp
= XTY_LD
;
4415 a
->x_csect
.x_parmhash
= 0;
4416 a
->x_csect
.x_snhash
= 0;
4417 if (symbol_get_tc (sym
)->class == -1)
4418 a
->x_csect
.x_smclas
= XMC_PR
;
4420 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
4421 a
->x_csect
.x_stab
= 0;
4422 a
->x_csect
.x_snstab
= 0;
4424 /* Don't let the COFF backend resort these symbols. */
4425 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
4427 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4429 /* We want the value to be the symbol index of the referenced
4430 csect symbol. BFD will do that for us if we set the right
4434 coffsymbol (symbol_get_bfdsym
4435 (symbol_get_tc (sym
)->within
))->native
));
4436 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
4438 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4443 /* The value is the offset from the enclosing csect. */
4444 block
= symbol_get_tc (sym
)->within
;
4445 csect
= symbol_get_tc (block
)->within
;
4446 resolve_symbol_value (csect
);
4447 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4449 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4450 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4452 /* We want the value to be a file offset into the line numbers.
4453 BFD will do that for us if we set the right flags. We have
4454 already set the value correctly. */
4455 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
4461 /* Adjust the symbol table. This creates csect symbols for all
4462 absolute symbols. */
4465 ppc_adjust_symtab ()
4472 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4476 union internal_auxent
*a
;
4478 if (S_GET_SEGMENT (sym
) != absolute_section
)
4481 csect
= symbol_create (".abs[XO]", absolute_section
,
4482 S_GET_VALUE (sym
), &zero_address_frag
);
4483 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
4484 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4485 i
= S_GET_NUMBER_AUXILIARY (csect
);
4486 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4487 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
4488 a
->x_csect
.x_scnlen
.l
= 0;
4489 a
->x_csect
.x_smtyp
= XTY_SD
;
4490 a
->x_csect
.x_parmhash
= 0;
4491 a
->x_csect
.x_snhash
= 0;
4492 a
->x_csect
.x_smclas
= XMC_XO
;
4493 a
->x_csect
.x_stab
= 0;
4494 a
->x_csect
.x_snstab
= 0;
4496 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4498 i
= S_GET_NUMBER_AUXILIARY (sym
);
4499 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
4500 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
4501 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
4504 ppc_saw_abs
= false;
4507 /* Set the VMA for a section. This is called on all the sections in
4511 ppc_frob_section (sec
)
4514 static bfd_size_type vma
= 0;
4516 bfd_set_section_vma (stdoutput
, sec
, vma
);
4517 vma
+= bfd_section_size (stdoutput
, sec
);
4520 #endif /* OBJ_XCOFF */
4522 /* Turn a string in input_line_pointer into a floating point constant
4523 of type TYPE, and store the appropriate bytes in *LITP. The number
4524 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4525 returned, or NULL on OK. */
4528 md_atof (type
, litp
, sizep
)
4534 LITTLENUM_TYPE words
[4];
4550 return _("bad call to md_atof");
4553 t
= atof_ieee (input_line_pointer
, type
, words
);
4555 input_line_pointer
= t
;
4559 if (target_big_endian
)
4561 for (i
= 0; i
< prec
; i
++)
4563 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4569 for (i
= prec
- 1; i
>= 0; i
--)
4571 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4579 /* Write a value out to the object file, using the appropriate
4583 md_number_to_chars (buf
, val
, n
)
4588 if (target_big_endian
)
4589 number_to_chars_bigendian (buf
, val
, n
);
4591 number_to_chars_littleendian (buf
, val
, n
);
4594 /* Align a section (I don't know why this is machine dependent). */
4597 md_section_align (seg
, addr
)
4601 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4603 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4606 /* We don't have any form of relaxing. */
4609 md_estimate_size_before_relax (fragp
, seg
)
4610 fragS
*fragp ATTRIBUTE_UNUSED
;
4611 asection
*seg ATTRIBUTE_UNUSED
;
4617 /* Convert a machine dependent frag. We never generate these. */
4620 md_convert_frag (abfd
, sec
, fragp
)
4621 bfd
*abfd ATTRIBUTE_UNUSED
;
4622 asection
*sec ATTRIBUTE_UNUSED
;
4623 fragS
*fragp ATTRIBUTE_UNUSED
;
4628 /* We have no need to default values of symbols. */
4631 md_undefined_symbol (name
)
4632 char *name ATTRIBUTE_UNUSED
;
4637 /* Functions concerning relocs. */
4639 /* The location from which a PC relative jump should be calculated,
4640 given a PC relative reloc. */
4643 md_pcrel_from_section (fixp
, sec
)
4645 segT sec ATTRIBUTE_UNUSED
;
4647 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4652 /* This is called to see whether a fixup should be adjusted to use a
4653 section symbol. We take the opportunity to change a fixup against
4654 a symbol in the TOC subsegment into a reloc against the
4655 corresponding .tc symbol. */
4658 ppc_fix_adjustable (fix
)
4663 resolve_symbol_value (fix
->fx_addsy
);
4664 val
= S_GET_VALUE (fix
->fx_addsy
);
4665 if (ppc_toc_csect
!= (symbolS
*) NULL
4666 && fix
->fx_addsy
!= (symbolS
*) NULL
4667 && fix
->fx_addsy
!= ppc_toc_csect
4668 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4669 && val
>= ppc_toc_frag
->fr_address
4670 && (ppc_after_toc_frag
== (fragS
*) NULL
4671 || val
< ppc_after_toc_frag
->fr_address
))
4675 for (sy
= symbol_next (ppc_toc_csect
);
4676 sy
!= (symbolS
*) NULL
;
4677 sy
= symbol_next (sy
))
4679 if (symbol_get_tc (sy
)->class == XMC_TC0
)
4681 if (symbol_get_tc (sy
)->class != XMC_TC
)
4683 resolve_symbol_value (sy
);
4684 if (val
== S_GET_VALUE (sy
))
4687 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4692 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4693 _("symbol in .toc does not match any .tc"));
4696 /* Possibly adjust the reloc to be against the csect. */
4697 if (fix
->fx_addsy
!= (symbolS
*) NULL
4698 && symbol_get_tc (fix
->fx_addsy
)->subseg
== 0
4699 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC0
4700 && symbol_get_tc (fix
->fx_addsy
)->class != XMC_TC
4701 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
4702 /* Don't adjust if this is a reloc in the toc section. */
4703 && (S_GET_SEGMENT (fix
->fx_addsy
) != data_section
4704 || ppc_toc_csect
== NULL
4705 || val
< ppc_toc_frag
->fr_address
4706 || (ppc_after_toc_frag
!= NULL
4707 && val
>= ppc_after_toc_frag
->fr_address
)))
4711 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4712 csect
= ppc_text_csects
;
4713 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4714 csect
= ppc_data_csects
;
4718 /* Skip the initial dummy symbol. */
4719 csect
= symbol_get_tc (csect
)->next
;
4721 if (csect
!= (symbolS
*) NULL
)
4723 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
4724 && (symbol_get_frag (symbol_get_tc (csect
)->next
)->fr_address
4727 /* If the csect address equals the symbol value, then we
4728 have to look through the full symbol table to see
4729 whether this is the csect we want. Note that we will
4730 only get here if the csect has zero length. */
4731 if ((symbol_get_frag (csect
)->fr_address
== val
)
4732 && S_GET_VALUE (csect
) == S_GET_VALUE (fix
->fx_addsy
))
4736 for (scan
= symbol_next (csect
);
4738 scan
= symbol_next (scan
))
4740 if (symbol_get_tc (scan
)->subseg
!= 0)
4742 if (scan
== fix
->fx_addsy
)
4746 /* If we found the symbol before the next csect
4747 symbol, then this is the csect we want. */
4748 if (scan
== fix
->fx_addsy
)
4752 csect
= symbol_get_tc (csect
)->next
;
4755 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4756 - symbol_get_frag (csect
)->fr_address
);
4757 fix
->fx_addsy
= csect
;
4761 /* Adjust a reloc against a .lcomm symbol to be against the base
4763 if (fix
->fx_addsy
!= (symbolS
*) NULL
4764 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4765 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4767 resolve_symbol_value (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
);
4769 (S_GET_VALUE (fix
->fx_addsy
)
4770 - S_GET_VALUE (symbol_get_frag (fix
->fx_addsy
)->fr_symbol
));
4771 fix
->fx_addsy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
4777 /* A reloc from one csect to another must be kept. The assembler
4778 will, of course, keep relocs between sections, and it will keep
4779 absolute relocs, but we need to force it to keep PC relative relocs
4780 between two csects in the same section. */
4783 ppc_force_relocation (fix
)
4786 /* At this point fix->fx_addsy should already have been converted to
4787 a csect symbol. If the csect does not include the fragment, then
4788 we need to force the relocation. */
4790 && fix
->fx_addsy
!= NULL
4791 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
4792 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
4793 > fix
->fx_frag
->fr_address
)
4794 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
4795 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
4796 <= fix
->fx_frag
->fr_address
))))
4802 #endif /* OBJ_XCOFF */
4804 /* See whether a symbol is in the TOC section. */
4807 ppc_is_toc_sym (sym
)
4811 return symbol_get_tc (sym
)->class == XMC_TC
;
4813 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4817 /* Apply a fixup to the object code. This is called for all the
4818 fixups we generated by the call to fix_new_exp, above. In the call
4819 above we used a reloc code which was the largest legal reloc code
4820 plus the operand index. Here we undo that to recover the operand
4821 index. At this point all symbol values should be fully resolved,
4822 and we attempt to completely resolve the reloc. If we can not do
4823 that, we determine the correct reloc code and put it back in the
4827 md_apply_fix3 (fixp
, valuep
, seg
)
4836 if (fixp
->fx_addsy
!= NULL
)
4838 /* `*valuep' may contain the value of the symbol on which the reloc
4839 will be based; we have to remove it. */
4840 if (symbol_used_in_reloc_p (fixp
->fx_addsy
)
4841 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
4842 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
4843 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
4844 value
-= S_GET_VALUE (fixp
->fx_addsy
);
4846 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4847 supposed to be? I think this is related to various similar
4848 FIXMEs in tc-i386.c and tc-sparc.c. */
4850 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4857 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4858 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4859 doing this relocation the code in write.c is going to call
4860 bfd_install_relocation, which is also going to use the symbol
4861 value. That means that if the reloc is fully resolved we want to
4862 use *valuep since bfd_install_relocation is not being used.
4863 However, if the reloc is not fully resolved we do not want to use
4864 *valuep, and must use fx_offset instead. However, if the reloc
4865 is PC relative, we do want to use *valuep since it includes the
4866 result of md_pcrel_from. This is confusing. */
4867 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4872 else if (fixp
->fx_pcrel
)
4876 value
= fixp
->fx_offset
;
4877 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4879 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4880 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4883 /* We can't actually support subtracting a symbol. */
4884 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4885 _("expression too complex"));
4891 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4894 const struct powerpc_operand
*operand
;
4898 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4900 operand
= &powerpc_operands
[opindex
];
4903 /* It appears that an instruction like
4905 when LC..1 is not a TOC symbol does not generate a reloc. It
4906 uses the offset of LC..1 within its csect. However, .long
4907 LC..1 will generate a reloc. I can't find any documentation
4908 on how these cases are to be distinguished, so this is a wild
4909 guess. These cases are generated by gcc -mminimal-toc. */
4910 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4911 && operand
->bits
== 16
4912 && operand
->shift
== 0
4913 && operand
->insert
== NULL
4914 && fixp
->fx_addsy
!= NULL
4915 && symbol_get_tc (fixp
->fx_addsy
)->subseg
!= 0
4916 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC
4917 && symbol_get_tc (fixp
->fx_addsy
)->class != XMC_TC0
4918 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4920 value
= fixp
->fx_offset
;
4925 /* Fetch the instruction, insert the fully resolved operand
4926 value, and stuff the instruction back again. */
4927 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4928 if (target_big_endian
)
4929 insn
= bfd_getb32 ((unsigned char *) where
);
4931 insn
= bfd_getl32 ((unsigned char *) where
);
4932 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4933 fixp
->fx_file
, fixp
->fx_line
);
4934 if (target_big_endian
)
4935 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4937 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4941 /* Nothing else to do here. */
4945 /* Determine a BFD reloc value based on the operand information.
4946 We are only prepared to turn a few of the operands into
4948 For other operand types, give an error. */
4949 if (operand
->reloc
== 0)
4954 /* Use expr_symbol_where to see if this is an expression
4956 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
4957 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4958 _("unresolved expression that must be resolved"));
4960 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4961 _("unsupported relocation type"));
4966 fixp
->fx_r_type
= operand
->reloc
;
4968 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0 && fixp
->fx_addsy
!= NULL
)
4970 /* For ld/st/la reloc types (`la' == load address).
4971 Instruction with D or DS field. */
4972 if (ppc_is_toc_sym (fixp
->fx_addsy
))
4975 if (target_big_endian
)
4976 fixp
->fx_where
+= 2;
4980 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4981 _("unsupported relocation against %s"),
4982 S_GET_NAME (fixp
->fx_addsy
));
4991 ppc_elf_validate_fix (fixp
, seg
);
4993 switch (fixp
->fx_r_type
)
4996 case BFD_RELOC_CTOR
:
4998 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
5002 case BFD_RELOC_32_PCREL
:
5003 case BFD_RELOC_32_BASEREL
:
5004 case BFD_RELOC_PPC_EMB_NADDR32
:
5005 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5011 fixp
->fx_r_type
= BFD_RELOC_64_PCREL
;
5014 case BFD_RELOC_64_PCREL
:
5015 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5019 case BFD_RELOC_LO16
:
5021 case BFD_RELOC_GPREL16
:
5022 case BFD_RELOC_16_GOT_PCREL
:
5023 case BFD_RELOC_16_GOTOFF
:
5024 case BFD_RELOC_LO16_GOTOFF
:
5025 case BFD_RELOC_HI16_GOTOFF
:
5026 case BFD_RELOC_HI16_S_GOTOFF
:
5027 case BFD_RELOC_LO16_BASEREL
:
5028 case BFD_RELOC_HI16_BASEREL
:
5029 case BFD_RELOC_HI16_S_BASEREL
:
5030 case BFD_RELOC_PPC_EMB_NADDR16
:
5031 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5032 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5033 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5034 case BFD_RELOC_PPC_EMB_SDAI16
:
5035 case BFD_RELOC_PPC_EMB_SDA2REL
:
5036 case BFD_RELOC_PPC_EMB_SDA2I16
:
5037 case BFD_RELOC_PPC_EMB_RELSEC16
:
5038 case BFD_RELOC_PPC_EMB_RELST_LO
:
5039 case BFD_RELOC_PPC_EMB_RELST_HI
:
5040 case BFD_RELOC_PPC_EMB_RELST_HA
:
5041 case BFD_RELOC_PPC_EMB_RELSDA
:
5042 case BFD_RELOC_PPC_TOC16
:
5045 if (fixp
->fx_addsy
!= NULL
)
5046 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5047 _("cannot emit PC relative %s relocation against %s"),
5048 bfd_get_reloc_code_name (fixp
->fx_r_type
),
5049 S_GET_NAME (fixp
->fx_addsy
));
5051 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5052 _("cannot emit PC relative %s relocation"),
5053 bfd_get_reloc_code_name (fixp
->fx_r_type
));
5056 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5060 /* This case happens when you write, for example,
5062 where L1 and L2 are defined later. */
5063 case BFD_RELOC_HI16
:
5066 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5070 case BFD_RELOC_HI16_S
:
5073 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5074 (value
+ 0x8000) >> 16, 2);
5077 /* Because SDA21 modifies the register field, the size is set to 4
5078 bytes, rather than 2, so offset it here appropriately. */
5079 case BFD_RELOC_PPC_EMB_SDA21
:
5083 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
5084 + ((target_big_endian
) ? 2 : 0),
5092 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
5096 case BFD_RELOC_24_PLT_PCREL
:
5097 case BFD_RELOC_PPC_LOCAL24PC
:
5098 if (!fixp
->fx_pcrel
&& !fixp
->fx_done
)
5106 /* Fetch the instruction, insert the fully resolved operand
5107 value, and stuff the instruction back again. */
5108 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
5109 if (target_big_endian
)
5110 insn
= bfd_getb32 ((unsigned char *) where
);
5112 insn
= bfd_getl32 ((unsigned char *) where
);
5113 if ((value
& 3) != 0)
5114 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5115 _("must branch to an address a multiple of 4"));
5116 if ((offsetT
) value
< -0x40000000
5117 || (offsetT
) value
>= 0x40000000)
5118 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5119 _("@local or @plt branch destination is too far away, %ld bytes"),
5121 insn
= insn
| (value
& 0x03fffffc);
5122 if (target_big_endian
)
5123 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5125 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5129 case BFD_RELOC_VTABLE_INHERIT
:
5132 && !S_IS_DEFINED (fixp
->fx_addsy
)
5133 && !S_IS_WEAK (fixp
->fx_addsy
))
5134 S_SET_WEAK (fixp
->fx_addsy
);
5137 case BFD_RELOC_VTABLE_ENTRY
:
5143 _("Gas failure, reloc value %d\n"), fixp
->fx_r_type
);
5150 fixp
->fx_addnumber
= value
;
5152 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
5153 fixp
->fx_addnumber
= 0;
5157 fixp
->fx_addnumber
= 0;
5159 /* We want to use the offset within the data segment of the
5160 symbol, not the actual VMA of the symbol. */
5161 fixp
->fx_addnumber
=
5162 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
5170 /* Generate a reloc for a fixup. */
5173 tc_gen_reloc (seg
, fixp
)
5174 asection
*seg ATTRIBUTE_UNUSED
;
5179 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5181 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5182 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5183 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5184 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5185 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
5187 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5188 _("reloc %d not supported by object file format"),
5189 (int) fixp
->fx_r_type
);
5192 reloc
->addend
= fixp
->fx_addnumber
;