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));
88 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
89 static void ppc_elf_cons
PARAMS ((int));
90 static void ppc_elf_rdata
PARAMS ((int));
91 static void ppc_elf_lcomm
PARAMS ((int));
92 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
96 static void ppc_set_current_section
PARAMS ((segT
));
97 static void ppc_previous
PARAMS ((int));
98 static void ppc_pdata
PARAMS ((int));
99 static void ppc_ydata
PARAMS ((int));
100 static void ppc_reldata
PARAMS ((int));
101 static void ppc_rdata
PARAMS ((int));
102 static void ppc_ualong
PARAMS ((int));
103 static void ppc_znop
PARAMS ((int));
104 static void ppc_pe_comm
PARAMS ((int));
105 static void ppc_pe_section
PARAMS ((int));
106 static void ppc_pe_function
PARAMS ((int));
107 static void ppc_pe_tocd
PARAMS ((int));
110 /* Generic assembler global variables which must be defined by all
113 /* Characters which always start a comment. */
114 #ifdef TARGET_SOLARIS_COMMENT
115 const char comment_chars
[] = "#!";
117 const char comment_chars
[] = "#";
120 /* Characters which start a comment at the beginning of a line. */
121 const char line_comment_chars
[] = "#";
123 /* Characters which may be used to separate multiple commands on a
125 const char line_separator_chars
[] = ";";
127 /* Characters which are used to indicate an exponent in a floating
129 const char EXP_CHARS
[] = "eE";
131 /* Characters which mean that a number is a floating point constant,
133 const char FLT_CHARS
[] = "dD";
135 /* The target specific pseudo-ops which we support. */
137 const pseudo_typeS md_pseudo_table
[] =
139 /* Pseudo-ops which must be overridden. */
140 { "byte", ppc_byte
, 0 },
143 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
144 legitimately belong in the obj-*.c file. However, XCOFF is based
145 on COFF, and is only implemented for the RS/6000. We just use
146 obj-coff.c, and add what we need here. */
147 { "comm", ppc_comm
, 0 },
148 { "lcomm", ppc_comm
, 1 },
152 { "bi", ppc_biei
, 0 },
154 { "csect", ppc_csect
, 0 },
155 { "data", ppc_section
, 'd' },
159 { "ei", ppc_biei
, 1 },
161 { "extern", ppc_extern
, 0 },
162 { "function", ppc_function
, 0 },
163 { "lglobl", ppc_lglobl
, 0 },
164 { "rename", ppc_rename
, 0 },
165 { "stabx", ppc_stabx
, 0 },
166 { "text", ppc_section
, 't' },
167 { "toc", ppc_toc
, 0 },
171 { "long", ppc_elf_cons
, 4 },
172 { "word", ppc_elf_cons
, 2 },
173 { "short", ppc_elf_cons
, 2 },
174 { "rdata", ppc_elf_rdata
, 0 },
175 { "rodata", ppc_elf_rdata
, 0 },
176 { "lcomm", ppc_elf_lcomm
, 0 },
180 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
181 { "previous", ppc_previous
, 0 },
182 { "pdata", ppc_pdata
, 0 },
183 { "ydata", ppc_ydata
, 0 },
184 { "reldata", ppc_reldata
, 0 },
185 { "rdata", ppc_rdata
, 0 },
186 { "ualong", ppc_ualong
, 0 },
187 { "znop", ppc_znop
, 0 },
188 { "comm", ppc_pe_comm
, 0 },
189 { "lcomm", ppc_pe_comm
, 1 },
190 { "section", ppc_pe_section
, 0 },
191 { "function", ppc_pe_function
,0 },
192 { "tocd", ppc_pe_tocd
, 0 },
195 /* This pseudo-op is used even when not generating XCOFF output. */
202 /* Predefined register names if -mregnames (or default for Windows NT). */
203 /* In general, there are lots of them, in an attempt to be compatible */
204 /* with a number of other Windows NT assemblers. */
206 /* Structure to hold information about predefined registers. */
213 /* List of registers that are pre-defined:
215 Each general register has predefined names of the form:
216 1. r<reg_num> which has the value <reg_num>.
217 2. r.<reg_num> which has the value <reg_num>.
220 Each floating point register has predefined names of the form:
221 1. f<reg_num> which has the value <reg_num>.
222 2. f.<reg_num> which has the value <reg_num>.
224 Each condition register has predefined names of the form:
225 1. cr<reg_num> which has the value <reg_num>.
226 2. cr.<reg_num> which has the value <reg_num>.
228 There are individual registers as well:
229 sp or r.sp has the value 1
230 rtoc or r.toc has the value 2
231 fpscr has the value 0
237 dsisr has the value 18
239 sdr1 has the value 25
240 srr0 has the value 26
241 srr1 has the value 27
243 The table is sorted. Suitable for searching by a binary search. */
245 static const struct pd_reg pre_defined_registers
[] =
247 { "cr.0", 0 }, /* Condition Registers */
267 { "dar", 19 }, /* Data Access Register */
268 { "dec", 22 }, /* Decrementer */
269 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
271 { "f.0", 0 }, /* Floating point registers */
339 { "lr", 8 }, /* Link Register */
343 { "r.0", 0 }, /* General Purpose Registers */
376 { "r.sp", 1 }, /* Stack Pointer */
378 { "r.toc", 2 }, /* Pointer to the table of contents */
380 { "r0", 0 }, /* More general purpose registers */
413 { "rtoc", 2 }, /* Table of contents */
415 { "sdr1", 25 }, /* Storage Description Register 1 */
419 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
420 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
426 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
428 /* Given NAME, find the register number associated with that name, return
429 the integer value associated with the given name or -1 on failure. */
431 static int reg_name_search
432 PARAMS ((const struct pd_reg
*, int, const char * name
));
435 reg_name_search (regs
, regcount
, name
)
436 const struct pd_reg
*regs
;
440 int middle
, low
, high
;
448 middle
= (low
+ high
) / 2;
449 cmp
= strcasecmp (name
, regs
[middle
].name
);
455 return regs
[middle
].value
;
463 * Summary of register_name().
465 * in: Input_line_pointer points to 1st char of operand.
467 * out: A expressionS.
468 * The operand may have been a register: in this case, X_op == O_register,
469 * X_add_number is set to the register number, and truth is returned.
470 * Input_line_pointer->(next non-blank) char after operand, or is in its
475 register_name (expressionP
)
476 expressionS
*expressionP
;
483 /* Find the spelling of the operand */
484 start
= name
= input_line_pointer
;
485 if (name
[0] == '%' && isalpha (name
[1]))
486 name
= ++input_line_pointer
;
488 else if (!reg_names_p
|| !isalpha (name
[0]))
491 c
= get_symbol_end ();
492 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
494 /* look to see if it's in the register table */
497 expressionP
->X_op
= O_register
;
498 expressionP
->X_add_number
= reg_number
;
500 /* make the rest nice */
501 expressionP
->X_add_symbol
= NULL
;
502 expressionP
->X_op_symbol
= NULL
;
503 *input_line_pointer
= c
; /* put back the delimiting char */
508 /* reset the line as if we had not done anything */
509 *input_line_pointer
= c
; /* put back the delimiting char */
510 input_line_pointer
= start
; /* reset input_line pointer */
515 /* This function is called for each symbol seen in an expression. It
516 handles the special parsing which PowerPC assemblers are supposed
517 to use for condition codes. */
519 /* Whether to do the special parsing. */
520 static boolean cr_operand
;
522 /* Names to recognize in a condition code. This table is sorted. */
523 static const struct pd_reg cr_names
[] =
540 /* Parsing function. This returns non-zero if it recognized an
544 ppc_parse_name (name
, expr
)
553 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
558 expr
->X_op
= O_constant
;
559 expr
->X_add_number
= val
;
564 /* Local variables. */
566 /* The type of processor we are assembling for. This is one or more
567 of the PPC_OPCODE flags defined in opcode/ppc.h. */
568 static int ppc_cpu
= 0;
570 /* The size of the processor we are assembling for. This is either
571 PPC_OPCODE_32 or PPC_OPCODE_64. */
572 static int ppc_size
= PPC_OPCODE_32
;
574 /* Opcode hash table. */
575 static struct hash_control
*ppc_hash
;
577 /* Macro hash table. */
578 static struct hash_control
*ppc_macro_hash
;
581 /* Whether to warn about non PC relative relocations that aren't
582 in the .got2 section. */
583 static boolean mrelocatable
= false;
585 /* Flags to set in the elf header */
586 static flagword ppc_flags
= 0;
591 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
592 using a bunch of different sections. These assembler sections,
593 however, are all encompassed within the .text or .data sections of
594 the final output file. We handle this by using different
595 subsegments within these main segments. */
597 /* Next subsegment to allocate within the .text segment. */
598 static subsegT ppc_text_subsegment
= 2;
600 /* Linked list of csects in the text section. */
601 static symbolS
*ppc_text_csects
;
603 /* Next subsegment to allocate within the .data segment. */
604 static subsegT ppc_data_subsegment
= 2;
606 /* Linked list of csects in the data section. */
607 static symbolS
*ppc_data_csects
;
609 /* The current csect. */
610 static symbolS
*ppc_current_csect
;
612 /* The RS/6000 assembler uses a TOC which holds addresses of functions
613 and variables. Symbols are put in the TOC with the .tc pseudo-op.
614 A special relocation is used when accessing TOC entries. We handle
615 the TOC as a subsegment within the .data segment. We set it up if
616 we see a .toc pseudo-op, and save the csect symbol here. */
617 static symbolS
*ppc_toc_csect
;
619 /* The first frag in the TOC subsegment. */
620 static fragS
*ppc_toc_frag
;
622 /* The first frag in the first subsegment after the TOC in the .data
623 segment. NULL if there are no subsegments after the TOC. */
624 static fragS
*ppc_after_toc_frag
;
626 /* The current static block. */
627 static symbolS
*ppc_current_block
;
629 /* The COFF debugging section; set by md_begin. This is not the
630 .debug section, but is instead the secret BFD section which will
631 cause BFD to set the section number of a symbol to N_DEBUG. */
632 static asection
*ppc_coff_debug_section
;
634 #endif /* OBJ_XCOFF */
638 /* Various sections that we need for PE coff support. */
639 static segT ydata_section
;
640 static segT pdata_section
;
641 static segT reldata_section
;
642 static segT rdata_section
;
643 static segT tocdata_section
;
645 /* The current section and the previous section. See ppc_previous. */
646 static segT ppc_previous_section
;
647 static segT ppc_current_section
;
652 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
655 #ifndef WORKING_DOT_WORD
656 const int md_short_jump_size
= 4;
657 const int md_long_jump_size
= 4;
661 CONST
char *md_shortopts
= "b:l:usm:K:VQ:";
663 CONST
char *md_shortopts
= "um:";
665 struct option md_longopts
[] = {
666 {NULL
, no_argument
, NULL
, 0}
668 size_t md_longopts_size
= sizeof(md_longopts
);
671 md_parse_option (c
, arg
)
678 /* -u means that any undefined symbols should be treated as
679 external, which is the default for gas anyhow. */
684 /* Solaris as takes -le (presumably for little endian). For completeness
685 sake, recognize -be also. */
686 if (strcmp (arg
, "e") == 0)
688 target_big_endian
= 0;
689 set_target_endian
= 1;
697 if (strcmp (arg
, "e") == 0)
699 target_big_endian
= 1;
700 set_target_endian
= 1;
708 /* Recognize -K PIC */
709 if (strcmp (arg
, "PIC") == 0)
712 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
721 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
723 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
724 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
725 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
726 else if (strcmp (arg
, "pwr") == 0)
727 ppc_cpu
= PPC_OPCODE_POWER
;
728 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
729 instructions that are holdovers from the Power. */
730 else if (strcmp (arg
, "601") == 0)
731 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
732 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
733 Motorola PowerPC 603/604. */
734 else if (strcmp (arg
, "ppc") == 0
735 || strcmp (arg
, "ppc32") == 0
736 || strcmp (arg
, "403") == 0
737 || strcmp (arg
, "603") == 0
738 || strcmp (arg
, "604") == 0)
739 ppc_cpu
= PPC_OPCODE_PPC
;
740 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
742 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
744 ppc_cpu
= PPC_OPCODE_PPC
;
745 ppc_size
= PPC_OPCODE_64
;
747 /* -mcom means assemble for the common intersection between Power
748 and PowerPC. At present, we just allow the union, rather
749 than the intersection. */
750 else if (strcmp (arg
, "com") == 0)
751 ppc_cpu
= PPC_OPCODE_COMMON
;
752 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
753 else if (strcmp (arg
, "any") == 0)
754 ppc_cpu
= PPC_OPCODE_ANY
;
756 else if (strcmp (arg
, "regnames") == 0)
759 else if (strcmp (arg
, "no-regnames") == 0)
763 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
764 else if (strcmp (arg
, "relocatable") == 0)
767 ppc_flags
|= EF_PPC_RELOCATABLE
;
770 else if (strcmp (arg
, "relocatable-lib") == 0)
773 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
776 /* -memb, set embedded bit */
777 else if (strcmp (arg
, "emb") == 0)
778 ppc_flags
|= EF_PPC_EMB
;
780 /* -mlittle/-mbig set the endianess */
781 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
783 target_big_endian
= 0;
784 set_target_endian
= 1;
787 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
789 target_big_endian
= 1;
790 set_target_endian
= 1;
795 as_bad ("invalid switch -m%s", arg
);
801 /* -V: SVR4 argument to print version ID. */
806 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
807 should be emitted or not. FIXME: Not implemented. */
811 /* Solaris takes -s to specify that .stabs go in a .stabs section,
812 rather than .stabs.excl, which is ignored by the linker.
813 FIXME: Not implemented. */
829 md_show_usage (stream
)
835 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
836 -mpwr generate code for IBM POWER (RIOS1)\n\
837 -m601 generate code for Motorola PowerPC 601\n\
838 -mppc, -mppc32, -m403, -m603, -m604\n\
839 generate code for Motorola PowerPC 603/604\n\
840 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
841 -mcom generate code Power/PowerPC common instructions\n\
842 -many generate code for any architecture (PWR/PWRX/PPC)\n\
843 -mregnames Allow symbolic names for registers\n\
844 -mno-regnames Do not allow symbolic names for registers\n");
847 -mrelocatable support for GCC's -mrelocatble option\n\
848 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
849 -memb set PPC_EMB bit in ELF flags\n\
850 -mlittle, -mlittle-endian\n\
851 generate code for a little endian machine\n\
852 -mbig, -mbig-endian generate code for a big endian machine\n\
853 -V print assembler version number\n\
854 -Qy, -Qn ignored\n");
858 /* Set ppc_cpu if it is not already set. */
863 const char *default_os
= TARGET_OS
;
864 const char *default_cpu
= TARGET_CPU
;
868 if (strncmp (default_os
, "aix", 3) == 0
869 && default_os
[3] >= '4' && default_os
[3] <= '9')
870 ppc_cpu
= PPC_OPCODE_COMMON
;
871 else if (strncmp (default_os
, "aix3", 4) == 0)
872 ppc_cpu
= PPC_OPCODE_POWER
;
873 else if (strcmp (default_cpu
, "rs6000") == 0)
874 ppc_cpu
= PPC_OPCODE_POWER
;
875 else if (strcmp (default_cpu
, "powerpc") == 0
876 || strcmp (default_cpu
, "powerpcle") == 0)
877 ppc_cpu
= PPC_OPCODE_PPC
;
879 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu
, default_os
);
883 /* Figure out the BFD architecture to use. */
885 enum bfd_architecture
888 const char *default_cpu
= TARGET_CPU
;
891 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
892 return bfd_arch_powerpc
;
893 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
894 return bfd_arch_rs6000
;
895 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
897 if (strcmp (default_cpu
, "rs6000") == 0)
898 return bfd_arch_rs6000
;
899 else if (strcmp (default_cpu
, "powerpc") == 0
900 || strcmp (default_cpu
, "powerpcle") == 0)
901 return bfd_arch_powerpc
;
904 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
905 return bfd_arch_unknown
;
908 /* This function is called when the assembler starts up. It is called
909 after the options have been parsed and the output file has been
915 register const struct powerpc_opcode
*op
;
916 const struct powerpc_opcode
*op_end
;
917 const struct powerpc_macro
*macro
;
918 const struct powerpc_macro
*macro_end
;
919 boolean dup_insn
= false;
924 /* Set the ELF flags if desired. */
926 bfd_set_private_flags (stdoutput
, ppc_flags
);
929 /* Insert the opcodes into a hash table. */
930 ppc_hash
= hash_new ();
932 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
933 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
935 know ((op
->opcode
& op
->mask
) == op
->opcode
);
937 if ((op
->flags
& ppc_cpu
) != 0
938 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
939 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
943 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
944 if (retval
!= (const char *) NULL
)
946 /* Ignore Power duplicates for -m601 */
947 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
948 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
951 as_bad ("Internal assembler error for instruction %s", op
->name
);
957 /* Insert the macros into a hash table. */
958 ppc_macro_hash
= hash_new ();
960 macro_end
= powerpc_macros
+ powerpc_num_macros
;
961 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
963 if ((macro
->flags
& ppc_cpu
) != 0)
967 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
968 if (retval
!= (const char *) NULL
)
970 as_bad ("Internal assembler error for macro %s", macro
->name
);
979 /* Tell the main code what the endianness is if it is not overidden by the user. */
980 if (!set_target_endian
)
982 set_target_endian
= 1;
983 target_big_endian
= PPC_BIG_ENDIAN
;
987 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
989 /* Create dummy symbols to serve as initial csects. This forces the
990 text csects to precede the data csects. These symbols will not
992 ppc_text_csects
= symbol_make ("dummy\001");
993 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
994 ppc_data_csects
= symbol_make ("dummy\001");
995 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
1000 ppc_current_section
= text_section
;
1001 ppc_previous_section
= 0;
1006 /* Insert an operand value into an instruction. */
1008 static unsigned long
1009 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1011 const struct powerpc_operand
*operand
;
1016 if (operand
->bits
!= 32)
1021 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1023 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
1024 && ppc_size
== PPC_OPCODE_32
)
1025 max
= (1 << operand
->bits
) - 1;
1027 max
= (1 << (operand
->bits
- 1)) - 1;
1028 min
= - (1 << (operand
->bits
- 1));
1032 max
= (1 << operand
->bits
) - 1;
1036 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1041 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1044 "operand out of range (%s not between %ld and %ld)";
1047 sprint_value (buf
, test
);
1048 if (file
== (char *) NULL
)
1049 as_bad (err
, buf
, min
, max
);
1051 as_bad_where (file
, line
, err
, buf
, min
, max
);
1055 if (operand
->insert
)
1060 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1061 if (errmsg
!= (const char *) NULL
)
1065 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1073 /* Parse @got, etc. and return the desired relocation. */
1074 static bfd_reloc_code_real_type
1075 ppc_elf_suffix (str_p
)
1081 bfd_reloc_code_real_type reloc
;
1089 struct map_bfd
*ptr
;
1091 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1093 static struct map_bfd mapping
[] = {
1094 MAP ("l", BFD_RELOC_LO16
),
1095 MAP ("h", BFD_RELOC_HI16
),
1096 MAP ("ha", BFD_RELOC_HI16_S
),
1097 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1098 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1099 MAP ("got", BFD_RELOC_16_GOTOFF
),
1100 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1101 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1102 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1103 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1104 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1105 MAP ("copy", BFD_RELOC_PPC_COPY
),
1106 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1107 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1108 MAP ("plt", BFD_RELOC_32_PLTOFF
),
1109 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1110 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1111 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1112 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1113 MAP ("sdarel", BFD_RELOC_GPREL16
),
1114 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1115 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1116 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1117 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1118 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1119 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1120 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1121 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1122 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1123 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1124 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1125 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1126 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1127 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1128 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1129 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1130 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1131 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1132 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1133 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1134 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1136 { (char *)0, 0, BFD_RELOC_UNUSED
}
1140 return BFD_RELOC_UNUSED
;
1142 for (ch
= *str
, str2
= ident
;
1143 (str2
< ident
+ sizeof (ident
) - 1
1144 && (isalnum (ch
) || ch
== '@'));
1147 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1154 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1155 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1161 return BFD_RELOC_UNUSED
;
1164 /* Like normal .long/.short/.word, except support @got, etc. */
1165 /* clobbers input_line_pointer, checks */
1168 ppc_elf_cons (nbytes
)
1169 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1172 bfd_reloc_code_real_type reloc
;
1174 if (is_it_end_of_statement ())
1176 demand_empty_rest_of_line ();
1183 if (exp
.X_op
== O_symbol
1184 && *input_line_pointer
== '@'
1185 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
1187 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1188 int size
= bfd_get_reloc_size (reloc_howto
);
1191 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
1195 register char *p
= frag_more ((int) nbytes
);
1196 int offset
= nbytes
- size
;
1198 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1202 emit_expr (&exp
, (unsigned int) nbytes
);
1204 while (*input_line_pointer
++ == ',');
1206 input_line_pointer
--; /* Put terminator back into stream. */
1207 demand_empty_rest_of_line ();
1210 /* Solaris pseduo op to change to the .rodata section. */
1215 char *save_line
= input_line_pointer
;
1216 static char section
[] = ".rodata\n";
1218 /* Just pretend this is .section .rodata */
1219 input_line_pointer
= section
;
1220 obj_elf_section (xxx
);
1222 input_line_pointer
= save_line
;
1225 /* Pseudo op to make file scope bss items */
1230 register char *name
;
1234 register symbolS
*symbolP
;
1241 name
= input_line_pointer
;
1242 c
= get_symbol_end ();
1244 /* just after name is now '\0' */
1245 p
= input_line_pointer
;
1248 if (*input_line_pointer
!= ',')
1250 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1251 ignore_rest_of_line ();
1255 input_line_pointer
++; /* skip ',' */
1256 if ((size
= get_absolute_expression ()) < 0)
1258 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size
);
1259 ignore_rest_of_line ();
1263 /* The third argument to .lcomm is the alignment. */
1264 if (*input_line_pointer
!= ',')
1268 ++input_line_pointer
;
1269 align
= get_absolute_expression ();
1272 as_warn ("ignoring bad alignment");
1278 symbolP
= symbol_find_or_make (name
);
1281 if (S_IS_DEFINED (symbolP
))
1283 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1284 S_GET_NAME (symbolP
));
1285 ignore_rest_of_line ();
1289 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1291 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1292 S_GET_NAME (symbolP
),
1293 (long) S_GET_VALUE (symbolP
),
1296 ignore_rest_of_line ();
1302 old_subsec
= now_subseg
;
1305 /* convert to a power of 2 alignment */
1306 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1309 as_bad ("Common alignment not a power of 2");
1310 ignore_rest_of_line ();
1317 record_alignment (bss_section
, align2
);
1318 subseg_set (bss_section
, 0);
1320 frag_align (align2
, 0);
1321 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1322 symbolP
->sy_frag
->fr_symbol
= 0;
1323 symbolP
->sy_frag
= frag_now
;
1324 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1327 S_SET_SIZE (symbolP
, size
);
1328 S_SET_SEGMENT (symbolP
, bss_section
);
1329 S_CLEAR_EXTERNAL (symbolP
);
1330 subseg_set (old_sec
, old_subsec
);
1331 demand_empty_rest_of_line ();
1334 /* Validate any relocations emitted for -mrelocatable, possibly adding
1335 fixups for word relocations in writable segments, so we can adjust
1338 ppc_elf_validate_fix (fixp
, seg
)
1345 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1346 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1347 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1348 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1349 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1350 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1351 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1352 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1353 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1354 && strcmp (segment_name (seg
), ".got2") != 0
1355 && strcmp (segment_name (seg
), ".dtors") != 0
1356 && strcmp (segment_name (seg
), ".ctors") != 0
1357 && strcmp (segment_name (seg
), ".fixup") != 0
1358 && strcmp (segment_name (seg
), ".stab") != 0
1359 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1360 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1362 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1363 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1365 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1366 "Relocation cannot be done when using -mrelocatable");
1370 #endif /* OBJ_ELF */
1375 * Summary of parse_toc_entry().
1377 * in: Input_line_pointer points to the '[' in one of:
1379 * [toc] [tocv] [toc32] [toc64]
1381 * Anything else is an error of one kind or another.
1384 * return value: success or failure
1385 * toc_kind: kind of toc reference
1386 * input_line_pointer:
1387 * success: first char after the ']'
1388 * failure: unchanged
1392 * [toc] - rv == success, toc_kind = default_toc
1393 * [tocv] - rv == success, toc_kind = data_in_toc
1394 * [toc32] - rv == success, toc_kind = must_be_32
1395 * [toc64] - rv == success, toc_kind = must_be_64
1399 enum toc_size_qualifier
1401 default_toc
, /* The toc cell constructed should be the system default size */
1402 data_in_toc
, /* This is a direct reference to a toc cell */
1403 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1404 must_be_64
/* The toc cell constructed must be 64 bits wide */
1408 parse_toc_entry(toc_kind
)
1409 enum toc_size_qualifier
*toc_kind
;
1414 enum toc_size_qualifier t
;
1416 /* save the input_line_pointer */
1417 start
= input_line_pointer
;
1419 /* skip over the '[' , and whitespace */
1420 ++input_line_pointer
;
1423 /* find the spelling of the operand */
1424 toc_spec
= input_line_pointer
;
1425 c
= get_symbol_end ();
1427 if (strcmp(toc_spec
, "toc") == 0)
1431 else if (strcmp(toc_spec
, "tocv") == 0)
1435 else if (strcmp(toc_spec
, "toc32") == 0)
1439 else if (strcmp(toc_spec
, "toc64") == 0)
1445 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1446 *input_line_pointer
= c
; /* put back the delimiting char */
1447 input_line_pointer
= start
; /* reset input_line pointer */
1451 /* now find the ']' */
1452 *input_line_pointer
= c
; /* put back the delimiting char */
1454 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1455 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1459 as_bad ("syntax error: expected `]', found `%c'", c
);
1460 input_line_pointer
= start
; /* reset input_line pointer */
1464 *toc_kind
= t
; /* set return value */
1470 /* We need to keep a list of fixups. We can't simply generate them as
1471 we go, because that would require us to first create the frag, and
1472 that would screw up references to ``.''. */
1478 bfd_reloc_code_real_type reloc
;
1481 #define MAX_INSN_FIXUPS (5)
1483 /* This routine is called for each instruction to be assembled. */
1490 const struct powerpc_opcode
*opcode
;
1492 const unsigned char *opindex_ptr
;
1496 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1501 bfd_reloc_code_real_type reloc
;
1504 /* Get the opcode. */
1505 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1510 /* Look up the opcode in the hash table. */
1511 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1512 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1514 const struct powerpc_macro
*macro
;
1516 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1517 if (macro
== (const struct powerpc_macro
*) NULL
)
1518 as_bad ("Unrecognized opcode: `%s'", str
);
1520 ppc_macro (s
, macro
);
1525 insn
= opcode
->opcode
;
1528 while (isspace (*str
))
1531 /* PowerPC operands are just expressions. The only real issue is
1532 that a few operand types are optional. All cases which might use
1533 an optional operand separate the operands only with commas (in
1534 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1535 cases never have optional operands). There is never more than
1536 one optional operand for an instruction. So, before we start
1537 seriously parsing the operands, we check to see if we have an
1538 optional operand, and, if we do, we count the number of commas to
1539 see whether the operand should be omitted. */
1541 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1543 const struct powerpc_operand
*operand
;
1545 operand
= &powerpc_operands
[*opindex_ptr
];
1546 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1548 unsigned int opcount
;
1550 /* There is an optional operand. Count the number of
1551 commas in the input line. */
1558 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1565 /* If there are fewer operands in the line then are called
1566 for by the instruction, we want to skip the optional
1568 if (opcount
< strlen (opcode
->operands
))
1575 /* Gather the operands. */
1579 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1581 const struct powerpc_operand
*operand
;
1587 if (next_opindex
== 0)
1588 operand
= &powerpc_operands
[*opindex_ptr
];
1591 operand
= &powerpc_operands
[next_opindex
];
1597 /* If this is a fake operand, then we do not expect anything
1599 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1601 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1602 if (errmsg
!= (const char *) NULL
)
1607 /* If this is an optional operand, and we are skipping it, just
1609 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1612 if (operand
->insert
)
1614 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1615 if (errmsg
!= (const char *) NULL
)
1618 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1619 next_opindex
= *opindex_ptr
+ 1;
1623 /* Gather the operand. */
1624 hold
= input_line_pointer
;
1625 input_line_pointer
= str
;
1628 if (*input_line_pointer
== '[')
1630 /* We are expecting something like the second argument here:
1632 lwz r4,[toc].GS.0.static_int(rtoc)
1633 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1634 The argument following the `]' must be a symbol name, and the
1635 register must be the toc register: 'rtoc' or '2'
1637 The effect is to 0 as the displacement field
1638 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1639 the appropriate variation) reloc against it based on the symbol.
1640 The linker will build the toc, and insert the resolved toc offset.
1643 o The size of the toc entry is currently assumed to be
1644 32 bits. This should not be assumed to be a hard coded
1646 o In an effort to cope with a change from 32 to 64 bits,
1647 there are also toc entries that are specified to be
1648 either 32 or 64 bits:
1649 lwz r4,[toc32].GS.0.static_int(rtoc)
1650 lwz r4,[toc64].GS.0.static_int(rtoc)
1651 These demand toc entries of the specified size, and the
1652 instruction probably requires it.
1656 enum toc_size_qualifier toc_kind
;
1657 bfd_reloc_code_real_type toc_reloc
;
1659 /* go parse off the [tocXX] part */
1660 valid_toc
= parse_toc_entry(&toc_kind
);
1664 /* Note: message has already been issued. */
1665 /* FIXME: what sort of recovery should we do? */
1666 /* demand_rest_of_line(); return; ? */
1669 /* Now get the symbol following the ']' */
1675 /* In this case, we may not have seen the symbol yet, since */
1676 /* it is allowed to appear on a .extern or .globl or just be */
1677 /* a label in the .data section. */
1678 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1681 /* 1. The symbol must be defined and either in the toc */
1682 /* section, or a global. */
1683 /* 2. The reloc generated must have the TOCDEFN flag set in */
1684 /* upper bit mess of the reloc type. */
1685 /* FIXME: It's a little confusing what the tocv qualifier can */
1686 /* be used for. At the very least, I've seen three */
1687 /* uses, only one of which I'm sure I can explain. */
1688 if (ex
.X_op
== O_symbol
)
1690 assert (ex
.X_add_symbol
!= NULL
);
1691 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1693 as_bad("[tocv] symbol is not a toc symbol");
1697 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1700 /* FIXME: these next two specifically specify 32/64 bit toc */
1701 /* entries. We don't support them today. Is this the */
1702 /* right way to say that? */
1703 toc_reloc
= BFD_RELOC_UNUSED
;
1704 as_bad ("Unimplemented toc32 expression modifier");
1707 /* FIXME: see above */
1708 toc_reloc
= BFD_RELOC_UNUSED
;
1709 as_bad ("Unimplemented toc64 expression modifier");
1713 "Unexpected return value [%d] from parse_toc_entry!\n",
1719 /* We need to generate a fixup for this expression. */
1720 if (fc
>= MAX_INSN_FIXUPS
)
1721 as_fatal ("too many fixups");
1723 fixups
[fc
].reloc
= toc_reloc
;
1724 fixups
[fc
].exp
= ex
;
1725 fixups
[fc
].opindex
= *opindex_ptr
;
1728 /* Ok. We've set up the fixup for the instruction. Now make it
1729 look like the constant 0 was found here */
1731 ex
.X_op
= O_constant
;
1732 ex
.X_add_number
= 0;
1733 ex
.X_add_symbol
= NULL
;
1734 ex
.X_op_symbol
= NULL
;
1740 if (! register_name (&ex
))
1742 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1749 str
= input_line_pointer
;
1750 input_line_pointer
= hold
;
1752 if (ex
.X_op
== O_illegal
)
1753 as_bad ("illegal operand");
1754 else if (ex
.X_op
== O_absent
)
1755 as_bad ("missing operand");
1756 else if (ex
.X_op
== O_register
)
1758 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1761 else if (ex
.X_op
== O_constant
)
1764 /* Allow @HA, @L, @H on constants. */
1765 char *orig_str
= str
;
1767 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1774 case BFD_RELOC_LO16
:
1776 ex
.X_add_number
&= 0xffff;
1778 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
1783 case BFD_RELOC_HI16
:
1784 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1787 case BFD_RELOC_HI16_S
:
1788 ex
.X_add_number
= (((ex
.X_add_number
>> 16) & 0xffff)
1789 + ((ex
.X_add_number
>> 15) & 1));
1793 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1797 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1799 /* For the absoulte forms of branchs, convert the PC relative form back into
1801 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1805 case BFD_RELOC_PPC_B26
:
1806 reloc
= BFD_RELOC_PPC_BA26
;
1808 case BFD_RELOC_PPC_B16
:
1809 reloc
= BFD_RELOC_PPC_BA16
;
1811 case BFD_RELOC_PPC_B16_BRTAKEN
:
1812 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
1814 case BFD_RELOC_PPC_B16_BRNTAKEN
:
1815 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
1822 /* We need to generate a fixup for this expression. */
1823 if (fc
>= MAX_INSN_FIXUPS
)
1824 as_fatal ("too many fixups");
1825 fixups
[fc
].exp
= ex
;
1826 fixups
[fc
].opindex
= 0;
1827 fixups
[fc
].reloc
= reloc
;
1830 #endif /* OBJ_ELF */
1834 /* We need to generate a fixup for this expression. */
1835 if (fc
>= MAX_INSN_FIXUPS
)
1836 as_fatal ("too many fixups");
1837 fixups
[fc
].exp
= ex
;
1838 fixups
[fc
].opindex
= *opindex_ptr
;
1839 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1848 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1856 /* The call to expression should have advanced str past any
1859 && (endc
!= ',' || *str
!= '\0'))
1861 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1869 while (isspace (*str
))
1873 as_bad ("junk at end of line: `%s'", str
);
1875 /* Write out the instruction. */
1877 md_number_to_chars (f
, insn
, 4);
1879 /* Create any fixups. At this point we do not use a
1880 bfd_reloc_code_real_type, but instead just use the
1881 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1882 handle fixups for any operand type, although that is admittedly
1883 not a very exciting feature. We pick a BFD reloc type in
1885 for (i
= 0; i
< fc
; i
++)
1887 const struct powerpc_operand
*operand
;
1889 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1890 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1892 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1900 size
= bfd_get_reloc_size (reloc_howto
);
1901 offset
= target_big_endian
? (4 - size
) : 0;
1903 if (size
< 1 || size
> 4)
1906 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1907 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1910 /* Turn off complaints that the addend is too large for things like
1912 switch (fixups
[i
].reloc
)
1914 case BFD_RELOC_16_GOTOFF
:
1915 case BFD_RELOC_PPC_TOC16
:
1916 case BFD_RELOC_LO16
:
1917 case BFD_RELOC_HI16
:
1918 case BFD_RELOC_HI16_S
:
1919 fixP
->fx_no_overflow
= 1;
1926 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1928 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1929 ((bfd_reloc_code_real_type
)
1930 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1934 #ifndef WORKING_DOT_WORD
1935 /* Handle long and short jumps */
1937 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1939 addressT from_addr
, to_addr
;
1947 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1949 addressT from_addr
, to_addr
;
1957 /* Handle a macro. Gather all the operands, transform them as
1958 described by the macro, and call md_assemble recursively. All the
1959 operands are separated by commas; we don't accept parentheses
1960 around operands here. */
1963 ppc_macro (str
, macro
)
1965 const struct powerpc_macro
*macro
;
1976 /* Gather the users operands into the operands array. */
1981 if (count
>= sizeof operands
/ sizeof operands
[0])
1983 operands
[count
++] = s
;
1984 s
= strchr (s
, ',');
1985 if (s
== (char *) NULL
)
1990 if (count
!= macro
->operands
)
1992 as_bad ("wrong number of operands");
1996 /* Work out how large the string must be (the size is unbounded
1997 because it includes user input). */
1999 format
= macro
->format
;
2000 while (*format
!= '\0')
2009 arg
= strtol (format
+ 1, &send
, 10);
2010 know (send
!= format
&& arg
>= 0 && arg
< count
);
2011 len
+= strlen (operands
[arg
]);
2016 /* Put the string together. */
2017 complete
= s
= (char *) alloca (len
+ 1);
2018 format
= macro
->format
;
2019 while (*format
!= '\0')
2025 arg
= strtol (format
+ 1, &send
, 10);
2026 strcpy (s
, operands
[arg
]);
2033 /* Assemble the constructed instruction. */
2034 md_assemble (complete
);
2038 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2041 ppc_section_letter (letter
, ptr_msg
)
2048 *ptr_msg
= "Bad .section directive: want a,w,x,e in string";
2053 ppc_section_word (ptr_str
)
2056 if (strncmp (*ptr_str
, "exclude", sizeof ("exclude")-1) == 0)
2058 *ptr_str
+= sizeof ("exclude")-1;
2066 ppc_section_type (ptr_str
)
2069 if (strncmp (*ptr_str
, "ordered", sizeof ("ordered")-1) == 0)
2071 *ptr_str
+= sizeof ("ordered")-1;
2079 ppc_section_flags (flags
, attr
, type
)
2084 if (type
== SHT_ORDERED
)
2085 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2087 if (attr
& SHF_EXCLUDE
)
2088 flags
|= SEC_EXCLUDE
;
2092 #endif /* OBJ_ELF */
2095 /* Pseudo-op handling. */
2097 /* The .byte pseudo-op. This is similar to the normal .byte
2098 pseudo-op, but it can also take a single ASCII string. */
2104 if (*input_line_pointer
!= '\"')
2110 /* Gather characters. A real double quote is doubled. Unusual
2111 characters are not permitted. */
2112 ++input_line_pointer
;
2117 c
= *input_line_pointer
++;
2121 if (*input_line_pointer
!= '\"')
2123 ++input_line_pointer
;
2126 FRAG_APPEND_1_CHAR (c
);
2129 demand_empty_rest_of_line ();
2134 /* XCOFF specific pseudo-op handling. */
2136 /* This is set if we are creating a .stabx symbol, since we don't want
2137 to handle symbol suffixes for such symbols. */
2138 static boolean ppc_stab_symbol
;
2140 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2141 symbols in the .bss segment as though they were local common
2142 symbols, and uses a different smclas. */
2148 asection
*current_seg
= now_seg
;
2149 subsegT current_subseg
= now_subseg
;
2155 symbolS
*lcomm_sym
= NULL
;
2159 name
= input_line_pointer
;
2160 endc
= get_symbol_end ();
2161 end_name
= input_line_pointer
;
2164 if (*input_line_pointer
!= ',')
2166 as_bad ("missing size");
2167 ignore_rest_of_line ();
2170 ++input_line_pointer
;
2172 size
= get_absolute_expression ();
2175 as_bad ("negative size");
2176 ignore_rest_of_line ();
2182 /* The third argument to .comm is the alignment. */
2183 if (*input_line_pointer
!= ',')
2187 ++input_line_pointer
;
2188 align
= get_absolute_expression ();
2191 as_warn ("ignoring bad alignment");
2210 /* The third argument to .lcomm appears to be the real local
2211 common symbol to create. References to the symbol named in
2212 the first argument are turned into references to the third
2214 if (*input_line_pointer
!= ',')
2216 as_bad ("missing real symbol name");
2217 ignore_rest_of_line ();
2220 ++input_line_pointer
;
2222 lcomm_name
= input_line_pointer
;
2223 lcomm_endc
= get_symbol_end ();
2225 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2227 *input_line_pointer
= lcomm_endc
;
2231 sym
= symbol_find_or_make (name
);
2234 if (S_IS_DEFINED (sym
)
2235 || S_GET_VALUE (sym
) != 0)
2237 as_bad ("attempt to redefine symbol");
2238 ignore_rest_of_line ();
2242 record_alignment (bss_section
, align
);
2245 || ! S_IS_DEFINED (lcomm_sym
))
2254 S_SET_EXTERNAL (sym
);
2258 lcomm_sym
->sy_tc
.output
= 1;
2259 def_sym
= lcomm_sym
;
2263 subseg_set (bss_section
, 1);
2264 frag_align (align
, 0);
2266 def_sym
->sy_frag
= frag_now
;
2267 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2268 def_size
, (char *) NULL
);
2270 S_SET_SEGMENT (def_sym
, bss_section
);
2271 def_sym
->sy_tc
.align
= align
;
2275 /* Align the size of lcomm_sym. */
2276 lcomm_sym
->sy_frag
->fr_offset
=
2277 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
2278 &~ ((1 << align
) - 1));
2279 if (align
> lcomm_sym
->sy_tc
.align
)
2280 lcomm_sym
->sy_tc
.align
= align
;
2285 /* Make sym an offset from lcomm_sym. */
2286 S_SET_SEGMENT (sym
, bss_section
);
2287 sym
->sy_frag
= lcomm_sym
->sy_frag
;
2288 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
2289 lcomm_sym
->sy_frag
->fr_offset
+= size
;
2292 subseg_set (current_seg
, current_subseg
);
2294 demand_empty_rest_of_line ();
2297 /* The .csect pseudo-op. This switches us into a different
2298 subsegment. The first argument is a symbol whose value is the
2299 start of the .csect. In COFF, csect symbols get special aux
2300 entries defined by the x_csect field of union internal_auxent. The
2301 optional second argument is the alignment (the default is 2). */
2311 name
= input_line_pointer
;
2312 endc
= get_symbol_end ();
2314 sym
= symbol_find_or_make (name
);
2316 *input_line_pointer
= endc
;
2318 if (S_GET_NAME (sym
)[0] == '\0')
2320 /* An unnamed csect is assumed to be [PR]. */
2321 sym
->sy_tc
.class = XMC_PR
;
2324 ppc_change_csect (sym
);
2326 if (*input_line_pointer
== ',')
2328 ++input_line_pointer
;
2329 sym
->sy_tc
.align
= get_absolute_expression ();
2332 demand_empty_rest_of_line ();
2335 /* Change to a different csect. */
2338 ppc_change_csect (sym
)
2341 if (S_IS_DEFINED (sym
))
2342 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
2349 /* This is a new csect. We need to look at the symbol class to
2350 figure out whether it should go in the text section or the
2353 switch (sym
->sy_tc
.class)
2363 S_SET_SEGMENT (sym
, text_section
);
2364 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
2365 ++ppc_text_subsegment
;
2366 list_ptr
= &ppc_text_csects
;
2375 if (ppc_toc_csect
!= NULL
2376 && ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
2378 S_SET_SEGMENT (sym
, data_section
);
2379 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
2380 ++ppc_data_subsegment
;
2381 list_ptr
= &ppc_data_csects
;
2387 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
2389 ppc_after_toc_frag
= frag_now
;
2391 sym
->sy_frag
= frag_now
;
2392 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2394 sym
->sy_tc
.align
= 2;
2395 sym
->sy_tc
.output
= 1;
2396 sym
->sy_tc
.within
= sym
;
2398 for (list
= *list_ptr
;
2399 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2400 list
= list
->sy_tc
.next
)
2402 list
->sy_tc
.next
= sym
;
2404 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2405 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2408 ppc_current_csect
= sym
;
2411 /* This function handles the .text and .data pseudo-ops. These
2412 pseudo-ops aren't really used by XCOFF; we implement them for the
2413 convenience of people who aren't used to XCOFF. */
2424 else if (type
== 'd')
2429 sym
= symbol_find_or_make (name
);
2431 ppc_change_csect (sym
);
2433 demand_empty_rest_of_line ();
2436 /* The .extern pseudo-op. We create an undefined symbol. */
2445 name
= input_line_pointer
;
2446 endc
= get_symbol_end ();
2448 (void) symbol_find_or_make (name
);
2450 *input_line_pointer
= endc
;
2452 demand_empty_rest_of_line ();
2455 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2465 name
= input_line_pointer
;
2466 endc
= get_symbol_end ();
2468 sym
= symbol_find_or_make (name
);
2470 *input_line_pointer
= endc
;
2472 sym
->sy_tc
.output
= 1;
2474 demand_empty_rest_of_line ();
2477 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2478 although I don't know why it bothers. */
2489 name
= input_line_pointer
;
2490 endc
= get_symbol_end ();
2492 sym
= symbol_find_or_make (name
);
2494 *input_line_pointer
= endc
;
2496 if (*input_line_pointer
!= ',')
2498 as_bad ("missing rename string");
2499 ignore_rest_of_line ();
2502 ++input_line_pointer
;
2504 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2506 demand_empty_rest_of_line ();
2509 /* The .stabx pseudo-op. This is similar to a normal .stabs
2510 pseudo-op, but slightly different. A sample is
2511 .stabx "main:F-1",.main,142,0
2512 The first argument is the symbol name to create. The second is the
2513 value, and the third is the storage class. The fourth seems to be
2514 always zero, and I am assuming it is the type. */
2525 name
= demand_copy_C_string (&len
);
2527 if (*input_line_pointer
!= ',')
2529 as_bad ("missing value");
2532 ++input_line_pointer
;
2534 ppc_stab_symbol
= true;
2535 sym
= symbol_make (name
);
2536 ppc_stab_symbol
= false;
2538 sym
->sy_tc
.real_name
= name
;
2540 (void) expression (&exp
);
2547 as_bad ("illegal .stabx expression; zero assumed");
2548 exp
.X_add_number
= 0;
2551 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2552 sym
->sy_frag
= &zero_address_frag
;
2556 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2557 sym
->sy_value
= exp
;
2561 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2562 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2567 /* The value is some complex expression. This will probably
2568 fail at some later point, but this is probably the right
2569 thing to do here. */
2570 sym
->sy_value
= exp
;
2574 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2575 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2577 if (*input_line_pointer
!= ',')
2579 as_bad ("missing class");
2582 ++input_line_pointer
;
2584 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2586 if (*input_line_pointer
!= ',')
2588 as_bad ("missing type");
2591 ++input_line_pointer
;
2593 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2595 sym
->sy_tc
.output
= 1;
2597 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2598 sym
->sy_tc
.within
= ppc_current_block
;
2600 if (exp
.X_op
!= O_symbol
2601 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2602 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2603 ppc_frob_label (sym
);
2606 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2607 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2608 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2609 ppc_current_csect
->sy_tc
.within
= sym
;
2612 demand_empty_rest_of_line ();
2615 /* The .function pseudo-op. This takes several arguments. The first
2616 argument seems to be the external name of the symbol. The second
2617 argment seems to be the label for the start of the function. gcc
2618 uses the same name for both. I have no idea what the third and
2619 fourth arguments are meant to be. The optional fifth argument is
2620 an expression for the size of the function. In COFF this symbol
2621 gets an aux entry like that used for a csect. */
2624 ppc_function (ignore
)
2633 name
= input_line_pointer
;
2634 endc
= get_symbol_end ();
2636 /* Ignore any [PR] suffix. */
2637 name
= ppc_canonicalize_symbol_name (name
);
2638 s
= strchr (name
, '[');
2639 if (s
!= (char *) NULL
2640 && strcmp (s
+ 1, "PR]") == 0)
2643 ext_sym
= symbol_find_or_make (name
);
2645 *input_line_pointer
= endc
;
2647 if (*input_line_pointer
!= ',')
2649 as_bad ("missing symbol name");
2650 ignore_rest_of_line ();
2653 ++input_line_pointer
;
2655 name
= input_line_pointer
;
2656 endc
= get_symbol_end ();
2658 lab_sym
= symbol_find_or_make (name
);
2660 *input_line_pointer
= endc
;
2662 if (ext_sym
!= lab_sym
)
2664 ext_sym
->sy_value
.X_op
= O_symbol
;
2665 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2666 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2667 ext_sym
->sy_value
.X_add_number
= 0;
2670 if (ext_sym
->sy_tc
.class == -1)
2671 ext_sym
->sy_tc
.class = XMC_PR
;
2672 ext_sym
->sy_tc
.output
= 1;
2674 if (*input_line_pointer
== ',')
2678 /* Ignore the third argument. */
2679 ++input_line_pointer
;
2680 expression (&ignore
);
2681 if (*input_line_pointer
== ',')
2683 /* Ignore the fourth argument. */
2684 ++input_line_pointer
;
2685 expression (&ignore
);
2686 if (*input_line_pointer
== ',')
2688 /* The fifth argument is the function size. */
2689 ++input_line_pointer
;
2690 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2693 &zero_address_frag
);
2694 pseudo_set (ext_sym
->sy_tc
.size
);
2699 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2700 SF_SET_FUNCTION (ext_sym
);
2701 SF_SET_PROCESS (ext_sym
);
2702 coff_add_linesym (ext_sym
);
2704 demand_empty_rest_of_line ();
2707 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2716 sym
= symbol_make (".bf");
2717 S_SET_SEGMENT (sym
, text_section
);
2718 sym
->sy_frag
= frag_now
;
2719 S_SET_VALUE (sym
, frag_now_fix ());
2720 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2722 coff_line_base
= get_absolute_expression ();
2724 S_SET_NUMBER_AUXILIARY (sym
, 1);
2725 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2727 sym
->sy_tc
.output
= 1;
2729 ppc_frob_label (sym
);
2731 demand_empty_rest_of_line ();
2734 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2735 ".ef", except that the line number is absolute, not relative to the
2736 most recent ".bf" symbol. */
2744 sym
= symbol_make (".ef");
2745 S_SET_SEGMENT (sym
, text_section
);
2746 sym
->sy_frag
= frag_now
;
2747 S_SET_VALUE (sym
, frag_now_fix ());
2748 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2749 S_SET_NUMBER_AUXILIARY (sym
, 1);
2750 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2751 sym
->sy_tc
.output
= 1;
2753 ppc_frob_label (sym
);
2755 demand_empty_rest_of_line ();
2758 /* The .bi and .ei pseudo-ops. These take a string argument and
2759 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2771 name
= demand_copy_C_string (&len
);
2773 /* The value of these symbols is actually file offset. Here we set
2774 the value to the index into the line number entries. In
2775 ppc_frob_symbols we set the fix_line field, which will cause BFD
2776 to do the right thing. */
2778 sym
= symbol_make (name
);
2779 /* obj-coff.c currently only handles line numbers correctly in the
2781 S_SET_SEGMENT (sym
, text_section
);
2782 S_SET_VALUE (sym
, coff_n_line_nos
);
2783 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2785 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2786 sym
->sy_tc
.output
= 1;
2788 for (look
= symbol_rootP
;
2789 (look
!= (symbolS
*) NULL
2790 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2791 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2792 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2793 look
= symbol_next (look
))
2795 if (look
!= (symbolS
*) NULL
)
2797 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2798 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2801 demand_empty_rest_of_line ();
2804 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2805 There is one argument, which is a csect symbol. The value of the
2806 .bs symbol is the index of this csect symbol. */
2817 if (ppc_current_block
!= NULL
)
2818 as_bad ("nested .bs blocks");
2820 name
= input_line_pointer
;
2821 endc
= get_symbol_end ();
2823 csect
= symbol_find_or_make (name
);
2825 *input_line_pointer
= endc
;
2827 sym
= symbol_make (".bs");
2828 S_SET_SEGMENT (sym
, now_seg
);
2829 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2830 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2831 sym
->sy_tc
.output
= 1;
2833 sym
->sy_tc
.within
= csect
;
2835 ppc_frob_label (sym
);
2837 ppc_current_block
= sym
;
2839 demand_empty_rest_of_line ();
2842 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2850 if (ppc_current_block
== NULL
)
2851 as_bad (".es without preceding .bs");
2853 sym
= symbol_make (".es");
2854 S_SET_SEGMENT (sym
, now_seg
);
2855 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2856 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2857 sym
->sy_tc
.output
= 1;
2859 ppc_frob_label (sym
);
2861 ppc_current_block
= NULL
;
2863 demand_empty_rest_of_line ();
2866 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2875 sym
= symbol_make (".bb");
2876 S_SET_SEGMENT (sym
, text_section
);
2877 sym
->sy_frag
= frag_now
;
2878 S_SET_VALUE (sym
, frag_now_fix ());
2879 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2881 S_SET_NUMBER_AUXILIARY (sym
, 1);
2882 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2884 sym
->sy_tc
.output
= 1;
2886 SF_SET_PROCESS (sym
);
2888 ppc_frob_label (sym
);
2890 demand_empty_rest_of_line ();
2893 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2902 sym
= symbol_make (".eb");
2903 S_SET_SEGMENT (sym
, text_section
);
2904 sym
->sy_frag
= frag_now
;
2905 S_SET_VALUE (sym
, frag_now_fix ());
2906 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2907 S_SET_NUMBER_AUXILIARY (sym
, 1);
2908 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2909 sym
->sy_tc
.output
= 1;
2911 SF_SET_PROCESS (sym
);
2913 ppc_frob_label (sym
);
2915 demand_empty_rest_of_line ();
2918 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
2929 name
= demand_copy_C_string (&len
);
2930 sym
= symbol_make (name
);
2931 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2932 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2933 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
2934 S_SET_VALUE (sym
, 0);
2935 sym
->sy_tc
.output
= 1;
2937 ppc_frob_label (sym
);
2939 demand_empty_rest_of_line ();
2942 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
2950 sym
= symbol_make (".ec");
2951 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2952 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2953 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
2954 S_SET_VALUE (sym
, 0);
2955 sym
->sy_tc
.output
= 1;
2957 ppc_frob_label (sym
);
2959 demand_empty_rest_of_line ();
2962 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2968 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2969 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2976 subseg
= ppc_data_subsegment
;
2977 ++ppc_data_subsegment
;
2979 subseg_new (segment_name (data_section
), subseg
);
2980 ppc_toc_frag
= frag_now
;
2982 sym
= symbol_find_or_make ("TOC[TC0]");
2983 sym
->sy_frag
= frag_now
;
2984 S_SET_SEGMENT (sym
, data_section
);
2985 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2986 sym
->sy_tc
.subseg
= subseg
;
2987 sym
->sy_tc
.output
= 1;
2988 sym
->sy_tc
.within
= sym
;
2990 ppc_toc_csect
= sym
;
2992 for (list
= ppc_data_csects
;
2993 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2994 list
= list
->sy_tc
.next
)
2996 list
->sy_tc
.next
= sym
;
2998 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2999 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
3002 ppc_current_csect
= ppc_toc_csect
;
3004 demand_empty_rest_of_line ();
3007 #endif /* OBJ_XCOFF */
3009 /* The .tc pseudo-op. This is used when generating either XCOFF or
3010 ELF. This takes two or more arguments.
3012 When generating XCOFF output, the first argument is the name to
3013 give to this location in the toc; this will be a symbol with class
3014 TC. The rest of the arguments are 4 byte values to actually put at
3015 this location in the TOC; often there is just one more argument, a
3016 relocateable symbol reference.
3018 When not generating XCOFF output, the arguments are the same, but
3019 the first argument is simply ignored. */
3027 /* Define the TOC symbol name. */
3033 if (ppc_toc_csect
== (symbolS
*) NULL
3034 || ppc_toc_csect
!= ppc_current_csect
)
3036 as_bad (".tc not in .toc section");
3037 ignore_rest_of_line ();
3041 name
= input_line_pointer
;
3042 endc
= get_symbol_end ();
3044 sym
= symbol_find_or_make (name
);
3046 *input_line_pointer
= endc
;
3048 if (S_IS_DEFINED (sym
))
3052 label
= ppc_current_csect
->sy_tc
.within
;
3053 if (label
->sy_tc
.class != XMC_TC0
)
3055 as_bad (".tc with no label");
3056 ignore_rest_of_line ();
3060 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3061 label
->sy_frag
= sym
->sy_frag
;
3062 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3064 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3065 ++input_line_pointer
;
3070 S_SET_SEGMENT (sym
, now_seg
);
3071 sym
->sy_frag
= frag_now
;
3072 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3073 sym
->sy_tc
.class = XMC_TC
;
3074 sym
->sy_tc
.output
= 1;
3076 ppc_frob_label (sym
);
3079 #else /* ! defined (OBJ_XCOFF) */
3081 /* Skip the TOC symbol name. */
3082 while (is_part_of_name (*input_line_pointer
)
3083 || *input_line_pointer
== '['
3084 || *input_line_pointer
== ']'
3085 || *input_line_pointer
== '{'
3086 || *input_line_pointer
== '}')
3087 ++input_line_pointer
;
3089 /* Align to a four byte boundary. */
3091 record_alignment (now_seg
, 2);
3093 #endif /* ! defined (OBJ_XCOFF) */
3095 if (*input_line_pointer
!= ',')
3096 demand_empty_rest_of_line ();
3099 ++input_line_pointer
;
3106 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3108 /* Set the current section. */
3110 ppc_set_current_section (new)
3113 ppc_previous_section
= ppc_current_section
;
3114 ppc_current_section
= new;
3117 /* pseudo-op: .previous
3118 behaviour: toggles the current section with the previous section.
3120 warnings: "No previous section"
3123 ppc_previous(ignore
)
3128 if (ppc_previous_section
== NULL
)
3130 as_warn("No previous section to return to. Directive ignored.");
3134 subseg_set(ppc_previous_section
, 0);
3136 ppc_set_current_section(ppc_previous_section
);
3139 /* pseudo-op: .pdata
3140 behaviour: predefined read only data section
3144 initial: .section .pdata "adr3"
3145 a - don't know -- maybe a misprint
3146 d - initialized data
3148 3 - double word aligned (that would be 4 byte boundary)
3151 Tag index tables (also known as the function table) for exception
3152 handling, debugging, etc.
3159 if (pdata_section
== 0)
3161 pdata_section
= subseg_new (".pdata", 0);
3163 bfd_set_section_flags (stdoutput
, pdata_section
,
3164 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3165 | SEC_READONLY
| SEC_DATA
));
3167 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3171 pdata_section
= subseg_new(".pdata", 0);
3173 ppc_set_current_section(pdata_section
);
3176 /* pseudo-op: .ydata
3177 behaviour: predefined read only data section
3181 initial: .section .ydata "drw3"
3182 a - don't know -- maybe a misprint
3183 d - initialized data
3185 3 - double word aligned (that would be 4 byte boundary)
3187 Tag tables (also known as the scope table) for exception handling,
3194 if (ydata_section
== 0)
3196 ydata_section
= subseg_new (".ydata", 0);
3197 bfd_set_section_flags (stdoutput
, ydata_section
,
3198 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3199 | SEC_READONLY
| SEC_DATA
));
3201 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3205 ydata_section
= subseg_new (".ydata", 0);
3207 ppc_set_current_section(ydata_section
);
3210 /* pseudo-op: .reldata
3211 behaviour: predefined read write data section
3212 double word aligned (4-byte)
3213 FIXME: relocation is applied to it
3214 FIXME: what's the difference between this and .data?
3217 initial: .section .reldata "drw3"
3218 d - initialized data
3221 3 - double word aligned (that would be 8 byte boundary)
3224 Like .data, but intended to hold data subject to relocation, such as
3225 function descriptors, etc.
3231 if (reldata_section
== 0)
3233 reldata_section
= subseg_new (".reldata", 0);
3235 bfd_set_section_flags (stdoutput
, reldata_section
,
3236 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3239 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3243 reldata_section
= subseg_new (".reldata", 0);
3245 ppc_set_current_section(reldata_section
);
3248 /* pseudo-op: .rdata
3249 behaviour: predefined read only data section
3253 initial: .section .rdata "dr3"
3254 d - initialized data
3256 3 - double word aligned (that would be 4 byte boundary)
3262 if (rdata_section
== 0)
3264 rdata_section
= subseg_new (".rdata", 0);
3265 bfd_set_section_flags (stdoutput
, rdata_section
,
3266 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3267 | SEC_READONLY
| SEC_DATA
));
3269 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3273 rdata_section
= subseg_new (".rdata", 0);
3275 ppc_set_current_section(rdata_section
);
3278 /* pseudo-op: .ualong
3279 behaviour: much like .int, with the exception that no alignment is
3281 FIXME: test the alignment statement
3293 /* pseudo-op: .znop <symbol name>
3294 behaviour: Issue a nop instruction
3295 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3296 the supplied symbol name.
3298 warnings: Missing symbol name
3305 const struct powerpc_opcode
*opcode
;
3311 /* Strip out the symbol name */
3319 symbol_name
= input_line_pointer
;
3320 c
= get_symbol_end ();
3322 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3323 strcpy (name
, symbol_name
);
3325 sym
= symbol_find_or_make (name
);
3327 *input_line_pointer
= c
;
3331 /* Look up the opcode in the hash table. */
3332 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3334 /* stick in the nop */
3335 insn
= opcode
->opcode
;
3337 /* Write out the instruction. */
3339 md_number_to_chars (f
, insn
, 4);
3341 f
- frag_now
->fr_literal
,
3346 BFD_RELOC_16_GOT_PCREL
);
3359 register char *name
;
3363 register symbolS
*symbolP
;
3366 name
= input_line_pointer
;
3367 c
= get_symbol_end ();
3369 /* just after name is now '\0' */
3370 p
= input_line_pointer
;
3373 if (*input_line_pointer
!= ',')
3375 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3376 ignore_rest_of_line ();
3380 input_line_pointer
++; /* skip ',' */
3381 if ((temp
= get_absolute_expression ()) < 0)
3383 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
3384 ignore_rest_of_line ();
3390 /* The third argument to .comm is the alignment. */
3391 if (*input_line_pointer
!= ',')
3395 ++input_line_pointer
;
3396 align
= get_absolute_expression ();
3399 as_warn ("ignoring bad alignment");
3406 symbolP
= symbol_find_or_make (name
);
3409 if (S_IS_DEFINED (symbolP
))
3411 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3412 S_GET_NAME (symbolP
));
3413 ignore_rest_of_line ();
3417 if (S_GET_VALUE (symbolP
))
3419 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3420 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3421 S_GET_NAME (symbolP
),
3422 (long) S_GET_VALUE (symbolP
),
3427 S_SET_VALUE (symbolP
, (valueT
) temp
);
3428 S_SET_EXTERNAL (symbolP
);
3431 demand_empty_rest_of_line ();
3435 * implement the .section pseudo op:
3436 * .section name {, "flags"}
3438 * | +--- optional flags: 'b' for bss
3440 * +-- section name 'l' for lib
3444 * 'd' (apparently m88k for data)
3446 * But if the argument is not a quoted string, treat it as a
3447 * subsegment number.
3449 * FIXME: this is a copy of the section processing from obj-coff.c, with
3450 * additions/changes for the moto-pas assembler support. There are three
3453 * FIXME: I just noticed this. This doesn't work at all really. It it
3454 * setting bits that bfd probably neither understands or uses. The
3455 * correct approach (?) will have to incorporate extra fields attached
3456 * to the section to hold the system specific stuff. (krk)
3459 * 'a' - unknown - referred to in documentation, but no definition supplied
3460 * 'c' - section has code
3461 * 'd' - section has initialized data
3462 * 'u' - section has uninitialized data
3463 * 'i' - section contains directives (info)
3464 * 'n' - section can be discarded
3465 * 'R' - remove section at link time
3467 * Section Protection:
3468 * 'r' - section is readable
3469 * 'w' - section is writeable
3470 * 'x' - section is executable
3471 * 's' - section is sharable
3473 * Section Alignment:
3474 * '0' - align to byte boundary
3475 * '1' - align to halfword undary
3476 * '2' - align to word boundary
3477 * '3' - align to doubleword boundary
3478 * '4' - align to quadword boundary
3479 * '5' - align to 32 byte boundary
3480 * '6' - align to 64 byte boundary
3485 ppc_pe_section (ignore
)
3488 /* Strip out the section name */
3497 section_name
= input_line_pointer
;
3498 c
= get_symbol_end ();
3500 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3501 strcpy (name
, section_name
);
3503 *input_line_pointer
= c
;
3508 flags
= SEC_NO_FLAGS
;
3510 if (strcmp (name
, ".idata$2") == 0)
3514 else if (strcmp (name
, ".idata$3") == 0)
3518 else if (strcmp (name
, ".idata$4") == 0)
3522 else if (strcmp (name
, ".idata$5") == 0)
3526 else if (strcmp (name
, ".idata$6") == 0)
3531 align
= 4; /* default alignment to 16 byte boundary */
3533 if (*input_line_pointer
== ',')
3535 ++input_line_pointer
;
3537 if (*input_line_pointer
!= '"')
3538 exp
= get_absolute_expression ();
3541 ++input_line_pointer
;
3542 while (*input_line_pointer
!= '"'
3543 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3545 switch (*input_line_pointer
)
3547 /* Section Contents */
3548 case 'a': /* unknown */
3549 as_bad ("Unsupported section attribute -- 'a'");
3551 case 'c': /* code section */
3554 case 'd': /* section has initialized data */
3557 case 'u': /* section has uninitialized data */
3558 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3562 case 'i': /* section contains directives (info) */
3563 /* FIXME: This is IMAGE_SCN_LNK_INFO
3565 flags
|= SEC_HAS_CONTENTS
;
3567 case 'n': /* section can be discarded */
3570 case 'R': /* Remove section at link time */
3571 flags
|= SEC_NEVER_LOAD
;
3574 /* Section Protection */
3575 case 'r': /* section is readable */
3576 flags
|= IMAGE_SCN_MEM_READ
;
3578 case 'w': /* section is writeable */
3579 flags
|= IMAGE_SCN_MEM_WRITE
;
3581 case 'x': /* section is executable */
3582 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3584 case 's': /* section is sharable */
3585 flags
|= IMAGE_SCN_MEM_SHARED
;
3588 /* Section Alignment */
3589 case '0': /* align to byte boundary */
3590 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3593 case '1': /* align to halfword boundary */
3594 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3597 case '2': /* align to word boundary */
3598 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3601 case '3': /* align to doubleword boundary */
3602 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3605 case '4': /* align to quadword boundary */
3606 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3609 case '5': /* align to 32 byte boundary */
3610 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3613 case '6': /* align to 64 byte boundary */
3614 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3619 as_bad("unknown section attribute '%c'",
3620 *input_line_pointer
);
3623 ++input_line_pointer
;
3625 if (*input_line_pointer
== '"')
3626 ++input_line_pointer
;
3630 sec
= subseg_new (name
, (subsegT
) exp
);
3632 ppc_set_current_section(sec
);
3634 if (flags
!= SEC_NO_FLAGS
)
3636 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3637 as_bad ("error setting flags for \"%s\": %s",
3638 bfd_section_name (stdoutput
, sec
),
3639 bfd_errmsg (bfd_get_error ()));
3642 bfd_set_section_alignment(stdoutput
, sec
, align
);
3647 ppc_pe_function (ignore
)
3654 name
= input_line_pointer
;
3655 endc
= get_symbol_end ();
3657 ext_sym
= symbol_find_or_make (name
);
3659 *input_line_pointer
= endc
;
3661 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3662 SF_SET_FUNCTION (ext_sym
);
3663 SF_SET_PROCESS (ext_sym
);
3664 coff_add_linesym (ext_sym
);
3666 demand_empty_rest_of_line ();
3670 ppc_pe_tocd (ignore
)
3673 if (tocdata_section
== 0)
3675 tocdata_section
= subseg_new (".tocd", 0);
3676 /* FIXME: section flags won't work */
3677 bfd_set_section_flags (stdoutput
, tocdata_section
,
3678 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3679 | SEC_READONLY
| SEC_DATA
));
3681 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3685 rdata_section
= subseg_new (".tocd", 0);
3688 ppc_set_current_section(tocdata_section
);
3690 demand_empty_rest_of_line ();
3693 /* Don't adjust TOC relocs to use the section symbol. */
3696 ppc_pe_fix_adjustable (fix
)
3699 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3706 /* XCOFF specific symbol and file handling. */
3708 /* Canonicalize the symbol name. We use the to force the suffix, if
3709 any, to use square brackets, and to be in upper case. */
3712 ppc_canonicalize_symbol_name (name
)
3717 if (ppc_stab_symbol
)
3720 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3734 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3738 if (*s
== '\0' || s
[1] != '\0')
3739 as_bad ("bad symbol suffix");
3747 /* Set the class of a symbol based on the suffix, if any. This is
3748 called whenever a new symbol is created. */
3751 ppc_symbol_new_hook (sym
)
3756 sym
->sy_tc
.next
= NULL
;
3757 sym
->sy_tc
.output
= 0;
3758 sym
->sy_tc
.class = -1;
3759 sym
->sy_tc
.real_name
= NULL
;
3760 sym
->sy_tc
.subseg
= 0;
3761 sym
->sy_tc
.align
= 0;
3762 sym
->sy_tc
.size
= NULL
;
3763 sym
->sy_tc
.within
= NULL
;
3765 if (ppc_stab_symbol
)
3768 s
= strchr (S_GET_NAME (sym
), '[');
3769 if (s
== (const char *) NULL
)
3771 /* There is no suffix. */
3780 if (strcmp (s
, "BS]") == 0)
3781 sym
->sy_tc
.class = XMC_BS
;
3784 if (strcmp (s
, "DB]") == 0)
3785 sym
->sy_tc
.class = XMC_DB
;
3786 else if (strcmp (s
, "DS]") == 0)
3787 sym
->sy_tc
.class = XMC_DS
;
3790 if (strcmp (s
, "GL]") == 0)
3791 sym
->sy_tc
.class = XMC_GL
;
3794 if (strcmp (s
, "PR]") == 0)
3795 sym
->sy_tc
.class = XMC_PR
;
3798 if (strcmp (s
, "RO]") == 0)
3799 sym
->sy_tc
.class = XMC_RO
;
3800 else if (strcmp (s
, "RW]") == 0)
3801 sym
->sy_tc
.class = XMC_RW
;
3804 if (strcmp (s
, "SV]") == 0)
3805 sym
->sy_tc
.class = XMC_SV
;
3808 if (strcmp (s
, "TC]") == 0)
3809 sym
->sy_tc
.class = XMC_TC
;
3810 else if (strcmp (s
, "TI]") == 0)
3811 sym
->sy_tc
.class = XMC_TI
;
3812 else if (strcmp (s
, "TB]") == 0)
3813 sym
->sy_tc
.class = XMC_TB
;
3814 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3815 sym
->sy_tc
.class = XMC_TC0
;
3818 if (strcmp (s
, "UA]") == 0)
3819 sym
->sy_tc
.class = XMC_UA
;
3820 else if (strcmp (s
, "UC]") == 0)
3821 sym
->sy_tc
.class = XMC_UC
;
3824 if (strcmp (s
, "XO]") == 0)
3825 sym
->sy_tc
.class = XMC_XO
;
3829 if (sym
->sy_tc
.class == -1)
3830 as_bad ("Unrecognized symbol suffix");
3833 /* Set the class of a label based on where it is defined. This
3834 handles symbols without suffixes. Also, move the symbol so that it
3835 follows the csect symbol. */
3838 ppc_frob_label (sym
)
3841 if (ppc_current_csect
!= (symbolS
*) NULL
)
3843 if (sym
->sy_tc
.class == -1)
3844 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3846 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3847 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3849 ppc_current_csect
->sy_tc
.within
= sym
;
3853 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3854 seen. It tells ppc_adjust_symtab whether it needs to look through
3857 static boolean ppc_saw_abs
;
3859 /* Change the name of a symbol just before writing it out. Set the
3860 real name if the .rename pseudo-op was used. Otherwise, remove any
3861 class suffix. Return 1 if the symbol should not be included in the
3865 ppc_frob_symbol (sym
)
3868 static symbolS
*ppc_last_function
;
3869 static symbolS
*set_end
;
3871 /* Discard symbols that should not be included in the output symbol
3873 if (! sym
->sy_used_in_reloc
3874 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3875 || (! S_IS_EXTERNAL (sym
)
3876 && ! sym
->sy_tc
.output
3877 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3880 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3881 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3887 name
= S_GET_NAME (sym
);
3888 s
= strchr (name
, '[');
3889 if (s
!= (char *) NULL
)
3895 snew
= xmalloc (len
+ 1);
3896 memcpy (snew
, name
, len
);
3899 S_SET_NAME (sym
, snew
);
3903 if (set_end
!= (symbolS
*) NULL
)
3905 SA_SET_SYM_ENDNDX (set_end
, sym
);
3909 if (SF_GET_FUNCTION (sym
))
3911 if (ppc_last_function
!= (symbolS
*) NULL
)
3912 as_bad ("two .function pseudo-ops with no intervening .ef");
3913 ppc_last_function
= sym
;
3914 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3916 resolve_symbol_value (sym
->sy_tc
.size
);
3917 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3920 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3921 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3923 if (ppc_last_function
== (symbolS
*) NULL
)
3924 as_bad (".ef with no preceding .function");
3927 set_end
= ppc_last_function
;
3928 ppc_last_function
= NULL
;
3930 /* We don't have a C_EFCN symbol, but we need to force the
3931 COFF backend to believe that it has seen one. */
3932 coff_last_function
= NULL
;
3936 if (! S_IS_EXTERNAL (sym
)
3937 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3938 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3939 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3940 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
3941 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3942 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3943 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
3944 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
3945 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3946 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3948 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
3949 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3952 union internal_auxent
*a
;
3954 /* Create a csect aux. */
3955 i
= S_GET_NUMBER_AUXILIARY (sym
);
3956 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3957 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3958 if (sym
->sy_tc
.class == XMC_TC0
)
3960 /* This is the TOC table. */
3961 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3962 a
->x_csect
.x_scnlen
.l
= 0;
3963 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3965 else if (sym
->sy_tc
.subseg
!= 0)
3967 /* This is a csect symbol. x_scnlen is the size of the
3969 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3970 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3971 S_GET_SEGMENT (sym
))
3972 - S_GET_VALUE (sym
));
3975 resolve_symbol_value (sym
->sy_tc
.next
);
3976 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3977 - S_GET_VALUE (sym
));
3979 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3981 else if (S_GET_SEGMENT (sym
) == bss_section
)
3983 /* This is a common symbol. */
3984 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3985 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3986 if (S_IS_EXTERNAL (sym
))
3987 sym
->sy_tc
.class = XMC_RW
;
3989 sym
->sy_tc
.class = XMC_BS
;
3991 else if (S_GET_SEGMENT (sym
) == absolute_section
)
3993 /* This is an absolute symbol. The csect will be created by
3994 ppc_adjust_symtab. */
3996 a
->x_csect
.x_smtyp
= XTY_LD
;
3997 if (sym
->sy_tc
.class == -1)
3998 sym
->sy_tc
.class = XMC_XO
;
4000 else if (! S_IS_DEFINED (sym
))
4002 /* This is an external symbol. */
4003 a
->x_csect
.x_scnlen
.l
= 0;
4004 a
->x_csect
.x_smtyp
= XTY_ER
;
4006 else if (sym
->sy_tc
.class == XMC_TC
)
4010 /* This is a TOC definition. x_scnlen is the size of the
4012 next
= symbol_next (sym
);
4013 while (next
->sy_tc
.class == XMC_TC0
)
4014 next
= symbol_next (next
);
4015 if (next
== (symbolS
*) NULL
4016 || next
->sy_tc
.class != XMC_TC
)
4018 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4019 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4021 - S_GET_VALUE (sym
));
4023 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4024 - S_GET_VALUE (sym
));
4028 resolve_symbol_value (next
);
4029 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4030 - S_GET_VALUE (sym
));
4032 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4038 /* This is a normal symbol definition. x_scnlen is the
4039 symbol index of the containing csect. */
4040 if (S_GET_SEGMENT (sym
) == text_section
)
4041 csect
= ppc_text_csects
;
4042 else if (S_GET_SEGMENT (sym
) == data_section
)
4043 csect
= ppc_data_csects
;
4047 /* Skip the initial dummy symbol. */
4048 csect
= csect
->sy_tc
.next
;
4050 if (csect
== (symbolS
*) NULL
)
4052 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym
));
4053 a
->x_csect
.x_scnlen
.l
= 0;
4057 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
4059 resolve_symbol_value (csect
->sy_tc
.next
);
4060 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
4062 csect
= csect
->sy_tc
.next
;
4065 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4066 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
4068 a
->x_csect
.x_smtyp
= XTY_LD
;
4071 a
->x_csect
.x_parmhash
= 0;
4072 a
->x_csect
.x_snhash
= 0;
4073 if (sym
->sy_tc
.class == -1)
4074 a
->x_csect
.x_smclas
= XMC_PR
;
4076 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
4077 a
->x_csect
.x_stab
= 0;
4078 a
->x_csect
.x_snstab
= 0;
4080 /* Don't let the COFF backend resort these symbols. */
4081 sym
->bsym
->flags
|= BSF_NOT_AT_END
;
4083 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4085 /* We want the value to be the symbol index of the referenced
4086 csect symbol. BFD will do that for us if we set the right
4089 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
4090 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
4092 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4097 /* The value is the offset from the enclosing csect. */
4098 block
= sym
->sy_tc
.within
;
4099 csect
= block
->sy_tc
.within
;
4100 resolve_symbol_value (csect
);
4101 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4103 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4104 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4106 /* We want the value to be a file offset into the line numbers.
4107 BFD will do that for us if we set the right flags. We have
4108 already set the value correctly. */
4109 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
4115 /* Adjust the symbol table. This creates csect symbols for all
4116 absolute symbols. */
4119 ppc_adjust_symtab ()
4126 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4130 union internal_auxent
*a
;
4132 if (S_GET_SEGMENT (sym
) != absolute_section
)
4135 csect
= symbol_create (".abs[XO]", absolute_section
,
4136 S_GET_VALUE (sym
), &zero_address_frag
);
4137 csect
->bsym
->value
= S_GET_VALUE (sym
);
4138 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4139 i
= S_GET_NUMBER_AUXILIARY (csect
);
4140 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4141 a
= &coffsymbol (csect
->bsym
)->native
[i
+ 1].u
.auxent
;
4142 a
->x_csect
.x_scnlen
.l
= 0;
4143 a
->x_csect
.x_smtyp
= XTY_SD
;
4144 a
->x_csect
.x_parmhash
= 0;
4145 a
->x_csect
.x_snhash
= 0;
4146 a
->x_csect
.x_smclas
= XMC_XO
;
4147 a
->x_csect
.x_stab
= 0;
4148 a
->x_csect
.x_snstab
= 0;
4150 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4152 i
= S_GET_NUMBER_AUXILIARY (sym
);
4153 a
= &coffsymbol (sym
->bsym
)->native
[i
].u
.auxent
;
4154 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4155 coffsymbol (sym
->bsym
)->native
[i
].fix_scnlen
= 1;
4158 ppc_saw_abs
= false;
4161 /* Set the VMA for a section. This is called on all the sections in
4165 ppc_frob_section (sec
)
4168 static bfd_size_type vma
= 0;
4170 bfd_set_section_vma (stdoutput
, sec
, vma
);
4171 vma
+= bfd_section_size (stdoutput
, sec
);
4174 #endif /* OBJ_XCOFF */
4176 /* Turn a string in input_line_pointer into a floating point constant
4177 of type type, and store the appropriate bytes in *litp. The number
4178 of LITTLENUMS emitted is stored in *sizep . An error message is
4179 returned, or NULL on OK. */
4182 md_atof (type
, litp
, sizep
)
4188 LITTLENUM_TYPE words
[4];
4204 return "bad call to md_atof";
4207 t
= atof_ieee (input_line_pointer
, type
, words
);
4209 input_line_pointer
= t
;
4213 if (target_big_endian
)
4215 for (i
= 0; i
< prec
; i
++)
4217 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4223 for (i
= prec
- 1; i
>= 0; i
--)
4225 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4233 /* Write a value out to the object file, using the appropriate
4237 md_number_to_chars (buf
, val
, n
)
4242 if (target_big_endian
)
4243 number_to_chars_bigendian (buf
, val
, n
);
4245 number_to_chars_littleendian (buf
, val
, n
);
4248 /* Align a section (I don't know why this is machine dependent). */
4251 md_section_align (seg
, addr
)
4255 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4257 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4260 /* We don't have any form of relaxing. */
4263 md_estimate_size_before_relax (fragp
, seg
)
4271 /* Convert a machine dependent frag. We never generate these. */
4274 md_convert_frag (abfd
, sec
, fragp
)
4282 /* We have no need to default values of symbols. */
4286 md_undefined_symbol (name
)
4292 /* Functions concerning relocs. */
4294 /* The location from which a PC relative jump should be calculated,
4295 given a PC relative reloc. */
4298 md_pcrel_from_section (fixp
, sec
)
4303 if (fixp
->fx_addsy
!= (symbolS
*) NULL
4304 && (! S_IS_DEFINED (fixp
->fx_addsy
)
4305 || TC_FORCE_RELOCATION_SECTION (fixp
, sec
)))
4309 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4314 /* This is called to see whether a fixup should be adjusted to use a
4315 section symbol. We take the opportunity to change a fixup against
4316 a symbol in the TOC subsegment into a reloc against the
4317 corresponding .tc symbol. */
4320 ppc_fix_adjustable (fix
)
4325 resolve_symbol_value (fix
->fx_addsy
);
4326 val
= S_GET_VALUE (fix
->fx_addsy
);
4327 if (ppc_toc_csect
!= (symbolS
*) NULL
4328 && fix
->fx_addsy
!= (symbolS
*) NULL
4329 && fix
->fx_addsy
!= ppc_toc_csect
4330 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4331 && val
>= ppc_toc_frag
->fr_address
4332 && (ppc_after_toc_frag
== (fragS
*) NULL
4333 || val
< ppc_after_toc_frag
->fr_address
))
4337 for (sy
= symbol_next (ppc_toc_csect
);
4338 sy
!= (symbolS
*) NULL
;
4339 sy
= symbol_next (sy
))
4341 if (sy
->sy_tc
.class == XMC_TC0
)
4343 if (sy
->sy_tc
.class != XMC_TC
)
4345 resolve_symbol_value (sy
);
4346 if (val
== S_GET_VALUE (sy
))
4349 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4354 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4355 "symbol in .toc does not match any .tc");
4358 /* Possibly adjust the reloc to be against the csect. */
4359 if (fix
->fx_addsy
!= (symbolS
*) NULL
4360 && fix
->fx_addsy
->sy_tc
.subseg
== 0
4361 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
4362 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
4363 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
4367 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4368 csect
= ppc_text_csects
;
4369 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4370 csect
= ppc_data_csects
;
4374 /* Skip the initial dummy symbol. */
4375 csect
= csect
->sy_tc
.next
;
4377 if (csect
!= (symbolS
*) NULL
)
4379 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
4380 && (csect
->sy_tc
.next
->sy_frag
->fr_address
4381 <= fix
->fx_addsy
->sy_frag
->fr_address
))
4382 csect
= csect
->sy_tc
.next
;
4384 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4385 - csect
->sy_frag
->fr_address
);
4386 fix
->fx_addsy
= csect
;
4390 /* Adjust a reloc against a .lcomm symbol to be against the base
4392 if (fix
->fx_addsy
!= (symbolS
*) NULL
4393 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4394 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4396 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
4397 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4398 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
4399 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
4405 /* A reloc from one csect to another must be kept. The assembler
4406 will, of course, keep relocs between sections, and it will keep
4407 absolute relocs, but we need to force it to keep PC relative relocs
4408 between two csects in the same section. */
4411 ppc_force_relocation (fix
)
4414 /* At this point fix->fx_addsy should already have been converted to
4415 a csect symbol. If the csect does not include the fragment, then
4416 we need to force the relocation. */
4418 && fix
->fx_addsy
!= NULL
4419 && fix
->fx_addsy
->sy_tc
.subseg
!= 0
4420 && (fix
->fx_addsy
->sy_frag
->fr_address
> fix
->fx_frag
->fr_address
4421 || (fix
->fx_addsy
->sy_tc
.next
!= NULL
4422 && (fix
->fx_addsy
->sy_tc
.next
->sy_frag
->fr_address
4423 <= fix
->fx_frag
->fr_address
))))
4429 #endif /* OBJ_XCOFF */
4431 /* See whether a symbol is in the TOC section. */
4434 ppc_is_toc_sym (sym
)
4438 return sym
->sy_tc
.class == XMC_TC
;
4440 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4444 /* Apply a fixup to the object code. This is called for all the
4445 fixups we generated by the call to fix_new_exp, above. In the call
4446 above we used a reloc code which was the largest legal reloc code
4447 plus the operand index. Here we undo that to recover the operand
4448 index. At this point all symbol values should be fully resolved,
4449 and we attempt to completely resolve the reloc. If we can not do
4450 that, we determine the correct reloc code and put it back in the
4454 md_apply_fix3 (fixp
, valuep
, seg
)
4461 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4462 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4463 doing this relocation the code in write.c is going to call
4464 bfd_perform_relocation, which is also going to use the symbol
4465 value. That means that if the reloc is fully resolved we want to
4466 use *valuep since bfd_perform_relocation is not being used.
4467 However, if the reloc is not fully resolved we do not want to use
4468 *valuep, and must use fx_offset instead. However, if the reloc
4469 is PC relative, we do want to use *valuep since it includes the
4470 result of md_pcrel_from. This is confusing. */
4472 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4477 else if (fixp
->fx_pcrel
)
4481 value
= fixp
->fx_offset
;
4482 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4484 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4485 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4488 /* We can't actually support subtracting a symbol. */
4489 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4490 "expression too complex");
4495 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4498 const struct powerpc_operand
*operand
;
4502 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4504 operand
= &powerpc_operands
[opindex
];
4507 /* It appears that an instruction like
4509 when LC..1 is not a TOC symbol does not generate a reloc. It
4510 uses the offset of LC..1 within its csect. However, .long
4511 LC..1 will generate a reloc. I can't find any documentation
4512 on how these cases are to be distinguished, so this is a wild
4513 guess. These cases are generated by gcc -mminimal-toc. */
4514 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4515 && operand
->bits
== 16
4516 && operand
->shift
== 0
4517 && operand
->insert
== NULL
4518 && fixp
->fx_addsy
!= NULL
4519 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
4520 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
4521 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
4522 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4524 value
= fixp
->fx_offset
;
4529 /* Fetch the instruction, insert the fully resolved operand
4530 value, and stuff the instruction back again. */
4531 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4532 if (target_big_endian
)
4533 insn
= bfd_getb32 ((unsigned char *) where
);
4535 insn
= bfd_getl32 ((unsigned char *) where
);
4536 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4537 fixp
->fx_file
, fixp
->fx_line
);
4538 if (target_big_endian
)
4539 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4541 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4545 /* Nothing else to do here. */
4549 /* Determine a BFD reloc value based on the operand information.
4550 We are only prepared to turn a few of the operands into
4552 FIXME: We need to handle the DS field at the very least.
4553 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4554 there should be a new field in the operand table. */
4555 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4556 && operand
->bits
== 26
4557 && operand
->shift
== 0)
4558 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4559 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4560 && operand
->bits
== 16
4561 && operand
->shift
== 0)
4562 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4563 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4564 && operand
->bits
== 26
4565 && operand
->shift
== 0)
4566 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4567 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4568 && operand
->bits
== 16
4569 && operand
->shift
== 0)
4570 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4571 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4572 && operand
->bits
== 16
4573 && operand
->shift
== 0
4574 && operand
->insert
== NULL
4575 && fixp
->fx_addsy
!= NULL
4576 && ppc_is_toc_sym (fixp
->fx_addsy
))
4579 if (target_big_endian
)
4580 fixp
->fx_where
+= 2;
4581 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4585 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4586 "unresolved expression that must be resolved");
4594 ppc_elf_validate_fix (fixp
, seg
);
4596 switch (fixp
->fx_r_type
)
4599 case BFD_RELOC_CTOR
:
4601 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4605 case BFD_RELOC_32_PCREL
:
4606 case BFD_RELOC_32_BASEREL
:
4607 case BFD_RELOC_PPC_EMB_NADDR32
:
4608 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4612 case BFD_RELOC_LO16
:
4613 case BFD_RELOC_HI16
:
4614 case BFD_RELOC_HI16_S
:
4616 case BFD_RELOC_GPREL16
:
4617 case BFD_RELOC_16_GOT_PCREL
:
4618 case BFD_RELOC_16_GOTOFF
:
4619 case BFD_RELOC_LO16_GOTOFF
:
4620 case BFD_RELOC_HI16_GOTOFF
:
4621 case BFD_RELOC_HI16_S_GOTOFF
:
4622 case BFD_RELOC_LO16_BASEREL
:
4623 case BFD_RELOC_HI16_BASEREL
:
4624 case BFD_RELOC_HI16_S_BASEREL
:
4625 case BFD_RELOC_PPC_EMB_NADDR16
:
4626 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
4627 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
4628 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
4629 case BFD_RELOC_PPC_EMB_SDAI16
:
4630 case BFD_RELOC_PPC_EMB_SDA2REL
:
4631 case BFD_RELOC_PPC_EMB_SDA2I16
:
4632 case BFD_RELOC_PPC_EMB_RELSEC16
:
4633 case BFD_RELOC_PPC_EMB_RELST_LO
:
4634 case BFD_RELOC_PPC_EMB_RELST_HI
:
4635 case BFD_RELOC_PPC_EMB_RELST_HA
:
4636 case BFD_RELOC_PPC_EMB_RELSDA
:
4637 case BFD_RELOC_PPC_TOC16
:
4639 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4640 "cannot emit PC relative %s relocation%s%s",
4641 bfd_get_reloc_code_name (fixp
->fx_r_type
),
4642 fixp
->fx_addsy
!= NULL
? " against " : "",
4643 (fixp
->fx_addsy
!= NULL
4644 ? S_GET_NAME (fixp
->fx_addsy
)
4647 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4651 /* Because SDA21 modifies the register field, the size is set to 4
4652 bytes, rather than 2, so offset it here appropriately */
4653 case BFD_RELOC_PPC_EMB_SDA21
:
4657 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
4658 + ((target_big_endian
) ? 2 : 0),
4666 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4672 "Gas failure, reloc value %d\n", fixp
->fx_r_type
);
4679 fixp
->fx_addnumber
= value
;
4681 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4682 fixp
->fx_addnumber
= 0;
4686 fixp
->fx_addnumber
= 0;
4688 /* We want to use the offset within the data segment of the
4689 symbol, not the actual VMA of the symbol. */
4690 fixp
->fx_addnumber
=
4691 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4699 /* Generate a reloc for a fixup. */
4702 tc_gen_reloc (seg
, fixp
)
4708 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4710 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4711 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4712 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4713 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4715 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4716 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4719 reloc
->addend
= fixp
->fx_addnumber
;