1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 1995, 1996 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 void ppc_set_cpu
PARAMS ((void));
57 static unsigned long ppc_insert_operand
58 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
59 offsetT val
, char *file
, unsigned int line
));
60 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
61 static void ppc_byte
PARAMS ((int));
62 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
63 static void ppc_tc
PARAMS ((int));
66 static void ppc_comm
PARAMS ((int));
67 static void ppc_bb
PARAMS ((int));
68 static void ppc_bc
PARAMS ((int));
69 static void ppc_bf
PARAMS ((int));
70 static void ppc_biei
PARAMS ((int));
71 static void ppc_bs
PARAMS ((int));
72 static void ppc_eb
PARAMS ((int));
73 static void ppc_ec
PARAMS ((int));
74 static void ppc_ef
PARAMS ((int));
75 static void ppc_es
PARAMS ((int));
76 static void ppc_csect
PARAMS ((int));
77 static void ppc_change_csect
PARAMS ((symbolS
*));
78 static void ppc_function
PARAMS ((int));
79 static void ppc_extern
PARAMS ((int));
80 static void ppc_lglobl
PARAMS ((int));
81 static void ppc_section
PARAMS ((int));
82 static void ppc_stabx
PARAMS ((int));
83 static void ppc_rename
PARAMS ((int));
84 static void ppc_toc
PARAMS ((int));
85 static void ppc_xcoff_cons
PARAMS ((int));
89 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
90 static void ppc_elf_cons
PARAMS ((int));
91 static void ppc_elf_rdata
PARAMS ((int));
92 static void ppc_elf_lcomm
PARAMS ((int));
93 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
97 static void ppc_set_current_section
PARAMS ((segT
));
98 static void ppc_previous
PARAMS ((int));
99 static void ppc_pdata
PARAMS ((int));
100 static void ppc_ydata
PARAMS ((int));
101 static void ppc_reldata
PARAMS ((int));
102 static void ppc_rdata
PARAMS ((int));
103 static void ppc_ualong
PARAMS ((int));
104 static void ppc_znop
PARAMS ((int));
105 static void ppc_pe_comm
PARAMS ((int));
106 static void ppc_pe_section
PARAMS ((int));
107 static void ppc_pe_function
PARAMS ((int));
108 static void ppc_pe_tocd
PARAMS ((int));
111 /* Generic assembler global variables which must be defined by all
115 /* This string holds the chars that always start a comment. If the
116 pre-processor is disabled, these aren't very useful. The macro
117 tc_comment_chars points to this. We use this, rather than the
118 usual comment_chars, so that we can switch for Solaris conventions. */
119 static const char ppc_solaris_comment_chars
[] = "#!";
120 static const char ppc_eabi_comment_chars
[] = "#";
122 #ifdef TARGET_SOLARIS_COMMENT
123 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
125 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
128 const char comment_chars
[] = "#";
131 /* Characters which start a comment at the beginning of a line. */
132 const char line_comment_chars
[] = "#";
134 /* Characters which may be used to separate multiple commands on a
136 const char line_separator_chars
[] = ";";
138 /* Characters which are used to indicate an exponent in a floating
140 const char EXP_CHARS
[] = "eE";
142 /* Characters which mean that a number is a floating point constant,
144 const char FLT_CHARS
[] = "dD";
146 /* The target specific pseudo-ops which we support. */
148 const pseudo_typeS md_pseudo_table
[] =
150 /* Pseudo-ops which must be overridden. */
151 { "byte", ppc_byte
, 0 },
154 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
155 legitimately belong in the obj-*.c file. However, XCOFF is based
156 on COFF, and is only implemented for the RS/6000. We just use
157 obj-coff.c, and add what we need here. */
158 { "comm", ppc_comm
, 0 },
159 { "lcomm", ppc_comm
, 1 },
163 { "bi", ppc_biei
, 0 },
165 { "csect", ppc_csect
, 0 },
166 { "data", ppc_section
, 'd' },
170 { "ei", ppc_biei
, 1 },
172 { "extern", ppc_extern
, 0 },
173 { "function", ppc_function
, 0 },
174 { "lglobl", ppc_lglobl
, 0 },
175 { "rename", ppc_rename
, 0 },
176 { "stabx", ppc_stabx
, 0 },
177 { "text", ppc_section
, 't' },
178 { "toc", ppc_toc
, 0 },
179 { "long", ppc_xcoff_cons
, 2 },
180 { "word", ppc_xcoff_cons
, 1 },
181 { "short", ppc_xcoff_cons
, 1 },
185 { "long", ppc_elf_cons
, 4 },
186 { "word", ppc_elf_cons
, 2 },
187 { "short", ppc_elf_cons
, 2 },
188 { "rdata", ppc_elf_rdata
, 0 },
189 { "rodata", ppc_elf_rdata
, 0 },
190 { "lcomm", ppc_elf_lcomm
, 0 },
194 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
195 { "previous", ppc_previous
, 0 },
196 { "pdata", ppc_pdata
, 0 },
197 { "ydata", ppc_ydata
, 0 },
198 { "reldata", ppc_reldata
, 0 },
199 { "rdata", ppc_rdata
, 0 },
200 { "ualong", ppc_ualong
, 0 },
201 { "znop", ppc_znop
, 0 },
202 { "comm", ppc_pe_comm
, 0 },
203 { "lcomm", ppc_pe_comm
, 1 },
204 { "section", ppc_pe_section
, 0 },
205 { "function", ppc_pe_function
,0 },
206 { "tocd", ppc_pe_tocd
, 0 },
209 /* This pseudo-op is used even when not generating XCOFF output. */
216 /* Predefined register names if -mregnames (or default for Windows NT). */
217 /* In general, there are lots of them, in an attempt to be compatible */
218 /* with a number of other Windows NT assemblers. */
220 /* Structure to hold information about predefined registers. */
227 /* List of registers that are pre-defined:
229 Each general register has predefined names of the form:
230 1. r<reg_num> which has the value <reg_num>.
231 2. r.<reg_num> which has the value <reg_num>.
234 Each floating point register has predefined names of the form:
235 1. f<reg_num> which has the value <reg_num>.
236 2. f.<reg_num> which has the value <reg_num>.
238 Each condition register has predefined names of the form:
239 1. cr<reg_num> which has the value <reg_num>.
240 2. cr.<reg_num> which has the value <reg_num>.
242 There are individual registers as well:
243 sp or r.sp has the value 1
244 rtoc or r.toc has the value 2
245 fpscr has the value 0
251 dsisr has the value 18
253 sdr1 has the value 25
254 srr0 has the value 26
255 srr1 has the value 27
257 The table is sorted. Suitable for searching by a binary search. */
259 static const struct pd_reg pre_defined_registers
[] =
261 { "cr.0", 0 }, /* Condition Registers */
281 { "dar", 19 }, /* Data Access Register */
282 { "dec", 22 }, /* Decrementer */
283 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
285 { "f.0", 0 }, /* Floating point registers */
353 { "lr", 8 }, /* Link Register */
357 { "r.0", 0 }, /* General Purpose Registers */
390 { "r.sp", 1 }, /* Stack Pointer */
392 { "r.toc", 2 }, /* Pointer to the table of contents */
394 { "r0", 0 }, /* More general purpose registers */
427 { "rtoc", 2 }, /* Table of contents */
429 { "sdr1", 25 }, /* Storage Description Register 1 */
433 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
434 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
440 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
442 /* Given NAME, find the register number associated with that name, return
443 the integer value associated with the given name or -1 on failure. */
445 static int reg_name_search
446 PARAMS ((const struct pd_reg
*, int, const char * name
));
449 reg_name_search (regs
, regcount
, name
)
450 const struct pd_reg
*regs
;
454 int middle
, low
, high
;
462 middle
= (low
+ high
) / 2;
463 cmp
= strcasecmp (name
, regs
[middle
].name
);
469 return regs
[middle
].value
;
477 * Summary of register_name().
479 * in: Input_line_pointer points to 1st char of operand.
481 * out: A expressionS.
482 * The operand may have been a register: in this case, X_op == O_register,
483 * X_add_number is set to the register number, and truth is returned.
484 * Input_line_pointer->(next non-blank) char after operand, or is in its
489 register_name (expressionP
)
490 expressionS
*expressionP
;
497 /* Find the spelling of the operand */
498 start
= name
= input_line_pointer
;
499 if (name
[0] == '%' && isalpha (name
[1]))
500 name
= ++input_line_pointer
;
502 else if (!reg_names_p
|| !isalpha (name
[0]))
505 c
= get_symbol_end ();
506 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
508 /* look to see if it's in the register table */
511 expressionP
->X_op
= O_register
;
512 expressionP
->X_add_number
= reg_number
;
514 /* make the rest nice */
515 expressionP
->X_add_symbol
= NULL
;
516 expressionP
->X_op_symbol
= NULL
;
517 *input_line_pointer
= c
; /* put back the delimiting char */
522 /* reset the line as if we had not done anything */
523 *input_line_pointer
= c
; /* put back the delimiting char */
524 input_line_pointer
= start
; /* reset input_line pointer */
529 /* This function is called for each symbol seen in an expression. It
530 handles the special parsing which PowerPC assemblers are supposed
531 to use for condition codes. */
533 /* Whether to do the special parsing. */
534 static boolean cr_operand
;
536 /* Names to recognize in a condition code. This table is sorted. */
537 static const struct pd_reg cr_names
[] =
554 /* Parsing function. This returns non-zero if it recognized an
558 ppc_parse_name (name
, expr
)
567 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
572 expr
->X_op
= O_constant
;
573 expr
->X_add_number
= val
;
578 /* Local variables. */
580 /* The type of processor we are assembling for. This is one or more
581 of the PPC_OPCODE flags defined in opcode/ppc.h. */
582 static int ppc_cpu
= 0;
584 /* The size of the processor we are assembling for. This is either
585 PPC_OPCODE_32 or PPC_OPCODE_64. */
586 static int ppc_size
= PPC_OPCODE_32
;
588 /* Opcode hash table. */
589 static struct hash_control
*ppc_hash
;
591 /* Macro hash table. */
592 static struct hash_control
*ppc_macro_hash
;
595 /* What type of shared library support to use */
596 static enum { SHLIB_NONE
, SHLIB_PIC
, SHILB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
598 /* Flags to set in the elf header */
599 static flagword ppc_flags
= 0;
601 /* Whether this is Solaris or not. */
602 #ifdef TARGET_SOLARIS_COMMENT
603 #define SOLARIS_P true
605 #define SOLARIS_P false
608 static boolean msolaris
= SOLARIS_P
;
613 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
614 using a bunch of different sections. These assembler sections,
615 however, are all encompassed within the .text or .data sections of
616 the final output file. We handle this by using different
617 subsegments within these main segments. */
619 /* Next subsegment to allocate within the .text segment. */
620 static subsegT ppc_text_subsegment
= 2;
622 /* Linked list of csects in the text section. */
623 static symbolS
*ppc_text_csects
;
625 /* Next subsegment to allocate within the .data segment. */
626 static subsegT ppc_data_subsegment
= 2;
628 /* Linked list of csects in the data section. */
629 static symbolS
*ppc_data_csects
;
631 /* The current csect. */
632 static symbolS
*ppc_current_csect
;
634 /* The RS/6000 assembler uses a TOC which holds addresses of functions
635 and variables. Symbols are put in the TOC with the .tc pseudo-op.
636 A special relocation is used when accessing TOC entries. We handle
637 the TOC as a subsegment within the .data segment. We set it up if
638 we see a .toc pseudo-op, and save the csect symbol here. */
639 static symbolS
*ppc_toc_csect
;
641 /* The first frag in the TOC subsegment. */
642 static fragS
*ppc_toc_frag
;
644 /* The first frag in the first subsegment after the TOC in the .data
645 segment. NULL if there are no subsegments after the TOC. */
646 static fragS
*ppc_after_toc_frag
;
648 /* The current static block. */
649 static symbolS
*ppc_current_block
;
651 /* The COFF debugging section; set by md_begin. This is not the
652 .debug section, but is instead the secret BFD section which will
653 cause BFD to set the section number of a symbol to N_DEBUG. */
654 static asection
*ppc_coff_debug_section
;
656 #endif /* OBJ_XCOFF */
660 /* Various sections that we need for PE coff support. */
661 static segT ydata_section
;
662 static segT pdata_section
;
663 static segT reldata_section
;
664 static segT rdata_section
;
665 static segT tocdata_section
;
667 /* The current section and the previous section. See ppc_previous. */
668 static segT ppc_previous_section
;
669 static segT ppc_current_section
;
674 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
677 #ifndef WORKING_DOT_WORD
678 const int md_short_jump_size
= 4;
679 const int md_long_jump_size
= 4;
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 /* -mcom means assemble for the common intersection between Power
770 and PowerPC. At present, we just allow the union, rather
771 than the intersection. */
772 else if (strcmp (arg
, "com") == 0)
773 ppc_cpu
= PPC_OPCODE_COMMON
;
774 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
775 else if (strcmp (arg
, "any") == 0)
776 ppc_cpu
= PPC_OPCODE_ANY
;
778 else if (strcmp (arg
, "regnames") == 0)
781 else if (strcmp (arg
, "no-regnames") == 0)
785 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
786 else if (strcmp (arg
, "relocatable") == 0)
788 shlib
= SHILB_MRELOCATABLE
;
789 ppc_flags
|= EF_PPC_RELOCATABLE
;
792 else if (strcmp (arg
, "relocatable-lib") == 0)
794 shlib
= SHILB_MRELOCATABLE
;
795 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
798 /* -memb, set embedded bit */
799 else if (strcmp (arg
, "emb") == 0)
800 ppc_flags
|= EF_PPC_EMB
;
802 /* -mlittle/-mbig set the endianess */
803 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
805 target_big_endian
= 0;
806 set_target_endian
= 1;
809 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
811 target_big_endian
= 1;
812 set_target_endian
= 1;
815 else if (strcmp (arg
, "solaris") == 0)
818 ppc_comment_chars
= ppc_solaris_comment_chars
;
821 else if (strcmp (arg
, "no-solaris") == 0)
824 ppc_comment_chars
= ppc_eabi_comment_chars
;
829 as_bad ("invalid switch -m%s", arg
);
835 /* -V: SVR4 argument to print version ID. */
840 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
841 should be emitted or not. FIXME: Not implemented. */
845 /* Solaris takes -s to specify that .stabs go in a .stabs section,
846 rather than .stabs.excl, which is ignored by the linker.
847 FIXME: Not implemented. */
863 md_show_usage (stream
)
869 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
870 -mpwr generate code for IBM POWER (RIOS1)\n\
871 -m601 generate code for Motorola PowerPC 601\n\
872 -mppc, -mppc32, -m403, -m603, -m604\n\
873 generate code for Motorola PowerPC 603/604\n\
874 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
875 -mcom generate code Power/PowerPC common instructions\n\
876 -many generate code for any architecture (PWR/PWRX/PPC)\n\
877 -mregnames Allow symbolic names for registers\n\
878 -mno-regnames Do not allow symbolic names for registers\n");
881 -mrelocatable support for GCC's -mrelocatble option\n\
882 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
883 -memb set PPC_EMB bit in ELF flags\n\
884 -mlittle, -mlittle-endian\n\
885 generate code for a little endian machine\n\
886 -mbig, -mbig-endian generate code for a big endian machine\n\
887 -msolaris generate code for Solaris\n\
888 -mno-solaris do not generate code for Solaris\n\
889 -V print assembler version number\n\
890 -Qy, -Qn ignored\n");
894 /* Set ppc_cpu if it is not already set. */
899 const char *default_os
= TARGET_OS
;
900 const char *default_cpu
= TARGET_CPU
;
904 if (strncmp (default_os
, "aix", 3) == 0
905 && default_os
[3] >= '4' && default_os
[3] <= '9')
906 ppc_cpu
= PPC_OPCODE_COMMON
;
907 else if (strncmp (default_os
, "aix3", 4) == 0)
908 ppc_cpu
= PPC_OPCODE_POWER
;
909 else if (strcmp (default_cpu
, "rs6000") == 0)
910 ppc_cpu
= PPC_OPCODE_POWER
;
911 else if (strcmp (default_cpu
, "powerpc") == 0
912 || strcmp (default_cpu
, "powerpcle") == 0)
913 ppc_cpu
= PPC_OPCODE_PPC
;
915 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu
, default_os
);
919 /* Figure out the BFD architecture to use. */
921 enum bfd_architecture
924 const char *default_cpu
= TARGET_CPU
;
927 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
928 return bfd_arch_powerpc
;
929 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
930 return bfd_arch_rs6000
;
931 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
933 if (strcmp (default_cpu
, "rs6000") == 0)
934 return bfd_arch_rs6000
;
935 else if (strcmp (default_cpu
, "powerpc") == 0
936 || strcmp (default_cpu
, "powerpcle") == 0)
937 return bfd_arch_powerpc
;
940 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
941 return bfd_arch_unknown
;
944 /* This function is called when the assembler starts up. It is called
945 after the options have been parsed and the output file has been
951 register const struct powerpc_opcode
*op
;
952 const struct powerpc_opcode
*op_end
;
953 const struct powerpc_macro
*macro
;
954 const struct powerpc_macro
*macro_end
;
955 boolean dup_insn
= false;
960 /* Set the ELF flags if desired. */
961 if (ppc_flags
&& !msolaris
)
962 bfd_set_private_flags (stdoutput
, ppc_flags
);
965 /* Insert the opcodes into a hash table. */
966 ppc_hash
= hash_new ();
968 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
969 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
971 know ((op
->opcode
& op
->mask
) == op
->opcode
);
973 if ((op
->flags
& ppc_cpu
) != 0
974 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
975 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
979 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
980 if (retval
!= (const char *) NULL
)
982 /* Ignore Power duplicates for -m601 */
983 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
984 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
987 as_bad ("Internal assembler error for instruction %s", op
->name
);
993 /* Insert the macros into a hash table. */
994 ppc_macro_hash
= hash_new ();
996 macro_end
= powerpc_macros
+ powerpc_num_macros
;
997 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
999 if ((macro
->flags
& ppc_cpu
) != 0)
1003 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1004 if (retval
!= (const char *) NULL
)
1006 as_bad ("Internal assembler error for macro %s", macro
->name
);
1015 /* Tell the main code what the endianness is if it is not overidden by the user. */
1016 if (!set_target_endian
)
1018 set_target_endian
= 1;
1019 target_big_endian
= PPC_BIG_ENDIAN
;
1023 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1025 /* Create dummy symbols to serve as initial csects. This forces the
1026 text csects to precede the data csects. These symbols will not
1028 ppc_text_csects
= symbol_make ("dummy\001");
1029 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
1030 ppc_data_csects
= symbol_make ("dummy\001");
1031 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
1036 ppc_current_section
= text_section
;
1037 ppc_previous_section
= 0;
1042 /* Insert an operand value into an instruction. */
1044 static unsigned long
1045 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1047 const struct powerpc_operand
*operand
;
1052 if (operand
->bits
!= 32)
1057 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1059 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
1060 && ppc_size
== PPC_OPCODE_32
)
1061 max
= (1 << operand
->bits
) - 1;
1063 max
= (1 << (operand
->bits
- 1)) - 1;
1064 min
= - (1 << (operand
->bits
- 1));
1068 max
= (1 << operand
->bits
) - 1;
1072 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1077 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1080 "operand out of range (%s not between %ld and %ld)";
1083 sprint_value (buf
, test
);
1084 if (file
== (char *) NULL
)
1085 as_bad (err
, buf
, min
, max
);
1087 as_bad_where (file
, line
, err
, buf
, min
, max
);
1091 if (operand
->insert
)
1096 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1097 if (errmsg
!= (const char *) NULL
)
1101 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1109 /* Parse @got, etc. and return the desired relocation. */
1110 static bfd_reloc_code_real_type
1111 ppc_elf_suffix (str_p
, exp_p
)
1118 bfd_reloc_code_real_type reloc
;
1126 struct map_bfd
*ptr
;
1128 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1130 static struct map_bfd mapping
[] = {
1131 MAP ("l", BFD_RELOC_LO16
),
1132 MAP ("h", BFD_RELOC_HI16
),
1133 MAP ("ha", BFD_RELOC_HI16_S
),
1134 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1135 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1136 MAP ("got", BFD_RELOC_16_GOTOFF
),
1137 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1138 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1139 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1140 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1141 MAP ("plt", BFD_RELOC_24_PLT_PCREL
),
1142 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1143 MAP ("copy", BFD_RELOC_PPC_COPY
),
1144 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1145 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1146 MAP ("local", BFD_RELOC_PPC_LOCAL24PC
),
1147 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1148 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1149 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1150 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1151 MAP ("sdarel", BFD_RELOC_GPREL16
),
1152 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1153 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1154 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1155 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1156 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1157 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1158 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1159 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1160 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1161 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1162 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1163 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1164 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1165 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1166 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1167 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1168 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1169 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1170 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1171 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1172 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1174 { (char *)0, 0, BFD_RELOC_UNUSED
}
1178 return BFD_RELOC_UNUSED
;
1180 for (ch
= *str
, str2
= ident
;
1181 (str2
< ident
+ sizeof (ident
) - 1
1182 && (isalnum (ch
) || ch
== '@'));
1185 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1192 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1193 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1195 /* Now check for identifier@suffix+constant */
1196 if (*str
== '-' || *str
== '+')
1198 char *orig_line
= input_line_pointer
;
1199 expressionS new_exp
;
1201 input_line_pointer
= str
;
1202 expression (&new_exp
);
1203 if (new_exp
.X_op
== O_constant
)
1205 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1206 str
= input_line_pointer
;
1209 if (&input_line_pointer
!= str_p
)
1210 input_line_pointer
= orig_line
;
1217 return BFD_RELOC_UNUSED
;
1220 /* Like normal .long/.short/.word, except support @got, etc. */
1221 /* clobbers input_line_pointer, checks */
1224 ppc_elf_cons (nbytes
)
1225 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1228 bfd_reloc_code_real_type reloc
;
1230 if (is_it_end_of_statement ())
1232 demand_empty_rest_of_line ();
1239 if (exp
.X_op
== O_symbol
1240 && *input_line_pointer
== '@'
1241 && (reloc
= ppc_elf_suffix (&input_line_pointer
, &exp
)) != BFD_RELOC_UNUSED
)
1243 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1244 int size
= bfd_get_reloc_size (reloc_howto
);
1247 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
1251 register char *p
= frag_more ((int) nbytes
);
1252 int offset
= nbytes
- size
;
1254 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1258 emit_expr (&exp
, (unsigned int) nbytes
);
1260 while (*input_line_pointer
++ == ',');
1262 input_line_pointer
--; /* Put terminator back into stream. */
1263 demand_empty_rest_of_line ();
1266 /* Solaris pseduo op to change to the .rodata section. */
1271 char *save_line
= input_line_pointer
;
1272 static char section
[] = ".rodata\n";
1274 /* Just pretend this is .section .rodata */
1275 input_line_pointer
= section
;
1276 obj_elf_section (xxx
);
1278 input_line_pointer
= save_line
;
1281 /* Pseudo op to make file scope bss items */
1286 register char *name
;
1290 register symbolS
*symbolP
;
1297 name
= input_line_pointer
;
1298 c
= get_symbol_end ();
1300 /* just after name is now '\0' */
1301 p
= input_line_pointer
;
1304 if (*input_line_pointer
!= ',')
1306 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1307 ignore_rest_of_line ();
1311 input_line_pointer
++; /* skip ',' */
1312 if ((size
= get_absolute_expression ()) < 0)
1314 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size
);
1315 ignore_rest_of_line ();
1319 /* The third argument to .lcomm is the alignment. */
1320 if (*input_line_pointer
!= ',')
1324 ++input_line_pointer
;
1325 align
= get_absolute_expression ();
1328 as_warn ("ignoring bad alignment");
1334 symbolP
= symbol_find_or_make (name
);
1337 if (S_IS_DEFINED (symbolP
))
1339 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1340 S_GET_NAME (symbolP
));
1341 ignore_rest_of_line ();
1345 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1347 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1348 S_GET_NAME (symbolP
),
1349 (long) S_GET_VALUE (symbolP
),
1352 ignore_rest_of_line ();
1358 old_subsec
= now_subseg
;
1361 /* convert to a power of 2 alignment */
1362 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1365 as_bad ("Common alignment not a power of 2");
1366 ignore_rest_of_line ();
1373 record_alignment (bss_section
, align2
);
1374 subseg_set (bss_section
, 0);
1376 frag_align (align2
, 0);
1377 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1378 symbolP
->sy_frag
->fr_symbol
= 0;
1379 symbolP
->sy_frag
= frag_now
;
1380 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1383 S_SET_SIZE (symbolP
, size
);
1384 S_SET_SEGMENT (symbolP
, bss_section
);
1385 S_CLEAR_EXTERNAL (symbolP
);
1386 subseg_set (old_sec
, old_subsec
);
1387 demand_empty_rest_of_line ();
1390 /* Validate any relocations emitted for -mrelocatable, possibly adding
1391 fixups for word relocations in writable segments, so we can adjust
1394 ppc_elf_validate_fix (fixp
, seg
)
1398 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1407 case SHILB_MRELOCATABLE
:
1408 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1409 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1410 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1411 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1412 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1413 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1414 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1415 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1416 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1417 && strcmp (segment_name (seg
), ".got2") != 0
1418 && strcmp (segment_name (seg
), ".dtors") != 0
1419 && strcmp (segment_name (seg
), ".ctors") != 0
1420 && strcmp (segment_name (seg
), ".fixup") != 0
1421 && strcmp (segment_name (seg
), ".stab") != 0
1422 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1423 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1425 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1426 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1428 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1429 "Relocation cannot be done when using -mrelocatable");
1435 #endif /* OBJ_ELF */
1440 * Summary of parse_toc_entry().
1442 * in: Input_line_pointer points to the '[' in one of:
1444 * [toc] [tocv] [toc32] [toc64]
1446 * Anything else is an error of one kind or another.
1449 * return value: success or failure
1450 * toc_kind: kind of toc reference
1451 * input_line_pointer:
1452 * success: first char after the ']'
1453 * failure: unchanged
1457 * [toc] - rv == success, toc_kind = default_toc
1458 * [tocv] - rv == success, toc_kind = data_in_toc
1459 * [toc32] - rv == success, toc_kind = must_be_32
1460 * [toc64] - rv == success, toc_kind = must_be_64
1464 enum toc_size_qualifier
1466 default_toc
, /* The toc cell constructed should be the system default size */
1467 data_in_toc
, /* This is a direct reference to a toc cell */
1468 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1469 must_be_64
/* The toc cell constructed must be 64 bits wide */
1473 parse_toc_entry(toc_kind
)
1474 enum toc_size_qualifier
*toc_kind
;
1479 enum toc_size_qualifier t
;
1481 /* save the input_line_pointer */
1482 start
= input_line_pointer
;
1484 /* skip over the '[' , and whitespace */
1485 ++input_line_pointer
;
1488 /* find the spelling of the operand */
1489 toc_spec
= input_line_pointer
;
1490 c
= get_symbol_end ();
1492 if (strcmp(toc_spec
, "toc") == 0)
1496 else if (strcmp(toc_spec
, "tocv") == 0)
1500 else if (strcmp(toc_spec
, "toc32") == 0)
1504 else if (strcmp(toc_spec
, "toc64") == 0)
1510 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1511 *input_line_pointer
= c
; /* put back the delimiting char */
1512 input_line_pointer
= start
; /* reset input_line pointer */
1516 /* now find the ']' */
1517 *input_line_pointer
= c
; /* put back the delimiting char */
1519 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1520 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1524 as_bad ("syntax error: expected `]', found `%c'", c
);
1525 input_line_pointer
= start
; /* reset input_line pointer */
1529 *toc_kind
= t
; /* set return value */
1535 /* We need to keep a list of fixups. We can't simply generate them as
1536 we go, because that would require us to first create the frag, and
1537 that would screw up references to ``.''. */
1543 bfd_reloc_code_real_type reloc
;
1546 #define MAX_INSN_FIXUPS (5)
1548 /* This routine is called for each instruction to be assembled. */
1555 const struct powerpc_opcode
*opcode
;
1557 const unsigned char *opindex_ptr
;
1561 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1566 bfd_reloc_code_real_type reloc
;
1569 /* Get the opcode. */
1570 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1575 /* Look up the opcode in the hash table. */
1576 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1577 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1579 const struct powerpc_macro
*macro
;
1581 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1582 if (macro
== (const struct powerpc_macro
*) NULL
)
1583 as_bad ("Unrecognized opcode: `%s'", str
);
1585 ppc_macro (s
, macro
);
1590 insn
= opcode
->opcode
;
1593 while (isspace (*str
))
1596 /* PowerPC operands are just expressions. The only real issue is
1597 that a few operand types are optional. All cases which might use
1598 an optional operand separate the operands only with commas (in
1599 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1600 cases never have optional operands). There is never more than
1601 one optional operand for an instruction. So, before we start
1602 seriously parsing the operands, we check to see if we have an
1603 optional operand, and, if we do, we count the number of commas to
1604 see whether the operand should be omitted. */
1606 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1608 const struct powerpc_operand
*operand
;
1610 operand
= &powerpc_operands
[*opindex_ptr
];
1611 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1613 unsigned int opcount
;
1615 /* There is an optional operand. Count the number of
1616 commas in the input line. */
1623 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1630 /* If there are fewer operands in the line then are called
1631 for by the instruction, we want to skip the optional
1633 if (opcount
< strlen (opcode
->operands
))
1640 /* Gather the operands. */
1644 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1646 const struct powerpc_operand
*operand
;
1652 if (next_opindex
== 0)
1653 operand
= &powerpc_operands
[*opindex_ptr
];
1656 operand
= &powerpc_operands
[next_opindex
];
1662 /* If this is a fake operand, then we do not expect anything
1664 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1666 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1667 if (errmsg
!= (const char *) NULL
)
1672 /* If this is an optional operand, and we are skipping it, just
1674 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1677 if (operand
->insert
)
1679 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1680 if (errmsg
!= (const char *) NULL
)
1683 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1684 next_opindex
= *opindex_ptr
+ 1;
1688 /* Gather the operand. */
1689 hold
= input_line_pointer
;
1690 input_line_pointer
= str
;
1693 if (*input_line_pointer
== '[')
1695 /* We are expecting something like the second argument here:
1697 lwz r4,[toc].GS.0.static_int(rtoc)
1698 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1699 The argument following the `]' must be a symbol name, and the
1700 register must be the toc register: 'rtoc' or '2'
1702 The effect is to 0 as the displacement field
1703 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1704 the appropriate variation) reloc against it based on the symbol.
1705 The linker will build the toc, and insert the resolved toc offset.
1708 o The size of the toc entry is currently assumed to be
1709 32 bits. This should not be assumed to be a hard coded
1711 o In an effort to cope with a change from 32 to 64 bits,
1712 there are also toc entries that are specified to be
1713 either 32 or 64 bits:
1714 lwz r4,[toc32].GS.0.static_int(rtoc)
1715 lwz r4,[toc64].GS.0.static_int(rtoc)
1716 These demand toc entries of the specified size, and the
1717 instruction probably requires it.
1721 enum toc_size_qualifier toc_kind
;
1722 bfd_reloc_code_real_type toc_reloc
;
1724 /* go parse off the [tocXX] part */
1725 valid_toc
= parse_toc_entry(&toc_kind
);
1729 /* Note: message has already been issued. */
1730 /* FIXME: what sort of recovery should we do? */
1731 /* demand_rest_of_line(); return; ? */
1734 /* Now get the symbol following the ']' */
1740 /* In this case, we may not have seen the symbol yet, since */
1741 /* it is allowed to appear on a .extern or .globl or just be */
1742 /* a label in the .data section. */
1743 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1746 /* 1. The symbol must be defined and either in the toc */
1747 /* section, or a global. */
1748 /* 2. The reloc generated must have the TOCDEFN flag set in */
1749 /* upper bit mess of the reloc type. */
1750 /* FIXME: It's a little confusing what the tocv qualifier can */
1751 /* be used for. At the very least, I've seen three */
1752 /* uses, only one of which I'm sure I can explain. */
1753 if (ex
.X_op
== O_symbol
)
1755 assert (ex
.X_add_symbol
!= NULL
);
1756 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1758 as_bad("[tocv] symbol is not a toc symbol");
1762 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1765 /* FIXME: these next two specifically specify 32/64 bit toc */
1766 /* entries. We don't support them today. Is this the */
1767 /* right way to say that? */
1768 toc_reloc
= BFD_RELOC_UNUSED
;
1769 as_bad ("Unimplemented toc32 expression modifier");
1772 /* FIXME: see above */
1773 toc_reloc
= BFD_RELOC_UNUSED
;
1774 as_bad ("Unimplemented toc64 expression modifier");
1778 "Unexpected return value [%d] from parse_toc_entry!\n",
1784 /* We need to generate a fixup for this expression. */
1785 if (fc
>= MAX_INSN_FIXUPS
)
1786 as_fatal ("too many fixups");
1788 fixups
[fc
].reloc
= toc_reloc
;
1789 fixups
[fc
].exp
= ex
;
1790 fixups
[fc
].opindex
= *opindex_ptr
;
1793 /* Ok. We've set up the fixup for the instruction. Now make it
1794 look like the constant 0 was found here */
1796 ex
.X_op
= O_constant
;
1797 ex
.X_add_number
= 0;
1798 ex
.X_add_symbol
= NULL
;
1799 ex
.X_op_symbol
= NULL
;
1805 if (! register_name (&ex
))
1807 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1814 str
= input_line_pointer
;
1815 input_line_pointer
= hold
;
1817 if (ex
.X_op
== O_illegal
)
1818 as_bad ("illegal operand");
1819 else if (ex
.X_op
== O_absent
)
1820 as_bad ("missing operand");
1821 else if (ex
.X_op
== O_register
)
1823 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1826 else if (ex
.X_op
== O_constant
)
1829 /* Allow @HA, @L, @H on constants. */
1830 char *orig_str
= str
;
1832 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1839 case BFD_RELOC_LO16
:
1841 ex
.X_add_number
&= 0xffff;
1843 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
1848 case BFD_RELOC_HI16
:
1849 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1852 case BFD_RELOC_HI16_S
:
1853 ex
.X_add_number
= (((ex
.X_add_number
>> 16) & 0xffff)
1854 + ((ex
.X_add_number
>> 15) & 1));
1858 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1862 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1864 /* For the absoulte forms of branchs, convert the PC relative form back into
1866 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1870 case BFD_RELOC_PPC_B26
:
1871 reloc
= BFD_RELOC_PPC_BA26
;
1873 case BFD_RELOC_PPC_B16
:
1874 reloc
= BFD_RELOC_PPC_BA16
;
1876 case BFD_RELOC_PPC_B16_BRTAKEN
:
1877 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
1879 case BFD_RELOC_PPC_B16_BRNTAKEN
:
1880 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
1887 /* We need to generate a fixup for this expression. */
1888 if (fc
>= MAX_INSN_FIXUPS
)
1889 as_fatal ("too many fixups");
1890 fixups
[fc
].exp
= ex
;
1891 fixups
[fc
].opindex
= 0;
1892 fixups
[fc
].reloc
= reloc
;
1895 #endif /* OBJ_ELF */
1899 /* We need to generate a fixup for this expression. */
1900 if (fc
>= MAX_INSN_FIXUPS
)
1901 as_fatal ("too many fixups");
1902 fixups
[fc
].exp
= ex
;
1903 fixups
[fc
].opindex
= *opindex_ptr
;
1904 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1913 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1921 /* The call to expression should have advanced str past any
1924 && (endc
!= ',' || *str
!= '\0'))
1926 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1934 while (isspace (*str
))
1938 as_bad ("junk at end of line: `%s'", str
);
1940 /* Write out the instruction. */
1942 md_number_to_chars (f
, insn
, 4);
1944 /* Create any fixups. At this point we do not use a
1945 bfd_reloc_code_real_type, but instead just use the
1946 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1947 handle fixups for any operand type, although that is admittedly
1948 not a very exciting feature. We pick a BFD reloc type in
1950 for (i
= 0; i
< fc
; i
++)
1952 const struct powerpc_operand
*operand
;
1954 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1955 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1957 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1965 size
= bfd_get_reloc_size (reloc_howto
);
1966 offset
= target_big_endian
? (4 - size
) : 0;
1968 if (size
< 1 || size
> 4)
1971 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1972 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1975 /* Turn off complaints that the addend is too large for things like
1977 switch (fixups
[i
].reloc
)
1979 case BFD_RELOC_16_GOTOFF
:
1980 case BFD_RELOC_PPC_TOC16
:
1981 case BFD_RELOC_LO16
:
1982 case BFD_RELOC_HI16
:
1983 case BFD_RELOC_HI16_S
:
1984 fixP
->fx_no_overflow
= 1;
1991 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1993 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1994 ((bfd_reloc_code_real_type
)
1995 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1999 #ifndef WORKING_DOT_WORD
2000 /* Handle long and short jumps */
2002 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2004 addressT from_addr
, to_addr
;
2012 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2014 addressT from_addr
, to_addr
;
2022 /* Handle a macro. Gather all the operands, transform them as
2023 described by the macro, and call md_assemble recursively. All the
2024 operands are separated by commas; we don't accept parentheses
2025 around operands here. */
2028 ppc_macro (str
, macro
)
2030 const struct powerpc_macro
*macro
;
2041 /* Gather the users operands into the operands array. */
2046 if (count
>= sizeof operands
/ sizeof operands
[0])
2048 operands
[count
++] = s
;
2049 s
= strchr (s
, ',');
2050 if (s
== (char *) NULL
)
2055 if (count
!= macro
->operands
)
2057 as_bad ("wrong number of operands");
2061 /* Work out how large the string must be (the size is unbounded
2062 because it includes user input). */
2064 format
= macro
->format
;
2065 while (*format
!= '\0')
2074 arg
= strtol (format
+ 1, &send
, 10);
2075 know (send
!= format
&& arg
>= 0 && arg
< count
);
2076 len
+= strlen (operands
[arg
]);
2081 /* Put the string together. */
2082 complete
= s
= (char *) alloca (len
+ 1);
2083 format
= macro
->format
;
2084 while (*format
!= '\0')
2090 arg
= strtol (format
+ 1, &send
, 10);
2091 strcpy (s
, operands
[arg
]);
2098 /* Assemble the constructed instruction. */
2099 md_assemble (complete
);
2103 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2106 ppc_section_letter (letter
, ptr_msg
)
2113 *ptr_msg
= "Bad .section directive: want a,w,x,e in string";
2118 ppc_section_word (ptr_str
)
2121 if (strncmp (*ptr_str
, "exclude", sizeof ("exclude")-1) == 0)
2123 *ptr_str
+= sizeof ("exclude")-1;
2131 ppc_section_type (ptr_str
)
2134 if (strncmp (*ptr_str
, "ordered", sizeof ("ordered")-1) == 0)
2136 *ptr_str
+= sizeof ("ordered")-1;
2144 ppc_section_flags (flags
, attr
, type
)
2149 if (type
== SHT_ORDERED
)
2150 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2152 if (attr
& SHF_EXCLUDE
)
2153 flags
|= SEC_EXCLUDE
;
2157 #endif /* OBJ_ELF */
2160 /* Pseudo-op handling. */
2162 /* The .byte pseudo-op. This is similar to the normal .byte
2163 pseudo-op, but it can also take a single ASCII string. */
2169 if (*input_line_pointer
!= '\"')
2175 /* Gather characters. A real double quote is doubled. Unusual
2176 characters are not permitted. */
2177 ++input_line_pointer
;
2182 c
= *input_line_pointer
++;
2186 if (*input_line_pointer
!= '\"')
2188 ++input_line_pointer
;
2191 FRAG_APPEND_1_CHAR (c
);
2194 demand_empty_rest_of_line ();
2199 /* XCOFF specific pseudo-op handling. */
2201 /* This is set if we are creating a .stabx symbol, since we don't want
2202 to handle symbol suffixes for such symbols. */
2203 static boolean ppc_stab_symbol
;
2205 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2206 symbols in the .bss segment as though they were local common
2207 symbols, and uses a different smclas. */
2213 asection
*current_seg
= now_seg
;
2214 subsegT current_subseg
= now_subseg
;
2220 symbolS
*lcomm_sym
= NULL
;
2224 name
= input_line_pointer
;
2225 endc
= get_symbol_end ();
2226 end_name
= input_line_pointer
;
2229 if (*input_line_pointer
!= ',')
2231 as_bad ("missing size");
2232 ignore_rest_of_line ();
2235 ++input_line_pointer
;
2237 size
= get_absolute_expression ();
2240 as_bad ("negative size");
2241 ignore_rest_of_line ();
2247 /* The third argument to .comm is the alignment. */
2248 if (*input_line_pointer
!= ',')
2252 ++input_line_pointer
;
2253 align
= get_absolute_expression ();
2256 as_warn ("ignoring bad alignment");
2275 /* The third argument to .lcomm appears to be the real local
2276 common symbol to create. References to the symbol named in
2277 the first argument are turned into references to the third
2279 if (*input_line_pointer
!= ',')
2281 as_bad ("missing real symbol name");
2282 ignore_rest_of_line ();
2285 ++input_line_pointer
;
2287 lcomm_name
= input_line_pointer
;
2288 lcomm_endc
= get_symbol_end ();
2290 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2292 *input_line_pointer
= lcomm_endc
;
2296 sym
= symbol_find_or_make (name
);
2299 if (S_IS_DEFINED (sym
)
2300 || S_GET_VALUE (sym
) != 0)
2302 as_bad ("attempt to redefine symbol");
2303 ignore_rest_of_line ();
2307 record_alignment (bss_section
, align
);
2310 || ! S_IS_DEFINED (lcomm_sym
))
2319 S_SET_EXTERNAL (sym
);
2323 lcomm_sym
->sy_tc
.output
= 1;
2324 def_sym
= lcomm_sym
;
2328 subseg_set (bss_section
, 1);
2329 frag_align (align
, 0);
2331 def_sym
->sy_frag
= frag_now
;
2332 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2333 def_size
, (char *) NULL
);
2335 S_SET_SEGMENT (def_sym
, bss_section
);
2336 def_sym
->sy_tc
.align
= align
;
2340 /* Align the size of lcomm_sym. */
2341 lcomm_sym
->sy_frag
->fr_offset
=
2342 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
2343 &~ ((1 << align
) - 1));
2344 if (align
> lcomm_sym
->sy_tc
.align
)
2345 lcomm_sym
->sy_tc
.align
= align
;
2350 /* Make sym an offset from lcomm_sym. */
2351 S_SET_SEGMENT (sym
, bss_section
);
2352 sym
->sy_frag
= lcomm_sym
->sy_frag
;
2353 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
2354 lcomm_sym
->sy_frag
->fr_offset
+= size
;
2357 subseg_set (current_seg
, current_subseg
);
2359 demand_empty_rest_of_line ();
2362 /* The .csect pseudo-op. This switches us into a different
2363 subsegment. The first argument is a symbol whose value is the
2364 start of the .csect. In COFF, csect symbols get special aux
2365 entries defined by the x_csect field of union internal_auxent. The
2366 optional second argument is the alignment (the default is 2). */
2376 name
= input_line_pointer
;
2377 endc
= get_symbol_end ();
2379 sym
= symbol_find_or_make (name
);
2381 *input_line_pointer
= endc
;
2383 if (S_GET_NAME (sym
)[0] == '\0')
2385 /* An unnamed csect is assumed to be [PR]. */
2386 sym
->sy_tc
.class = XMC_PR
;
2389 ppc_change_csect (sym
);
2391 if (*input_line_pointer
== ',')
2393 ++input_line_pointer
;
2394 sym
->sy_tc
.align
= get_absolute_expression ();
2397 demand_empty_rest_of_line ();
2400 /* Change to a different csect. */
2403 ppc_change_csect (sym
)
2406 if (S_IS_DEFINED (sym
))
2407 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
2414 /* This is a new csect. We need to look at the symbol class to
2415 figure out whether it should go in the text section or the
2418 switch (sym
->sy_tc
.class)
2428 S_SET_SEGMENT (sym
, text_section
);
2429 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
2430 ++ppc_text_subsegment
;
2431 list_ptr
= &ppc_text_csects
;
2440 if (ppc_toc_csect
!= NULL
2441 && ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
2443 S_SET_SEGMENT (sym
, data_section
);
2444 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
2445 ++ppc_data_subsegment
;
2446 list_ptr
= &ppc_data_csects
;
2452 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
2454 ppc_after_toc_frag
= frag_now
;
2456 sym
->sy_frag
= frag_now
;
2457 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2459 sym
->sy_tc
.align
= 2;
2460 sym
->sy_tc
.output
= 1;
2461 sym
->sy_tc
.within
= sym
;
2463 for (list
= *list_ptr
;
2464 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2465 list
= list
->sy_tc
.next
)
2467 list
->sy_tc
.next
= sym
;
2469 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2470 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2473 ppc_current_csect
= sym
;
2476 /* This function handles the .text and .data pseudo-ops. These
2477 pseudo-ops aren't really used by XCOFF; we implement them for the
2478 convenience of people who aren't used to XCOFF. */
2489 else if (type
== 'd')
2494 sym
= symbol_find_or_make (name
);
2496 ppc_change_csect (sym
);
2498 demand_empty_rest_of_line ();
2501 /* The .extern pseudo-op. We create an undefined symbol. */
2510 name
= input_line_pointer
;
2511 endc
= get_symbol_end ();
2513 (void) symbol_find_or_make (name
);
2515 *input_line_pointer
= endc
;
2517 demand_empty_rest_of_line ();
2520 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2530 name
= input_line_pointer
;
2531 endc
= get_symbol_end ();
2533 sym
= symbol_find_or_make (name
);
2535 *input_line_pointer
= endc
;
2537 sym
->sy_tc
.output
= 1;
2539 demand_empty_rest_of_line ();
2542 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2543 although I don't know why it bothers. */
2554 name
= input_line_pointer
;
2555 endc
= get_symbol_end ();
2557 sym
= symbol_find_or_make (name
);
2559 *input_line_pointer
= endc
;
2561 if (*input_line_pointer
!= ',')
2563 as_bad ("missing rename string");
2564 ignore_rest_of_line ();
2567 ++input_line_pointer
;
2569 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2571 demand_empty_rest_of_line ();
2574 /* The .stabx pseudo-op. This is similar to a normal .stabs
2575 pseudo-op, but slightly different. A sample is
2576 .stabx "main:F-1",.main,142,0
2577 The first argument is the symbol name to create. The second is the
2578 value, and the third is the storage class. The fourth seems to be
2579 always zero, and I am assuming it is the type. */
2590 name
= demand_copy_C_string (&len
);
2592 if (*input_line_pointer
!= ',')
2594 as_bad ("missing value");
2597 ++input_line_pointer
;
2599 ppc_stab_symbol
= true;
2600 sym
= symbol_make (name
);
2601 ppc_stab_symbol
= false;
2603 sym
->sy_tc
.real_name
= name
;
2605 (void) expression (&exp
);
2612 as_bad ("illegal .stabx expression; zero assumed");
2613 exp
.X_add_number
= 0;
2616 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2617 sym
->sy_frag
= &zero_address_frag
;
2621 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2622 sym
->sy_value
= exp
;
2626 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2627 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2632 /* The value is some complex expression. This will probably
2633 fail at some later point, but this is probably the right
2634 thing to do here. */
2635 sym
->sy_value
= exp
;
2639 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2640 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2642 if (*input_line_pointer
!= ',')
2644 as_bad ("missing class");
2647 ++input_line_pointer
;
2649 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2651 if (*input_line_pointer
!= ',')
2653 as_bad ("missing type");
2656 ++input_line_pointer
;
2658 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2660 sym
->sy_tc
.output
= 1;
2662 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2663 sym
->sy_tc
.within
= ppc_current_block
;
2665 if (exp
.X_op
!= O_symbol
2666 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2667 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2668 ppc_frob_label (sym
);
2671 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2672 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2673 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2674 ppc_current_csect
->sy_tc
.within
= sym
;
2677 demand_empty_rest_of_line ();
2680 /* The .function pseudo-op. This takes several arguments. The first
2681 argument seems to be the external name of the symbol. The second
2682 argment seems to be the label for the start of the function. gcc
2683 uses the same name for both. I have no idea what the third and
2684 fourth arguments are meant to be. The optional fifth argument is
2685 an expression for the size of the function. In COFF this symbol
2686 gets an aux entry like that used for a csect. */
2689 ppc_function (ignore
)
2698 name
= input_line_pointer
;
2699 endc
= get_symbol_end ();
2701 /* Ignore any [PR] suffix. */
2702 name
= ppc_canonicalize_symbol_name (name
);
2703 s
= strchr (name
, '[');
2704 if (s
!= (char *) NULL
2705 && strcmp (s
+ 1, "PR]") == 0)
2708 ext_sym
= symbol_find_or_make (name
);
2710 *input_line_pointer
= endc
;
2712 if (*input_line_pointer
!= ',')
2714 as_bad ("missing symbol name");
2715 ignore_rest_of_line ();
2718 ++input_line_pointer
;
2720 name
= input_line_pointer
;
2721 endc
= get_symbol_end ();
2723 lab_sym
= symbol_find_or_make (name
);
2725 *input_line_pointer
= endc
;
2727 if (ext_sym
!= lab_sym
)
2729 ext_sym
->sy_value
.X_op
= O_symbol
;
2730 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2731 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2732 ext_sym
->sy_value
.X_add_number
= 0;
2735 if (ext_sym
->sy_tc
.class == -1)
2736 ext_sym
->sy_tc
.class = XMC_PR
;
2737 ext_sym
->sy_tc
.output
= 1;
2739 if (*input_line_pointer
== ',')
2743 /* Ignore the third argument. */
2744 ++input_line_pointer
;
2745 expression (&ignore
);
2746 if (*input_line_pointer
== ',')
2748 /* Ignore the fourth argument. */
2749 ++input_line_pointer
;
2750 expression (&ignore
);
2751 if (*input_line_pointer
== ',')
2753 /* The fifth argument is the function size. */
2754 ++input_line_pointer
;
2755 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2758 &zero_address_frag
);
2759 pseudo_set (ext_sym
->sy_tc
.size
);
2764 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2765 SF_SET_FUNCTION (ext_sym
);
2766 SF_SET_PROCESS (ext_sym
);
2767 coff_add_linesym (ext_sym
);
2769 demand_empty_rest_of_line ();
2772 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2781 sym
= symbol_make (".bf");
2782 S_SET_SEGMENT (sym
, text_section
);
2783 sym
->sy_frag
= frag_now
;
2784 S_SET_VALUE (sym
, frag_now_fix ());
2785 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2787 coff_line_base
= get_absolute_expression ();
2789 S_SET_NUMBER_AUXILIARY (sym
, 1);
2790 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2792 sym
->sy_tc
.output
= 1;
2794 ppc_frob_label (sym
);
2796 demand_empty_rest_of_line ();
2799 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2800 ".ef", except that the line number is absolute, not relative to the
2801 most recent ".bf" symbol. */
2809 sym
= symbol_make (".ef");
2810 S_SET_SEGMENT (sym
, text_section
);
2811 sym
->sy_frag
= frag_now
;
2812 S_SET_VALUE (sym
, frag_now_fix ());
2813 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2814 S_SET_NUMBER_AUXILIARY (sym
, 1);
2815 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2816 sym
->sy_tc
.output
= 1;
2818 ppc_frob_label (sym
);
2820 demand_empty_rest_of_line ();
2823 /* The .bi and .ei pseudo-ops. These take a string argument and
2824 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2836 name
= demand_copy_C_string (&len
);
2838 /* The value of these symbols is actually file offset. Here we set
2839 the value to the index into the line number entries. In
2840 ppc_frob_symbols we set the fix_line field, which will cause BFD
2841 to do the right thing. */
2843 sym
= symbol_make (name
);
2844 /* obj-coff.c currently only handles line numbers correctly in the
2846 S_SET_SEGMENT (sym
, text_section
);
2847 S_SET_VALUE (sym
, coff_n_line_nos
);
2848 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2850 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2851 sym
->sy_tc
.output
= 1;
2853 for (look
= symbol_rootP
;
2854 (look
!= (symbolS
*) NULL
2855 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2856 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2857 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2858 look
= symbol_next (look
))
2860 if (look
!= (symbolS
*) NULL
)
2862 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2863 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2866 demand_empty_rest_of_line ();
2869 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2870 There is one argument, which is a csect symbol. The value of the
2871 .bs symbol is the index of this csect symbol. */
2882 if (ppc_current_block
!= NULL
)
2883 as_bad ("nested .bs blocks");
2885 name
= input_line_pointer
;
2886 endc
= get_symbol_end ();
2888 csect
= symbol_find_or_make (name
);
2890 *input_line_pointer
= endc
;
2892 sym
= symbol_make (".bs");
2893 S_SET_SEGMENT (sym
, now_seg
);
2894 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2895 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2896 sym
->sy_tc
.output
= 1;
2898 sym
->sy_tc
.within
= csect
;
2900 ppc_frob_label (sym
);
2902 ppc_current_block
= sym
;
2904 demand_empty_rest_of_line ();
2907 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2915 if (ppc_current_block
== NULL
)
2916 as_bad (".es without preceding .bs");
2918 sym
= symbol_make (".es");
2919 S_SET_SEGMENT (sym
, now_seg
);
2920 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2921 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2922 sym
->sy_tc
.output
= 1;
2924 ppc_frob_label (sym
);
2926 ppc_current_block
= NULL
;
2928 demand_empty_rest_of_line ();
2931 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2940 sym
= symbol_make (".bb");
2941 S_SET_SEGMENT (sym
, text_section
);
2942 sym
->sy_frag
= frag_now
;
2943 S_SET_VALUE (sym
, frag_now_fix ());
2944 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2946 S_SET_NUMBER_AUXILIARY (sym
, 1);
2947 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2949 sym
->sy_tc
.output
= 1;
2951 SF_SET_PROCESS (sym
);
2953 ppc_frob_label (sym
);
2955 demand_empty_rest_of_line ();
2958 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2967 sym
= symbol_make (".eb");
2968 S_SET_SEGMENT (sym
, text_section
);
2969 sym
->sy_frag
= frag_now
;
2970 S_SET_VALUE (sym
, frag_now_fix ());
2971 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2972 S_SET_NUMBER_AUXILIARY (sym
, 1);
2973 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2974 sym
->sy_tc
.output
= 1;
2976 SF_SET_PROCESS (sym
);
2978 ppc_frob_label (sym
);
2980 demand_empty_rest_of_line ();
2983 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
2994 name
= demand_copy_C_string (&len
);
2995 sym
= symbol_make (name
);
2996 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2997 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2998 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
2999 S_SET_VALUE (sym
, 0);
3000 sym
->sy_tc
.output
= 1;
3002 ppc_frob_label (sym
);
3004 demand_empty_rest_of_line ();
3007 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3015 sym
= symbol_make (".ec");
3016 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3017 sym
->bsym
->flags
|= BSF_DEBUGGING
;
3018 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3019 S_SET_VALUE (sym
, 0);
3020 sym
->sy_tc
.output
= 1;
3022 ppc_frob_label (sym
);
3024 demand_empty_rest_of_line ();
3027 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3033 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3034 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
3041 subseg
= ppc_data_subsegment
;
3042 ++ppc_data_subsegment
;
3044 subseg_new (segment_name (data_section
), subseg
);
3045 ppc_toc_frag
= frag_now
;
3047 sym
= symbol_find_or_make ("TOC[TC0]");
3048 sym
->sy_frag
= frag_now
;
3049 S_SET_SEGMENT (sym
, data_section
);
3050 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3051 sym
->sy_tc
.subseg
= subseg
;
3052 sym
->sy_tc
.output
= 1;
3053 sym
->sy_tc
.within
= sym
;
3055 ppc_toc_csect
= sym
;
3057 for (list
= ppc_data_csects
;
3058 list
->sy_tc
.next
!= (symbolS
*) NULL
;
3059 list
= list
->sy_tc
.next
)
3061 list
->sy_tc
.next
= sym
;
3063 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3064 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
3067 ppc_current_csect
= ppc_toc_csect
;
3069 demand_empty_rest_of_line ();
3072 /* The AIX assembler automatically aligns the operands of a .long or
3073 .short pseudo-op, and we want to be compatible. */
3076 ppc_xcoff_cons (log_size
)
3079 frag_align (log_size
, 0);
3080 record_alignment (now_seg
, log_size
);
3081 cons (1 << log_size
);
3084 #endif /* OBJ_XCOFF */
3086 /* The .tc pseudo-op. This is used when generating either XCOFF or
3087 ELF. This takes two or more arguments.
3089 When generating XCOFF output, the first argument is the name to
3090 give to this location in the toc; this will be a symbol with class
3091 TC. The rest of the arguments are 4 byte values to actually put at
3092 this location in the TOC; often there is just one more argument, a
3093 relocateable symbol reference.
3095 When not generating XCOFF output, the arguments are the same, but
3096 the first argument is simply ignored. */
3104 /* Define the TOC symbol name. */
3110 if (ppc_toc_csect
== (symbolS
*) NULL
3111 || ppc_toc_csect
!= ppc_current_csect
)
3113 as_bad (".tc not in .toc section");
3114 ignore_rest_of_line ();
3118 name
= input_line_pointer
;
3119 endc
= get_symbol_end ();
3121 sym
= symbol_find_or_make (name
);
3123 *input_line_pointer
= endc
;
3125 if (S_IS_DEFINED (sym
))
3129 label
= ppc_current_csect
->sy_tc
.within
;
3130 if (label
->sy_tc
.class != XMC_TC0
)
3132 as_bad (".tc with no label");
3133 ignore_rest_of_line ();
3137 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3138 label
->sy_frag
= sym
->sy_frag
;
3139 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3141 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3142 ++input_line_pointer
;
3147 S_SET_SEGMENT (sym
, now_seg
);
3148 sym
->sy_frag
= frag_now
;
3149 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3150 sym
->sy_tc
.class = XMC_TC
;
3151 sym
->sy_tc
.output
= 1;
3153 ppc_frob_label (sym
);
3156 #else /* ! defined (OBJ_XCOFF) */
3158 /* Skip the TOC symbol name. */
3159 while (is_part_of_name (*input_line_pointer
)
3160 || *input_line_pointer
== '['
3161 || *input_line_pointer
== ']'
3162 || *input_line_pointer
== '{'
3163 || *input_line_pointer
== '}')
3164 ++input_line_pointer
;
3166 /* Align to a four byte boundary. */
3168 record_alignment (now_seg
, 2);
3170 #endif /* ! defined (OBJ_XCOFF) */
3172 if (*input_line_pointer
!= ',')
3173 demand_empty_rest_of_line ();
3176 ++input_line_pointer
;
3183 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3185 /* Set the current section. */
3187 ppc_set_current_section (new)
3190 ppc_previous_section
= ppc_current_section
;
3191 ppc_current_section
= new;
3194 /* pseudo-op: .previous
3195 behaviour: toggles the current section with the previous section.
3197 warnings: "No previous section"
3200 ppc_previous(ignore
)
3205 if (ppc_previous_section
== NULL
)
3207 as_warn("No previous section to return to. Directive ignored.");
3211 subseg_set(ppc_previous_section
, 0);
3213 ppc_set_current_section(ppc_previous_section
);
3216 /* pseudo-op: .pdata
3217 behaviour: predefined read only data section
3221 initial: .section .pdata "adr3"
3222 a - don't know -- maybe a misprint
3223 d - initialized data
3225 3 - double word aligned (that would be 4 byte boundary)
3228 Tag index tables (also known as the function table) for exception
3229 handling, debugging, etc.
3236 if (pdata_section
== 0)
3238 pdata_section
= subseg_new (".pdata", 0);
3240 bfd_set_section_flags (stdoutput
, pdata_section
,
3241 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3242 | SEC_READONLY
| SEC_DATA
));
3244 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3248 pdata_section
= subseg_new(".pdata", 0);
3250 ppc_set_current_section(pdata_section
);
3253 /* pseudo-op: .ydata
3254 behaviour: predefined read only data section
3258 initial: .section .ydata "drw3"
3259 a - don't know -- maybe a misprint
3260 d - initialized data
3262 3 - double word aligned (that would be 4 byte boundary)
3264 Tag tables (also known as the scope table) for exception handling,
3271 if (ydata_section
== 0)
3273 ydata_section
= subseg_new (".ydata", 0);
3274 bfd_set_section_flags (stdoutput
, ydata_section
,
3275 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3276 | SEC_READONLY
| SEC_DATA
));
3278 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3282 ydata_section
= subseg_new (".ydata", 0);
3284 ppc_set_current_section(ydata_section
);
3287 /* pseudo-op: .reldata
3288 behaviour: predefined read write data section
3289 double word aligned (4-byte)
3290 FIXME: relocation is applied to it
3291 FIXME: what's the difference between this and .data?
3294 initial: .section .reldata "drw3"
3295 d - initialized data
3298 3 - double word aligned (that would be 8 byte boundary)
3301 Like .data, but intended to hold data subject to relocation, such as
3302 function descriptors, etc.
3308 if (reldata_section
== 0)
3310 reldata_section
= subseg_new (".reldata", 0);
3312 bfd_set_section_flags (stdoutput
, reldata_section
,
3313 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3316 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3320 reldata_section
= subseg_new (".reldata", 0);
3322 ppc_set_current_section(reldata_section
);
3325 /* pseudo-op: .rdata
3326 behaviour: predefined read only data section
3330 initial: .section .rdata "dr3"
3331 d - initialized data
3333 3 - double word aligned (that would be 4 byte boundary)
3339 if (rdata_section
== 0)
3341 rdata_section
= subseg_new (".rdata", 0);
3342 bfd_set_section_flags (stdoutput
, rdata_section
,
3343 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3344 | SEC_READONLY
| SEC_DATA
));
3346 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3350 rdata_section
= subseg_new (".rdata", 0);
3352 ppc_set_current_section(rdata_section
);
3355 /* pseudo-op: .ualong
3356 behaviour: much like .int, with the exception that no alignment is
3358 FIXME: test the alignment statement
3370 /* pseudo-op: .znop <symbol name>
3371 behaviour: Issue a nop instruction
3372 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3373 the supplied symbol name.
3375 warnings: Missing symbol name
3382 const struct powerpc_opcode
*opcode
;
3388 /* Strip out the symbol name */
3396 symbol_name
= input_line_pointer
;
3397 c
= get_symbol_end ();
3399 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3400 strcpy (name
, symbol_name
);
3402 sym
= symbol_find_or_make (name
);
3404 *input_line_pointer
= c
;
3408 /* Look up the opcode in the hash table. */
3409 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3411 /* stick in the nop */
3412 insn
= opcode
->opcode
;
3414 /* Write out the instruction. */
3416 md_number_to_chars (f
, insn
, 4);
3418 f
- frag_now
->fr_literal
,
3423 BFD_RELOC_16_GOT_PCREL
);
3436 register char *name
;
3440 register symbolS
*symbolP
;
3443 name
= input_line_pointer
;
3444 c
= get_symbol_end ();
3446 /* just after name is now '\0' */
3447 p
= input_line_pointer
;
3450 if (*input_line_pointer
!= ',')
3452 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3453 ignore_rest_of_line ();
3457 input_line_pointer
++; /* skip ',' */
3458 if ((temp
= get_absolute_expression ()) < 0)
3460 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
3461 ignore_rest_of_line ();
3467 /* The third argument to .comm is the alignment. */
3468 if (*input_line_pointer
!= ',')
3472 ++input_line_pointer
;
3473 align
= get_absolute_expression ();
3476 as_warn ("ignoring bad alignment");
3483 symbolP
= symbol_find_or_make (name
);
3486 if (S_IS_DEFINED (symbolP
))
3488 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3489 S_GET_NAME (symbolP
));
3490 ignore_rest_of_line ();
3494 if (S_GET_VALUE (symbolP
))
3496 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3497 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3498 S_GET_NAME (symbolP
),
3499 (long) S_GET_VALUE (symbolP
),
3504 S_SET_VALUE (symbolP
, (valueT
) temp
);
3505 S_SET_EXTERNAL (symbolP
);
3508 demand_empty_rest_of_line ();
3512 * implement the .section pseudo op:
3513 * .section name {, "flags"}
3515 * | +--- optional flags: 'b' for bss
3517 * +-- section name 'l' for lib
3521 * 'd' (apparently m88k for data)
3523 * But if the argument is not a quoted string, treat it as a
3524 * subsegment number.
3526 * FIXME: this is a copy of the section processing from obj-coff.c, with
3527 * additions/changes for the moto-pas assembler support. There are three
3530 * FIXME: I just noticed this. This doesn't work at all really. It it
3531 * setting bits that bfd probably neither understands or uses. The
3532 * correct approach (?) will have to incorporate extra fields attached
3533 * to the section to hold the system specific stuff. (krk)
3536 * 'a' - unknown - referred to in documentation, but no definition supplied
3537 * 'c' - section has code
3538 * 'd' - section has initialized data
3539 * 'u' - section has uninitialized data
3540 * 'i' - section contains directives (info)
3541 * 'n' - section can be discarded
3542 * 'R' - remove section at link time
3544 * Section Protection:
3545 * 'r' - section is readable
3546 * 'w' - section is writeable
3547 * 'x' - section is executable
3548 * 's' - section is sharable
3550 * Section Alignment:
3551 * '0' - align to byte boundary
3552 * '1' - align to halfword undary
3553 * '2' - align to word boundary
3554 * '3' - align to doubleword boundary
3555 * '4' - align to quadword boundary
3556 * '5' - align to 32 byte boundary
3557 * '6' - align to 64 byte boundary
3562 ppc_pe_section (ignore
)
3565 /* Strip out the section name */
3574 section_name
= input_line_pointer
;
3575 c
= get_symbol_end ();
3577 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3578 strcpy (name
, section_name
);
3580 *input_line_pointer
= c
;
3585 flags
= SEC_NO_FLAGS
;
3587 if (strcmp (name
, ".idata$2") == 0)
3591 else if (strcmp (name
, ".idata$3") == 0)
3595 else if (strcmp (name
, ".idata$4") == 0)
3599 else if (strcmp (name
, ".idata$5") == 0)
3603 else if (strcmp (name
, ".idata$6") == 0)
3608 align
= 4; /* default alignment to 16 byte boundary */
3610 if (*input_line_pointer
== ',')
3612 ++input_line_pointer
;
3614 if (*input_line_pointer
!= '"')
3615 exp
= get_absolute_expression ();
3618 ++input_line_pointer
;
3619 while (*input_line_pointer
!= '"'
3620 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3622 switch (*input_line_pointer
)
3624 /* Section Contents */
3625 case 'a': /* unknown */
3626 as_bad ("Unsupported section attribute -- 'a'");
3628 case 'c': /* code section */
3631 case 'd': /* section has initialized data */
3634 case 'u': /* section has uninitialized data */
3635 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3639 case 'i': /* section contains directives (info) */
3640 /* FIXME: This is IMAGE_SCN_LNK_INFO
3642 flags
|= SEC_HAS_CONTENTS
;
3644 case 'n': /* section can be discarded */
3647 case 'R': /* Remove section at link time */
3648 flags
|= SEC_NEVER_LOAD
;
3651 /* Section Protection */
3652 case 'r': /* section is readable */
3653 flags
|= IMAGE_SCN_MEM_READ
;
3655 case 'w': /* section is writeable */
3656 flags
|= IMAGE_SCN_MEM_WRITE
;
3658 case 'x': /* section is executable */
3659 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3661 case 's': /* section is sharable */
3662 flags
|= IMAGE_SCN_MEM_SHARED
;
3665 /* Section Alignment */
3666 case '0': /* align to byte boundary */
3667 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3670 case '1': /* align to halfword boundary */
3671 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3674 case '2': /* align to word boundary */
3675 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3678 case '3': /* align to doubleword boundary */
3679 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3682 case '4': /* align to quadword boundary */
3683 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3686 case '5': /* align to 32 byte boundary */
3687 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3690 case '6': /* align to 64 byte boundary */
3691 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3696 as_bad("unknown section attribute '%c'",
3697 *input_line_pointer
);
3700 ++input_line_pointer
;
3702 if (*input_line_pointer
== '"')
3703 ++input_line_pointer
;
3707 sec
= subseg_new (name
, (subsegT
) exp
);
3709 ppc_set_current_section(sec
);
3711 if (flags
!= SEC_NO_FLAGS
)
3713 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3714 as_bad ("error setting flags for \"%s\": %s",
3715 bfd_section_name (stdoutput
, sec
),
3716 bfd_errmsg (bfd_get_error ()));
3719 bfd_set_section_alignment(stdoutput
, sec
, align
);
3724 ppc_pe_function (ignore
)
3731 name
= input_line_pointer
;
3732 endc
= get_symbol_end ();
3734 ext_sym
= symbol_find_or_make (name
);
3736 *input_line_pointer
= endc
;
3738 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3739 SF_SET_FUNCTION (ext_sym
);
3740 SF_SET_PROCESS (ext_sym
);
3741 coff_add_linesym (ext_sym
);
3743 demand_empty_rest_of_line ();
3747 ppc_pe_tocd (ignore
)
3750 if (tocdata_section
== 0)
3752 tocdata_section
= subseg_new (".tocd", 0);
3753 /* FIXME: section flags won't work */
3754 bfd_set_section_flags (stdoutput
, tocdata_section
,
3755 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3756 | SEC_READONLY
| SEC_DATA
));
3758 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3762 rdata_section
= subseg_new (".tocd", 0);
3765 ppc_set_current_section(tocdata_section
);
3767 demand_empty_rest_of_line ();
3770 /* Don't adjust TOC relocs to use the section symbol. */
3773 ppc_pe_fix_adjustable (fix
)
3776 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3783 /* XCOFF specific symbol and file handling. */
3785 /* Canonicalize the symbol name. We use the to force the suffix, if
3786 any, to use square brackets, and to be in upper case. */
3789 ppc_canonicalize_symbol_name (name
)
3794 if (ppc_stab_symbol
)
3797 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3811 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3815 if (*s
== '\0' || s
[1] != '\0')
3816 as_bad ("bad symbol suffix");
3824 /* Set the class of a symbol based on the suffix, if any. This is
3825 called whenever a new symbol is created. */
3828 ppc_symbol_new_hook (sym
)
3833 sym
->sy_tc
.next
= NULL
;
3834 sym
->sy_tc
.output
= 0;
3835 sym
->sy_tc
.class = -1;
3836 sym
->sy_tc
.real_name
= NULL
;
3837 sym
->sy_tc
.subseg
= 0;
3838 sym
->sy_tc
.align
= 0;
3839 sym
->sy_tc
.size
= NULL
;
3840 sym
->sy_tc
.within
= NULL
;
3842 if (ppc_stab_symbol
)
3845 s
= strchr (S_GET_NAME (sym
), '[');
3846 if (s
== (const char *) NULL
)
3848 /* There is no suffix. */
3857 if (strcmp (s
, "BS]") == 0)
3858 sym
->sy_tc
.class = XMC_BS
;
3861 if (strcmp (s
, "DB]") == 0)
3862 sym
->sy_tc
.class = XMC_DB
;
3863 else if (strcmp (s
, "DS]") == 0)
3864 sym
->sy_tc
.class = XMC_DS
;
3867 if (strcmp (s
, "GL]") == 0)
3868 sym
->sy_tc
.class = XMC_GL
;
3871 if (strcmp (s
, "PR]") == 0)
3872 sym
->sy_tc
.class = XMC_PR
;
3875 if (strcmp (s
, "RO]") == 0)
3876 sym
->sy_tc
.class = XMC_RO
;
3877 else if (strcmp (s
, "RW]") == 0)
3878 sym
->sy_tc
.class = XMC_RW
;
3881 if (strcmp (s
, "SV]") == 0)
3882 sym
->sy_tc
.class = XMC_SV
;
3885 if (strcmp (s
, "TC]") == 0)
3886 sym
->sy_tc
.class = XMC_TC
;
3887 else if (strcmp (s
, "TI]") == 0)
3888 sym
->sy_tc
.class = XMC_TI
;
3889 else if (strcmp (s
, "TB]") == 0)
3890 sym
->sy_tc
.class = XMC_TB
;
3891 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3892 sym
->sy_tc
.class = XMC_TC0
;
3895 if (strcmp (s
, "UA]") == 0)
3896 sym
->sy_tc
.class = XMC_UA
;
3897 else if (strcmp (s
, "UC]") == 0)
3898 sym
->sy_tc
.class = XMC_UC
;
3901 if (strcmp (s
, "XO]") == 0)
3902 sym
->sy_tc
.class = XMC_XO
;
3906 if (sym
->sy_tc
.class == -1)
3907 as_bad ("Unrecognized symbol suffix");
3910 /* Set the class of a label based on where it is defined. This
3911 handles symbols without suffixes. Also, move the symbol so that it
3912 follows the csect symbol. */
3915 ppc_frob_label (sym
)
3918 if (ppc_current_csect
!= (symbolS
*) NULL
)
3920 if (sym
->sy_tc
.class == -1)
3921 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3923 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3924 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3926 ppc_current_csect
->sy_tc
.within
= sym
;
3930 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3931 seen. It tells ppc_adjust_symtab whether it needs to look through
3934 static boolean ppc_saw_abs
;
3936 /* Change the name of a symbol just before writing it out. Set the
3937 real name if the .rename pseudo-op was used. Otherwise, remove any
3938 class suffix. Return 1 if the symbol should not be included in the
3942 ppc_frob_symbol (sym
)
3945 static symbolS
*ppc_last_function
;
3946 static symbolS
*set_end
;
3948 /* Discard symbols that should not be included in the output symbol
3950 if (! sym
->sy_used_in_reloc
3951 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3952 || (! S_IS_EXTERNAL (sym
)
3953 && ! sym
->sy_tc
.output
3954 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3957 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3958 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3964 name
= S_GET_NAME (sym
);
3965 s
= strchr (name
, '[');
3966 if (s
!= (char *) NULL
)
3972 snew
= xmalloc (len
+ 1);
3973 memcpy (snew
, name
, len
);
3976 S_SET_NAME (sym
, snew
);
3980 if (set_end
!= (symbolS
*) NULL
)
3982 SA_SET_SYM_ENDNDX (set_end
, sym
);
3986 if (SF_GET_FUNCTION (sym
))
3988 if (ppc_last_function
!= (symbolS
*) NULL
)
3989 as_bad ("two .function pseudo-ops with no intervening .ef");
3990 ppc_last_function
= sym
;
3991 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3993 resolve_symbol_value (sym
->sy_tc
.size
);
3994 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3997 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3998 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4000 if (ppc_last_function
== (symbolS
*) NULL
)
4001 as_bad (".ef with no preceding .function");
4004 set_end
= ppc_last_function
;
4005 ppc_last_function
= NULL
;
4007 /* We don't have a C_EFCN symbol, but we need to force the
4008 COFF backend to believe that it has seen one. */
4009 coff_last_function
= NULL
;
4013 if (! S_IS_EXTERNAL (sym
)
4014 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
4015 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4016 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4017 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4018 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4019 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4020 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4021 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4022 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4023 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4025 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4026 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4029 union internal_auxent
*a
;
4031 /* Create a csect aux. */
4032 i
= S_GET_NUMBER_AUXILIARY (sym
);
4033 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4034 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
4035 if (sym
->sy_tc
.class == XMC_TC0
)
4037 /* This is the TOC table. */
4038 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4039 a
->x_csect
.x_scnlen
.l
= 0;
4040 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4042 else if (sym
->sy_tc
.subseg
!= 0)
4044 /* This is a csect symbol. x_scnlen is the size of the
4046 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
4047 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4048 S_GET_SEGMENT (sym
))
4049 - S_GET_VALUE (sym
));
4052 resolve_symbol_value (sym
->sy_tc
.next
);
4053 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
4054 - S_GET_VALUE (sym
));
4056 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
4058 else if (S_GET_SEGMENT (sym
) == bss_section
)
4060 /* This is a common symbol. */
4061 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
4062 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
4063 if (S_IS_EXTERNAL (sym
))
4064 sym
->sy_tc
.class = XMC_RW
;
4066 sym
->sy_tc
.class = XMC_BS
;
4068 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4070 /* This is an absolute symbol. The csect will be created by
4071 ppc_adjust_symtab. */
4073 a
->x_csect
.x_smtyp
= XTY_LD
;
4074 if (sym
->sy_tc
.class == -1)
4075 sym
->sy_tc
.class = XMC_XO
;
4077 else if (! S_IS_DEFINED (sym
))
4079 /* This is an external symbol. */
4080 a
->x_csect
.x_scnlen
.l
= 0;
4081 a
->x_csect
.x_smtyp
= XTY_ER
;
4083 else if (sym
->sy_tc
.class == XMC_TC
)
4087 /* This is a TOC definition. x_scnlen is the size of the
4089 next
= symbol_next (sym
);
4090 while (next
->sy_tc
.class == XMC_TC0
)
4091 next
= symbol_next (next
);
4092 if (next
== (symbolS
*) NULL
4093 || next
->sy_tc
.class != XMC_TC
)
4095 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4096 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4098 - S_GET_VALUE (sym
));
4100 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4101 - S_GET_VALUE (sym
));
4105 resolve_symbol_value (next
);
4106 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4107 - S_GET_VALUE (sym
));
4109 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4115 /* This is a normal symbol definition. x_scnlen is the
4116 symbol index of the containing csect. */
4117 if (S_GET_SEGMENT (sym
) == text_section
)
4118 csect
= ppc_text_csects
;
4119 else if (S_GET_SEGMENT (sym
) == data_section
)
4120 csect
= ppc_data_csects
;
4124 /* Skip the initial dummy symbol. */
4125 csect
= csect
->sy_tc
.next
;
4127 if (csect
== (symbolS
*) NULL
)
4129 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym
));
4130 a
->x_csect
.x_scnlen
.l
= 0;
4134 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
4136 resolve_symbol_value (csect
->sy_tc
.next
);
4137 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
4139 csect
= csect
->sy_tc
.next
;
4142 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4143 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
4145 a
->x_csect
.x_smtyp
= XTY_LD
;
4148 a
->x_csect
.x_parmhash
= 0;
4149 a
->x_csect
.x_snhash
= 0;
4150 if (sym
->sy_tc
.class == -1)
4151 a
->x_csect
.x_smclas
= XMC_PR
;
4153 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
4154 a
->x_csect
.x_stab
= 0;
4155 a
->x_csect
.x_snstab
= 0;
4157 /* Don't let the COFF backend resort these symbols. */
4158 sym
->bsym
->flags
|= BSF_NOT_AT_END
;
4160 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4162 /* We want the value to be the symbol index of the referenced
4163 csect symbol. BFD will do that for us if we set the right
4166 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
4167 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
4169 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4174 /* The value is the offset from the enclosing csect. */
4175 block
= sym
->sy_tc
.within
;
4176 csect
= block
->sy_tc
.within
;
4177 resolve_symbol_value (csect
);
4178 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4180 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4181 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4183 /* We want the value to be a file offset into the line numbers.
4184 BFD will do that for us if we set the right flags. We have
4185 already set the value correctly. */
4186 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
4192 /* Adjust the symbol table. This creates csect symbols for all
4193 absolute symbols. */
4196 ppc_adjust_symtab ()
4203 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4207 union internal_auxent
*a
;
4209 if (S_GET_SEGMENT (sym
) != absolute_section
)
4212 csect
= symbol_create (".abs[XO]", absolute_section
,
4213 S_GET_VALUE (sym
), &zero_address_frag
);
4214 csect
->bsym
->value
= S_GET_VALUE (sym
);
4215 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4216 i
= S_GET_NUMBER_AUXILIARY (csect
);
4217 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4218 a
= &coffsymbol (csect
->bsym
)->native
[i
+ 1].u
.auxent
;
4219 a
->x_csect
.x_scnlen
.l
= 0;
4220 a
->x_csect
.x_smtyp
= XTY_SD
;
4221 a
->x_csect
.x_parmhash
= 0;
4222 a
->x_csect
.x_snhash
= 0;
4223 a
->x_csect
.x_smclas
= XMC_XO
;
4224 a
->x_csect
.x_stab
= 0;
4225 a
->x_csect
.x_snstab
= 0;
4227 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4229 i
= S_GET_NUMBER_AUXILIARY (sym
);
4230 a
= &coffsymbol (sym
->bsym
)->native
[i
].u
.auxent
;
4231 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4232 coffsymbol (sym
->bsym
)->native
[i
].fix_scnlen
= 1;
4235 ppc_saw_abs
= false;
4238 /* Set the VMA for a section. This is called on all the sections in
4242 ppc_frob_section (sec
)
4245 static bfd_size_type vma
= 0;
4247 bfd_set_section_vma (stdoutput
, sec
, vma
);
4248 vma
+= bfd_section_size (stdoutput
, sec
);
4251 #endif /* OBJ_XCOFF */
4253 /* Turn a string in input_line_pointer into a floating point constant
4254 of type type, and store the appropriate bytes in *litp. The number
4255 of LITTLENUMS emitted is stored in *sizep . An error message is
4256 returned, or NULL on OK. */
4259 md_atof (type
, litp
, sizep
)
4265 LITTLENUM_TYPE words
[4];
4281 return "bad call to md_atof";
4284 t
= atof_ieee (input_line_pointer
, type
, words
);
4286 input_line_pointer
= t
;
4290 if (target_big_endian
)
4292 for (i
= 0; i
< prec
; i
++)
4294 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4300 for (i
= prec
- 1; i
>= 0; i
--)
4302 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4310 /* Write a value out to the object file, using the appropriate
4314 md_number_to_chars (buf
, val
, n
)
4319 if (target_big_endian
)
4320 number_to_chars_bigendian (buf
, val
, n
);
4322 number_to_chars_littleendian (buf
, val
, n
);
4325 /* Align a section (I don't know why this is machine dependent). */
4328 md_section_align (seg
, addr
)
4332 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4334 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4337 /* We don't have any form of relaxing. */
4340 md_estimate_size_before_relax (fragp
, seg
)
4348 /* Convert a machine dependent frag. We never generate these. */
4351 md_convert_frag (abfd
, sec
, fragp
)
4359 /* We have no need to default values of symbols. */
4363 md_undefined_symbol (name
)
4369 /* Functions concerning relocs. */
4371 /* The location from which a PC relative jump should be calculated,
4372 given a PC relative reloc. */
4375 md_pcrel_from_section (fixp
, sec
)
4380 if (fixp
->fx_addsy
!= (symbolS
*) NULL
4381 && (! S_IS_DEFINED (fixp
->fx_addsy
)
4382 || TC_FORCE_RELOCATION_SECTION (fixp
, sec
)))
4386 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4391 /* This is called to see whether a fixup should be adjusted to use a
4392 section symbol. We take the opportunity to change a fixup against
4393 a symbol in the TOC subsegment into a reloc against the
4394 corresponding .tc symbol. */
4397 ppc_fix_adjustable (fix
)
4402 resolve_symbol_value (fix
->fx_addsy
);
4403 val
= S_GET_VALUE (fix
->fx_addsy
);
4404 if (ppc_toc_csect
!= (symbolS
*) NULL
4405 && fix
->fx_addsy
!= (symbolS
*) NULL
4406 && fix
->fx_addsy
!= ppc_toc_csect
4407 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4408 && val
>= ppc_toc_frag
->fr_address
4409 && (ppc_after_toc_frag
== (fragS
*) NULL
4410 || val
< ppc_after_toc_frag
->fr_address
))
4414 for (sy
= symbol_next (ppc_toc_csect
);
4415 sy
!= (symbolS
*) NULL
;
4416 sy
= symbol_next (sy
))
4418 if (sy
->sy_tc
.class == XMC_TC0
)
4420 if (sy
->sy_tc
.class != XMC_TC
)
4422 resolve_symbol_value (sy
);
4423 if (val
== S_GET_VALUE (sy
))
4426 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4431 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4432 "symbol in .toc does not match any .tc");
4435 /* Possibly adjust the reloc to be against the csect. */
4436 if (fix
->fx_addsy
!= (symbolS
*) NULL
4437 && fix
->fx_addsy
->sy_tc
.subseg
== 0
4438 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
4439 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
4440 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
4444 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4445 csect
= ppc_text_csects
;
4446 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4447 csect
= ppc_data_csects
;
4451 /* Skip the initial dummy symbol. */
4452 csect
= csect
->sy_tc
.next
;
4454 if (csect
!= (symbolS
*) NULL
)
4456 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
4457 && (csect
->sy_tc
.next
->sy_frag
->fr_address
4458 <= fix
->fx_addsy
->sy_frag
->fr_address
))
4459 csect
= csect
->sy_tc
.next
;
4461 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4462 - csect
->sy_frag
->fr_address
);
4463 fix
->fx_addsy
= csect
;
4467 /* Adjust a reloc against a .lcomm symbol to be against the base
4469 if (fix
->fx_addsy
!= (symbolS
*) NULL
4470 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4471 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4473 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
4474 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4475 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
4476 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
4482 /* A reloc from one csect to another must be kept. The assembler
4483 will, of course, keep relocs between sections, and it will keep
4484 absolute relocs, but we need to force it to keep PC relative relocs
4485 between two csects in the same section. */
4488 ppc_force_relocation (fix
)
4491 /* At this point fix->fx_addsy should already have been converted to
4492 a csect symbol. If the csect does not include the fragment, then
4493 we need to force the relocation. */
4495 && fix
->fx_addsy
!= NULL
4496 && fix
->fx_addsy
->sy_tc
.subseg
!= 0
4497 && (fix
->fx_addsy
->sy_frag
->fr_address
> fix
->fx_frag
->fr_address
4498 || (fix
->fx_addsy
->sy_tc
.next
!= NULL
4499 && (fix
->fx_addsy
->sy_tc
.next
->sy_frag
->fr_address
4500 <= fix
->fx_frag
->fr_address
))))
4506 #endif /* OBJ_XCOFF */
4508 /* See whether a symbol is in the TOC section. */
4511 ppc_is_toc_sym (sym
)
4515 return sym
->sy_tc
.class == XMC_TC
;
4517 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4521 /* Apply a fixup to the object code. This is called for all the
4522 fixups we generated by the call to fix_new_exp, above. In the call
4523 above we used a reloc code which was the largest legal reloc code
4524 plus the operand index. Here we undo that to recover the operand
4525 index. At this point all symbol values should be fully resolved,
4526 and we attempt to completely resolve the reloc. If we can not do
4527 that, we determine the correct reloc code and put it back in the
4531 md_apply_fix3 (fixp
, valuep
, seg
)
4538 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4539 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4540 doing this relocation the code in write.c is going to call
4541 bfd_perform_relocation, which is also going to use the symbol
4542 value. That means that if the reloc is fully resolved we want to
4543 use *valuep since bfd_perform_relocation is not being used.
4544 However, if the reloc is not fully resolved we do not want to use
4545 *valuep, and must use fx_offset instead. However, if the reloc
4546 is PC relative, we do want to use *valuep since it includes the
4547 result of md_pcrel_from. This is confusing. */
4549 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4554 else if (fixp
->fx_pcrel
)
4558 value
= fixp
->fx_offset
;
4559 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4561 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4562 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4565 /* We can't actually support subtracting a symbol. */
4566 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4567 "expression too complex");
4572 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4575 const struct powerpc_operand
*operand
;
4579 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4581 operand
= &powerpc_operands
[opindex
];
4584 /* It appears that an instruction like
4586 when LC..1 is not a TOC symbol does not generate a reloc. It
4587 uses the offset of LC..1 within its csect. However, .long
4588 LC..1 will generate a reloc. I can't find any documentation
4589 on how these cases are to be distinguished, so this is a wild
4590 guess. These cases are generated by gcc -mminimal-toc. */
4591 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4592 && operand
->bits
== 16
4593 && operand
->shift
== 0
4594 && operand
->insert
== NULL
4595 && fixp
->fx_addsy
!= NULL
4596 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
4597 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
4598 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
4599 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4601 value
= fixp
->fx_offset
;
4606 /* Fetch the instruction, insert the fully resolved operand
4607 value, and stuff the instruction back again. */
4608 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4609 if (target_big_endian
)
4610 insn
= bfd_getb32 ((unsigned char *) where
);
4612 insn
= bfd_getl32 ((unsigned char *) where
);
4613 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4614 fixp
->fx_file
, fixp
->fx_line
);
4615 if (target_big_endian
)
4616 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4618 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4622 /* Nothing else to do here. */
4626 /* Determine a BFD reloc value based on the operand information.
4627 We are only prepared to turn a few of the operands into
4629 FIXME: We need to handle the DS field at the very least.
4630 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4631 there should be a new field in the operand table. */
4632 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4633 && operand
->bits
== 26
4634 && operand
->shift
== 0)
4635 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4636 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4637 && operand
->bits
== 16
4638 && operand
->shift
== 0)
4639 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4640 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4641 && operand
->bits
== 26
4642 && operand
->shift
== 0)
4643 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4644 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4645 && operand
->bits
== 16
4646 && operand
->shift
== 0)
4647 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4648 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4649 && operand
->bits
== 16
4650 && operand
->shift
== 0
4651 && operand
->insert
== NULL
4652 && fixp
->fx_addsy
!= NULL
4653 && ppc_is_toc_sym (fixp
->fx_addsy
))
4656 if (target_big_endian
)
4657 fixp
->fx_where
+= 2;
4658 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4665 /* Use expr_symbol_where to see if this is an expression
4667 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
4668 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4669 "unresolved expression that must be resolved");
4671 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4672 "unsupported relocation type");
4680 ppc_elf_validate_fix (fixp
, seg
);
4682 switch (fixp
->fx_r_type
)
4685 case BFD_RELOC_CTOR
:
4687 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4691 case BFD_RELOC_32_PCREL
:
4692 case BFD_RELOC_32_BASEREL
:
4693 case BFD_RELOC_PPC_EMB_NADDR32
:
4694 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4698 case BFD_RELOC_LO16
:
4699 case BFD_RELOC_HI16
:
4700 case BFD_RELOC_HI16_S
:
4702 case BFD_RELOC_GPREL16
:
4703 case BFD_RELOC_16_GOT_PCREL
:
4704 case BFD_RELOC_16_GOTOFF
:
4705 case BFD_RELOC_LO16_GOTOFF
:
4706 case BFD_RELOC_HI16_GOTOFF
:
4707 case BFD_RELOC_HI16_S_GOTOFF
:
4708 case BFD_RELOC_LO16_BASEREL
:
4709 case BFD_RELOC_HI16_BASEREL
:
4710 case BFD_RELOC_HI16_S_BASEREL
:
4711 case BFD_RELOC_PPC_EMB_NADDR16
:
4712 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
4713 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
4714 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
4715 case BFD_RELOC_PPC_EMB_SDAI16
:
4716 case BFD_RELOC_PPC_EMB_SDA2REL
:
4717 case BFD_RELOC_PPC_EMB_SDA2I16
:
4718 case BFD_RELOC_PPC_EMB_RELSEC16
:
4719 case BFD_RELOC_PPC_EMB_RELST_LO
:
4720 case BFD_RELOC_PPC_EMB_RELST_HI
:
4721 case BFD_RELOC_PPC_EMB_RELST_HA
:
4722 case BFD_RELOC_PPC_EMB_RELSDA
:
4723 case BFD_RELOC_PPC_TOC16
:
4725 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4726 "cannot emit PC relative %s relocation%s%s",
4727 bfd_get_reloc_code_name (fixp
->fx_r_type
),
4728 fixp
->fx_addsy
!= NULL
? " against " : "",
4729 (fixp
->fx_addsy
!= NULL
4730 ? S_GET_NAME (fixp
->fx_addsy
)
4733 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4737 /* Because SDA21 modifies the register field, the size is set to 4
4738 bytes, rather than 2, so offset it here appropriately */
4739 case BFD_RELOC_PPC_EMB_SDA21
:
4743 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
4744 + ((target_big_endian
) ? 2 : 0),
4752 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4756 case BFD_RELOC_24_PLT_PCREL
:
4757 case BFD_RELOC_PPC_LOCAL24PC
:
4758 if (!fixp
->fx_pcrel
)
4765 "Gas failure, reloc value %d\n", fixp
->fx_r_type
);
4772 fixp
->fx_addnumber
= value
;
4774 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4775 fixp
->fx_addnumber
= 0;
4779 fixp
->fx_addnumber
= 0;
4781 /* We want to use the offset within the data segment of the
4782 symbol, not the actual VMA of the symbol. */
4783 fixp
->fx_addnumber
=
4784 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4792 /* Generate a reloc for a fixup. */
4795 tc_gen_reloc (seg
, fixp
)
4801 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4803 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4804 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4805 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4806 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4808 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4809 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4812 reloc
->addend
= fixp
->fx_addnumber
;