1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/ppc.h"
37 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
39 /* Tell the main code what the endianness is. */
40 extern int target_big_endian
;
42 /* Whether or not, we've set target_big_endian. */
43 static int set_target_endian
= 0;
45 /* Whether to use user friendly register names. */
46 #ifndef TARGET_REG_NAMES_P
48 #define TARGET_REG_NAMES_P true
50 #define TARGET_REG_NAMES_P false
54 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
56 static boolean register_name
PARAMS ((expressionS
*));
57 static void ppc_set_cpu
PARAMS ((void));
58 static unsigned long ppc_insert_operand
59 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
60 offsetT val
, char *file
, unsigned int line
));
61 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
62 static void ppc_byte
PARAMS ((int));
63 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
64 static void ppc_tc
PARAMS ((int));
67 static void ppc_comm
PARAMS ((int));
68 static void ppc_bb
PARAMS ((int));
69 static void ppc_bc
PARAMS ((int));
70 static void ppc_bf
PARAMS ((int));
71 static void ppc_biei
PARAMS ((int));
72 static void ppc_bs
PARAMS ((int));
73 static void ppc_eb
PARAMS ((int));
74 static void ppc_ec
PARAMS ((int));
75 static void ppc_ef
PARAMS ((int));
76 static void ppc_es
PARAMS ((int));
77 static void ppc_csect
PARAMS ((int));
78 static void ppc_change_csect
PARAMS ((symbolS
*));
79 static void ppc_function
PARAMS ((int));
80 static void ppc_extern
PARAMS ((int));
81 static void ppc_lglobl
PARAMS ((int));
82 static void ppc_section
PARAMS ((int));
83 static void ppc_named_section
PARAMS ((int));
84 static void ppc_stabx
PARAMS ((int));
85 static void ppc_rename
PARAMS ((int));
86 static void ppc_toc
PARAMS ((int));
87 static void ppc_xcoff_cons
PARAMS ((int));
88 static void ppc_vbyte
PARAMS ((int));
92 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
93 static void ppc_elf_cons
PARAMS ((int));
94 static void ppc_elf_rdata
PARAMS ((int));
95 static void ppc_elf_lcomm
PARAMS ((int));
96 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
100 static void ppc_set_current_section
PARAMS ((segT
));
101 static void ppc_previous
PARAMS ((int));
102 static void ppc_pdata
PARAMS ((int));
103 static void ppc_ydata
PARAMS ((int));
104 static void ppc_reldata
PARAMS ((int));
105 static void ppc_rdata
PARAMS ((int));
106 static void ppc_ualong
PARAMS ((int));
107 static void ppc_znop
PARAMS ((int));
108 static void ppc_pe_comm
PARAMS ((int));
109 static void ppc_pe_section
PARAMS ((int));
110 static void ppc_pe_function
PARAMS ((int));
111 static void ppc_pe_tocd
PARAMS ((int));
114 /* Generic assembler global variables which must be defined by all
118 /* This string holds the chars that always start a comment. If the
119 pre-processor is disabled, these aren't very useful. The macro
120 tc_comment_chars points to this. We use this, rather than the
121 usual comment_chars, so that we can switch for Solaris conventions. */
122 static const char ppc_solaris_comment_chars
[] = "#!";
123 static const char ppc_eabi_comment_chars
[] = "#";
125 #ifdef TARGET_SOLARIS_COMMENT
126 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
128 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
131 const char comment_chars
[] = "#";
134 /* Characters which start a comment at the beginning of a line. */
135 const char line_comment_chars
[] = "#";
137 /* Characters which may be used to separate multiple commands on a
139 const char line_separator_chars
[] = ";";
141 /* Characters which are used to indicate an exponent in a floating
143 const char EXP_CHARS
[] = "eE";
145 /* Characters which mean that a number is a floating point constant,
147 const char FLT_CHARS
[] = "dD";
149 /* The target specific pseudo-ops which we support. */
151 const pseudo_typeS md_pseudo_table
[] =
153 /* Pseudo-ops which must be overridden. */
154 { "byte", ppc_byte
, 0 },
157 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
158 legitimately belong in the obj-*.c file. However, XCOFF is based
159 on COFF, and is only implemented for the RS/6000. We just use
160 obj-coff.c, and add what we need here. */
161 { "comm", ppc_comm
, 0 },
162 { "lcomm", ppc_comm
, 1 },
166 { "bi", ppc_biei
, 0 },
168 { "csect", ppc_csect
, 0 },
169 { "data", ppc_section
, 'd' },
173 { "ei", ppc_biei
, 1 },
175 { "extern", ppc_extern
, 0 },
176 { "function", ppc_function
, 0 },
177 { "lglobl", ppc_lglobl
, 0 },
178 { "rename", ppc_rename
, 0 },
179 { "section", ppc_named_section
, 0 },
180 { "stabx", ppc_stabx
, 0 },
181 { "text", ppc_section
, 't' },
182 { "toc", ppc_toc
, 0 },
183 { "long", ppc_xcoff_cons
, 2 },
184 { "word", ppc_xcoff_cons
, 1 },
185 { "short", ppc_xcoff_cons
, 1 },
186 { "vbyte", ppc_vbyte
, 0 },
190 { "long", ppc_elf_cons
, 4 },
191 { "word", ppc_elf_cons
, 2 },
192 { "short", ppc_elf_cons
, 2 },
193 { "rdata", ppc_elf_rdata
, 0 },
194 { "rodata", ppc_elf_rdata
, 0 },
195 { "lcomm", ppc_elf_lcomm
, 0 },
199 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
200 { "previous", ppc_previous
, 0 },
201 { "pdata", ppc_pdata
, 0 },
202 { "ydata", ppc_ydata
, 0 },
203 { "reldata", ppc_reldata
, 0 },
204 { "rdata", ppc_rdata
, 0 },
205 { "ualong", ppc_ualong
, 0 },
206 { "znop", ppc_znop
, 0 },
207 { "comm", ppc_pe_comm
, 0 },
208 { "lcomm", ppc_pe_comm
, 1 },
209 { "section", ppc_pe_section
, 0 },
210 { "function", ppc_pe_function
,0 },
211 { "tocd", ppc_pe_tocd
, 0 },
214 /* This pseudo-op is used even when not generating XCOFF output. */
221 /* Predefined register names if -mregnames (or default for Windows NT). */
222 /* In general, there are lots of them, in an attempt to be compatible */
223 /* with a number of other Windows NT assemblers. */
225 /* Structure to hold information about predefined registers. */
232 /* List of registers that are pre-defined:
234 Each general register has predefined names of the form:
235 1. r<reg_num> which has the value <reg_num>.
236 2. r.<reg_num> which has the value <reg_num>.
239 Each floating point register has predefined names of the form:
240 1. f<reg_num> which has the value <reg_num>.
241 2. f.<reg_num> which has the value <reg_num>.
243 Each condition register has predefined names of the form:
244 1. cr<reg_num> which has the value <reg_num>.
245 2. cr.<reg_num> which has the value <reg_num>.
247 There are individual registers as well:
248 sp or r.sp has the value 1
249 rtoc or r.toc has the value 2
250 fpscr has the value 0
256 dsisr has the value 18
258 sdr1 has the value 25
259 srr0 has the value 26
260 srr1 has the value 27
262 The table is sorted. Suitable for searching by a binary search. */
264 static const struct pd_reg pre_defined_registers
[] =
266 { "cr.0", 0 }, /* Condition Registers */
286 { "dar", 19 }, /* Data Access Register */
287 { "dec", 22 }, /* Decrementer */
288 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
290 { "f.0", 0 }, /* Floating point registers */
358 { "lr", 8 }, /* Link Register */
362 { "r.0", 0 }, /* General Purpose Registers */
395 { "r.sp", 1 }, /* Stack Pointer */
397 { "r.toc", 2 }, /* Pointer to the table of contents */
399 { "r0", 0 }, /* More general purpose registers */
432 { "rtoc", 2 }, /* Table of contents */
434 { "sdr1", 25 }, /* Storage Description Register 1 */
438 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
439 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
445 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
447 /* Given NAME, find the register number associated with that name, return
448 the integer value associated with the given name or -1 on failure. */
450 static int reg_name_search
451 PARAMS ((const struct pd_reg
*, int, const char * name
));
454 reg_name_search (regs
, regcount
, name
)
455 const struct pd_reg
*regs
;
459 int middle
, low
, high
;
467 middle
= (low
+ high
) / 2;
468 cmp
= strcasecmp (name
, regs
[middle
].name
);
474 return regs
[middle
].value
;
482 * Summary of register_name().
484 * in: Input_line_pointer points to 1st char of operand.
486 * out: A expressionS.
487 * The operand may have been a register: in this case, X_op == O_register,
488 * X_add_number is set to the register number, and truth is returned.
489 * Input_line_pointer->(next non-blank) char after operand, or is in its
494 register_name (expressionP
)
495 expressionS
*expressionP
;
502 /* Find the spelling of the operand */
503 start
= name
= input_line_pointer
;
504 if (name
[0] == '%' && isalpha (name
[1]))
505 name
= ++input_line_pointer
;
507 else if (!reg_names_p
|| !isalpha (name
[0]))
510 c
= get_symbol_end ();
511 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
513 /* look to see if it's in the register table */
516 expressionP
->X_op
= O_register
;
517 expressionP
->X_add_number
= reg_number
;
519 /* make the rest nice */
520 expressionP
->X_add_symbol
= NULL
;
521 expressionP
->X_op_symbol
= NULL
;
522 *input_line_pointer
= c
; /* put back the delimiting char */
527 /* reset the line as if we had not done anything */
528 *input_line_pointer
= c
; /* put back the delimiting char */
529 input_line_pointer
= start
; /* reset input_line pointer */
534 /* This function is called for each symbol seen in an expression. It
535 handles the special parsing which PowerPC assemblers are supposed
536 to use for condition codes. */
538 /* Whether to do the special parsing. */
539 static boolean cr_operand
;
541 /* Names to recognize in a condition code. This table is sorted. */
542 static const struct pd_reg cr_names
[] =
559 /* Parsing function. This returns non-zero if it recognized an
563 ppc_parse_name (name
, expr
)
572 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
577 expr
->X_op
= O_constant
;
578 expr
->X_add_number
= val
;
583 /* Local variables. */
585 /* The type of processor we are assembling for. This is one or more
586 of the PPC_OPCODE flags defined in opcode/ppc.h. */
587 static int ppc_cpu
= 0;
589 /* The size of the processor we are assembling for. This is either
590 PPC_OPCODE_32 or PPC_OPCODE_64. */
591 static int ppc_size
= PPC_OPCODE_32
;
593 /* Opcode hash table. */
594 static struct hash_control
*ppc_hash
;
596 /* Macro hash table. */
597 static struct hash_control
*ppc_macro_hash
;
600 /* What type of shared library support to use */
601 static enum { SHLIB_NONE
, SHLIB_PIC
, SHILB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
603 /* Flags to set in the elf header */
604 static flagword ppc_flags
= 0;
606 /* Whether this is Solaris or not. */
607 #ifdef TARGET_SOLARIS_COMMENT
608 #define SOLARIS_P true
610 #define SOLARIS_P false
613 static boolean msolaris
= SOLARIS_P
;
618 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
619 using a bunch of different sections. These assembler sections,
620 however, are all encompassed within the .text or .data sections of
621 the final output file. We handle this by using different
622 subsegments within these main segments. */
624 /* Next subsegment to allocate within the .text segment. */
625 static subsegT ppc_text_subsegment
= 2;
627 /* Linked list of csects in the text section. */
628 static symbolS
*ppc_text_csects
;
630 /* Next subsegment to allocate within the .data segment. */
631 static subsegT ppc_data_subsegment
= 2;
633 /* Linked list of csects in the data section. */
634 static symbolS
*ppc_data_csects
;
636 /* The current csect. */
637 static symbolS
*ppc_current_csect
;
639 /* The RS/6000 assembler uses a TOC which holds addresses of functions
640 and variables. Symbols are put in the TOC with the .tc pseudo-op.
641 A special relocation is used when accessing TOC entries. We handle
642 the TOC as a subsegment within the .data segment. We set it up if
643 we see a .toc pseudo-op, and save the csect symbol here. */
644 static symbolS
*ppc_toc_csect
;
646 /* The first frag in the TOC subsegment. */
647 static fragS
*ppc_toc_frag
;
649 /* The first frag in the first subsegment after the TOC in the .data
650 segment. NULL if there are no subsegments after the TOC. */
651 static fragS
*ppc_after_toc_frag
;
653 /* The current static block. */
654 static symbolS
*ppc_current_block
;
656 /* The COFF debugging section; set by md_begin. This is not the
657 .debug section, but is instead the secret BFD section which will
658 cause BFD to set the section number of a symbol to N_DEBUG. */
659 static asection
*ppc_coff_debug_section
;
661 #endif /* OBJ_XCOFF */
665 /* Various sections that we need for PE coff support. */
666 static segT ydata_section
;
667 static segT pdata_section
;
668 static segT reldata_section
;
669 static segT rdata_section
;
670 static segT tocdata_section
;
672 /* The current section and the previous section. See ppc_previous. */
673 static segT ppc_previous_section
;
674 static segT ppc_current_section
;
679 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
683 CONST
char *md_shortopts
= "b:l:usm:K:VQ:";
685 CONST
char *md_shortopts
= "um:";
687 struct option md_longopts
[] = {
688 {NULL
, no_argument
, NULL
, 0}
690 size_t md_longopts_size
= sizeof(md_longopts
);
693 md_parse_option (c
, arg
)
700 /* -u means that any undefined symbols should be treated as
701 external, which is the default for gas anyhow. */
706 /* Solaris as takes -le (presumably for little endian). For completeness
707 sake, recognize -be also. */
708 if (strcmp (arg
, "e") == 0)
710 target_big_endian
= 0;
711 set_target_endian
= 1;
719 if (strcmp (arg
, "e") == 0)
721 target_big_endian
= 1;
722 set_target_endian
= 1;
730 /* Recognize -K PIC */
731 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
734 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
743 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
745 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
746 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
747 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
748 else if (strcmp (arg
, "pwr") == 0)
749 ppc_cpu
= PPC_OPCODE_POWER
;
750 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
751 instructions that are holdovers from the Power. */
752 else if (strcmp (arg
, "601") == 0)
753 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
754 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
755 Motorola PowerPC 603/604. */
756 else if (strcmp (arg
, "ppc") == 0
757 || strcmp (arg
, "ppc32") == 0
758 || strcmp (arg
, "403") == 0
759 || strcmp (arg
, "603") == 0
760 || strcmp (arg
, "604") == 0)
761 ppc_cpu
= PPC_OPCODE_PPC
;
762 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
764 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
766 ppc_cpu
= PPC_OPCODE_PPC
;
767 ppc_size
= PPC_OPCODE_64
;
769 else if (strcmp (arg
, "ppc64bridge") == 0)
771 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_64_BRIDGE
;
772 ppc_size
= PPC_OPCODE_64
;
774 /* -mcom means assemble for the common intersection between Power
775 and PowerPC. At present, we just allow the union, rather
776 than the intersection. */
777 else if (strcmp (arg
, "com") == 0)
778 ppc_cpu
= PPC_OPCODE_COMMON
;
779 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
780 else if (strcmp (arg
, "any") == 0)
781 ppc_cpu
= PPC_OPCODE_ANY
;
783 else if (strcmp (arg
, "regnames") == 0)
786 else if (strcmp (arg
, "no-regnames") == 0)
790 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
791 else if (strcmp (arg
, "relocatable") == 0)
793 shlib
= SHILB_MRELOCATABLE
;
794 ppc_flags
|= EF_PPC_RELOCATABLE
;
797 else if (strcmp (arg
, "relocatable-lib") == 0)
799 shlib
= SHILB_MRELOCATABLE
;
800 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
803 /* -memb, set embedded bit */
804 else if (strcmp (arg
, "emb") == 0)
805 ppc_flags
|= EF_PPC_EMB
;
807 /* -mlittle/-mbig set the endianess */
808 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
810 target_big_endian
= 0;
811 set_target_endian
= 1;
814 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
816 target_big_endian
= 1;
817 set_target_endian
= 1;
820 else if (strcmp (arg
, "solaris") == 0)
823 ppc_comment_chars
= ppc_solaris_comment_chars
;
826 else if (strcmp (arg
, "no-solaris") == 0)
829 ppc_comment_chars
= ppc_eabi_comment_chars
;
834 as_bad (_("invalid switch -m%s"), arg
);
840 /* -V: SVR4 argument to print version ID. */
845 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
846 should be emitted or not. FIXME: Not implemented. */
850 /* Solaris takes -s to specify that .stabs go in a .stabs section,
851 rather than .stabs.excl, which is ignored by the linker.
852 FIXME: Not implemented. */
868 md_show_usage (stream
)
874 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
875 -mpwr generate code for IBM POWER (RIOS1)\n\
876 -m601 generate code for Motorola PowerPC 601\n\
877 -mppc, -mppc32, -m403, -m603, -m604\n\
878 generate code for Motorola PowerPC 603/604\n\
879 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
880 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
881 -mcom generate code Power/PowerPC common instructions\n\
882 -many generate code for any architecture (PWR/PWRX/PPC)\n\
883 -mregnames Allow symbolic names for registers\n\
884 -mno-regnames Do not allow symbolic names for registers\n"));
887 -mrelocatable support for GCC's -mrelocatble option\n\
888 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
889 -memb set PPC_EMB bit in ELF flags\n\
890 -mlittle, -mlittle-endian\n\
891 generate code for a little endian machine\n\
892 -mbig, -mbig-endian generate code for a big endian machine\n\
893 -msolaris generate code for Solaris\n\
894 -mno-solaris do not generate code for Solaris\n\
895 -V print assembler version number\n\
896 -Qy, -Qn ignored\n"));
900 /* Set ppc_cpu if it is not already set. */
905 const char *default_os
= TARGET_OS
;
906 const char *default_cpu
= TARGET_CPU
;
910 if (strncmp (default_os
, "aix", 3) == 0
911 && default_os
[3] >= '4' && default_os
[3] <= '9')
912 ppc_cpu
= PPC_OPCODE_COMMON
;
913 else if (strncmp (default_os
, "aix3", 4) == 0)
914 ppc_cpu
= PPC_OPCODE_POWER
;
915 else if (strcmp (default_cpu
, "rs6000") == 0)
916 ppc_cpu
= PPC_OPCODE_POWER
;
917 else if (strcmp (default_cpu
, "powerpc") == 0
918 || strcmp (default_cpu
, "powerpcle") == 0)
919 ppc_cpu
= PPC_OPCODE_PPC
;
921 as_fatal (_("Unknown default cpu = %s, os = %s"), default_cpu
, default_os
);
925 /* Figure out the BFD architecture to use. */
927 enum bfd_architecture
930 const char *default_cpu
= TARGET_CPU
;
933 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
934 return bfd_arch_powerpc
;
935 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
936 return bfd_arch_rs6000
;
937 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
939 if (strcmp (default_cpu
, "rs6000") == 0)
940 return bfd_arch_rs6000
;
941 else if (strcmp (default_cpu
, "powerpc") == 0
942 || strcmp (default_cpu
, "powerpcle") == 0)
943 return bfd_arch_powerpc
;
946 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
947 return bfd_arch_unknown
;
950 /* This function is called when the assembler starts up. It is called
951 after the options have been parsed and the output file has been
957 register const struct powerpc_opcode
*op
;
958 const struct powerpc_opcode
*op_end
;
959 const struct powerpc_macro
*macro
;
960 const struct powerpc_macro
*macro_end
;
961 boolean dup_insn
= false;
966 /* Set the ELF flags if desired. */
967 if (ppc_flags
&& !msolaris
)
968 bfd_set_private_flags (stdoutput
, ppc_flags
);
971 /* Insert the opcodes into a hash table. */
972 ppc_hash
= hash_new ();
974 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
975 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
977 know ((op
->opcode
& op
->mask
) == op
->opcode
);
979 if ((op
->flags
& ppc_cpu
) != 0
980 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
981 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
982 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0))
986 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
987 if (retval
!= (const char *) NULL
)
989 /* Ignore Power duplicates for -m601 */
990 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
991 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
994 as_bad (_("Internal assembler error for instruction %s"), op
->name
);
1000 /* Insert the macros into a hash table. */
1001 ppc_macro_hash
= hash_new ();
1003 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1004 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1006 if ((macro
->flags
& ppc_cpu
) != 0)
1010 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1011 if (retval
!= (const char *) NULL
)
1013 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1022 /* Tell the main code what the endianness is if it is not overidden by the user. */
1023 if (!set_target_endian
)
1025 set_target_endian
= 1;
1026 target_big_endian
= PPC_BIG_ENDIAN
;
1030 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1032 /* Create dummy symbols to serve as initial csects. This forces the
1033 text csects to precede the data csects. These symbols will not
1035 ppc_text_csects
= symbol_make ("dummy\001");
1036 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
1037 ppc_data_csects
= symbol_make ("dummy\001");
1038 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
1043 ppc_current_section
= text_section
;
1044 ppc_previous_section
= 0;
1049 /* Insert an operand value into an instruction. */
1051 static unsigned long
1052 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1054 const struct powerpc_operand
*operand
;
1059 if (operand
->bits
!= 32)
1064 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1066 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1067 max
= (1 << operand
->bits
) - 1;
1069 max
= (1 << (operand
->bits
- 1)) - 1;
1070 min
= - (1 << (operand
->bits
- 1));
1072 if (ppc_size
== PPC_OPCODE_32
)
1074 /* Some people write 32 bit hex constants with the sign
1075 extension done by hand. This shouldn't really be
1076 valid, but, to permit this code to assemble on a 64
1077 bit host, we sign extend the 32 bit value. */
1079 && (val
& 0x80000000) != 0
1080 && (val
& 0xffffffff) == val
)
1089 max
= (1 << operand
->bits
) - 1;
1093 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1098 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1101 _("operand out of range (%s not between %ld and %ld)");
1104 sprint_value (buf
, test
);
1105 if (file
== (char *) NULL
)
1106 as_bad (err
, buf
, min
, max
);
1108 as_bad_where (file
, line
, err
, buf
, min
, max
);
1112 if (operand
->insert
)
1117 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1118 if (errmsg
!= (const char *) NULL
)
1122 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1130 /* Parse @got, etc. and return the desired relocation. */
1131 static bfd_reloc_code_real_type
1132 ppc_elf_suffix (str_p
, exp_p
)
1139 bfd_reloc_code_real_type reloc
;
1147 struct map_bfd
*ptr
;
1149 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1151 static struct map_bfd mapping
[] = {
1152 MAP ("l", BFD_RELOC_LO16
),
1153 MAP ("h", BFD_RELOC_HI16
),
1154 MAP ("ha", BFD_RELOC_HI16_S
),
1155 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1156 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1157 MAP ("got", BFD_RELOC_16_GOTOFF
),
1158 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1159 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1160 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1161 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1162 MAP ("plt", BFD_RELOC_24_PLT_PCREL
),
1163 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1164 MAP ("copy", BFD_RELOC_PPC_COPY
),
1165 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1166 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1167 MAP ("local", BFD_RELOC_PPC_LOCAL24PC
),
1168 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1169 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1170 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1171 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1172 MAP ("sdarel", BFD_RELOC_GPREL16
),
1173 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1174 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1175 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1176 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1177 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1178 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1179 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1180 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1181 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1182 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1183 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1184 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1185 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1186 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1187 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1188 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1189 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1190 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1191 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1192 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1193 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1195 { (char *)0, 0, BFD_RELOC_UNUSED
}
1199 return BFD_RELOC_UNUSED
;
1201 for (ch
= *str
, str2
= ident
;
1202 (str2
< ident
+ sizeof (ident
) - 1
1203 && (isalnum (ch
) || ch
== '@'));
1206 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1213 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1214 if (ch
== ptr
->string
[0]
1215 && len
== ptr
->length
1216 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1218 if (exp_p
->X_add_number
!= 0
1219 && (ptr
->reloc
== BFD_RELOC_16_GOTOFF
1220 || ptr
->reloc
== BFD_RELOC_LO16_GOTOFF
1221 || ptr
->reloc
== BFD_RELOC_HI16_GOTOFF
1222 || ptr
->reloc
== BFD_RELOC_HI16_S_GOTOFF
))
1223 as_warn (_("identifier+constant@got means identifier@got+constant"));
1225 /* Now check for identifier@suffix+constant */
1226 if (*str
== '-' || *str
== '+')
1228 char *orig_line
= input_line_pointer
;
1229 expressionS new_exp
;
1231 input_line_pointer
= str
;
1232 expression (&new_exp
);
1233 if (new_exp
.X_op
== O_constant
)
1235 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1236 str
= input_line_pointer
;
1239 if (&input_line_pointer
!= str_p
)
1240 input_line_pointer
= orig_line
;
1247 return BFD_RELOC_UNUSED
;
1250 /* Like normal .long/.short/.word, except support @got, etc. */
1251 /* clobbers input_line_pointer, checks */
1254 ppc_elf_cons (nbytes
)
1255 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1258 bfd_reloc_code_real_type reloc
;
1260 if (is_it_end_of_statement ())
1262 demand_empty_rest_of_line ();
1269 if (exp
.X_op
== O_symbol
1270 && *input_line_pointer
== '@'
1271 && (reloc
= ppc_elf_suffix (&input_line_pointer
, &exp
)) != BFD_RELOC_UNUSED
)
1273 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1274 int size
= bfd_get_reloc_size (reloc_howto
);
1277 as_bad (_("%s relocations do not fit in %d bytes\n"), reloc_howto
->name
, nbytes
);
1281 register char *p
= frag_more ((int) nbytes
);
1282 int offset
= nbytes
- size
;
1284 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1288 emit_expr (&exp
, (unsigned int) nbytes
);
1290 while (*input_line_pointer
++ == ',');
1292 input_line_pointer
--; /* Put terminator back into stream. */
1293 demand_empty_rest_of_line ();
1296 /* Solaris pseduo op to change to the .rodata section. */
1301 char *save_line
= input_line_pointer
;
1302 static char section
[] = ".rodata\n";
1304 /* Just pretend this is .section .rodata */
1305 input_line_pointer
= section
;
1306 obj_elf_section (xxx
);
1308 input_line_pointer
= save_line
;
1311 /* Pseudo op to make file scope bss items */
1316 register char *name
;
1320 register symbolS
*symbolP
;
1327 name
= input_line_pointer
;
1328 c
= get_symbol_end ();
1330 /* just after name is now '\0' */
1331 p
= input_line_pointer
;
1334 if (*input_line_pointer
!= ',')
1336 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1337 ignore_rest_of_line ();
1341 input_line_pointer
++; /* skip ',' */
1342 if ((size
= get_absolute_expression ()) < 0)
1344 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1345 ignore_rest_of_line ();
1349 /* The third argument to .lcomm is the alignment. */
1350 if (*input_line_pointer
!= ',')
1354 ++input_line_pointer
;
1355 align
= get_absolute_expression ();
1358 as_warn (_("ignoring bad alignment"));
1364 symbolP
= symbol_find_or_make (name
);
1367 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1369 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1370 S_GET_NAME (symbolP
));
1371 ignore_rest_of_line ();
1375 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1377 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1378 S_GET_NAME (symbolP
),
1379 (long) S_GET_VALUE (symbolP
),
1382 ignore_rest_of_line ();
1388 old_subsec
= now_subseg
;
1391 /* convert to a power of 2 alignment */
1392 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1395 as_bad (_("Common alignment not a power of 2"));
1396 ignore_rest_of_line ();
1403 record_alignment (bss_section
, align2
);
1404 subseg_set (bss_section
, 0);
1406 frag_align (align2
, 0, 0);
1407 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1408 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1409 symbol_set_frag (symbolP
, frag_now
);
1410 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1413 S_SET_SIZE (symbolP
, size
);
1414 S_SET_SEGMENT (symbolP
, bss_section
);
1415 subseg_set (old_sec
, old_subsec
);
1416 demand_empty_rest_of_line ();
1419 /* Validate any relocations emitted for -mrelocatable, possibly adding
1420 fixups for word relocations in writable segments, so we can adjust
1423 ppc_elf_validate_fix (fixp
, seg
)
1427 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1436 case SHILB_MRELOCATABLE
:
1437 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1438 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1439 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1440 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1441 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1442 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1443 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1444 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1445 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1446 && strcmp (segment_name (seg
), ".got2") != 0
1447 && strcmp (segment_name (seg
), ".dtors") != 0
1448 && strcmp (segment_name (seg
), ".ctors") != 0
1449 && strcmp (segment_name (seg
), ".fixup") != 0
1450 && strcmp (segment_name (seg
), ".stab") != 0
1451 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1452 && strcmp (segment_name (seg
), ".eh_frame") != 0
1453 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1455 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1456 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1458 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1459 _("Relocation cannot be done when using -mrelocatable"));
1465 #endif /* OBJ_ELF */
1470 * Summary of parse_toc_entry().
1472 * in: Input_line_pointer points to the '[' in one of:
1474 * [toc] [tocv] [toc32] [toc64]
1476 * Anything else is an error of one kind or another.
1479 * return value: success or failure
1480 * toc_kind: kind of toc reference
1481 * input_line_pointer:
1482 * success: first char after the ']'
1483 * failure: unchanged
1487 * [toc] - rv == success, toc_kind = default_toc
1488 * [tocv] - rv == success, toc_kind = data_in_toc
1489 * [toc32] - rv == success, toc_kind = must_be_32
1490 * [toc64] - rv == success, toc_kind = must_be_64
1494 enum toc_size_qualifier
1496 default_toc
, /* The toc cell constructed should be the system default size */
1497 data_in_toc
, /* This is a direct reference to a toc cell */
1498 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1499 must_be_64
/* The toc cell constructed must be 64 bits wide */
1503 parse_toc_entry(toc_kind
)
1504 enum toc_size_qualifier
*toc_kind
;
1509 enum toc_size_qualifier t
;
1511 /* save the input_line_pointer */
1512 start
= input_line_pointer
;
1514 /* skip over the '[' , and whitespace */
1515 ++input_line_pointer
;
1518 /* find the spelling of the operand */
1519 toc_spec
= input_line_pointer
;
1520 c
= get_symbol_end ();
1522 if (strcmp(toc_spec
, "toc") == 0)
1526 else if (strcmp(toc_spec
, "tocv") == 0)
1530 else if (strcmp(toc_spec
, "toc32") == 0)
1534 else if (strcmp(toc_spec
, "toc64") == 0)
1540 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1541 *input_line_pointer
= c
; /* put back the delimiting char */
1542 input_line_pointer
= start
; /* reset input_line pointer */
1546 /* now find the ']' */
1547 *input_line_pointer
= c
; /* put back the delimiting char */
1549 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1550 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1554 as_bad (_("syntax error: expected `]', found `%c'"), c
);
1555 input_line_pointer
= start
; /* reset input_line pointer */
1559 *toc_kind
= t
; /* set return value */
1565 /* We need to keep a list of fixups. We can't simply generate them as
1566 we go, because that would require us to first create the frag, and
1567 that would screw up references to ``.''. */
1573 bfd_reloc_code_real_type reloc
;
1576 #define MAX_INSN_FIXUPS (5)
1578 /* This routine is called for each instruction to be assembled. */
1585 const struct powerpc_opcode
*opcode
;
1587 const unsigned char *opindex_ptr
;
1591 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1596 bfd_reloc_code_real_type reloc
;
1599 /* Get the opcode. */
1600 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1605 /* Look up the opcode in the hash table. */
1606 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1607 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1609 const struct powerpc_macro
*macro
;
1611 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1612 if (macro
== (const struct powerpc_macro
*) NULL
)
1613 as_bad (_("Unrecognized opcode: `%s'"), str
);
1615 ppc_macro (s
, macro
);
1620 insn
= opcode
->opcode
;
1623 while (isspace (*str
))
1626 /* PowerPC operands are just expressions. The only real issue is
1627 that a few operand types are optional. All cases which might use
1628 an optional operand separate the operands only with commas (in
1629 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1630 cases never have optional operands). There is never more than
1631 one optional operand for an instruction. So, before we start
1632 seriously parsing the operands, we check to see if we have an
1633 optional operand, and, if we do, we count the number of commas to
1634 see whether the operand should be omitted. */
1636 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1638 const struct powerpc_operand
*operand
;
1640 operand
= &powerpc_operands
[*opindex_ptr
];
1641 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1643 unsigned int opcount
;
1645 /* There is an optional operand. Count the number of
1646 commas in the input line. */
1653 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1660 /* If there are fewer operands in the line then are called
1661 for by the instruction, we want to skip the optional
1663 if (opcount
< strlen (opcode
->operands
))
1670 /* Gather the operands. */
1674 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1676 const struct powerpc_operand
*operand
;
1682 if (next_opindex
== 0)
1683 operand
= &powerpc_operands
[*opindex_ptr
];
1686 operand
= &powerpc_operands
[next_opindex
];
1692 /* If this is a fake operand, then we do not expect anything
1694 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1696 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1697 if (errmsg
!= (const char *) NULL
)
1702 /* If this is an optional operand, and we are skipping it, just
1704 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1707 if (operand
->insert
)
1709 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1710 if (errmsg
!= (const char *) NULL
)
1713 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1714 next_opindex
= *opindex_ptr
+ 1;
1718 /* Gather the operand. */
1719 hold
= input_line_pointer
;
1720 input_line_pointer
= str
;
1723 if (*input_line_pointer
== '[')
1725 /* We are expecting something like the second argument here:
1727 lwz r4,[toc].GS.0.static_int(rtoc)
1728 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1729 The argument following the `]' must be a symbol name, and the
1730 register must be the toc register: 'rtoc' or '2'
1732 The effect is to 0 as the displacement field
1733 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1734 the appropriate variation) reloc against it based on the symbol.
1735 The linker will build the toc, and insert the resolved toc offset.
1738 o The size of the toc entry is currently assumed to be
1739 32 bits. This should not be assumed to be a hard coded
1741 o In an effort to cope with a change from 32 to 64 bits,
1742 there are also toc entries that are specified to be
1743 either 32 or 64 bits:
1744 lwz r4,[toc32].GS.0.static_int(rtoc)
1745 lwz r4,[toc64].GS.0.static_int(rtoc)
1746 These demand toc entries of the specified size, and the
1747 instruction probably requires it.
1751 enum toc_size_qualifier toc_kind
;
1752 bfd_reloc_code_real_type toc_reloc
;
1754 /* go parse off the [tocXX] part */
1755 valid_toc
= parse_toc_entry(&toc_kind
);
1759 /* Note: message has already been issued. */
1760 /* FIXME: what sort of recovery should we do? */
1761 /* demand_rest_of_line(); return; ? */
1764 /* Now get the symbol following the ']' */
1770 /* In this case, we may not have seen the symbol yet, since */
1771 /* it is allowed to appear on a .extern or .globl or just be */
1772 /* a label in the .data section. */
1773 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1776 /* 1. The symbol must be defined and either in the toc */
1777 /* section, or a global. */
1778 /* 2. The reloc generated must have the TOCDEFN flag set in */
1779 /* upper bit mess of the reloc type. */
1780 /* FIXME: It's a little confusing what the tocv qualifier can */
1781 /* be used for. At the very least, I've seen three */
1782 /* uses, only one of which I'm sure I can explain. */
1783 if (ex
.X_op
== O_symbol
)
1785 assert (ex
.X_add_symbol
!= NULL
);
1786 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1788 as_bad(_("[tocv] symbol is not a toc symbol"));
1792 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1795 /* FIXME: these next two specifically specify 32/64 bit toc */
1796 /* entries. We don't support them today. Is this the */
1797 /* right way to say that? */
1798 toc_reloc
= BFD_RELOC_UNUSED
;
1799 as_bad (_("Unimplemented toc32 expression modifier"));
1802 /* FIXME: see above */
1803 toc_reloc
= BFD_RELOC_UNUSED
;
1804 as_bad (_("Unimplemented toc64 expression modifier"));
1808 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1814 /* We need to generate a fixup for this expression. */
1815 if (fc
>= MAX_INSN_FIXUPS
)
1816 as_fatal (_("too many fixups"));
1818 fixups
[fc
].reloc
= toc_reloc
;
1819 fixups
[fc
].exp
= ex
;
1820 fixups
[fc
].opindex
= *opindex_ptr
;
1823 /* Ok. We've set up the fixup for the instruction. Now make it
1824 look like the constant 0 was found here */
1826 ex
.X_op
= O_constant
;
1827 ex
.X_add_number
= 0;
1828 ex
.X_add_symbol
= NULL
;
1829 ex
.X_op_symbol
= NULL
;
1835 if (! register_name (&ex
))
1837 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1844 str
= input_line_pointer
;
1845 input_line_pointer
= hold
;
1847 if (ex
.X_op
== O_illegal
)
1848 as_bad (_("illegal operand"));
1849 else if (ex
.X_op
== O_absent
)
1850 as_bad (_("missing operand"));
1851 else if (ex
.X_op
== O_register
)
1853 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1856 else if (ex
.X_op
== O_constant
)
1859 /* Allow @HA, @L, @H on constants. */
1860 char *orig_str
= str
;
1862 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1869 case BFD_RELOC_LO16
:
1870 /* X_unsigned is the default, so if the user has done
1871 something which cleared it, we always produce a
1874 && (operand
->flags
& PPC_OPERAND_SIGNED
) == 0)
1875 ex
.X_add_number
&= 0xffff;
1877 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
1882 case BFD_RELOC_HI16
:
1883 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1886 case BFD_RELOC_HI16_S
:
1887 ex
.X_add_number
= (((ex
.X_add_number
>> 16) & 0xffff)
1888 + ((ex
.X_add_number
>> 15) & 1));
1892 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1896 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1898 /* For the absoulte forms of branchs, convert the PC relative form back into
1900 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1904 case BFD_RELOC_PPC_B26
:
1905 reloc
= BFD_RELOC_PPC_BA26
;
1907 case BFD_RELOC_PPC_B16
:
1908 reloc
= BFD_RELOC_PPC_BA16
;
1910 case BFD_RELOC_PPC_B16_BRTAKEN
:
1911 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
1913 case BFD_RELOC_PPC_B16_BRNTAKEN
:
1914 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
1921 /* We need to generate a fixup for this expression. */
1922 if (fc
>= MAX_INSN_FIXUPS
)
1923 as_fatal (_("too many fixups"));
1924 fixups
[fc
].exp
= ex
;
1925 fixups
[fc
].opindex
= 0;
1926 fixups
[fc
].reloc
= reloc
;
1929 #endif /* OBJ_ELF */
1933 /* We need to generate a fixup for this expression. */
1934 if (fc
>= MAX_INSN_FIXUPS
)
1935 as_fatal (_("too many fixups"));
1936 fixups
[fc
].exp
= ex
;
1937 fixups
[fc
].opindex
= *opindex_ptr
;
1938 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1947 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1955 /* The call to expression should have advanced str past any
1958 && (endc
!= ',' || *str
!= '\0'))
1960 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
1968 while (isspace (*str
))
1972 as_bad (_("junk at end of line: `%s'"), str
);
1974 /* Write out the instruction. */
1976 md_number_to_chars (f
, insn
, 4);
1978 /* Create any fixups. At this point we do not use a
1979 bfd_reloc_code_real_type, but instead just use the
1980 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1981 handle fixups for any operand type, although that is admittedly
1982 not a very exciting feature. We pick a BFD reloc type in
1984 for (i
= 0; i
< fc
; i
++)
1986 const struct powerpc_operand
*operand
;
1988 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1989 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1991 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1999 size
= bfd_get_reloc_size (reloc_howto
);
2000 offset
= target_big_endian
? (4 - size
) : 0;
2002 if (size
< 1 || size
> 4)
2005 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
2006 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
2009 /* Turn off complaints that the addend is too large for things like
2011 switch (fixups
[i
].reloc
)
2013 case BFD_RELOC_16_GOTOFF
:
2014 case BFD_RELOC_PPC_TOC16
:
2015 case BFD_RELOC_LO16
:
2016 case BFD_RELOC_HI16
:
2017 case BFD_RELOC_HI16_S
:
2018 fixP
->fx_no_overflow
= 1;
2025 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
2027 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2028 ((bfd_reloc_code_real_type
)
2029 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2033 /* Handle a macro. Gather all the operands, transform them as
2034 described by the macro, and call md_assemble recursively. All the
2035 operands are separated by commas; we don't accept parentheses
2036 around operands here. */
2039 ppc_macro (str
, macro
)
2041 const struct powerpc_macro
*macro
;
2052 /* Gather the users operands into the operands array. */
2057 if (count
>= sizeof operands
/ sizeof operands
[0])
2059 operands
[count
++] = s
;
2060 s
= strchr (s
, ',');
2061 if (s
== (char *) NULL
)
2066 if (count
!= macro
->operands
)
2068 as_bad (_("wrong number of operands"));
2072 /* Work out how large the string must be (the size is unbounded
2073 because it includes user input). */
2075 format
= macro
->format
;
2076 while (*format
!= '\0')
2085 arg
= strtol (format
+ 1, &send
, 10);
2086 know (send
!= format
&& arg
>= 0 && arg
< count
);
2087 len
+= strlen (operands
[arg
]);
2092 /* Put the string together. */
2093 complete
= s
= (char *) alloca (len
+ 1);
2094 format
= macro
->format
;
2095 while (*format
!= '\0')
2101 arg
= strtol (format
+ 1, &send
, 10);
2102 strcpy (s
, operands
[arg
]);
2109 /* Assemble the constructed instruction. */
2110 md_assemble (complete
);
2114 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2117 ppc_section_letter (letter
, ptr_msg
)
2124 *ptr_msg
= _("Bad .section directive: want a,w,x,e in string");
2129 ppc_section_word (str
, len
)
2133 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2140 ppc_section_type (str
, len
)
2144 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2151 ppc_section_flags (flags
, attr
, type
)
2156 if (type
== SHT_ORDERED
)
2157 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2159 if (attr
& SHF_EXCLUDE
)
2160 flags
|= SEC_EXCLUDE
;
2164 #endif /* OBJ_ELF */
2167 /* Pseudo-op handling. */
2169 /* The .byte pseudo-op. This is similar to the normal .byte
2170 pseudo-op, but it can also take a single ASCII string. */
2176 if (*input_line_pointer
!= '\"')
2182 /* Gather characters. A real double quote is doubled. Unusual
2183 characters are not permitted. */
2184 ++input_line_pointer
;
2189 c
= *input_line_pointer
++;
2193 if (*input_line_pointer
!= '\"')
2195 ++input_line_pointer
;
2198 FRAG_APPEND_1_CHAR (c
);
2201 demand_empty_rest_of_line ();
2206 /* XCOFF specific pseudo-op handling. */
2208 /* This is set if we are creating a .stabx symbol, since we don't want
2209 to handle symbol suffixes for such symbols. */
2210 static boolean ppc_stab_symbol
;
2212 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2213 symbols in the .bss segment as though they were local common
2214 symbols, and uses a different smclas. */
2220 asection
*current_seg
= now_seg
;
2221 subsegT current_subseg
= now_subseg
;
2227 symbolS
*lcomm_sym
= NULL
;
2231 name
= input_line_pointer
;
2232 endc
= get_symbol_end ();
2233 end_name
= input_line_pointer
;
2236 if (*input_line_pointer
!= ',')
2238 as_bad (_("missing size"));
2239 ignore_rest_of_line ();
2242 ++input_line_pointer
;
2244 size
= get_absolute_expression ();
2247 as_bad (_("negative size"));
2248 ignore_rest_of_line ();
2254 /* The third argument to .comm is the alignment. */
2255 if (*input_line_pointer
!= ',')
2259 ++input_line_pointer
;
2260 align
= get_absolute_expression ();
2263 as_warn (_("ignoring bad alignment"));
2282 /* The third argument to .lcomm appears to be the real local
2283 common symbol to create. References to the symbol named in
2284 the first argument are turned into references to the third
2286 if (*input_line_pointer
!= ',')
2288 as_bad (_("missing real symbol name"));
2289 ignore_rest_of_line ();
2292 ++input_line_pointer
;
2294 lcomm_name
= input_line_pointer
;
2295 lcomm_endc
= get_symbol_end ();
2297 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2299 *input_line_pointer
= lcomm_endc
;
2303 sym
= symbol_find_or_make (name
);
2306 if (S_IS_DEFINED (sym
)
2307 || S_GET_VALUE (sym
) != 0)
2309 as_bad (_("attempt to redefine symbol"));
2310 ignore_rest_of_line ();
2314 record_alignment (bss_section
, align
);
2317 || ! S_IS_DEFINED (lcomm_sym
))
2326 S_SET_EXTERNAL (sym
);
2330 lcomm_sym
->sy_tc
.output
= 1;
2331 def_sym
= lcomm_sym
;
2335 subseg_set (bss_section
, 1);
2336 frag_align (align
, 0, 0);
2338 def_sym
->sy_frag
= frag_now
;
2339 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2340 def_size
, (char *) NULL
);
2342 S_SET_SEGMENT (def_sym
, bss_section
);
2343 def_sym
->sy_tc
.align
= align
;
2347 /* Align the size of lcomm_sym. */
2348 lcomm_sym
->sy_frag
->fr_offset
=
2349 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
2350 &~ ((1 << align
) - 1));
2351 if (align
> lcomm_sym
->sy_tc
.align
)
2352 lcomm_sym
->sy_tc
.align
= align
;
2357 /* Make sym an offset from lcomm_sym. */
2358 S_SET_SEGMENT (sym
, bss_section
);
2359 sym
->sy_frag
= lcomm_sym
->sy_frag
;
2360 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
2361 lcomm_sym
->sy_frag
->fr_offset
+= size
;
2364 subseg_set (current_seg
, current_subseg
);
2366 demand_empty_rest_of_line ();
2369 /* The .csect pseudo-op. This switches us into a different
2370 subsegment. The first argument is a symbol whose value is the
2371 start of the .csect. In COFF, csect symbols get special aux
2372 entries defined by the x_csect field of union internal_auxent. The
2373 optional second argument is the alignment (the default is 2). */
2383 name
= input_line_pointer
;
2384 endc
= get_symbol_end ();
2386 sym
= symbol_find_or_make (name
);
2388 *input_line_pointer
= endc
;
2390 if (S_GET_NAME (sym
)[0] == '\0')
2392 /* An unnamed csect is assumed to be [PR]. */
2393 sym
->sy_tc
.class = XMC_PR
;
2396 ppc_change_csect (sym
);
2398 if (*input_line_pointer
== ',')
2400 ++input_line_pointer
;
2401 sym
->sy_tc
.align
= get_absolute_expression ();
2404 demand_empty_rest_of_line ();
2407 /* Change to a different csect. */
2410 ppc_change_csect (sym
)
2413 if (S_IS_DEFINED (sym
))
2414 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
2422 /* This is a new csect. We need to look at the symbol class to
2423 figure out whether it should go in the text section or the
2426 switch (sym
->sy_tc
.class)
2436 S_SET_SEGMENT (sym
, text_section
);
2437 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
2438 ++ppc_text_subsegment
;
2439 list_ptr
= &ppc_text_csects
;
2448 if (ppc_toc_csect
!= NULL
2449 && ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
2451 S_SET_SEGMENT (sym
, data_section
);
2452 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
2453 ++ppc_data_subsegment
;
2454 list_ptr
= &ppc_data_csects
;
2460 /* We set the obstack chunk size to a small value before
2461 changing subsegments, so that we don't use a lot of memory
2462 space for what may be a small section. */
2463 hold_chunksize
= chunksize
;
2466 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
2468 chunksize
= hold_chunksize
;
2471 ppc_after_toc_frag
= frag_now
;
2473 sym
->sy_frag
= frag_now
;
2474 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2476 sym
->sy_tc
.align
= 2;
2477 sym
->sy_tc
.output
= 1;
2478 sym
->sy_tc
.within
= sym
;
2480 for (list
= *list_ptr
;
2481 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2482 list
= list
->sy_tc
.next
)
2484 list
->sy_tc
.next
= sym
;
2486 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2487 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2490 ppc_current_csect
= sym
;
2493 /* This function handles the .text and .data pseudo-ops. These
2494 pseudo-ops aren't really used by XCOFF; we implement them for the
2495 convenience of people who aren't used to XCOFF. */
2506 else if (type
== 'd')
2511 sym
= symbol_find_or_make (name
);
2513 ppc_change_csect (sym
);
2515 demand_empty_rest_of_line ();
2518 /* This function handles the .section pseudo-op. This is mostly to
2519 give an error, since XCOFF only supports .text, .data and .bss, but
2520 we do permit the user to name the text or data section. */
2523 ppc_named_section (ignore
)
2527 const char *real_name
;
2531 user_name
= input_line_pointer
;
2532 c
= get_symbol_end ();
2534 if (strcmp (user_name
, ".text") == 0)
2535 real_name
= ".text[PR]";
2536 else if (strcmp (user_name
, ".data") == 0)
2537 real_name
= ".data[RW]";
2540 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2541 *input_line_pointer
= c
;
2542 ignore_rest_of_line ();
2546 *input_line_pointer
= c
;
2548 sym
= symbol_find_or_make (real_name
);
2550 ppc_change_csect (sym
);
2552 demand_empty_rest_of_line ();
2555 /* The .extern pseudo-op. We create an undefined symbol. */
2564 name
= input_line_pointer
;
2565 endc
= get_symbol_end ();
2567 (void) symbol_find_or_make (name
);
2569 *input_line_pointer
= endc
;
2571 demand_empty_rest_of_line ();
2574 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2584 name
= input_line_pointer
;
2585 endc
= get_symbol_end ();
2587 sym
= symbol_find_or_make (name
);
2589 *input_line_pointer
= endc
;
2591 sym
->sy_tc
.output
= 1;
2593 demand_empty_rest_of_line ();
2596 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2597 although I don't know why it bothers. */
2608 name
= input_line_pointer
;
2609 endc
= get_symbol_end ();
2611 sym
= symbol_find_or_make (name
);
2613 *input_line_pointer
= endc
;
2615 if (*input_line_pointer
!= ',')
2617 as_bad (_("missing rename string"));
2618 ignore_rest_of_line ();
2621 ++input_line_pointer
;
2623 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2625 demand_empty_rest_of_line ();
2628 /* The .stabx pseudo-op. This is similar to a normal .stabs
2629 pseudo-op, but slightly different. A sample is
2630 .stabx "main:F-1",.main,142,0
2631 The first argument is the symbol name to create. The second is the
2632 value, and the third is the storage class. The fourth seems to be
2633 always zero, and I am assuming it is the type. */
2644 name
= demand_copy_C_string (&len
);
2646 if (*input_line_pointer
!= ',')
2648 as_bad (_("missing value"));
2651 ++input_line_pointer
;
2653 ppc_stab_symbol
= true;
2654 sym
= symbol_make (name
);
2655 ppc_stab_symbol
= false;
2657 sym
->sy_tc
.real_name
= name
;
2659 (void) expression (&exp
);
2666 as_bad (_("illegal .stabx expression; zero assumed"));
2667 exp
.X_add_number
= 0;
2670 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2671 sym
->sy_frag
= &zero_address_frag
;
2675 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2676 sym
->sy_value
= exp
;
2680 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2681 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2686 /* The value is some complex expression. This will probably
2687 fail at some later point, but this is probably the right
2688 thing to do here. */
2689 sym
->sy_value
= exp
;
2693 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2694 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2696 if (*input_line_pointer
!= ',')
2698 as_bad (_("missing class"));
2701 ++input_line_pointer
;
2703 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2705 if (*input_line_pointer
!= ',')
2707 as_bad (_("missing type"));
2710 ++input_line_pointer
;
2712 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2714 sym
->sy_tc
.output
= 1;
2716 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2717 sym
->sy_tc
.within
= ppc_current_block
;
2719 if (exp
.X_op
!= O_symbol
2720 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2721 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2722 ppc_frob_label (sym
);
2725 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2726 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2727 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2728 ppc_current_csect
->sy_tc
.within
= sym
;
2731 demand_empty_rest_of_line ();
2734 /* The .function pseudo-op. This takes several arguments. The first
2735 argument seems to be the external name of the symbol. The second
2736 argment seems to be the label for the start of the function. gcc
2737 uses the same name for both. I have no idea what the third and
2738 fourth arguments are meant to be. The optional fifth argument is
2739 an expression for the size of the function. In COFF this symbol
2740 gets an aux entry like that used for a csect. */
2743 ppc_function (ignore
)
2752 name
= input_line_pointer
;
2753 endc
= get_symbol_end ();
2755 /* Ignore any [PR] suffix. */
2756 name
= ppc_canonicalize_symbol_name (name
);
2757 s
= strchr (name
, '[');
2758 if (s
!= (char *) NULL
2759 && strcmp (s
+ 1, "PR]") == 0)
2762 ext_sym
= symbol_find_or_make (name
);
2764 *input_line_pointer
= endc
;
2766 if (*input_line_pointer
!= ',')
2768 as_bad (_("missing symbol name"));
2769 ignore_rest_of_line ();
2772 ++input_line_pointer
;
2774 name
= input_line_pointer
;
2775 endc
= get_symbol_end ();
2777 lab_sym
= symbol_find_or_make (name
);
2779 *input_line_pointer
= endc
;
2781 if (ext_sym
!= lab_sym
)
2783 ext_sym
->sy_value
.X_op
= O_symbol
;
2784 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2785 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2786 ext_sym
->sy_value
.X_add_number
= 0;
2789 if (ext_sym
->sy_tc
.class == -1)
2790 ext_sym
->sy_tc
.class = XMC_PR
;
2791 ext_sym
->sy_tc
.output
= 1;
2793 if (*input_line_pointer
== ',')
2797 /* Ignore the third argument. */
2798 ++input_line_pointer
;
2799 expression (&ignore
);
2800 if (*input_line_pointer
== ',')
2802 /* Ignore the fourth argument. */
2803 ++input_line_pointer
;
2804 expression (&ignore
);
2805 if (*input_line_pointer
== ',')
2807 /* The fifth argument is the function size. */
2808 ++input_line_pointer
;
2809 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2812 &zero_address_frag
);
2813 pseudo_set (ext_sym
->sy_tc
.size
);
2818 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2819 SF_SET_FUNCTION (ext_sym
);
2820 SF_SET_PROCESS (ext_sym
);
2821 coff_add_linesym (ext_sym
);
2823 demand_empty_rest_of_line ();
2826 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2835 sym
= symbol_make (".bf");
2836 S_SET_SEGMENT (sym
, text_section
);
2837 sym
->sy_frag
= frag_now
;
2838 S_SET_VALUE (sym
, frag_now_fix ());
2839 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2841 coff_line_base
= get_absolute_expression ();
2843 S_SET_NUMBER_AUXILIARY (sym
, 1);
2844 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2846 sym
->sy_tc
.output
= 1;
2848 ppc_frob_label (sym
);
2850 demand_empty_rest_of_line ();
2853 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2854 ".ef", except that the line number is absolute, not relative to the
2855 most recent ".bf" symbol. */
2863 sym
= symbol_make (".ef");
2864 S_SET_SEGMENT (sym
, text_section
);
2865 sym
->sy_frag
= frag_now
;
2866 S_SET_VALUE (sym
, frag_now_fix ());
2867 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2868 S_SET_NUMBER_AUXILIARY (sym
, 1);
2869 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2870 sym
->sy_tc
.output
= 1;
2872 ppc_frob_label (sym
);
2874 demand_empty_rest_of_line ();
2877 /* The .bi and .ei pseudo-ops. These take a string argument and
2878 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2885 static symbolS
*last_biei
;
2892 name
= demand_copy_C_string (&len
);
2894 /* The value of these symbols is actually file offset. Here we set
2895 the value to the index into the line number entries. In
2896 ppc_frob_symbols we set the fix_line field, which will cause BFD
2897 to do the right thing. */
2899 sym
= symbol_make (name
);
2900 /* obj-coff.c currently only handles line numbers correctly in the
2902 S_SET_SEGMENT (sym
, text_section
);
2903 S_SET_VALUE (sym
, coff_n_line_nos
);
2904 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2906 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2907 sym
->sy_tc
.output
= 1;
2909 for (look
= last_biei
? last_biei
: symbol_rootP
;
2910 (look
!= (symbolS
*) NULL
2911 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2912 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2913 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2914 look
= symbol_next (look
))
2916 if (look
!= (symbolS
*) NULL
)
2918 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2919 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2923 demand_empty_rest_of_line ();
2926 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2927 There is one argument, which is a csect symbol. The value of the
2928 .bs symbol is the index of this csect symbol. */
2939 if (ppc_current_block
!= NULL
)
2940 as_bad (_("nested .bs blocks"));
2942 name
= input_line_pointer
;
2943 endc
= get_symbol_end ();
2945 csect
= symbol_find_or_make (name
);
2947 *input_line_pointer
= endc
;
2949 sym
= symbol_make (".bs");
2950 S_SET_SEGMENT (sym
, now_seg
);
2951 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2952 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2953 sym
->sy_tc
.output
= 1;
2955 sym
->sy_tc
.within
= csect
;
2957 ppc_frob_label (sym
);
2959 ppc_current_block
= sym
;
2961 demand_empty_rest_of_line ();
2964 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2972 if (ppc_current_block
== NULL
)
2973 as_bad (_(".es without preceding .bs"));
2975 sym
= symbol_make (".es");
2976 S_SET_SEGMENT (sym
, now_seg
);
2977 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2978 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2979 sym
->sy_tc
.output
= 1;
2981 ppc_frob_label (sym
);
2983 ppc_current_block
= NULL
;
2985 demand_empty_rest_of_line ();
2988 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2997 sym
= symbol_make (".bb");
2998 S_SET_SEGMENT (sym
, text_section
);
2999 sym
->sy_frag
= frag_now
;
3000 S_SET_VALUE (sym
, frag_now_fix ());
3001 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3003 S_SET_NUMBER_AUXILIARY (sym
, 1);
3004 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3006 sym
->sy_tc
.output
= 1;
3008 SF_SET_PROCESS (sym
);
3010 ppc_frob_label (sym
);
3012 demand_empty_rest_of_line ();
3015 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3024 sym
= symbol_make (".eb");
3025 S_SET_SEGMENT (sym
, text_section
);
3026 sym
->sy_frag
= frag_now
;
3027 S_SET_VALUE (sym
, frag_now_fix ());
3028 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3029 S_SET_NUMBER_AUXILIARY (sym
, 1);
3030 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3031 sym
->sy_tc
.output
= 1;
3033 SF_SET_PROCESS (sym
);
3035 ppc_frob_label (sym
);
3037 demand_empty_rest_of_line ();
3040 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3051 name
= demand_copy_C_string (&len
);
3052 sym
= symbol_make (name
);
3053 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3054 sym
->bsym
->flags
|= BSF_DEBUGGING
;
3055 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3056 S_SET_VALUE (sym
, 0);
3057 sym
->sy_tc
.output
= 1;
3059 ppc_frob_label (sym
);
3061 demand_empty_rest_of_line ();
3064 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3072 sym
= symbol_make (".ec");
3073 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3074 sym
->bsym
->flags
|= BSF_DEBUGGING
;
3075 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3076 S_SET_VALUE (sym
, 0);
3077 sym
->sy_tc
.output
= 1;
3079 ppc_frob_label (sym
);
3081 demand_empty_rest_of_line ();
3084 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3090 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3091 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
3098 subseg
= ppc_data_subsegment
;
3099 ++ppc_data_subsegment
;
3101 subseg_new (segment_name (data_section
), subseg
);
3102 ppc_toc_frag
= frag_now
;
3104 sym
= symbol_find_or_make ("TOC[TC0]");
3105 sym
->sy_frag
= frag_now
;
3106 S_SET_SEGMENT (sym
, data_section
);
3107 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3108 sym
->sy_tc
.subseg
= subseg
;
3109 sym
->sy_tc
.output
= 1;
3110 sym
->sy_tc
.within
= sym
;
3112 ppc_toc_csect
= sym
;
3114 for (list
= ppc_data_csects
;
3115 list
->sy_tc
.next
!= (symbolS
*) NULL
;
3116 list
= list
->sy_tc
.next
)
3118 list
->sy_tc
.next
= sym
;
3120 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3121 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
3124 ppc_current_csect
= ppc_toc_csect
;
3126 demand_empty_rest_of_line ();
3129 /* The AIX assembler automatically aligns the operands of a .long or
3130 .short pseudo-op, and we want to be compatible. */
3133 ppc_xcoff_cons (log_size
)
3136 frag_align (log_size
, 0, 0);
3137 record_alignment (now_seg
, log_size
);
3138 cons (1 << log_size
);
3148 (void) expression (&exp
);
3150 if (exp
.X_op
!= O_constant
)
3152 as_bad (_("non-constant byte count"));
3156 byte_count
= exp
.X_add_number
;
3158 if (*input_line_pointer
!= ',')
3160 as_bad (_("missing value"));
3164 ++input_line_pointer
;
3168 #endif /* OBJ_XCOFF */
3170 /* The .tc pseudo-op. This is used when generating either XCOFF or
3171 ELF. This takes two or more arguments.
3173 When generating XCOFF output, the first argument is the name to
3174 give to this location in the toc; this will be a symbol with class
3175 TC. The rest of the arguments are 4 byte values to actually put at
3176 this location in the TOC; often there is just one more argument, a
3177 relocateable symbol reference.
3179 When not generating XCOFF output, the arguments are the same, but
3180 the first argument is simply ignored. */
3188 /* Define the TOC symbol name. */
3194 if (ppc_toc_csect
== (symbolS
*) NULL
3195 || ppc_toc_csect
!= ppc_current_csect
)
3197 as_bad (_(".tc not in .toc section"));
3198 ignore_rest_of_line ();
3202 name
= input_line_pointer
;
3203 endc
= get_symbol_end ();
3205 sym
= symbol_find_or_make (name
);
3207 *input_line_pointer
= endc
;
3209 if (S_IS_DEFINED (sym
))
3213 label
= ppc_current_csect
->sy_tc
.within
;
3214 if (label
->sy_tc
.class != XMC_TC0
)
3216 as_bad (_(".tc with no label"));
3217 ignore_rest_of_line ();
3221 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3222 label
->sy_frag
= sym
->sy_frag
;
3223 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3225 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3226 ++input_line_pointer
;
3231 S_SET_SEGMENT (sym
, now_seg
);
3232 sym
->sy_frag
= frag_now
;
3233 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3234 sym
->sy_tc
.class = XMC_TC
;
3235 sym
->sy_tc
.output
= 1;
3237 ppc_frob_label (sym
);
3240 #else /* ! defined (OBJ_XCOFF) */
3242 /* Skip the TOC symbol name. */
3243 while (is_part_of_name (*input_line_pointer
)
3244 || *input_line_pointer
== '['
3245 || *input_line_pointer
== ']'
3246 || *input_line_pointer
== '{'
3247 || *input_line_pointer
== '}')
3248 ++input_line_pointer
;
3250 /* Align to a four byte boundary. */
3251 frag_align (2, 0, 0);
3252 record_alignment (now_seg
, 2);
3254 #endif /* ! defined (OBJ_XCOFF) */
3256 if (*input_line_pointer
!= ',')
3257 demand_empty_rest_of_line ();
3260 ++input_line_pointer
;
3267 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3269 /* Set the current section. */
3271 ppc_set_current_section (new)
3274 ppc_previous_section
= ppc_current_section
;
3275 ppc_current_section
= new;
3278 /* pseudo-op: .previous
3279 behaviour: toggles the current section with the previous section.
3281 warnings: "No previous section"
3284 ppc_previous(ignore
)
3289 if (ppc_previous_section
== NULL
)
3291 as_warn(_("No previous section to return to. Directive ignored."));
3295 subseg_set(ppc_previous_section
, 0);
3297 ppc_set_current_section(ppc_previous_section
);
3300 /* pseudo-op: .pdata
3301 behaviour: predefined read only data section
3305 initial: .section .pdata "adr3"
3306 a - don't know -- maybe a misprint
3307 d - initialized data
3309 3 - double word aligned (that would be 4 byte boundary)
3312 Tag index tables (also known as the function table) for exception
3313 handling, debugging, etc.
3320 if (pdata_section
== 0)
3322 pdata_section
= subseg_new (".pdata", 0);
3324 bfd_set_section_flags (stdoutput
, pdata_section
,
3325 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3326 | SEC_READONLY
| SEC_DATA
));
3328 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3332 pdata_section
= subseg_new(".pdata", 0);
3334 ppc_set_current_section(pdata_section
);
3337 /* pseudo-op: .ydata
3338 behaviour: predefined read only data section
3342 initial: .section .ydata "drw3"
3343 a - don't know -- maybe a misprint
3344 d - initialized data
3346 3 - double word aligned (that would be 4 byte boundary)
3348 Tag tables (also known as the scope table) for exception handling,
3355 if (ydata_section
== 0)
3357 ydata_section
= subseg_new (".ydata", 0);
3358 bfd_set_section_flags (stdoutput
, ydata_section
,
3359 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3360 | SEC_READONLY
| SEC_DATA
));
3362 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3366 ydata_section
= subseg_new (".ydata", 0);
3368 ppc_set_current_section(ydata_section
);
3371 /* pseudo-op: .reldata
3372 behaviour: predefined read write data section
3373 double word aligned (4-byte)
3374 FIXME: relocation is applied to it
3375 FIXME: what's the difference between this and .data?
3378 initial: .section .reldata "drw3"
3379 d - initialized data
3382 3 - double word aligned (that would be 8 byte boundary)
3385 Like .data, but intended to hold data subject to relocation, such as
3386 function descriptors, etc.
3392 if (reldata_section
== 0)
3394 reldata_section
= subseg_new (".reldata", 0);
3396 bfd_set_section_flags (stdoutput
, reldata_section
,
3397 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3400 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3404 reldata_section
= subseg_new (".reldata", 0);
3406 ppc_set_current_section(reldata_section
);
3409 /* pseudo-op: .rdata
3410 behaviour: predefined read only data section
3414 initial: .section .rdata "dr3"
3415 d - initialized data
3417 3 - double word aligned (that would be 4 byte boundary)
3423 if (rdata_section
== 0)
3425 rdata_section
= subseg_new (".rdata", 0);
3426 bfd_set_section_flags (stdoutput
, rdata_section
,
3427 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3428 | SEC_READONLY
| SEC_DATA
));
3430 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3434 rdata_section
= subseg_new (".rdata", 0);
3436 ppc_set_current_section(rdata_section
);
3439 /* pseudo-op: .ualong
3440 behaviour: much like .int, with the exception that no alignment is
3442 FIXME: test the alignment statement
3454 /* pseudo-op: .znop <symbol name>
3455 behaviour: Issue a nop instruction
3456 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3457 the supplied symbol name.
3459 warnings: Missing symbol name
3466 const struct powerpc_opcode
*opcode
;
3472 /* Strip out the symbol name */
3480 symbol_name
= input_line_pointer
;
3481 c
= get_symbol_end ();
3483 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3484 strcpy (name
, symbol_name
);
3486 sym
= symbol_find_or_make (name
);
3488 *input_line_pointer
= c
;
3492 /* Look up the opcode in the hash table. */
3493 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3495 /* stick in the nop */
3496 insn
= opcode
->opcode
;
3498 /* Write out the instruction. */
3500 md_number_to_chars (f
, insn
, 4);
3502 f
- frag_now
->fr_literal
,
3507 BFD_RELOC_16_GOT_PCREL
);
3520 register char *name
;
3524 register symbolS
*symbolP
;
3527 name
= input_line_pointer
;
3528 c
= get_symbol_end ();
3530 /* just after name is now '\0' */
3531 p
= input_line_pointer
;
3534 if (*input_line_pointer
!= ',')
3536 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3537 ignore_rest_of_line ();
3541 input_line_pointer
++; /* skip ',' */
3542 if ((temp
= get_absolute_expression ()) < 0)
3544 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
3545 ignore_rest_of_line ();
3551 /* The third argument to .comm is the alignment. */
3552 if (*input_line_pointer
!= ',')
3556 ++input_line_pointer
;
3557 align
= get_absolute_expression ();
3560 as_warn (_("ignoring bad alignment"));
3567 symbolP
= symbol_find_or_make (name
);
3570 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
3572 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3573 S_GET_NAME (symbolP
));
3574 ignore_rest_of_line ();
3578 if (S_GET_VALUE (symbolP
))
3580 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3581 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3582 S_GET_NAME (symbolP
),
3583 (long) S_GET_VALUE (symbolP
),
3588 S_SET_VALUE (symbolP
, (valueT
) temp
);
3589 S_SET_EXTERNAL (symbolP
);
3592 demand_empty_rest_of_line ();
3596 * implement the .section pseudo op:
3597 * .section name {, "flags"}
3599 * | +--- optional flags: 'b' for bss
3601 * +-- section name 'l' for lib
3605 * 'd' (apparently m88k for data)
3607 * But if the argument is not a quoted string, treat it as a
3608 * subsegment number.
3610 * FIXME: this is a copy of the section processing from obj-coff.c, with
3611 * additions/changes for the moto-pas assembler support. There are three
3614 * FIXME: I just noticed this. This doesn't work at all really. It it
3615 * setting bits that bfd probably neither understands or uses. The
3616 * correct approach (?) will have to incorporate extra fields attached
3617 * to the section to hold the system specific stuff. (krk)
3620 * 'a' - unknown - referred to in documentation, but no definition supplied
3621 * 'c' - section has code
3622 * 'd' - section has initialized data
3623 * 'u' - section has uninitialized data
3624 * 'i' - section contains directives (info)
3625 * 'n' - section can be discarded
3626 * 'R' - remove section at link time
3628 * Section Protection:
3629 * 'r' - section is readable
3630 * 'w' - section is writeable
3631 * 'x' - section is executable
3632 * 's' - section is sharable
3634 * Section Alignment:
3635 * '0' - align to byte boundary
3636 * '1' - align to halfword undary
3637 * '2' - align to word boundary
3638 * '3' - align to doubleword boundary
3639 * '4' - align to quadword boundary
3640 * '5' - align to 32 byte boundary
3641 * '6' - align to 64 byte boundary
3646 ppc_pe_section (ignore
)
3649 /* Strip out the section name */
3658 section_name
= input_line_pointer
;
3659 c
= get_symbol_end ();
3661 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3662 strcpy (name
, section_name
);
3664 *input_line_pointer
= c
;
3669 flags
= SEC_NO_FLAGS
;
3671 if (strcmp (name
, ".idata$2") == 0)
3675 else if (strcmp (name
, ".idata$3") == 0)
3679 else if (strcmp (name
, ".idata$4") == 0)
3683 else if (strcmp (name
, ".idata$5") == 0)
3687 else if (strcmp (name
, ".idata$6") == 0)
3692 align
= 4; /* default alignment to 16 byte boundary */
3694 if (*input_line_pointer
== ',')
3696 ++input_line_pointer
;
3698 if (*input_line_pointer
!= '"')
3699 exp
= get_absolute_expression ();
3702 ++input_line_pointer
;
3703 while (*input_line_pointer
!= '"'
3704 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3706 switch (*input_line_pointer
)
3708 /* Section Contents */
3709 case 'a': /* unknown */
3710 as_bad (_("Unsupported section attribute -- 'a'"));
3712 case 'c': /* code section */
3715 case 'd': /* section has initialized data */
3718 case 'u': /* section has uninitialized data */
3719 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3723 case 'i': /* section contains directives (info) */
3724 /* FIXME: This is IMAGE_SCN_LNK_INFO
3726 flags
|= SEC_HAS_CONTENTS
;
3728 case 'n': /* section can be discarded */
3731 case 'R': /* Remove section at link time */
3732 flags
|= SEC_NEVER_LOAD
;
3735 /* Section Protection */
3736 case 'r': /* section is readable */
3737 flags
|= IMAGE_SCN_MEM_READ
;
3739 case 'w': /* section is writeable */
3740 flags
|= IMAGE_SCN_MEM_WRITE
;
3742 case 'x': /* section is executable */
3743 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3745 case 's': /* section is sharable */
3746 flags
|= IMAGE_SCN_MEM_SHARED
;
3749 /* Section Alignment */
3750 case '0': /* align to byte boundary */
3751 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3754 case '1': /* align to halfword boundary */
3755 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3758 case '2': /* align to word boundary */
3759 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3762 case '3': /* align to doubleword boundary */
3763 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3766 case '4': /* align to quadword boundary */
3767 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3770 case '5': /* align to 32 byte boundary */
3771 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3774 case '6': /* align to 64 byte boundary */
3775 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3780 as_bad(_("unknown section attribute '%c'"),
3781 *input_line_pointer
);
3784 ++input_line_pointer
;
3786 if (*input_line_pointer
== '"')
3787 ++input_line_pointer
;
3791 sec
= subseg_new (name
, (subsegT
) exp
);
3793 ppc_set_current_section(sec
);
3795 if (flags
!= SEC_NO_FLAGS
)
3797 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3798 as_bad (_("error setting flags for \"%s\": %s"),
3799 bfd_section_name (stdoutput
, sec
),
3800 bfd_errmsg (bfd_get_error ()));
3803 bfd_set_section_alignment(stdoutput
, sec
, align
);
3808 ppc_pe_function (ignore
)
3815 name
= input_line_pointer
;
3816 endc
= get_symbol_end ();
3818 ext_sym
= symbol_find_or_make (name
);
3820 *input_line_pointer
= endc
;
3822 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3823 SF_SET_FUNCTION (ext_sym
);
3824 SF_SET_PROCESS (ext_sym
);
3825 coff_add_linesym (ext_sym
);
3827 demand_empty_rest_of_line ();
3831 ppc_pe_tocd (ignore
)
3834 if (tocdata_section
== 0)
3836 tocdata_section
= subseg_new (".tocd", 0);
3837 /* FIXME: section flags won't work */
3838 bfd_set_section_flags (stdoutput
, tocdata_section
,
3839 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3840 | SEC_READONLY
| SEC_DATA
));
3842 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3846 rdata_section
= subseg_new (".tocd", 0);
3849 ppc_set_current_section(tocdata_section
);
3851 demand_empty_rest_of_line ();
3854 /* Don't adjust TOC relocs to use the section symbol. */
3857 ppc_pe_fix_adjustable (fix
)
3860 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3867 /* XCOFF specific symbol and file handling. */
3869 /* Canonicalize the symbol name. We use the to force the suffix, if
3870 any, to use square brackets, and to be in upper case. */
3873 ppc_canonicalize_symbol_name (name
)
3878 if (ppc_stab_symbol
)
3881 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3895 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3899 if (*s
== '\0' || s
[1] != '\0')
3900 as_bad (_("bad symbol suffix"));
3908 /* Set the class of a symbol based on the suffix, if any. This is
3909 called whenever a new symbol is created. */
3912 ppc_symbol_new_hook (sym
)
3917 sym
->sy_tc
.next
= NULL
;
3918 sym
->sy_tc
.output
= 0;
3919 sym
->sy_tc
.class = -1;
3920 sym
->sy_tc
.real_name
= NULL
;
3921 sym
->sy_tc
.subseg
= 0;
3922 sym
->sy_tc
.align
= 0;
3923 sym
->sy_tc
.size
= NULL
;
3924 sym
->sy_tc
.within
= NULL
;
3926 if (ppc_stab_symbol
)
3929 s
= strchr (S_GET_NAME (sym
), '[');
3930 if (s
== (const char *) NULL
)
3932 /* There is no suffix. */
3941 if (strcmp (s
, "BS]") == 0)
3942 sym
->sy_tc
.class = XMC_BS
;
3945 if (strcmp (s
, "DB]") == 0)
3946 sym
->sy_tc
.class = XMC_DB
;
3947 else if (strcmp (s
, "DS]") == 0)
3948 sym
->sy_tc
.class = XMC_DS
;
3951 if (strcmp (s
, "GL]") == 0)
3952 sym
->sy_tc
.class = XMC_GL
;
3955 if (strcmp (s
, "PR]") == 0)
3956 sym
->sy_tc
.class = XMC_PR
;
3959 if (strcmp (s
, "RO]") == 0)
3960 sym
->sy_tc
.class = XMC_RO
;
3961 else if (strcmp (s
, "RW]") == 0)
3962 sym
->sy_tc
.class = XMC_RW
;
3965 if (strcmp (s
, "SV]") == 0)
3966 sym
->sy_tc
.class = XMC_SV
;
3969 if (strcmp (s
, "TC]") == 0)
3970 sym
->sy_tc
.class = XMC_TC
;
3971 else if (strcmp (s
, "TI]") == 0)
3972 sym
->sy_tc
.class = XMC_TI
;
3973 else if (strcmp (s
, "TB]") == 0)
3974 sym
->sy_tc
.class = XMC_TB
;
3975 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3976 sym
->sy_tc
.class = XMC_TC0
;
3979 if (strcmp (s
, "UA]") == 0)
3980 sym
->sy_tc
.class = XMC_UA
;
3981 else if (strcmp (s
, "UC]") == 0)
3982 sym
->sy_tc
.class = XMC_UC
;
3985 if (strcmp (s
, "XO]") == 0)
3986 sym
->sy_tc
.class = XMC_XO
;
3990 if (sym
->sy_tc
.class == -1)
3991 as_bad (_("Unrecognized symbol suffix"));
3994 /* Set the class of a label based on where it is defined. This
3995 handles symbols without suffixes. Also, move the symbol so that it
3996 follows the csect symbol. */
3999 ppc_frob_label (sym
)
4002 if (ppc_current_csect
!= (symbolS
*) NULL
)
4004 if (sym
->sy_tc
.class == -1)
4005 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
4007 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4008 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
4010 ppc_current_csect
->sy_tc
.within
= sym
;
4014 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4015 seen. It tells ppc_adjust_symtab whether it needs to look through
4018 static boolean ppc_saw_abs
;
4020 /* Change the name of a symbol just before writing it out. Set the
4021 real name if the .rename pseudo-op was used. Otherwise, remove any
4022 class suffix. Return 1 if the symbol should not be included in the
4026 ppc_frob_symbol (sym
)
4029 static symbolS
*ppc_last_function
;
4030 static symbolS
*set_end
;
4032 /* Discard symbols that should not be included in the output symbol
4034 if (! sym
->sy_used_in_reloc
4035 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
4036 || (! S_IS_EXTERNAL (sym
)
4037 && ! sym
->sy_tc
.output
4038 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4041 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
4042 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
4048 name
= S_GET_NAME (sym
);
4049 s
= strchr (name
, '[');
4050 if (s
!= (char *) NULL
)
4056 snew
= xmalloc (len
+ 1);
4057 memcpy (snew
, name
, len
);
4060 S_SET_NAME (sym
, snew
);
4064 if (set_end
!= (symbolS
*) NULL
)
4066 SA_SET_SYM_ENDNDX (set_end
, sym
);
4070 if (SF_GET_FUNCTION (sym
))
4072 if (ppc_last_function
!= (symbolS
*) NULL
)
4073 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4074 ppc_last_function
= sym
;
4075 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
4077 resolve_symbol_value (sym
->sy_tc
.size
, 1);
4078 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
4081 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4082 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4084 if (ppc_last_function
== (symbolS
*) NULL
)
4085 as_bad (_(".ef with no preceding .function"));
4088 set_end
= ppc_last_function
;
4089 ppc_last_function
= NULL
;
4091 /* We don't have a C_EFCN symbol, but we need to force the
4092 COFF backend to believe that it has seen one. */
4093 coff_last_function
= NULL
;
4097 if (! S_IS_EXTERNAL (sym
)
4098 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
4099 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4100 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4101 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4102 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4103 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4104 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4105 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4106 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4107 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4109 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4110 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4113 union internal_auxent
*a
;
4115 /* Create a csect aux. */
4116 i
= S_GET_NUMBER_AUXILIARY (sym
);
4117 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4118 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
4119 if (sym
->sy_tc
.class == XMC_TC0
)
4121 /* This is the TOC table. */
4122 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4123 a
->x_csect
.x_scnlen
.l
= 0;
4124 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4126 else if (sym
->sy_tc
.subseg
!= 0)
4128 /* This is a csect symbol. x_scnlen is the size of the
4130 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
4131 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4132 S_GET_SEGMENT (sym
))
4133 - S_GET_VALUE (sym
));
4136 resolve_symbol_value (sym
->sy_tc
.next
, 1);
4137 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
4138 - S_GET_VALUE (sym
));
4140 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
4142 else if (S_GET_SEGMENT (sym
) == bss_section
)
4144 /* This is a common symbol. */
4145 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
4146 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
4147 if (S_IS_EXTERNAL (sym
))
4148 sym
->sy_tc
.class = XMC_RW
;
4150 sym
->sy_tc
.class = XMC_BS
;
4152 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4154 /* This is an absolute symbol. The csect will be created by
4155 ppc_adjust_symtab. */
4157 a
->x_csect
.x_smtyp
= XTY_LD
;
4158 if (sym
->sy_tc
.class == -1)
4159 sym
->sy_tc
.class = XMC_XO
;
4161 else if (! S_IS_DEFINED (sym
))
4163 /* This is an external symbol. */
4164 a
->x_csect
.x_scnlen
.l
= 0;
4165 a
->x_csect
.x_smtyp
= XTY_ER
;
4167 else if (sym
->sy_tc
.class == XMC_TC
)
4171 /* This is a TOC definition. x_scnlen is the size of the
4173 next
= symbol_next (sym
);
4174 while (next
->sy_tc
.class == XMC_TC0
)
4175 next
= symbol_next (next
);
4176 if (next
== (symbolS
*) NULL
4177 || next
->sy_tc
.class != XMC_TC
)
4179 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4180 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4182 - S_GET_VALUE (sym
));
4184 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4185 - S_GET_VALUE (sym
));
4189 resolve_symbol_value (next
, 1);
4190 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4191 - S_GET_VALUE (sym
));
4193 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4199 /* This is a normal symbol definition. x_scnlen is the
4200 symbol index of the containing csect. */
4201 if (S_GET_SEGMENT (sym
) == text_section
)
4202 csect
= ppc_text_csects
;
4203 else if (S_GET_SEGMENT (sym
) == data_section
)
4204 csect
= ppc_data_csects
;
4208 /* Skip the initial dummy symbol. */
4209 csect
= csect
->sy_tc
.next
;
4211 if (csect
== (symbolS
*) NULL
)
4213 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4214 a
->x_csect
.x_scnlen
.l
= 0;
4218 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
4220 resolve_symbol_value (csect
->sy_tc
.next
, 1);
4221 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
4223 csect
= csect
->sy_tc
.next
;
4226 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4227 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
4229 a
->x_csect
.x_smtyp
= XTY_LD
;
4232 a
->x_csect
.x_parmhash
= 0;
4233 a
->x_csect
.x_snhash
= 0;
4234 if (sym
->sy_tc
.class == -1)
4235 a
->x_csect
.x_smclas
= XMC_PR
;
4237 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
4238 a
->x_csect
.x_stab
= 0;
4239 a
->x_csect
.x_snstab
= 0;
4241 /* Don't let the COFF backend resort these symbols. */
4242 sym
->bsym
->flags
|= BSF_NOT_AT_END
;
4244 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4246 /* We want the value to be the symbol index of the referenced
4247 csect symbol. BFD will do that for us if we set the right
4250 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
4251 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
4253 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4258 /* The value is the offset from the enclosing csect. */
4259 block
= sym
->sy_tc
.within
;
4260 csect
= block
->sy_tc
.within
;
4261 resolve_symbol_value (csect
, 1);
4262 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4264 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4265 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4267 /* We want the value to be a file offset into the line numbers.
4268 BFD will do that for us if we set the right flags. We have
4269 already set the value correctly. */
4270 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
4276 /* Adjust the symbol table. This creates csect symbols for all
4277 absolute symbols. */
4280 ppc_adjust_symtab ()
4287 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4291 union internal_auxent
*a
;
4293 if (S_GET_SEGMENT (sym
) != absolute_section
)
4296 csect
= symbol_create (".abs[XO]", absolute_section
,
4297 S_GET_VALUE (sym
), &zero_address_frag
);
4298 csect
->bsym
->value
= S_GET_VALUE (sym
);
4299 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4300 i
= S_GET_NUMBER_AUXILIARY (csect
);
4301 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4302 a
= &coffsymbol (csect
->bsym
)->native
[i
+ 1].u
.auxent
;
4303 a
->x_csect
.x_scnlen
.l
= 0;
4304 a
->x_csect
.x_smtyp
= XTY_SD
;
4305 a
->x_csect
.x_parmhash
= 0;
4306 a
->x_csect
.x_snhash
= 0;
4307 a
->x_csect
.x_smclas
= XMC_XO
;
4308 a
->x_csect
.x_stab
= 0;
4309 a
->x_csect
.x_snstab
= 0;
4311 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4313 i
= S_GET_NUMBER_AUXILIARY (sym
);
4314 a
= &coffsymbol (sym
->bsym
)->native
[i
].u
.auxent
;
4315 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4316 coffsymbol (sym
->bsym
)->native
[i
].fix_scnlen
= 1;
4319 ppc_saw_abs
= false;
4322 /* Set the VMA for a section. This is called on all the sections in
4326 ppc_frob_section (sec
)
4329 static bfd_size_type vma
= 0;
4331 bfd_set_section_vma (stdoutput
, sec
, vma
);
4332 vma
+= bfd_section_size (stdoutput
, sec
);
4335 #endif /* OBJ_XCOFF */
4337 /* Turn a string in input_line_pointer into a floating point constant
4338 of type type, and store the appropriate bytes in *litp. The number
4339 of LITTLENUMS emitted is stored in *sizep . An error message is
4340 returned, or NULL on OK. */
4343 md_atof (type
, litp
, sizep
)
4349 LITTLENUM_TYPE words
[4];
4365 return _("bad call to md_atof");
4368 t
= atof_ieee (input_line_pointer
, type
, words
);
4370 input_line_pointer
= t
;
4374 if (target_big_endian
)
4376 for (i
= 0; i
< prec
; i
++)
4378 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4384 for (i
= prec
- 1; i
>= 0; i
--)
4386 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4394 /* Write a value out to the object file, using the appropriate
4398 md_number_to_chars (buf
, val
, n
)
4403 if (target_big_endian
)
4404 number_to_chars_bigendian (buf
, val
, n
);
4406 number_to_chars_littleendian (buf
, val
, n
);
4409 /* Align a section (I don't know why this is machine dependent). */
4412 md_section_align (seg
, addr
)
4416 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4418 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4421 /* We don't have any form of relaxing. */
4424 md_estimate_size_before_relax (fragp
, seg
)
4432 /* Convert a machine dependent frag. We never generate these. */
4435 md_convert_frag (abfd
, sec
, fragp
)
4443 /* We have no need to default values of symbols. */
4447 md_undefined_symbol (name
)
4453 /* Functions concerning relocs. */
4455 /* The location from which a PC relative jump should be calculated,
4456 given a PC relative reloc. */
4459 md_pcrel_from_section (fixp
, sec
)
4463 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4468 /* This is called to see whether a fixup should be adjusted to use a
4469 section symbol. We take the opportunity to change a fixup against
4470 a symbol in the TOC subsegment into a reloc against the
4471 corresponding .tc symbol. */
4474 ppc_fix_adjustable (fix
)
4479 resolve_symbol_value (fix
->fx_addsy
, 1);
4480 val
= S_GET_VALUE (fix
->fx_addsy
);
4481 if (ppc_toc_csect
!= (symbolS
*) NULL
4482 && fix
->fx_addsy
!= (symbolS
*) NULL
4483 && fix
->fx_addsy
!= ppc_toc_csect
4484 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4485 && val
>= ppc_toc_frag
->fr_address
4486 && (ppc_after_toc_frag
== (fragS
*) NULL
4487 || val
< ppc_after_toc_frag
->fr_address
))
4491 for (sy
= symbol_next (ppc_toc_csect
);
4492 sy
!= (symbolS
*) NULL
;
4493 sy
= symbol_next (sy
))
4495 if (sy
->sy_tc
.class == XMC_TC0
)
4497 if (sy
->sy_tc
.class != XMC_TC
)
4499 resolve_symbol_value (sy
, 1);
4500 if (val
== S_GET_VALUE (sy
))
4503 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4508 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4509 _("symbol in .toc does not match any .tc"));
4512 /* Possibly adjust the reloc to be against the csect. */
4513 if (fix
->fx_addsy
!= (symbolS
*) NULL
4514 && fix
->fx_addsy
->sy_tc
.subseg
== 0
4515 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
4516 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
4517 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
4518 /* Don't adjust if this is a reloc in the toc section. */
4519 && (S_GET_SEGMENT (fix
->fx_addsy
) != data_section
4520 || ppc_toc_csect
== NULL
4521 || val
< ppc_toc_frag
->fr_address
4522 || (ppc_after_toc_frag
!= NULL
4523 && val
>= ppc_after_toc_frag
->fr_address
)))
4527 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4528 csect
= ppc_text_csects
;
4529 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4530 csect
= ppc_data_csects
;
4534 /* Skip the initial dummy symbol. */
4535 csect
= csect
->sy_tc
.next
;
4537 if (csect
!= (symbolS
*) NULL
)
4539 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
4540 && (csect
->sy_tc
.next
->sy_frag
->fr_address
4541 <= fix
->fx_addsy
->sy_frag
->fr_address
))
4543 /* If the csect address equals the symbol value, then we
4544 have to look through the full symbol table to see
4545 whether this is the csect we want. Note that we will
4546 only get here if the csect has zero length. */
4547 if ((csect
->sy_frag
->fr_address
4548 == fix
->fx_addsy
->sy_frag
->fr_address
)
4549 && S_GET_VALUE (csect
) == S_GET_VALUE (fix
->fx_addsy
))
4553 for (scan
= csect
->sy_next
;
4555 scan
= scan
->sy_next
)
4557 if (scan
->sy_tc
.subseg
!= 0)
4559 if (scan
== fix
->fx_addsy
)
4563 /* If we found the symbol before the next csect
4564 symbol, then this is the csect we want. */
4565 if (scan
== fix
->fx_addsy
)
4569 csect
= csect
->sy_tc
.next
;
4572 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4573 - csect
->sy_frag
->fr_address
);
4574 fix
->fx_addsy
= csect
;
4578 /* Adjust a reloc against a .lcomm symbol to be against the base
4580 if (fix
->fx_addsy
!= (symbolS
*) NULL
4581 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4582 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4584 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
, 1);
4585 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4586 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
4587 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
4593 /* A reloc from one csect to another must be kept. The assembler
4594 will, of course, keep relocs between sections, and it will keep
4595 absolute relocs, but we need to force it to keep PC relative relocs
4596 between two csects in the same section. */
4599 ppc_force_relocation (fix
)
4602 /* At this point fix->fx_addsy should already have been converted to
4603 a csect symbol. If the csect does not include the fragment, then
4604 we need to force the relocation. */
4606 && fix
->fx_addsy
!= NULL
4607 && fix
->fx_addsy
->sy_tc
.subseg
!= 0
4608 && (fix
->fx_addsy
->sy_frag
->fr_address
> fix
->fx_frag
->fr_address
4609 || (fix
->fx_addsy
->sy_tc
.next
!= NULL
4610 && (fix
->fx_addsy
->sy_tc
.next
->sy_frag
->fr_address
4611 <= fix
->fx_frag
->fr_address
))))
4617 #endif /* OBJ_XCOFF */
4619 /* See whether a symbol is in the TOC section. */
4622 ppc_is_toc_sym (sym
)
4626 return sym
->sy_tc
.class == XMC_TC
;
4628 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4632 /* Apply a fixup to the object code. This is called for all the
4633 fixups we generated by the call to fix_new_exp, above. In the call
4634 above we used a reloc code which was the largest legal reloc code
4635 plus the operand index. Here we undo that to recover the operand
4636 index. At this point all symbol values should be fully resolved,
4637 and we attempt to completely resolve the reloc. If we can not do
4638 that, we determine the correct reloc code and put it back in the
4642 md_apply_fix3 (fixp
, valuep
, seg
)
4651 if (fixp
->fx_addsy
!= NULL
)
4653 /* `*valuep' may contain the value of the symbol on which the reloc
4654 will be based; we have to remove it. */
4655 if (symbol_used_in_reloc_p (fixp
->fx_addsy
)
4656 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
4657 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
4658 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
4659 value
-= S_GET_VALUE (fixp
->fx_addsy
);
4661 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4662 supposed to be? I think this is related to various similar
4663 FIXMEs in tc-i386.c and tc-sparc.c. */
4665 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4672 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4673 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4674 doing this relocation the code in write.c is going to call
4675 bfd_install_relocation, which is also going to use the symbol
4676 value. That means that if the reloc is fully resolved we want to
4677 use *valuep since bfd_install_relocation is not being used.
4678 However, if the reloc is not fully resolved we do not want to use
4679 *valuep, and must use fx_offset instead. However, if the reloc
4680 is PC relative, we do want to use *valuep since it includes the
4681 result of md_pcrel_from. This is confusing. */
4682 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4687 else if (fixp
->fx_pcrel
)
4691 value
= fixp
->fx_offset
;
4692 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4694 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4695 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4698 /* We can't actually support subtracting a symbol. */
4699 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4700 _("expression too complex"));
4706 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4709 const struct powerpc_operand
*operand
;
4713 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4715 operand
= &powerpc_operands
[opindex
];
4718 /* It appears that an instruction like
4720 when LC..1 is not a TOC symbol does not generate a reloc. It
4721 uses the offset of LC..1 within its csect. However, .long
4722 LC..1 will generate a reloc. I can't find any documentation
4723 on how these cases are to be distinguished, so this is a wild
4724 guess. These cases are generated by gcc -mminimal-toc. */
4725 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4726 && operand
->bits
== 16
4727 && operand
->shift
== 0
4728 && operand
->insert
== NULL
4729 && fixp
->fx_addsy
!= NULL
4730 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
4731 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
4732 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
4733 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4735 value
= fixp
->fx_offset
;
4740 /* Fetch the instruction, insert the fully resolved operand
4741 value, and stuff the instruction back again. */
4742 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4743 if (target_big_endian
)
4744 insn
= bfd_getb32 ((unsigned char *) where
);
4746 insn
= bfd_getl32 ((unsigned char *) where
);
4747 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4748 fixp
->fx_file
, fixp
->fx_line
);
4749 if (target_big_endian
)
4750 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4752 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4756 /* Nothing else to do here. */
4760 /* Determine a BFD reloc value based on the operand information.
4761 We are only prepared to turn a few of the operands into
4763 FIXME: We need to handle the DS field at the very least.
4764 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4765 there should be a new field in the operand table. */
4766 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4767 && operand
->bits
== 26
4768 && operand
->shift
== 0)
4769 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4770 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4771 && operand
->bits
== 16
4772 && operand
->shift
== 0)
4773 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4774 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4775 && operand
->bits
== 26
4776 && operand
->shift
== 0)
4777 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4778 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4779 && operand
->bits
== 16
4780 && operand
->shift
== 0)
4781 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4782 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4783 && operand
->bits
== 16
4784 && operand
->shift
== 0
4785 && operand
->insert
== NULL
4786 && fixp
->fx_addsy
!= NULL
4787 && ppc_is_toc_sym (fixp
->fx_addsy
))
4790 if (target_big_endian
)
4791 fixp
->fx_where
+= 2;
4792 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4799 /* Use expr_symbol_where to see if this is an expression
4801 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
4802 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4803 _("unresolved expression that must be resolved"));
4805 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4806 _("unsupported relocation type"));
4814 ppc_elf_validate_fix (fixp
, seg
);
4816 switch (fixp
->fx_r_type
)
4819 case BFD_RELOC_CTOR
:
4821 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4825 case BFD_RELOC_32_PCREL
:
4826 case BFD_RELOC_32_BASEREL
:
4827 case BFD_RELOC_PPC_EMB_NADDR32
:
4828 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4832 case BFD_RELOC_LO16
:
4834 case BFD_RELOC_GPREL16
:
4835 case BFD_RELOC_16_GOT_PCREL
:
4836 case BFD_RELOC_16_GOTOFF
:
4837 case BFD_RELOC_LO16_GOTOFF
:
4838 case BFD_RELOC_HI16_GOTOFF
:
4839 case BFD_RELOC_HI16_S_GOTOFF
:
4840 case BFD_RELOC_LO16_BASEREL
:
4841 case BFD_RELOC_HI16_BASEREL
:
4842 case BFD_RELOC_HI16_S_BASEREL
:
4843 case BFD_RELOC_PPC_EMB_NADDR16
:
4844 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
4845 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
4846 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
4847 case BFD_RELOC_PPC_EMB_SDAI16
:
4848 case BFD_RELOC_PPC_EMB_SDA2REL
:
4849 case BFD_RELOC_PPC_EMB_SDA2I16
:
4850 case BFD_RELOC_PPC_EMB_RELSEC16
:
4851 case BFD_RELOC_PPC_EMB_RELST_LO
:
4852 case BFD_RELOC_PPC_EMB_RELST_HI
:
4853 case BFD_RELOC_PPC_EMB_RELST_HA
:
4854 case BFD_RELOC_PPC_EMB_RELSDA
:
4855 case BFD_RELOC_PPC_TOC16
:
4858 if (fixp
->fx_addsy
!= NULL
)
4859 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4860 _("cannot emit PC relative %s relocation against %s"),
4861 bfd_get_reloc_code_name (fixp
->fx_r_type
),
4862 S_GET_NAME (fixp
->fx_addsy
));
4864 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4865 _("cannot emit PC relative %s relocation"),
4866 bfd_get_reloc_code_name (fixp
->fx_r_type
));
4869 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4873 /* This case happens when you write, for example,
4875 where L1 and L2 are defined later. */
4876 case BFD_RELOC_HI16
:
4879 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4882 case BFD_RELOC_HI16_S
:
4885 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4886 (value
+ 0x8000) >> 16, 2);
4889 /* Because SDA21 modifies the register field, the size is set to 4
4890 bytes, rather than 2, so offset it here appropriately */
4891 case BFD_RELOC_PPC_EMB_SDA21
:
4895 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
4896 + ((target_big_endian
) ? 2 : 0),
4904 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4908 case BFD_RELOC_24_PLT_PCREL
:
4909 case BFD_RELOC_PPC_LOCAL24PC
:
4910 if (!fixp
->fx_pcrel
&& !fixp
->fx_done
)
4918 /* Fetch the instruction, insert the fully resolved operand
4919 value, and stuff the instruction back again. */
4920 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4921 if (target_big_endian
)
4922 insn
= bfd_getb32 ((unsigned char *) where
);
4924 insn
= bfd_getl32 ((unsigned char *) where
);
4925 if ((value
& 3) != 0)
4926 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4927 _("must branch to an address a multiple of 4"));
4928 if ((offsetT
) value
< -0x40000000
4929 || (offsetT
) value
>= 0x40000000)
4930 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4931 _("@local or @plt branch destination is too far away, %ld bytes"),
4933 insn
= insn
| (value
& 0x03fffffc);
4934 if (target_big_endian
)
4935 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4937 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4941 case BFD_RELOC_VTABLE_INHERIT
:
4944 && !S_IS_DEFINED (fixp
->fx_addsy
)
4945 && !S_IS_WEAK (fixp
->fx_addsy
))
4946 S_SET_WEAK (fixp
->fx_addsy
);
4949 case BFD_RELOC_VTABLE_ENTRY
:
4955 _("Gas failure, reloc value %d\n"), fixp
->fx_r_type
);
4962 fixp
->fx_addnumber
= value
;
4964 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4965 fixp
->fx_addnumber
= 0;
4969 fixp
->fx_addnumber
= 0;
4971 /* We want to use the offset within the data segment of the
4972 symbol, not the actual VMA of the symbol. */
4973 fixp
->fx_addnumber
=
4974 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4982 /* Generate a reloc for a fixup. */
4985 tc_gen_reloc (seg
, fixp
)
4991 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
4993 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
4994 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
4995 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4996 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4997 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4999 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5000 _("reloc %d not supported by object file format"), (int)fixp
->fx_r_type
);
5003 reloc
->addend
= fixp
->fx_addnumber
;