1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/ppc.h"
37 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
39 /* Tell the main code what the endianness is. */
40 extern int target_big_endian;
42 /* Whether or not, we've set target_big_endian. */
43 static int set_target_endian = 0;
45 /* Whether to use user friendly register names. */
46 #ifndef TARGET_REG_NAMES_P
48 #define TARGET_REG_NAMES_P true
50 #define TARGET_REG_NAMES_P false
54 static boolean reg_names_p = TARGET_REG_NAMES_P;
56 static boolean register_name PARAMS ((expressionS *));
57 static void ppc_set_cpu PARAMS ((void));
58 static unsigned long ppc_insert_operand
59 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
60 offsetT val, char *file, unsigned int line));
61 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
62 static void ppc_byte PARAMS ((int));
63 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
64 static void ppc_tc PARAMS ((int));
67 static void ppc_comm PARAMS ((int));
68 static void ppc_bb PARAMS ((int));
69 static void ppc_bc PARAMS ((int));
70 static void ppc_bf PARAMS ((int));
71 static void ppc_biei PARAMS ((int));
72 static void ppc_bs PARAMS ((int));
73 static void ppc_eb PARAMS ((int));
74 static void ppc_ec PARAMS ((int));
75 static void ppc_ef PARAMS ((int));
76 static void ppc_es PARAMS ((int));
77 static void ppc_csect PARAMS ((int));
78 static void ppc_change_csect PARAMS ((symbolS *));
79 static void ppc_function PARAMS ((int));
80 static void ppc_extern PARAMS ((int));
81 static void ppc_lglobl PARAMS ((int));
82 static void ppc_section PARAMS ((int));
83 static void ppc_named_section PARAMS ((int));
84 static void ppc_stabx PARAMS ((int));
85 static void ppc_rename PARAMS ((int));
86 static void ppc_toc PARAMS ((int));
87 static void ppc_xcoff_cons PARAMS ((int));
91 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
92 static void ppc_elf_cons PARAMS ((int));
93 static void ppc_elf_rdata PARAMS ((int));
94 static void ppc_elf_lcomm PARAMS ((int));
95 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
99 static void ppc_set_current_section PARAMS ((segT));
100 static void ppc_previous PARAMS ((int));
101 static void ppc_pdata PARAMS ((int));
102 static void ppc_ydata PARAMS ((int));
103 static void ppc_reldata PARAMS ((int));
104 static void ppc_rdata PARAMS ((int));
105 static void ppc_ualong PARAMS ((int));
106 static void ppc_znop PARAMS ((int));
107 static void ppc_pe_comm PARAMS ((int));
108 static void ppc_pe_section PARAMS ((int));
109 static void ppc_pe_function PARAMS ((int));
110 static void ppc_pe_tocd PARAMS ((int));
113 /* Generic assembler global variables which must be defined by all
117 /* This string holds the chars that always start a comment. If the
118 pre-processor is disabled, these aren't very useful. The macro
119 tc_comment_chars points to this. We use this, rather than the
120 usual comment_chars, so that we can switch for Solaris conventions. */
121 static const char ppc_solaris_comment_chars[] = "#!";
122 static const char ppc_eabi_comment_chars[] = "#";
124 #ifdef TARGET_SOLARIS_COMMENT
125 const char *ppc_comment_chars = ppc_solaris_comment_chars;
127 const char *ppc_comment_chars = ppc_eabi_comment_chars;
130 const char comment_chars[] = "#";
133 /* Characters which start a comment at the beginning of a line. */
134 const char line_comment_chars[] = "#";
136 /* Characters which may be used to separate multiple commands on a
138 const char line_separator_chars[] = ";";
140 /* Characters which are used to indicate an exponent in a floating
142 const char EXP_CHARS[] = "eE";
144 /* Characters which mean that a number is a floating point constant,
146 const char FLT_CHARS[] = "dD";
148 /* The target specific pseudo-ops which we support. */
150 const pseudo_typeS md_pseudo_table[] =
152 /* Pseudo-ops which must be overridden. */
153 { "byte", ppc_byte, 0 },
156 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
157 legitimately belong in the obj-*.c file. However, XCOFF is based
158 on COFF, and is only implemented for the RS/6000. We just use
159 obj-coff.c, and add what we need here. */
160 { "comm", ppc_comm, 0 },
161 { "lcomm", ppc_comm, 1 },
165 { "bi", ppc_biei, 0 },
167 { "csect", ppc_csect, 0 },
168 { "data", ppc_section, 'd' },
172 { "ei", ppc_biei, 1 },
174 { "extern", ppc_extern, 0 },
175 { "function", ppc_function, 0 },
176 { "lglobl", ppc_lglobl, 0 },
177 { "rename", ppc_rename, 0 },
178 { "section", ppc_named_section, 0 },
179 { "stabx", ppc_stabx, 0 },
180 { "text", ppc_section, 't' },
181 { "toc", ppc_toc, 0 },
182 { "long", ppc_xcoff_cons, 2 },
183 { "word", ppc_xcoff_cons, 1 },
184 { "short", ppc_xcoff_cons, 1 },
188 { "long", ppc_elf_cons, 4 },
189 { "word", ppc_elf_cons, 2 },
190 { "short", ppc_elf_cons, 2 },
191 { "rdata", ppc_elf_rdata, 0 },
192 { "rodata", ppc_elf_rdata, 0 },
193 { "lcomm", ppc_elf_lcomm, 0 },
197 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
198 { "previous", ppc_previous, 0 },
199 { "pdata", ppc_pdata, 0 },
200 { "ydata", ppc_ydata, 0 },
201 { "reldata", ppc_reldata, 0 },
202 { "rdata", ppc_rdata, 0 },
203 { "ualong", ppc_ualong, 0 },
204 { "znop", ppc_znop, 0 },
205 { "comm", ppc_pe_comm, 0 },
206 { "lcomm", ppc_pe_comm, 1 },
207 { "section", ppc_pe_section, 0 },
208 { "function", ppc_pe_function,0 },
209 { "tocd", ppc_pe_tocd, 0 },
212 /* This pseudo-op is used even when not generating XCOFF output. */
219 /* Predefined register names if -mregnames (or default for Windows NT). */
220 /* In general, there are lots of them, in an attempt to be compatible */
221 /* with a number of other Windows NT assemblers. */
223 /* Structure to hold information about predefined registers. */
230 /* List of registers that are pre-defined:
232 Each general register has predefined names of the form:
233 1. r<reg_num> which has the value <reg_num>.
234 2. r.<reg_num> which has the value <reg_num>.
237 Each floating point register has predefined names of the form:
238 1. f<reg_num> which has the value <reg_num>.
239 2. f.<reg_num> which has the value <reg_num>.
241 Each condition register has predefined names of the form:
242 1. cr<reg_num> which has the value <reg_num>.
243 2. cr.<reg_num> which has the value <reg_num>.
245 There are individual registers as well:
246 sp or r.sp has the value 1
247 rtoc or r.toc has the value 2
248 fpscr has the value 0
254 dsisr has the value 18
256 sdr1 has the value 25
257 srr0 has the value 26
258 srr1 has the value 27
260 The table is sorted. Suitable for searching by a binary search. */
262 static const struct pd_reg pre_defined_registers[] =
264 { "cr.0", 0 }, /* Condition Registers */
284 { "dar", 19 }, /* Data Access Register */
285 { "dec", 22 }, /* Decrementer */
286 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
288 { "f.0", 0 }, /* Floating point registers */
356 { "lr", 8 }, /* Link Register */
360 { "r.0", 0 }, /* General Purpose Registers */
393 { "r.sp", 1 }, /* Stack Pointer */
395 { "r.toc", 2 }, /* Pointer to the table of contents */
397 { "r0", 0 }, /* More general purpose registers */
430 { "rtoc", 2 }, /* Table of contents */
432 { "sdr1", 25 }, /* Storage Description Register 1 */
436 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
437 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
443 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
445 /* Given NAME, find the register number associated with that name, return
446 the integer value associated with the given name or -1 on failure. */
448 static int reg_name_search
449 PARAMS ((const struct pd_reg *, int, const char * name));
452 reg_name_search (regs, regcount, name)
453 const struct pd_reg *regs;
457 int middle, low, high;
465 middle = (low + high) / 2;
466 cmp = strcasecmp (name, regs[middle].name);
472 return regs[middle].value;
480 * Summary of register_name().
482 * in: Input_line_pointer points to 1st char of operand.
484 * out: A expressionS.
485 * The operand may have been a register: in this case, X_op == O_register,
486 * X_add_number is set to the register number, and truth is returned.
487 * Input_line_pointer->(next non-blank) char after operand, or is in its
492 register_name (expressionP)
493 expressionS *expressionP;
500 /* Find the spelling of the operand */
501 start = name = input_line_pointer;
502 if (name[0] == '%' && isalpha (name[1]))
503 name = ++input_line_pointer;
505 else if (!reg_names_p || !isalpha (name[0]))
508 c = get_symbol_end ();
509 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
511 /* look to see if it's in the register table */
514 expressionP->X_op = O_register;
515 expressionP->X_add_number = reg_number;
517 /* make the rest nice */
518 expressionP->X_add_symbol = NULL;
519 expressionP->X_op_symbol = NULL;
520 *input_line_pointer = c; /* put back the delimiting char */
525 /* reset the line as if we had not done anything */
526 *input_line_pointer = c; /* put back the delimiting char */
527 input_line_pointer = start; /* reset input_line pointer */
532 /* This function is called for each symbol seen in an expression. It
533 handles the special parsing which PowerPC assemblers are supposed
534 to use for condition codes. */
536 /* Whether to do the special parsing. */
537 static boolean cr_operand;
539 /* Names to recognize in a condition code. This table is sorted. */
540 static const struct pd_reg cr_names[] =
557 /* Parsing function. This returns non-zero if it recognized an
561 ppc_parse_name (name, expr)
570 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
575 expr->X_op = O_constant;
576 expr->X_add_number = val;
581 /* Local variables. */
583 /* The type of processor we are assembling for. This is one or more
584 of the PPC_OPCODE flags defined in opcode/ppc.h. */
585 static int ppc_cpu = 0;
587 /* The size of the processor we are assembling for. This is either
588 PPC_OPCODE_32 or PPC_OPCODE_64. */
589 static int ppc_size = PPC_OPCODE_32;
591 /* Opcode hash table. */
592 static struct hash_control *ppc_hash;
594 /* Macro hash table. */
595 static struct hash_control *ppc_macro_hash;
598 /* What type of shared library support to use */
599 static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
601 /* Flags to set in the elf header */
602 static flagword ppc_flags = 0;
604 /* Whether this is Solaris or not. */
605 #ifdef TARGET_SOLARIS_COMMENT
606 #define SOLARIS_P true
608 #define SOLARIS_P false
611 static boolean msolaris = SOLARIS_P;
616 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
617 using a bunch of different sections. These assembler sections,
618 however, are all encompassed within the .text or .data sections of
619 the final output file. We handle this by using different
620 subsegments within these main segments. */
622 /* Next subsegment to allocate within the .text segment. */
623 static subsegT ppc_text_subsegment = 2;
625 /* Linked list of csects in the text section. */
626 static symbolS *ppc_text_csects;
628 /* Next subsegment to allocate within the .data segment. */
629 static subsegT ppc_data_subsegment = 2;
631 /* Linked list of csects in the data section. */
632 static symbolS *ppc_data_csects;
634 /* The current csect. */
635 static symbolS *ppc_current_csect;
637 /* The RS/6000 assembler uses a TOC which holds addresses of functions
638 and variables. Symbols are put in the TOC with the .tc pseudo-op.
639 A special relocation is used when accessing TOC entries. We handle
640 the TOC as a subsegment within the .data segment. We set it up if
641 we see a .toc pseudo-op, and save the csect symbol here. */
642 static symbolS *ppc_toc_csect;
644 /* The first frag in the TOC subsegment. */
645 static fragS *ppc_toc_frag;
647 /* The first frag in the first subsegment after the TOC in the .data
648 segment. NULL if there are no subsegments after the TOC. */
649 static fragS *ppc_after_toc_frag;
651 /* The current static block. */
652 static symbolS *ppc_current_block;
654 /* The COFF debugging section; set by md_begin. This is not the
655 .debug section, but is instead the secret BFD section which will
656 cause BFD to set the section number of a symbol to N_DEBUG. */
657 static asection *ppc_coff_debug_section;
659 #endif /* OBJ_XCOFF */
663 /* Various sections that we need for PE coff support. */
664 static segT ydata_section;
665 static segT pdata_section;
666 static segT reldata_section;
667 static segT rdata_section;
668 static segT tocdata_section;
670 /* The current section and the previous section. See ppc_previous. */
671 static segT ppc_previous_section;
672 static segT ppc_current_section;
677 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
680 #ifndef WORKING_DOT_WORD
681 const int md_short_jump_size = 4;
682 const int md_long_jump_size = 4;
686 CONST char *md_shortopts = "b:l:usm:K:VQ:";
688 CONST char *md_shortopts = "um:";
690 struct option md_longopts[] = {
691 {NULL, no_argument, NULL, 0}
693 size_t md_longopts_size = sizeof(md_longopts);
696 md_parse_option (c, arg)
703 /* -u means that any undefined symbols should be treated as
704 external, which is the default for gas anyhow. */
709 /* Solaris as takes -le (presumably for little endian). For completeness
710 sake, recognize -be also. */
711 if (strcmp (arg, "e") == 0)
713 target_big_endian = 0;
714 set_target_endian = 1;
722 if (strcmp (arg, "e") == 0)
724 target_big_endian = 1;
725 set_target_endian = 1;
733 /* Recognize -K PIC */
734 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
737 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
746 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
748 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
749 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
750 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
751 else if (strcmp (arg, "pwr") == 0)
752 ppc_cpu = PPC_OPCODE_POWER;
753 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
754 instructions that are holdovers from the Power. */
755 else if (strcmp (arg, "601") == 0)
756 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
757 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
758 Motorola PowerPC 603/604. */
759 else if (strcmp (arg, "ppc") == 0
760 || strcmp (arg, "ppc32") == 0
761 || strcmp (arg, "403") == 0
762 || strcmp (arg, "603") == 0
763 || strcmp (arg, "604") == 0)
764 ppc_cpu = PPC_OPCODE_PPC;
765 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
767 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
769 ppc_cpu = PPC_OPCODE_PPC;
770 ppc_size = PPC_OPCODE_64;
772 /* -mcom means assemble for the common intersection between Power
773 and PowerPC. At present, we just allow the union, rather
774 than the intersection. */
775 else if (strcmp (arg, "com") == 0)
776 ppc_cpu = PPC_OPCODE_COMMON;
777 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
778 else if (strcmp (arg, "any") == 0)
779 ppc_cpu = PPC_OPCODE_ANY;
781 else if (strcmp (arg, "regnames") == 0)
784 else if (strcmp (arg, "no-regnames") == 0)
788 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
789 else if (strcmp (arg, "relocatable") == 0)
791 shlib = SHILB_MRELOCATABLE;
792 ppc_flags |= EF_PPC_RELOCATABLE;
795 else if (strcmp (arg, "relocatable-lib") == 0)
797 shlib = SHILB_MRELOCATABLE;
798 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
801 /* -memb, set embedded bit */
802 else if (strcmp (arg, "emb") == 0)
803 ppc_flags |= EF_PPC_EMB;
805 /* -mlittle/-mbig set the endianess */
806 else if (strcmp (arg, "little") == 0 || strcmp (arg, "little-endian") == 0)
808 target_big_endian = 0;
809 set_target_endian = 1;
812 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
814 target_big_endian = 1;
815 set_target_endian = 1;
818 else if (strcmp (arg, "solaris") == 0)
821 ppc_comment_chars = ppc_solaris_comment_chars;
824 else if (strcmp (arg, "no-solaris") == 0)
827 ppc_comment_chars = ppc_eabi_comment_chars;
832 as_bad (_("invalid switch -m%s"), arg);
838 /* -V: SVR4 argument to print version ID. */
843 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
844 should be emitted or not. FIXME: Not implemented. */
848 /* Solaris takes -s to specify that .stabs go in a .stabs section,
849 rather than .stabs.excl, which is ignored by the linker.
850 FIXME: Not implemented. */
866 md_show_usage (stream)
872 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
873 -mpwr generate code for IBM POWER (RIOS1)\n\
874 -m601 generate code for Motorola PowerPC 601\n\
875 -mppc, -mppc32, -m403, -m603, -m604\n\
876 generate code for Motorola PowerPC 603/604\n\
877 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
878 -mcom generate code Power/PowerPC common instructions\n\
879 -many generate code for any architecture (PWR/PWRX/PPC)\n\
880 -mregnames Allow symbolic names for registers\n\
881 -mno-regnames Do not allow symbolic names for registers\n"));
884 -mrelocatable support for GCC's -mrelocatble option\n\
885 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
886 -memb set PPC_EMB bit in ELF flags\n\
887 -mlittle, -mlittle-endian\n\
888 generate code for a little endian machine\n\
889 -mbig, -mbig-endian generate code for a big endian machine\n\
890 -msolaris generate code for Solaris\n\
891 -mno-solaris do not generate code for Solaris\n\
892 -V print assembler version number\n\
893 -Qy, -Qn ignored\n"));
897 /* Set ppc_cpu if it is not already set. */
902 const char *default_os = TARGET_OS;
903 const char *default_cpu = TARGET_CPU;
907 if (strncmp (default_os, "aix", 3) == 0
908 && default_os[3] >= '4' && default_os[3] <= '9')
909 ppc_cpu = PPC_OPCODE_COMMON;
910 else if (strncmp (default_os, "aix3", 4) == 0)
911 ppc_cpu = PPC_OPCODE_POWER;
912 else if (strcmp (default_cpu, "rs6000") == 0)
913 ppc_cpu = PPC_OPCODE_POWER;
914 else if (strcmp (default_cpu, "powerpc") == 0
915 || strcmp (default_cpu, "powerpcle") == 0)
916 ppc_cpu = PPC_OPCODE_PPC;
918 as_fatal (_("Unknown default cpu = %s, os = %s"), default_cpu, default_os);
922 /* Figure out the BFD architecture to use. */
924 enum bfd_architecture
927 const char *default_cpu = TARGET_CPU;
930 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
931 return bfd_arch_powerpc;
932 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
933 return bfd_arch_rs6000;
934 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
936 if (strcmp (default_cpu, "rs6000") == 0)
937 return bfd_arch_rs6000;
938 else if (strcmp (default_cpu, "powerpc") == 0
939 || strcmp (default_cpu, "powerpcle") == 0)
940 return bfd_arch_powerpc;
943 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
944 return bfd_arch_unknown;
947 /* This function is called when the assembler starts up. It is called
948 after the options have been parsed and the output file has been
954 register const struct powerpc_opcode *op;
955 const struct powerpc_opcode *op_end;
956 const struct powerpc_macro *macro;
957 const struct powerpc_macro *macro_end;
958 boolean dup_insn = false;
963 /* Set the ELF flags if desired. */
964 if (ppc_flags && !msolaris)
965 bfd_set_private_flags (stdoutput, ppc_flags);
968 /* Insert the opcodes into a hash table. */
969 ppc_hash = hash_new ();
971 op_end = powerpc_opcodes + powerpc_num_opcodes;
972 for (op = powerpc_opcodes; op < op_end; op++)
974 know ((op->opcode & op->mask) == op->opcode);
976 if ((op->flags & ppc_cpu) != 0
977 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
978 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size))
982 retval = hash_insert (ppc_hash, op->name, (PTR) op);
983 if (retval != (const char *) NULL)
985 /* Ignore Power duplicates for -m601 */
986 if ((ppc_cpu & PPC_OPCODE_601) != 0
987 && (op->flags & PPC_OPCODE_POWER) != 0)
990 as_bad (_("Internal assembler error for instruction %s"), op->name);
996 /* Insert the macros into a hash table. */
997 ppc_macro_hash = hash_new ();
999 macro_end = powerpc_macros + powerpc_num_macros;
1000 for (macro = powerpc_macros; macro < macro_end; macro++)
1002 if ((macro->flags & ppc_cpu) != 0)
1006 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1007 if (retval != (const char *) NULL)
1009 as_bad (_("Internal assembler error for macro %s"), macro->name);
1018 /* Tell the main code what the endianness is if it is not overidden by the user. */
1019 if (!set_target_endian)
1021 set_target_endian = 1;
1022 target_big_endian = PPC_BIG_ENDIAN;
1026 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1028 /* Create dummy symbols to serve as initial csects. This forces the
1029 text csects to precede the data csects. These symbols will not
1031 ppc_text_csects = symbol_make ("dummy\001");
1032 ppc_text_csects->sy_tc.within = ppc_text_csects;
1033 ppc_data_csects = symbol_make ("dummy\001");
1034 ppc_data_csects->sy_tc.within = ppc_data_csects;
1039 ppc_current_section = text_section;
1040 ppc_previous_section = 0;
1045 /* Insert an operand value into an instruction. */
1047 static unsigned long
1048 ppc_insert_operand (insn, operand, val, file, line)
1050 const struct powerpc_operand *operand;
1055 if (operand->bits != 32)
1060 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1062 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0
1063 && ppc_size == PPC_OPCODE_32)
1064 max = (1 << operand->bits) - 1;
1066 max = (1 << (operand->bits - 1)) - 1;
1067 min = - (1 << (operand->bits - 1));
1069 if (ppc_size == PPC_OPCODE_32)
1071 /* Some people write 32 bit hex constants with the sign
1072 extension done by hand. This shouldn't really be
1073 valid, but, to permit this code to assemble on a 64
1074 bit host, we sign extend the 32 bit value. */
1076 && (val & 0x80000000) != 0
1077 && (val & 0xffffffff) == val)
1086 max = (1 << operand->bits) - 1;
1090 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1095 if (test < (offsetT) min || test > (offsetT) max)
1098 _("operand out of range (%s not between %ld and %ld)");
1101 sprint_value (buf, test);
1102 if (file == (char *) NULL)
1103 as_bad (err, buf, min, max);
1105 as_bad_where (file, line, err, buf, min, max);
1109 if (operand->insert)
1114 insn = (*operand->insert) (insn, (long) val, &errmsg);
1115 if (errmsg != (const char *) NULL)
1119 insn |= (((long) val & ((1 << operand->bits) - 1))
1127 /* Parse @got, etc. and return the desired relocation. */
1128 static bfd_reloc_code_real_type
1129 ppc_elf_suffix (str_p, exp_p)
1136 bfd_reloc_code_real_type reloc;
1144 struct map_bfd *ptr;
1146 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1148 static struct map_bfd mapping[] = {
1149 MAP ("l", BFD_RELOC_LO16),
1150 MAP ("h", BFD_RELOC_HI16),
1151 MAP ("ha", BFD_RELOC_HI16_S),
1152 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1153 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1154 MAP ("got", BFD_RELOC_16_GOTOFF),
1155 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1156 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1157 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1158 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
1159 MAP ("plt", BFD_RELOC_24_PLT_PCREL),
1160 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1161 MAP ("copy", BFD_RELOC_PPC_COPY),
1162 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1163 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1164 MAP ("local", BFD_RELOC_PPC_LOCAL24PC),
1165 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
1166 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1167 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1168 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1169 MAP ("sdarel", BFD_RELOC_GPREL16),
1170 MAP ("sectoff", BFD_RELOC_32_BASEREL),
1171 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1172 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1173 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1174 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1175 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1176 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1177 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1178 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1179 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1180 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1181 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1182 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1183 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1184 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1185 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1186 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1187 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1188 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1189 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1190 MAP ("xgot", BFD_RELOC_PPC_TOC16),
1192 { (char *)0, 0, BFD_RELOC_UNUSED }
1196 return BFD_RELOC_UNUSED;
1198 for (ch = *str, str2 = ident;
1199 (str2 < ident + sizeof (ident) - 1
1200 && (isalnum (ch) || ch == '@'));
1203 *str2++ = (islower (ch)) ? ch : tolower (ch);
1210 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1211 if (ch == ptr->string[0]
1212 && len == ptr->length
1213 && memcmp (ident, ptr->string, ptr->length) == 0)
1215 if (exp_p->X_add_number != 0
1216 && (ptr->reloc == BFD_RELOC_16_GOTOFF
1217 || ptr->reloc == BFD_RELOC_LO16_GOTOFF
1218 || ptr->reloc == BFD_RELOC_HI16_GOTOFF
1219 || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
1220 as_warn (_("identifier+constant@got means identifier@got+constant"));
1222 /* Now check for identifier@suffix+constant */
1223 if (*str == '-' || *str == '+')
1225 char *orig_line = input_line_pointer;
1226 expressionS new_exp;
1228 input_line_pointer = str;
1229 expression (&new_exp);
1230 if (new_exp.X_op == O_constant)
1232 exp_p->X_add_number += new_exp.X_add_number;
1233 str = input_line_pointer;
1236 if (&input_line_pointer != str_p)
1237 input_line_pointer = orig_line;
1244 return BFD_RELOC_UNUSED;
1247 /* Like normal .long/.short/.word, except support @got, etc. */
1248 /* clobbers input_line_pointer, checks */
1251 ppc_elf_cons (nbytes)
1252 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1255 bfd_reloc_code_real_type reloc;
1257 if (is_it_end_of_statement ())
1259 demand_empty_rest_of_line ();
1266 if (exp.X_op == O_symbol
1267 && *input_line_pointer == '@'
1268 && (reloc = ppc_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
1270 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1271 int size = bfd_get_reloc_size (reloc_howto);
1274 as_bad (_("%s relocations do not fit in %d bytes\n"), reloc_howto->name, nbytes);
1278 register char *p = frag_more ((int) nbytes);
1279 int offset = nbytes - size;
1281 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
1285 emit_expr (&exp, (unsigned int) nbytes);
1287 while (*input_line_pointer++ == ',');
1289 input_line_pointer--; /* Put terminator back into stream. */
1290 demand_empty_rest_of_line ();
1293 /* Solaris pseduo op to change to the .rodata section. */
1298 char *save_line = input_line_pointer;
1299 static char section[] = ".rodata\n";
1301 /* Just pretend this is .section .rodata */
1302 input_line_pointer = section;
1303 obj_elf_section (xxx);
1305 input_line_pointer = save_line;
1308 /* Pseudo op to make file scope bss items */
1313 register char *name;
1317 register symbolS *symbolP;
1324 name = input_line_pointer;
1325 c = get_symbol_end ();
1327 /* just after name is now '\0' */
1328 p = input_line_pointer;
1331 if (*input_line_pointer != ',')
1333 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1334 ignore_rest_of_line ();
1338 input_line_pointer++; /* skip ',' */
1339 if ((size = get_absolute_expression ()) < 0)
1341 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
1342 ignore_rest_of_line ();
1346 /* The third argument to .lcomm is the alignment. */
1347 if (*input_line_pointer != ',')
1351 ++input_line_pointer;
1352 align = get_absolute_expression ();
1355 as_warn (_("ignoring bad alignment"));
1361 symbolP = symbol_find_or_make (name);
1364 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1366 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1367 S_GET_NAME (symbolP));
1368 ignore_rest_of_line ();
1372 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1374 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1375 S_GET_NAME (symbolP),
1376 (long) S_GET_VALUE (symbolP),
1379 ignore_rest_of_line ();
1385 old_subsec = now_subseg;
1388 /* convert to a power of 2 alignment */
1389 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1392 as_bad (_("Common alignment not a power of 2"));
1393 ignore_rest_of_line ();
1400 record_alignment (bss_section, align2);
1401 subseg_set (bss_section, 0);
1403 frag_align (align2, 0, 0);
1404 if (S_GET_SEGMENT (symbolP) == bss_section)
1405 symbolP->sy_frag->fr_symbol = 0;
1406 symbolP->sy_frag = frag_now;
1407 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1410 S_SET_SIZE (symbolP, size);
1411 S_SET_SEGMENT (symbolP, bss_section);
1412 subseg_set (old_sec, old_subsec);
1413 demand_empty_rest_of_line ();
1416 /* Validate any relocations emitted for -mrelocatable, possibly adding
1417 fixups for word relocations in writable segments, so we can adjust
1420 ppc_elf_validate_fix (fixp, seg)
1424 if (fixp->fx_done || fixp->fx_pcrel)
1433 case SHILB_MRELOCATABLE:
1434 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1435 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1436 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1437 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1438 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1439 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1440 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1441 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1442 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1443 && strcmp (segment_name (seg), ".got2") != 0
1444 && strcmp (segment_name (seg), ".dtors") != 0
1445 && strcmp (segment_name (seg), ".ctors") != 0
1446 && strcmp (segment_name (seg), ".fixup") != 0
1447 && strcmp (segment_name (seg), ".stab") != 0
1448 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1449 && strcmp (segment_name (seg), ".ex_shared") != 0)
1451 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1452 || fixp->fx_r_type != BFD_RELOC_CTOR)
1454 as_bad_where (fixp->fx_file, fixp->fx_line,
1455 _("Relocation cannot be done when using -mrelocatable"));
1461 #endif /* OBJ_ELF */
1466 * Summary of parse_toc_entry().
1468 * in: Input_line_pointer points to the '[' in one of:
1470 * [toc] [tocv] [toc32] [toc64]
1472 * Anything else is an error of one kind or another.
1475 * return value: success or failure
1476 * toc_kind: kind of toc reference
1477 * input_line_pointer:
1478 * success: first char after the ']'
1479 * failure: unchanged
1483 * [toc] - rv == success, toc_kind = default_toc
1484 * [tocv] - rv == success, toc_kind = data_in_toc
1485 * [toc32] - rv == success, toc_kind = must_be_32
1486 * [toc64] - rv == success, toc_kind = must_be_64
1490 enum toc_size_qualifier
1492 default_toc, /* The toc cell constructed should be the system default size */
1493 data_in_toc, /* This is a direct reference to a toc cell */
1494 must_be_32, /* The toc cell constructed must be 32 bits wide */
1495 must_be_64 /* The toc cell constructed must be 64 bits wide */
1499 parse_toc_entry(toc_kind)
1500 enum toc_size_qualifier *toc_kind;
1505 enum toc_size_qualifier t;
1507 /* save the input_line_pointer */
1508 start = input_line_pointer;
1510 /* skip over the '[' , and whitespace */
1511 ++input_line_pointer;
1514 /* find the spelling of the operand */
1515 toc_spec = input_line_pointer;
1516 c = get_symbol_end ();
1518 if (strcmp(toc_spec, "toc") == 0)
1522 else if (strcmp(toc_spec, "tocv") == 0)
1526 else if (strcmp(toc_spec, "toc32") == 0)
1530 else if (strcmp(toc_spec, "toc64") == 0)
1536 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
1537 *input_line_pointer = c; /* put back the delimiting char */
1538 input_line_pointer = start; /* reset input_line pointer */
1542 /* now find the ']' */
1543 *input_line_pointer = c; /* put back the delimiting char */
1545 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1546 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1550 as_bad (_("syntax error: expected `]', found `%c'"), c);
1551 input_line_pointer = start; /* reset input_line pointer */
1555 *toc_kind = t; /* set return value */
1561 /* We need to keep a list of fixups. We can't simply generate them as
1562 we go, because that would require us to first create the frag, and
1563 that would screw up references to ``.''. */
1569 bfd_reloc_code_real_type reloc;
1572 #define MAX_INSN_FIXUPS (5)
1574 /* This routine is called for each instruction to be assembled. */
1581 const struct powerpc_opcode *opcode;
1583 const unsigned char *opindex_ptr;
1587 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1592 bfd_reloc_code_real_type reloc;
1595 /* Get the opcode. */
1596 for (s = str; *s != '\0' && ! isspace (*s); s++)
1601 /* Look up the opcode in the hash table. */
1602 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1603 if (opcode == (const struct powerpc_opcode *) NULL)
1605 const struct powerpc_macro *macro;
1607 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1608 if (macro == (const struct powerpc_macro *) NULL)
1609 as_bad (_("Unrecognized opcode: `%s'"), str);
1611 ppc_macro (s, macro);
1616 insn = opcode->opcode;
1619 while (isspace (*str))
1622 /* PowerPC operands are just expressions. The only real issue is
1623 that a few operand types are optional. All cases which might use
1624 an optional operand separate the operands only with commas (in
1625 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1626 cases never have optional operands). There is never more than
1627 one optional operand for an instruction. So, before we start
1628 seriously parsing the operands, we check to see if we have an
1629 optional operand, and, if we do, we count the number of commas to
1630 see whether the operand should be omitted. */
1632 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1634 const struct powerpc_operand *operand;
1636 operand = &powerpc_operands[*opindex_ptr];
1637 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1639 unsigned int opcount;
1641 /* There is an optional operand. Count the number of
1642 commas in the input line. */
1649 while ((s = strchr (s, ',')) != (char *) NULL)
1656 /* If there are fewer operands in the line then are called
1657 for by the instruction, we want to skip the optional
1659 if (opcount < strlen (opcode->operands))
1666 /* Gather the operands. */
1670 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1672 const struct powerpc_operand *operand;
1678 if (next_opindex == 0)
1679 operand = &powerpc_operands[*opindex_ptr];
1682 operand = &powerpc_operands[next_opindex];
1688 /* If this is a fake operand, then we do not expect anything
1690 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1692 insn = (*operand->insert) (insn, 0L, &errmsg);
1693 if (errmsg != (const char *) NULL)
1698 /* If this is an optional operand, and we are skipping it, just
1700 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1703 if (operand->insert)
1705 insn = (*operand->insert) (insn, 0L, &errmsg);
1706 if (errmsg != (const char *) NULL)
1709 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1710 next_opindex = *opindex_ptr + 1;
1714 /* Gather the operand. */
1715 hold = input_line_pointer;
1716 input_line_pointer = str;
1719 if (*input_line_pointer == '[')
1721 /* We are expecting something like the second argument here:
1723 lwz r4,[toc].GS.0.static_int(rtoc)
1724 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1725 The argument following the `]' must be a symbol name, and the
1726 register must be the toc register: 'rtoc' or '2'
1728 The effect is to 0 as the displacement field
1729 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1730 the appropriate variation) reloc against it based on the symbol.
1731 The linker will build the toc, and insert the resolved toc offset.
1734 o The size of the toc entry is currently assumed to be
1735 32 bits. This should not be assumed to be a hard coded
1737 o In an effort to cope with a change from 32 to 64 bits,
1738 there are also toc entries that are specified to be
1739 either 32 or 64 bits:
1740 lwz r4,[toc32].GS.0.static_int(rtoc)
1741 lwz r4,[toc64].GS.0.static_int(rtoc)
1742 These demand toc entries of the specified size, and the
1743 instruction probably requires it.
1747 enum toc_size_qualifier toc_kind;
1748 bfd_reloc_code_real_type toc_reloc;
1750 /* go parse off the [tocXX] part */
1751 valid_toc = parse_toc_entry(&toc_kind);
1755 /* Note: message has already been issued. */
1756 /* FIXME: what sort of recovery should we do? */
1757 /* demand_rest_of_line(); return; ? */
1760 /* Now get the symbol following the ']' */
1766 /* In this case, we may not have seen the symbol yet, since */
1767 /* it is allowed to appear on a .extern or .globl or just be */
1768 /* a label in the .data section. */
1769 toc_reloc = BFD_RELOC_PPC_TOC16;
1772 /* 1. The symbol must be defined and either in the toc */
1773 /* section, or a global. */
1774 /* 2. The reloc generated must have the TOCDEFN flag set in */
1775 /* upper bit mess of the reloc type. */
1776 /* FIXME: It's a little confusing what the tocv qualifier can */
1777 /* be used for. At the very least, I've seen three */
1778 /* uses, only one of which I'm sure I can explain. */
1779 if (ex.X_op == O_symbol)
1781 assert (ex.X_add_symbol != NULL);
1782 if (ex.X_add_symbol->bsym->section != tocdata_section)
1784 as_bad(_("[tocv] symbol is not a toc symbol"));
1788 toc_reloc = BFD_RELOC_PPC_TOC16;
1791 /* FIXME: these next two specifically specify 32/64 bit toc */
1792 /* entries. We don't support them today. Is this the */
1793 /* right way to say that? */
1794 toc_reloc = BFD_RELOC_UNUSED;
1795 as_bad (_("Unimplemented toc32 expression modifier"));
1798 /* FIXME: see above */
1799 toc_reloc = BFD_RELOC_UNUSED;
1800 as_bad (_("Unimplemented toc64 expression modifier"));
1804 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1810 /* We need to generate a fixup for this expression. */
1811 if (fc >= MAX_INSN_FIXUPS)
1812 as_fatal (_("too many fixups"));
1814 fixups[fc].reloc = toc_reloc;
1815 fixups[fc].exp = ex;
1816 fixups[fc].opindex = *opindex_ptr;
1819 /* Ok. We've set up the fixup for the instruction. Now make it
1820 look like the constant 0 was found here */
1822 ex.X_op = O_constant;
1823 ex.X_add_number = 0;
1824 ex.X_add_symbol = NULL;
1825 ex.X_op_symbol = NULL;
1831 if (! register_name (&ex))
1833 if ((operand->flags & PPC_OPERAND_CR) != 0)
1840 str = input_line_pointer;
1841 input_line_pointer = hold;
1843 if (ex.X_op == O_illegal)
1844 as_bad (_("illegal operand"));
1845 else if (ex.X_op == O_absent)
1846 as_bad (_("missing operand"));
1847 else if (ex.X_op == O_register)
1849 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1852 else if (ex.X_op == O_constant)
1855 /* Allow @HA, @L, @H on constants. */
1856 char *orig_str = str;
1858 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
1865 case BFD_RELOC_LO16:
1866 /* X_unsigned is the default, so if the user has done
1867 something which cleared it, we always produce a
1870 && (operand->flags & PPC_OPERAND_SIGNED) == 0)
1871 ex.X_add_number &= 0xffff;
1873 ex.X_add_number = (((ex.X_add_number & 0xffff)
1878 case BFD_RELOC_HI16:
1879 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
1882 case BFD_RELOC_HI16_S:
1883 ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
1884 + ((ex.X_add_number >> 15) & 1));
1888 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1892 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
1894 /* For the absoulte forms of branchs, convert the PC relative form back into
1896 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
1900 case BFD_RELOC_PPC_B26:
1901 reloc = BFD_RELOC_PPC_BA26;
1903 case BFD_RELOC_PPC_B16:
1904 reloc = BFD_RELOC_PPC_BA16;
1906 case BFD_RELOC_PPC_B16_BRTAKEN:
1907 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
1909 case BFD_RELOC_PPC_B16_BRNTAKEN:
1910 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
1917 /* We need to generate a fixup for this expression. */
1918 if (fc >= MAX_INSN_FIXUPS)
1919 as_fatal (_("too many fixups"));
1920 fixups[fc].exp = ex;
1921 fixups[fc].opindex = 0;
1922 fixups[fc].reloc = reloc;
1925 #endif /* OBJ_ELF */
1929 /* We need to generate a fixup for this expression. */
1930 if (fc >= MAX_INSN_FIXUPS)
1931 as_fatal (_("too many fixups"));
1932 fixups[fc].exp = ex;
1933 fixups[fc].opindex = *opindex_ptr;
1934 fixups[fc].reloc = BFD_RELOC_UNUSED;
1943 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
1951 /* The call to expression should have advanced str past any
1954 && (endc != ',' || *str != '\0'))
1956 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
1964 while (isspace (*str))
1968 as_bad (_("junk at end of line: `%s'"), str);
1970 /* Write out the instruction. */
1972 md_number_to_chars (f, insn, 4);
1974 /* Create any fixups. At this point we do not use a
1975 bfd_reloc_code_real_type, but instead just use the
1976 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1977 handle fixups for any operand type, although that is admittedly
1978 not a very exciting feature. We pick a BFD reloc type in
1980 for (i = 0; i < fc; i++)
1982 const struct powerpc_operand *operand;
1984 operand = &powerpc_operands[fixups[i].opindex];
1985 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1987 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1995 size = bfd_get_reloc_size (reloc_howto);
1996 offset = target_big_endian ? (4 - size) : 0;
1998 if (size < 1 || size > 4)
2001 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, size,
2002 &fixups[i].exp, reloc_howto->pc_relative,
2005 /* Turn off complaints that the addend is too large for things like
2007 switch (fixups[i].reloc)
2009 case BFD_RELOC_16_GOTOFF:
2010 case BFD_RELOC_PPC_TOC16:
2011 case BFD_RELOC_LO16:
2012 case BFD_RELOC_HI16:
2013 case BFD_RELOC_HI16_S:
2014 fixP->fx_no_overflow = 1;
2021 fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
2023 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2024 ((bfd_reloc_code_real_type)
2025 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2029 #ifndef WORKING_DOT_WORD
2030 /* Handle long and short jumps */
2032 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2034 addressT from_addr, to_addr;
2042 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2044 addressT from_addr, to_addr;
2052 /* Handle a macro. Gather all the operands, transform them as
2053 described by the macro, and call md_assemble recursively. All the
2054 operands are separated by commas; we don't accept parentheses
2055 around operands here. */
2058 ppc_macro (str, macro)
2060 const struct powerpc_macro *macro;
2071 /* Gather the users operands into the operands array. */
2076 if (count >= sizeof operands / sizeof operands[0])
2078 operands[count++] = s;
2079 s = strchr (s, ',');
2080 if (s == (char *) NULL)
2085 if (count != macro->operands)
2087 as_bad (_("wrong number of operands"));
2091 /* Work out how large the string must be (the size is unbounded
2092 because it includes user input). */
2094 format = macro->format;
2095 while (*format != '\0')
2104 arg = strtol (format + 1, &send, 10);
2105 know (send != format && arg >= 0 && arg < count);
2106 len += strlen (operands[arg]);
2111 /* Put the string together. */
2112 complete = s = (char *) alloca (len + 1);
2113 format = macro->format;
2114 while (*format != '\0')
2120 arg = strtol (format + 1, &send, 10);
2121 strcpy (s, operands[arg]);
2128 /* Assemble the constructed instruction. */
2129 md_assemble (complete);
2133 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2136 ppc_section_letter (letter, ptr_msg)
2143 *ptr_msg = _("Bad .section directive: want a,w,x,e in string");
2148 ppc_section_word (ptr_str)
2151 if (strncmp (*ptr_str, "exclude", sizeof ("exclude")-1) == 0)
2153 *ptr_str += sizeof ("exclude")-1;
2161 ppc_section_type (ptr_str)
2164 if (strncmp (*ptr_str, "ordered", sizeof ("ordered")-1) == 0)
2166 *ptr_str += sizeof ("ordered")-1;
2174 ppc_section_flags (flags, attr, type)
2179 if (type == SHT_ORDERED)
2180 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2182 if (attr & SHF_EXCLUDE)
2183 flags |= SEC_EXCLUDE;
2187 #endif /* OBJ_ELF */
2190 /* Pseudo-op handling. */
2192 /* The .byte pseudo-op. This is similar to the normal .byte
2193 pseudo-op, but it can also take a single ASCII string. */
2199 if (*input_line_pointer != '\"')
2205 /* Gather characters. A real double quote is doubled. Unusual
2206 characters are not permitted. */
2207 ++input_line_pointer;
2212 c = *input_line_pointer++;
2216 if (*input_line_pointer != '\"')
2218 ++input_line_pointer;
2221 FRAG_APPEND_1_CHAR (c);
2224 demand_empty_rest_of_line ();
2229 /* XCOFF specific pseudo-op handling. */
2231 /* This is set if we are creating a .stabx symbol, since we don't want
2232 to handle symbol suffixes for such symbols. */
2233 static boolean ppc_stab_symbol;
2235 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2236 symbols in the .bss segment as though they were local common
2237 symbols, and uses a different smclas. */
2243 asection *current_seg = now_seg;
2244 subsegT current_subseg = now_subseg;
2250 symbolS *lcomm_sym = NULL;
2254 name = input_line_pointer;
2255 endc = get_symbol_end ();
2256 end_name = input_line_pointer;
2259 if (*input_line_pointer != ',')
2261 as_bad (_("missing size"));
2262 ignore_rest_of_line ();
2265 ++input_line_pointer;
2267 size = get_absolute_expression ();
2270 as_bad (_("negative size"));
2271 ignore_rest_of_line ();
2277 /* The third argument to .comm is the alignment. */
2278 if (*input_line_pointer != ',')
2282 ++input_line_pointer;
2283 align = get_absolute_expression ();
2286 as_warn (_("ignoring bad alignment"));
2305 /* The third argument to .lcomm appears to be the real local
2306 common symbol to create. References to the symbol named in
2307 the first argument are turned into references to the third
2309 if (*input_line_pointer != ',')
2311 as_bad (_("missing real symbol name"));
2312 ignore_rest_of_line ();
2315 ++input_line_pointer;
2317 lcomm_name = input_line_pointer;
2318 lcomm_endc = get_symbol_end ();
2320 lcomm_sym = symbol_find_or_make (lcomm_name);
2322 *input_line_pointer = lcomm_endc;
2326 sym = symbol_find_or_make (name);
2329 if (S_IS_DEFINED (sym)
2330 || S_GET_VALUE (sym) != 0)
2332 as_bad (_("attempt to redefine symbol"));
2333 ignore_rest_of_line ();
2337 record_alignment (bss_section, align);
2340 || ! S_IS_DEFINED (lcomm_sym))
2349 S_SET_EXTERNAL (sym);
2353 lcomm_sym->sy_tc.output = 1;
2354 def_sym = lcomm_sym;
2358 subseg_set (bss_section, 1);
2359 frag_align (align, 0, 0);
2361 def_sym->sy_frag = frag_now;
2362 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2363 def_size, (char *) NULL);
2365 S_SET_SEGMENT (def_sym, bss_section);
2366 def_sym->sy_tc.align = align;
2370 /* Align the size of lcomm_sym. */
2371 lcomm_sym->sy_frag->fr_offset =
2372 ((lcomm_sym->sy_frag->fr_offset + (1 << align) - 1)
2373 &~ ((1 << align) - 1));
2374 if (align > lcomm_sym->sy_tc.align)
2375 lcomm_sym->sy_tc.align = align;
2380 /* Make sym an offset from lcomm_sym. */
2381 S_SET_SEGMENT (sym, bss_section);
2382 sym->sy_frag = lcomm_sym->sy_frag;
2383 S_SET_VALUE (sym, lcomm_sym->sy_frag->fr_offset);
2384 lcomm_sym->sy_frag->fr_offset += size;
2387 subseg_set (current_seg, current_subseg);
2389 demand_empty_rest_of_line ();
2392 /* The .csect pseudo-op. This switches us into a different
2393 subsegment. The first argument is a symbol whose value is the
2394 start of the .csect. In COFF, csect symbols get special aux
2395 entries defined by the x_csect field of union internal_auxent. The
2396 optional second argument is the alignment (the default is 2). */
2406 name = input_line_pointer;
2407 endc = get_symbol_end ();
2409 sym = symbol_find_or_make (name);
2411 *input_line_pointer = endc;
2413 if (S_GET_NAME (sym)[0] == '\0')
2415 /* An unnamed csect is assumed to be [PR]. */
2416 sym->sy_tc.class = XMC_PR;
2419 ppc_change_csect (sym);
2421 if (*input_line_pointer == ',')
2423 ++input_line_pointer;
2424 sym->sy_tc.align = get_absolute_expression ();
2427 demand_empty_rest_of_line ();
2430 /* Change to a different csect. */
2433 ppc_change_csect (sym)
2436 if (S_IS_DEFINED (sym))
2437 subseg_set (S_GET_SEGMENT (sym), sym->sy_tc.subseg);
2445 /* This is a new csect. We need to look at the symbol class to
2446 figure out whether it should go in the text section or the
2449 switch (sym->sy_tc.class)
2459 S_SET_SEGMENT (sym, text_section);
2460 sym->sy_tc.subseg = ppc_text_subsegment;
2461 ++ppc_text_subsegment;
2462 list_ptr = &ppc_text_csects;
2471 if (ppc_toc_csect != NULL
2472 && ppc_toc_csect->sy_tc.subseg + 1 == ppc_data_subsegment)
2474 S_SET_SEGMENT (sym, data_section);
2475 sym->sy_tc.subseg = ppc_data_subsegment;
2476 ++ppc_data_subsegment;
2477 list_ptr = &ppc_data_csects;
2483 /* We set the obstack chunk size to a small value before
2484 changing subsegments, so that we don't use a lot of memory
2485 space for what may be a small section. */
2486 hold_chunksize = chunksize;
2489 subseg_new (segment_name (S_GET_SEGMENT (sym)), sym->sy_tc.subseg);
2491 chunksize = hold_chunksize;
2494 ppc_after_toc_frag = frag_now;
2496 sym->sy_frag = frag_now;
2497 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2499 sym->sy_tc.align = 2;
2500 sym->sy_tc.output = 1;
2501 sym->sy_tc.within = sym;
2503 for (list = *list_ptr;
2504 list->sy_tc.next != (symbolS *) NULL;
2505 list = list->sy_tc.next)
2507 list->sy_tc.next = sym;
2509 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2510 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2513 ppc_current_csect = sym;
2516 /* This function handles the .text and .data pseudo-ops. These
2517 pseudo-ops aren't really used by XCOFF; we implement them for the
2518 convenience of people who aren't used to XCOFF. */
2529 else if (type == 'd')
2534 sym = symbol_find_or_make (name);
2536 ppc_change_csect (sym);
2538 demand_empty_rest_of_line ();
2541 /* This function handles the .section pseudo-op. This is mostly to
2542 give an error, since XCOFF only supports .text, .data and .bss, but
2543 we do permit the user to name the text or data section. */
2546 ppc_named_section (ignore)
2550 const char *real_name;
2554 user_name = input_line_pointer;
2555 c = get_symbol_end ();
2557 if (strcmp (user_name, ".text") == 0)
2558 real_name = ".text[PR]";
2559 else if (strcmp (user_name, ".data") == 0)
2560 real_name = ".data[RW]";
2563 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2564 *input_line_pointer = c;
2565 ignore_rest_of_line ();
2569 *input_line_pointer = c;
2571 sym = symbol_find_or_make (real_name);
2573 ppc_change_csect (sym);
2575 demand_empty_rest_of_line ();
2578 /* The .extern pseudo-op. We create an undefined symbol. */
2587 name = input_line_pointer;
2588 endc = get_symbol_end ();
2590 (void) symbol_find_or_make (name);
2592 *input_line_pointer = endc;
2594 demand_empty_rest_of_line ();
2597 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2607 name = input_line_pointer;
2608 endc = get_symbol_end ();
2610 sym = symbol_find_or_make (name);
2612 *input_line_pointer = endc;
2614 sym->sy_tc.output = 1;
2616 demand_empty_rest_of_line ();
2619 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2620 although I don't know why it bothers. */
2631 name = input_line_pointer;
2632 endc = get_symbol_end ();
2634 sym = symbol_find_or_make (name);
2636 *input_line_pointer = endc;
2638 if (*input_line_pointer != ',')
2640 as_bad (_("missing rename string"));
2641 ignore_rest_of_line ();
2644 ++input_line_pointer;
2646 sym->sy_tc.real_name = demand_copy_C_string (&len);
2648 demand_empty_rest_of_line ();
2651 /* The .stabx pseudo-op. This is similar to a normal .stabs
2652 pseudo-op, but slightly different. A sample is
2653 .stabx "main:F-1",.main,142,0
2654 The first argument is the symbol name to create. The second is the
2655 value, and the third is the storage class. The fourth seems to be
2656 always zero, and I am assuming it is the type. */
2667 name = demand_copy_C_string (&len);
2669 if (*input_line_pointer != ',')
2671 as_bad (_("missing value"));
2674 ++input_line_pointer;
2676 ppc_stab_symbol = true;
2677 sym = symbol_make (name);
2678 ppc_stab_symbol = false;
2680 sym->sy_tc.real_name = name;
2682 (void) expression (&exp);
2689 as_bad (_("illegal .stabx expression; zero assumed"));
2690 exp.X_add_number = 0;
2693 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2694 sym->sy_frag = &zero_address_frag;
2698 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2699 sym->sy_value = exp;
2703 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2704 sym->sy_frag = exp.X_add_symbol->sy_frag;
2709 /* The value is some complex expression. This will probably
2710 fail at some later point, but this is probably the right
2711 thing to do here. */
2712 sym->sy_value = exp;
2716 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2717 sym->bsym->flags |= BSF_DEBUGGING;
2719 if (*input_line_pointer != ',')
2721 as_bad (_("missing class"));
2724 ++input_line_pointer;
2726 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2728 if (*input_line_pointer != ',')
2730 as_bad (_("missing type"));
2733 ++input_line_pointer;
2735 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2737 sym->sy_tc.output = 1;
2739 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
2740 sym->sy_tc.within = ppc_current_block;
2742 if (exp.X_op != O_symbol
2743 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2744 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2745 ppc_frob_label (sym);
2748 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2749 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2750 if (ppc_current_csect->sy_tc.within == exp.X_add_symbol)
2751 ppc_current_csect->sy_tc.within = sym;
2754 demand_empty_rest_of_line ();
2757 /* The .function pseudo-op. This takes several arguments. The first
2758 argument seems to be the external name of the symbol. The second
2759 argment seems to be the label for the start of the function. gcc
2760 uses the same name for both. I have no idea what the third and
2761 fourth arguments are meant to be. The optional fifth argument is
2762 an expression for the size of the function. In COFF this symbol
2763 gets an aux entry like that used for a csect. */
2766 ppc_function (ignore)
2775 name = input_line_pointer;
2776 endc = get_symbol_end ();
2778 /* Ignore any [PR] suffix. */
2779 name = ppc_canonicalize_symbol_name (name);
2780 s = strchr (name, '[');
2781 if (s != (char *) NULL
2782 && strcmp (s + 1, "PR]") == 0)
2785 ext_sym = symbol_find_or_make (name);
2787 *input_line_pointer = endc;
2789 if (*input_line_pointer != ',')
2791 as_bad (_("missing symbol name"));
2792 ignore_rest_of_line ();
2795 ++input_line_pointer;
2797 name = input_line_pointer;
2798 endc = get_symbol_end ();
2800 lab_sym = symbol_find_or_make (name);
2802 *input_line_pointer = endc;
2804 if (ext_sym != lab_sym)
2806 ext_sym->sy_value.X_op = O_symbol;
2807 ext_sym->sy_value.X_add_symbol = lab_sym;
2808 ext_sym->sy_value.X_op_symbol = NULL;
2809 ext_sym->sy_value.X_add_number = 0;
2812 if (ext_sym->sy_tc.class == -1)
2813 ext_sym->sy_tc.class = XMC_PR;
2814 ext_sym->sy_tc.output = 1;
2816 if (*input_line_pointer == ',')
2820 /* Ignore the third argument. */
2821 ++input_line_pointer;
2822 expression (&ignore);
2823 if (*input_line_pointer == ',')
2825 /* Ignore the fourth argument. */
2826 ++input_line_pointer;
2827 expression (&ignore);
2828 if (*input_line_pointer == ',')
2830 /* The fifth argument is the function size. */
2831 ++input_line_pointer;
2832 ext_sym->sy_tc.size = symbol_new ("L0\001",
2835 &zero_address_frag);
2836 pseudo_set (ext_sym->sy_tc.size);
2841 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2842 SF_SET_FUNCTION (ext_sym);
2843 SF_SET_PROCESS (ext_sym);
2844 coff_add_linesym (ext_sym);
2846 demand_empty_rest_of_line ();
2849 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2858 sym = symbol_make (".bf");
2859 S_SET_SEGMENT (sym, text_section);
2860 sym->sy_frag = frag_now;
2861 S_SET_VALUE (sym, frag_now_fix ());
2862 S_SET_STORAGE_CLASS (sym, C_FCN);
2864 coff_line_base = get_absolute_expression ();
2866 S_SET_NUMBER_AUXILIARY (sym, 1);
2867 SA_SET_SYM_LNNO (sym, coff_line_base);
2869 sym->sy_tc.output = 1;
2871 ppc_frob_label (sym);
2873 demand_empty_rest_of_line ();
2876 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2877 ".ef", except that the line number is absolute, not relative to the
2878 most recent ".bf" symbol. */
2886 sym = symbol_make (".ef");
2887 S_SET_SEGMENT (sym, text_section);
2888 sym->sy_frag = frag_now;
2889 S_SET_VALUE (sym, frag_now_fix ());
2890 S_SET_STORAGE_CLASS (sym, C_FCN);
2891 S_SET_NUMBER_AUXILIARY (sym, 1);
2892 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2893 sym->sy_tc.output = 1;
2895 ppc_frob_label (sym);
2897 demand_empty_rest_of_line ();
2900 /* The .bi and .ei pseudo-ops. These take a string argument and
2901 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2908 static symbolS *last_biei;
2915 name = demand_copy_C_string (&len);
2917 /* The value of these symbols is actually file offset. Here we set
2918 the value to the index into the line number entries. In
2919 ppc_frob_symbols we set the fix_line field, which will cause BFD
2920 to do the right thing. */
2922 sym = symbol_make (name);
2923 /* obj-coff.c currently only handles line numbers correctly in the
2925 S_SET_SEGMENT (sym, text_section);
2926 S_SET_VALUE (sym, coff_n_line_nos);
2927 sym->bsym->flags |= BSF_DEBUGGING;
2929 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
2930 sym->sy_tc.output = 1;
2932 for (look = last_biei ? last_biei : symbol_rootP;
2933 (look != (symbolS *) NULL
2934 && (S_GET_STORAGE_CLASS (look) == C_FILE
2935 || S_GET_STORAGE_CLASS (look) == C_BINCL
2936 || S_GET_STORAGE_CLASS (look) == C_EINCL));
2937 look = symbol_next (look))
2939 if (look != (symbolS *) NULL)
2941 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2942 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
2946 demand_empty_rest_of_line ();
2949 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2950 There is one argument, which is a csect symbol. The value of the
2951 .bs symbol is the index of this csect symbol. */
2962 if (ppc_current_block != NULL)
2963 as_bad (_("nested .bs blocks"));
2965 name = input_line_pointer;
2966 endc = get_symbol_end ();
2968 csect = symbol_find_or_make (name);
2970 *input_line_pointer = endc;
2972 sym = symbol_make (".bs");
2973 S_SET_SEGMENT (sym, now_seg);
2974 S_SET_STORAGE_CLASS (sym, C_BSTAT);
2975 sym->bsym->flags |= BSF_DEBUGGING;
2976 sym->sy_tc.output = 1;
2978 sym->sy_tc.within = csect;
2980 ppc_frob_label (sym);
2982 ppc_current_block = sym;
2984 demand_empty_rest_of_line ();
2987 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2995 if (ppc_current_block == NULL)
2996 as_bad (_(".es without preceding .bs"));
2998 sym = symbol_make (".es");
2999 S_SET_SEGMENT (sym, now_seg);
3000 S_SET_STORAGE_CLASS (sym, C_ESTAT);
3001 sym->bsym->flags |= BSF_DEBUGGING;
3002 sym->sy_tc.output = 1;
3004 ppc_frob_label (sym);
3006 ppc_current_block = NULL;
3008 demand_empty_rest_of_line ();
3011 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3020 sym = symbol_make (".bb");
3021 S_SET_SEGMENT (sym, text_section);
3022 sym->sy_frag = frag_now;
3023 S_SET_VALUE (sym, frag_now_fix ());
3024 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3026 S_SET_NUMBER_AUXILIARY (sym, 1);
3027 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3029 sym->sy_tc.output = 1;
3031 SF_SET_PROCESS (sym);
3033 ppc_frob_label (sym);
3035 demand_empty_rest_of_line ();
3038 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3047 sym = symbol_make (".eb");
3048 S_SET_SEGMENT (sym, text_section);
3049 sym->sy_frag = frag_now;
3050 S_SET_VALUE (sym, frag_now_fix ());
3051 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3052 S_SET_NUMBER_AUXILIARY (sym, 1);
3053 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3054 sym->sy_tc.output = 1;
3056 SF_SET_PROCESS (sym);
3058 ppc_frob_label (sym);
3060 demand_empty_rest_of_line ();
3063 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3074 name = demand_copy_C_string (&len);
3075 sym = symbol_make (name);
3076 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3077 sym->bsym->flags |= BSF_DEBUGGING;
3078 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3079 S_SET_VALUE (sym, 0);
3080 sym->sy_tc.output = 1;
3082 ppc_frob_label (sym);
3084 demand_empty_rest_of_line ();
3087 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3095 sym = symbol_make (".ec");
3096 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3097 sym->bsym->flags |= BSF_DEBUGGING;
3098 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3099 S_SET_VALUE (sym, 0);
3100 sym->sy_tc.output = 1;
3102 ppc_frob_label (sym);
3104 demand_empty_rest_of_line ();
3107 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3113 if (ppc_toc_csect != (symbolS *) NULL)
3114 subseg_set (data_section, ppc_toc_csect->sy_tc.subseg);
3121 subseg = ppc_data_subsegment;
3122 ++ppc_data_subsegment;
3124 subseg_new (segment_name (data_section), subseg);
3125 ppc_toc_frag = frag_now;
3127 sym = symbol_find_or_make ("TOC[TC0]");
3128 sym->sy_frag = frag_now;
3129 S_SET_SEGMENT (sym, data_section);
3130 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3131 sym->sy_tc.subseg = subseg;
3132 sym->sy_tc.output = 1;
3133 sym->sy_tc.within = sym;
3135 ppc_toc_csect = sym;
3137 for (list = ppc_data_csects;
3138 list->sy_tc.next != (symbolS *) NULL;
3139 list = list->sy_tc.next)
3141 list->sy_tc.next = sym;
3143 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3144 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
3147 ppc_current_csect = ppc_toc_csect;
3149 demand_empty_rest_of_line ();
3152 /* The AIX assembler automatically aligns the operands of a .long or
3153 .short pseudo-op, and we want to be compatible. */
3156 ppc_xcoff_cons (log_size)
3159 frag_align (log_size, 0, 0);
3160 record_alignment (now_seg, log_size);
3161 cons (1 << log_size);
3164 #endif /* OBJ_XCOFF */
3166 /* The .tc pseudo-op. This is used when generating either XCOFF or
3167 ELF. This takes two or more arguments.
3169 When generating XCOFF output, the first argument is the name to
3170 give to this location in the toc; this will be a symbol with class
3171 TC. The rest of the arguments are 4 byte values to actually put at
3172 this location in the TOC; often there is just one more argument, a
3173 relocateable symbol reference.
3175 When not generating XCOFF output, the arguments are the same, but
3176 the first argument is simply ignored. */
3184 /* Define the TOC symbol name. */
3190 if (ppc_toc_csect == (symbolS *) NULL
3191 || ppc_toc_csect != ppc_current_csect)
3193 as_bad (_(".tc not in .toc section"));
3194 ignore_rest_of_line ();
3198 name = input_line_pointer;
3199 endc = get_symbol_end ();
3201 sym = symbol_find_or_make (name);
3203 *input_line_pointer = endc;
3205 if (S_IS_DEFINED (sym))
3209 label = ppc_current_csect->sy_tc.within;
3210 if (label->sy_tc.class != XMC_TC0)
3212 as_bad (_(".tc with no label"));
3213 ignore_rest_of_line ();
3217 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3218 label->sy_frag = sym->sy_frag;
3219 S_SET_VALUE (label, S_GET_VALUE (sym));
3221 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3222 ++input_line_pointer;
3227 S_SET_SEGMENT (sym, now_seg);
3228 sym->sy_frag = frag_now;
3229 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3230 sym->sy_tc.class = XMC_TC;
3231 sym->sy_tc.output = 1;
3233 ppc_frob_label (sym);
3236 #else /* ! defined (OBJ_XCOFF) */
3238 /* Skip the TOC symbol name. */
3239 while (is_part_of_name (*input_line_pointer)
3240 || *input_line_pointer == '['
3241 || *input_line_pointer == ']'
3242 || *input_line_pointer == '{'
3243 || *input_line_pointer == '}')
3244 ++input_line_pointer;
3246 /* Align to a four byte boundary. */
3247 frag_align (2, 0, 0);
3248 record_alignment (now_seg, 2);
3250 #endif /* ! defined (OBJ_XCOFF) */
3252 if (*input_line_pointer != ',')
3253 demand_empty_rest_of_line ();
3256 ++input_line_pointer;
3263 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3265 /* Set the current section. */
3267 ppc_set_current_section (new)
3270 ppc_previous_section = ppc_current_section;
3271 ppc_current_section = new;
3274 /* pseudo-op: .previous
3275 behaviour: toggles the current section with the previous section.
3277 warnings: "No previous section"
3280 ppc_previous(ignore)
3285 if (ppc_previous_section == NULL)
3287 as_warn(_("No previous section to return to. Directive ignored."));
3291 subseg_set(ppc_previous_section, 0);
3293 ppc_set_current_section(ppc_previous_section);
3296 /* pseudo-op: .pdata
3297 behaviour: predefined read only data section
3301 initial: .section .pdata "adr3"
3302 a - don't know -- maybe a misprint
3303 d - initialized data
3305 3 - double word aligned (that would be 4 byte boundary)
3308 Tag index tables (also known as the function table) for exception
3309 handling, debugging, etc.
3316 if (pdata_section == 0)
3318 pdata_section = subseg_new (".pdata", 0);
3320 bfd_set_section_flags (stdoutput, pdata_section,
3321 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3322 | SEC_READONLY | SEC_DATA ));
3324 bfd_set_section_alignment (stdoutput, pdata_section, 2);
3328 pdata_section = subseg_new(".pdata", 0);
3330 ppc_set_current_section(pdata_section);
3333 /* pseudo-op: .ydata
3334 behaviour: predefined read only data section
3338 initial: .section .ydata "drw3"
3339 a - don't know -- maybe a misprint
3340 d - initialized data
3342 3 - double word aligned (that would be 4 byte boundary)
3344 Tag tables (also known as the scope table) for exception handling,
3351 if (ydata_section == 0)
3353 ydata_section = subseg_new (".ydata", 0);
3354 bfd_set_section_flags (stdoutput, ydata_section,
3355 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3356 | SEC_READONLY | SEC_DATA ));
3358 bfd_set_section_alignment (stdoutput, ydata_section, 3);
3362 ydata_section = subseg_new (".ydata", 0);
3364 ppc_set_current_section(ydata_section);
3367 /* pseudo-op: .reldata
3368 behaviour: predefined read write data section
3369 double word aligned (4-byte)
3370 FIXME: relocation is applied to it
3371 FIXME: what's the difference between this and .data?
3374 initial: .section .reldata "drw3"
3375 d - initialized data
3378 3 - double word aligned (that would be 8 byte boundary)
3381 Like .data, but intended to hold data subject to relocation, such as
3382 function descriptors, etc.
3388 if (reldata_section == 0)
3390 reldata_section = subseg_new (".reldata", 0);
3392 bfd_set_section_flags (stdoutput, reldata_section,
3393 ( SEC_ALLOC | SEC_LOAD | SEC_RELOC
3396 bfd_set_section_alignment (stdoutput, reldata_section, 2);
3400 reldata_section = subseg_new (".reldata", 0);
3402 ppc_set_current_section(reldata_section);
3405 /* pseudo-op: .rdata
3406 behaviour: predefined read only data section
3410 initial: .section .rdata "dr3"
3411 d - initialized data
3413 3 - double word aligned (that would be 4 byte boundary)
3419 if (rdata_section == 0)
3421 rdata_section = subseg_new (".rdata", 0);
3422 bfd_set_section_flags (stdoutput, rdata_section,
3423 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3424 | SEC_READONLY | SEC_DATA ));
3426 bfd_set_section_alignment (stdoutput, rdata_section, 2);
3430 rdata_section = subseg_new (".rdata", 0);
3432 ppc_set_current_section(rdata_section);
3435 /* pseudo-op: .ualong
3436 behaviour: much like .int, with the exception that no alignment is
3438 FIXME: test the alignment statement
3450 /* pseudo-op: .znop <symbol name>
3451 behaviour: Issue a nop instruction
3452 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3453 the supplied symbol name.
3455 warnings: Missing symbol name
3462 const struct powerpc_opcode *opcode;
3468 /* Strip out the symbol name */
3476 symbol_name = input_line_pointer;
3477 c = get_symbol_end ();
3479 name = xmalloc (input_line_pointer - symbol_name + 1);
3480 strcpy (name, symbol_name);
3482 sym = symbol_find_or_make (name);
3484 *input_line_pointer = c;
3488 /* Look up the opcode in the hash table. */
3489 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3491 /* stick in the nop */
3492 insn = opcode->opcode;
3494 /* Write out the instruction. */
3496 md_number_to_chars (f, insn, 4);
3498 f - frag_now->fr_literal,
3503 BFD_RELOC_16_GOT_PCREL);
3516 register char *name;
3520 register symbolS *symbolP;
3523 name = input_line_pointer;
3524 c = get_symbol_end ();
3526 /* just after name is now '\0' */
3527 p = input_line_pointer;
3530 if (*input_line_pointer != ',')
3532 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3533 ignore_rest_of_line ();
3537 input_line_pointer++; /* skip ',' */
3538 if ((temp = get_absolute_expression ()) < 0)
3540 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
3541 ignore_rest_of_line ();
3547 /* The third argument to .comm is the alignment. */
3548 if (*input_line_pointer != ',')
3552 ++input_line_pointer;
3553 align = get_absolute_expression ();
3556 as_warn (_("ignoring bad alignment"));
3563 symbolP = symbol_find_or_make (name);
3566 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
3568 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3569 S_GET_NAME (symbolP));
3570 ignore_rest_of_line ();
3574 if (S_GET_VALUE (symbolP))
3576 if (S_GET_VALUE (symbolP) != (valueT) temp)
3577 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3578 S_GET_NAME (symbolP),
3579 (long) S_GET_VALUE (symbolP),
3584 S_SET_VALUE (symbolP, (valueT) temp);
3585 S_SET_EXTERNAL (symbolP);
3588 demand_empty_rest_of_line ();
3592 * implement the .section pseudo op:
3593 * .section name {, "flags"}
3595 * | +--- optional flags: 'b' for bss
3597 * +-- section name 'l' for lib
3601 * 'd' (apparently m88k for data)
3603 * But if the argument is not a quoted string, treat it as a
3604 * subsegment number.
3606 * FIXME: this is a copy of the section processing from obj-coff.c, with
3607 * additions/changes for the moto-pas assembler support. There are three
3610 * FIXME: I just noticed this. This doesn't work at all really. It it
3611 * setting bits that bfd probably neither understands or uses. The
3612 * correct approach (?) will have to incorporate extra fields attached
3613 * to the section to hold the system specific stuff. (krk)
3616 * 'a' - unknown - referred to in documentation, but no definition supplied
3617 * 'c' - section has code
3618 * 'd' - section has initialized data
3619 * 'u' - section has uninitialized data
3620 * 'i' - section contains directives (info)
3621 * 'n' - section can be discarded
3622 * 'R' - remove section at link time
3624 * Section Protection:
3625 * 'r' - section is readable
3626 * 'w' - section is writeable
3627 * 'x' - section is executable
3628 * 's' - section is sharable
3630 * Section Alignment:
3631 * '0' - align to byte boundary
3632 * '1' - align to halfword undary
3633 * '2' - align to word boundary
3634 * '3' - align to doubleword boundary
3635 * '4' - align to quadword boundary
3636 * '5' - align to 32 byte boundary
3637 * '6' - align to 64 byte boundary
3642 ppc_pe_section (ignore)
3645 /* Strip out the section name */
3654 section_name = input_line_pointer;
3655 c = get_symbol_end ();
3657 name = xmalloc (input_line_pointer - section_name + 1);
3658 strcpy (name, section_name);
3660 *input_line_pointer = c;
3665 flags = SEC_NO_FLAGS;
3667 if (strcmp (name, ".idata$2") == 0)
3671 else if (strcmp (name, ".idata$3") == 0)
3675 else if (strcmp (name, ".idata$4") == 0)
3679 else if (strcmp (name, ".idata$5") == 0)
3683 else if (strcmp (name, ".idata$6") == 0)
3688 align = 4; /* default alignment to 16 byte boundary */
3690 if (*input_line_pointer == ',')
3692 ++input_line_pointer;
3694 if (*input_line_pointer != '"')
3695 exp = get_absolute_expression ();
3698 ++input_line_pointer;
3699 while (*input_line_pointer != '"'
3700 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3702 switch (*input_line_pointer)
3704 /* Section Contents */
3705 case 'a': /* unknown */
3706 as_bad (_("Unsupported section attribute -- 'a'"));
3708 case 'c': /* code section */
3711 case 'd': /* section has initialized data */
3714 case 'u': /* section has uninitialized data */
3715 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3719 case 'i': /* section contains directives (info) */
3720 /* FIXME: This is IMAGE_SCN_LNK_INFO
3722 flags |= SEC_HAS_CONTENTS;
3724 case 'n': /* section can be discarded */
3727 case 'R': /* Remove section at link time */
3728 flags |= SEC_NEVER_LOAD;
3731 /* Section Protection */
3732 case 'r': /* section is readable */
3733 flags |= IMAGE_SCN_MEM_READ;
3735 case 'w': /* section is writeable */
3736 flags |= IMAGE_SCN_MEM_WRITE;
3738 case 'x': /* section is executable */
3739 flags |= IMAGE_SCN_MEM_EXECUTE;
3741 case 's': /* section is sharable */
3742 flags |= IMAGE_SCN_MEM_SHARED;
3745 /* Section Alignment */
3746 case '0': /* align to byte boundary */
3747 flags |= IMAGE_SCN_ALIGN_1BYTES;
3750 case '1': /* align to halfword boundary */
3751 flags |= IMAGE_SCN_ALIGN_2BYTES;
3754 case '2': /* align to word boundary */
3755 flags |= IMAGE_SCN_ALIGN_4BYTES;
3758 case '3': /* align to doubleword boundary */
3759 flags |= IMAGE_SCN_ALIGN_8BYTES;
3762 case '4': /* align to quadword boundary */
3763 flags |= IMAGE_SCN_ALIGN_16BYTES;
3766 case '5': /* align to 32 byte boundary */
3767 flags |= IMAGE_SCN_ALIGN_32BYTES;
3770 case '6': /* align to 64 byte boundary */
3771 flags |= IMAGE_SCN_ALIGN_64BYTES;
3776 as_bad(_("unknown section attribute '%c'"),
3777 *input_line_pointer);
3780 ++input_line_pointer;
3782 if (*input_line_pointer == '"')
3783 ++input_line_pointer;
3787 sec = subseg_new (name, (subsegT) exp);
3789 ppc_set_current_section(sec);
3791 if (flags != SEC_NO_FLAGS)
3793 if (! bfd_set_section_flags (stdoutput, sec, flags))
3794 as_bad (_("error setting flags for \"%s\": %s"),
3795 bfd_section_name (stdoutput, sec),
3796 bfd_errmsg (bfd_get_error ()));
3799 bfd_set_section_alignment(stdoutput, sec, align);
3804 ppc_pe_function (ignore)
3811 name = input_line_pointer;
3812 endc = get_symbol_end ();
3814 ext_sym = symbol_find_or_make (name);
3816 *input_line_pointer = endc;
3818 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3819 SF_SET_FUNCTION (ext_sym);
3820 SF_SET_PROCESS (ext_sym);
3821 coff_add_linesym (ext_sym);
3823 demand_empty_rest_of_line ();
3827 ppc_pe_tocd (ignore)
3830 if (tocdata_section == 0)
3832 tocdata_section = subseg_new (".tocd", 0);
3833 /* FIXME: section flags won't work */
3834 bfd_set_section_flags (stdoutput, tocdata_section,
3835 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3836 | SEC_READONLY | SEC_DATA ));
3838 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
3842 rdata_section = subseg_new (".tocd", 0);
3845 ppc_set_current_section(tocdata_section);
3847 demand_empty_rest_of_line ();
3850 /* Don't adjust TOC relocs to use the section symbol. */
3853 ppc_pe_fix_adjustable (fix)
3856 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
3863 /* XCOFF specific symbol and file handling. */
3865 /* Canonicalize the symbol name. We use the to force the suffix, if
3866 any, to use square brackets, and to be in upper case. */
3869 ppc_canonicalize_symbol_name (name)
3874 if (ppc_stab_symbol)
3877 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
3891 for (s++; *s != '\0' && *s != brac; s++)
3895 if (*s == '\0' || s[1] != '\0')
3896 as_bad (_("bad symbol suffix"));
3904 /* Set the class of a symbol based on the suffix, if any. This is
3905 called whenever a new symbol is created. */
3908 ppc_symbol_new_hook (sym)
3913 sym->sy_tc.next = NULL;
3914 sym->sy_tc.output = 0;
3915 sym->sy_tc.class = -1;
3916 sym->sy_tc.real_name = NULL;
3917 sym->sy_tc.subseg = 0;
3918 sym->sy_tc.align = 0;
3919 sym->sy_tc.size = NULL;
3920 sym->sy_tc.within = NULL;
3922 if (ppc_stab_symbol)
3925 s = strchr (S_GET_NAME (sym), '[');
3926 if (s == (const char *) NULL)
3928 /* There is no suffix. */
3937 if (strcmp (s, "BS]") == 0)
3938 sym->sy_tc.class = XMC_BS;
3941 if (strcmp (s, "DB]") == 0)
3942 sym->sy_tc.class = XMC_DB;
3943 else if (strcmp (s, "DS]") == 0)
3944 sym->sy_tc.class = XMC_DS;
3947 if (strcmp (s, "GL]") == 0)
3948 sym->sy_tc.class = XMC_GL;
3951 if (strcmp (s, "PR]") == 0)
3952 sym->sy_tc.class = XMC_PR;
3955 if (strcmp (s, "RO]") == 0)
3956 sym->sy_tc.class = XMC_RO;
3957 else if (strcmp (s, "RW]") == 0)
3958 sym->sy_tc.class = XMC_RW;
3961 if (strcmp (s, "SV]") == 0)
3962 sym->sy_tc.class = XMC_SV;
3965 if (strcmp (s, "TC]") == 0)
3966 sym->sy_tc.class = XMC_TC;
3967 else if (strcmp (s, "TI]") == 0)
3968 sym->sy_tc.class = XMC_TI;
3969 else if (strcmp (s, "TB]") == 0)
3970 sym->sy_tc.class = XMC_TB;
3971 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
3972 sym->sy_tc.class = XMC_TC0;
3975 if (strcmp (s, "UA]") == 0)
3976 sym->sy_tc.class = XMC_UA;
3977 else if (strcmp (s, "UC]") == 0)
3978 sym->sy_tc.class = XMC_UC;
3981 if (strcmp (s, "XO]") == 0)
3982 sym->sy_tc.class = XMC_XO;
3986 if (sym->sy_tc.class == -1)
3987 as_bad (_("Unrecognized symbol suffix"));
3990 /* Set the class of a label based on where it is defined. This
3991 handles symbols without suffixes. Also, move the symbol so that it
3992 follows the csect symbol. */
3995 ppc_frob_label (sym)
3998 if (ppc_current_csect != (symbolS *) NULL)
4000 if (sym->sy_tc.class == -1)
4001 sym->sy_tc.class = ppc_current_csect->sy_tc.class;
4003 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4004 symbol_append (sym, ppc_current_csect->sy_tc.within, &symbol_rootP,
4006 ppc_current_csect->sy_tc.within = sym;
4010 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4011 seen. It tells ppc_adjust_symtab whether it needs to look through
4014 static boolean ppc_saw_abs;
4016 /* Change the name of a symbol just before writing it out. Set the
4017 real name if the .rename pseudo-op was used. Otherwise, remove any
4018 class suffix. Return 1 if the symbol should not be included in the
4022 ppc_frob_symbol (sym)
4025 static symbolS *ppc_last_function;
4026 static symbolS *set_end;
4028 /* Discard symbols that should not be included in the output symbol
4030 if (! sym->sy_used_in_reloc
4031 && ((sym->bsym->flags & BSF_SECTION_SYM) != 0
4032 || (! S_IS_EXTERNAL (sym)
4033 && ! sym->sy_tc.output
4034 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
4037 if (sym->sy_tc.real_name != (char *) NULL)
4038 S_SET_NAME (sym, sym->sy_tc.real_name);
4044 name = S_GET_NAME (sym);
4045 s = strchr (name, '[');
4046 if (s != (char *) NULL)
4052 snew = xmalloc (len + 1);
4053 memcpy (snew, name, len);
4056 S_SET_NAME (sym, snew);
4060 if (set_end != (symbolS *) NULL)
4062 SA_SET_SYM_ENDNDX (set_end, sym);
4066 if (SF_GET_FUNCTION (sym))
4068 if (ppc_last_function != (symbolS *) NULL)
4069 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4070 ppc_last_function = sym;
4071 if (sym->sy_tc.size != (symbolS *) NULL)
4073 resolve_symbol_value (sym->sy_tc.size, 1);
4074 SA_SET_SYM_FSIZE (sym, (long) S_GET_VALUE (sym->sy_tc.size));
4077 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4078 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4080 if (ppc_last_function == (symbolS *) NULL)
4081 as_bad (_(".ef with no preceding .function"));
4084 set_end = ppc_last_function;
4085 ppc_last_function = NULL;
4087 /* We don't have a C_EFCN symbol, but we need to force the
4088 COFF backend to believe that it has seen one. */
4089 coff_last_function = NULL;
4093 if (! S_IS_EXTERNAL (sym)
4094 && (sym->bsym->flags & BSF_SECTION_SYM) == 0
4095 && S_GET_STORAGE_CLASS (sym) != C_FILE
4096 && S_GET_STORAGE_CLASS (sym) != C_FCN
4097 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4098 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4099 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4100 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4101 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4102 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4103 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4105 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4106 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4109 union internal_auxent *a;
4111 /* Create a csect aux. */
4112 i = S_GET_NUMBER_AUXILIARY (sym);
4113 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4114 a = &coffsymbol (sym->bsym)->native[i + 1].u.auxent;
4115 if (sym->sy_tc.class == XMC_TC0)
4117 /* This is the TOC table. */
4118 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4119 a->x_csect.x_scnlen.l = 0;
4120 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4122 else if (sym->sy_tc.subseg != 0)
4124 /* This is a csect symbol. x_scnlen is the size of the
4126 if (sym->sy_tc.next == (symbolS *) NULL)
4127 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4128 S_GET_SEGMENT (sym))
4129 - S_GET_VALUE (sym));
4132 resolve_symbol_value (sym->sy_tc.next, 1);
4133 a->x_csect.x_scnlen.l = (S_GET_VALUE (sym->sy_tc.next)
4134 - S_GET_VALUE (sym));
4136 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_SD;
4138 else if (S_GET_SEGMENT (sym) == bss_section)
4140 /* This is a common symbol. */
4141 a->x_csect.x_scnlen.l = sym->sy_frag->fr_offset;
4142 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_CM;
4143 if (S_IS_EXTERNAL (sym))
4144 sym->sy_tc.class = XMC_RW;
4146 sym->sy_tc.class = XMC_BS;
4148 else if (S_GET_SEGMENT (sym) == absolute_section)
4150 /* This is an absolute symbol. The csect will be created by
4151 ppc_adjust_symtab. */
4153 a->x_csect.x_smtyp = XTY_LD;
4154 if (sym->sy_tc.class == -1)
4155 sym->sy_tc.class = XMC_XO;
4157 else if (! S_IS_DEFINED (sym))
4159 /* This is an external symbol. */
4160 a->x_csect.x_scnlen.l = 0;
4161 a->x_csect.x_smtyp = XTY_ER;
4163 else if (sym->sy_tc.class == XMC_TC)
4167 /* This is a TOC definition. x_scnlen is the size of the
4169 next = symbol_next (sym);
4170 while (next->sy_tc.class == XMC_TC0)
4171 next = symbol_next (next);
4172 if (next == (symbolS *) NULL
4173 || next->sy_tc.class != XMC_TC)
4175 if (ppc_after_toc_frag == (fragS *) NULL)
4176 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4178 - S_GET_VALUE (sym));
4180 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
4181 - S_GET_VALUE (sym));
4185 resolve_symbol_value (next, 1);
4186 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
4187 - S_GET_VALUE (sym));
4189 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4195 /* This is a normal symbol definition. x_scnlen is the
4196 symbol index of the containing csect. */
4197 if (S_GET_SEGMENT (sym) == text_section)
4198 csect = ppc_text_csects;
4199 else if (S_GET_SEGMENT (sym) == data_section)
4200 csect = ppc_data_csects;
4204 /* Skip the initial dummy symbol. */
4205 csect = csect->sy_tc.next;
4207 if (csect == (symbolS *) NULL)
4209 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
4210 a->x_csect.x_scnlen.l = 0;
4214 while (csect->sy_tc.next != (symbolS *) NULL)
4216 resolve_symbol_value (csect->sy_tc.next, 1);
4217 if (S_GET_VALUE (csect->sy_tc.next) > S_GET_VALUE (sym))
4219 csect = csect->sy_tc.next;
4222 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
4223 coffsymbol (sym->bsym)->native[i + 1].fix_scnlen = 1;
4225 a->x_csect.x_smtyp = XTY_LD;
4228 a->x_csect.x_parmhash = 0;
4229 a->x_csect.x_snhash = 0;
4230 if (sym->sy_tc.class == -1)
4231 a->x_csect.x_smclas = XMC_PR;
4233 a->x_csect.x_smclas = sym->sy_tc.class;
4234 a->x_csect.x_stab = 0;
4235 a->x_csect.x_snstab = 0;
4237 /* Don't let the COFF backend resort these symbols. */
4238 sym->bsym->flags |= BSF_NOT_AT_END;
4240 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4242 /* We want the value to be the symbol index of the referenced
4243 csect symbol. BFD will do that for us if we set the right
4246 (valueT) coffsymbol (sym->sy_tc.within->bsym)->native);
4247 coffsymbol (sym->bsym)->native->fix_value = 1;
4249 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4254 /* The value is the offset from the enclosing csect. */
4255 block = sym->sy_tc.within;
4256 csect = block->sy_tc.within;
4257 resolve_symbol_value (csect, 1);
4258 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
4260 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
4261 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
4263 /* We want the value to be a file offset into the line numbers.
4264 BFD will do that for us if we set the right flags. We have
4265 already set the value correctly. */
4266 coffsymbol (sym->bsym)->native->fix_line = 1;
4272 /* Adjust the symbol table. This creates csect symbols for all
4273 absolute symbols. */
4276 ppc_adjust_symtab ()
4283 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4287 union internal_auxent *a;
4289 if (S_GET_SEGMENT (sym) != absolute_section)
4292 csect = symbol_create (".abs[XO]", absolute_section,
4293 S_GET_VALUE (sym), &zero_address_frag);
4294 csect->bsym->value = S_GET_VALUE (sym);
4295 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
4296 i = S_GET_NUMBER_AUXILIARY (csect);
4297 S_SET_NUMBER_AUXILIARY (csect, i + 1);
4298 a = &coffsymbol (csect->bsym)->native[i + 1].u.auxent;
4299 a->x_csect.x_scnlen.l = 0;
4300 a->x_csect.x_smtyp = XTY_SD;
4301 a->x_csect.x_parmhash = 0;
4302 a->x_csect.x_snhash = 0;
4303 a->x_csect.x_smclas = XMC_XO;
4304 a->x_csect.x_stab = 0;
4305 a->x_csect.x_snstab = 0;
4307 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
4309 i = S_GET_NUMBER_AUXILIARY (sym);
4310 a = &coffsymbol (sym->bsym)->native[i].u.auxent;
4311 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
4312 coffsymbol (sym->bsym)->native[i].fix_scnlen = 1;
4315 ppc_saw_abs = false;
4318 /* Set the VMA for a section. This is called on all the sections in
4322 ppc_frob_section (sec)
4325 static bfd_size_type vma = 0;
4327 bfd_set_section_vma (stdoutput, sec, vma);
4328 vma += bfd_section_size (stdoutput, sec);
4331 #endif /* OBJ_XCOFF */
4333 /* Turn a string in input_line_pointer into a floating point constant
4334 of type type, and store the appropriate bytes in *litp. The number
4335 of LITTLENUMS emitted is stored in *sizep . An error message is
4336 returned, or NULL on OK. */
4339 md_atof (type, litp, sizep)
4345 LITTLENUM_TYPE words[4];
4361 return _("bad call to md_atof");
4364 t = atof_ieee (input_line_pointer, type, words);
4366 input_line_pointer = t;
4370 if (target_big_endian)
4372 for (i = 0; i < prec; i++)
4374 md_number_to_chars (litp, (valueT) words[i], 2);
4380 for (i = prec - 1; i >= 0; i--)
4382 md_number_to_chars (litp, (valueT) words[i], 2);
4390 /* Write a value out to the object file, using the appropriate
4394 md_number_to_chars (buf, val, n)
4399 if (target_big_endian)
4400 number_to_chars_bigendian (buf, val, n);
4402 number_to_chars_littleendian (buf, val, n);
4405 /* Align a section (I don't know why this is machine dependent). */
4408 md_section_align (seg, addr)
4412 int align = bfd_get_section_alignment (stdoutput, seg);
4414 return ((addr + (1 << align) - 1) & (-1 << align));
4417 /* We don't have any form of relaxing. */
4420 md_estimate_size_before_relax (fragp, seg)
4428 /* Convert a machine dependent frag. We never generate these. */
4431 md_convert_frag (abfd, sec, fragp)
4439 /* We have no need to default values of symbols. */
4443 md_undefined_symbol (name)
4449 /* Functions concerning relocs. */
4451 /* The location from which a PC relative jump should be calculated,
4452 given a PC relative reloc. */
4455 md_pcrel_from_section (fixp, sec)
4459 return fixp->fx_frag->fr_address + fixp->fx_where;
4464 /* This is called to see whether a fixup should be adjusted to use a
4465 section symbol. We take the opportunity to change a fixup against
4466 a symbol in the TOC subsegment into a reloc against the
4467 corresponding .tc symbol. */
4470 ppc_fix_adjustable (fix)
4475 resolve_symbol_value (fix->fx_addsy, 1);
4476 val = S_GET_VALUE (fix->fx_addsy);
4477 if (ppc_toc_csect != (symbolS *) NULL
4478 && fix->fx_addsy != (symbolS *) NULL
4479 && fix->fx_addsy != ppc_toc_csect
4480 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4481 && val >= ppc_toc_frag->fr_address
4482 && (ppc_after_toc_frag == (fragS *) NULL
4483 || val < ppc_after_toc_frag->fr_address))
4487 for (sy = symbol_next (ppc_toc_csect);
4488 sy != (symbolS *) NULL;
4489 sy = symbol_next (sy))
4491 if (sy->sy_tc.class == XMC_TC0)
4493 if (sy->sy_tc.class != XMC_TC)
4495 resolve_symbol_value (sy, 1);
4496 if (val == S_GET_VALUE (sy))
4499 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4504 as_bad_where (fix->fx_file, fix->fx_line,
4505 _("symbol in .toc does not match any .tc"));
4508 /* Possibly adjust the reloc to be against the csect. */
4509 if (fix->fx_addsy != (symbolS *) NULL
4510 && fix->fx_addsy->sy_tc.subseg == 0
4511 && fix->fx_addsy->sy_tc.class != XMC_TC0
4512 && fix->fx_addsy->sy_tc.class != XMC_TC
4513 && S_GET_SEGMENT (fix->fx_addsy) != bss_section
4514 /* Don't adjust if this is a reloc in the toc section. */
4515 && (S_GET_SEGMENT (fix->fx_addsy) != data_section
4516 || ppc_toc_csect == NULL
4517 || fix->fx_frag->fr_address < ppc_toc_frag->fr_address
4518 || (ppc_after_toc_frag != NULL
4519 && fix->fx_frag->fr_address >= ppc_after_toc_frag->fr_address)))
4523 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4524 csect = ppc_text_csects;
4525 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4526 csect = ppc_data_csects;
4530 /* Skip the initial dummy symbol. */
4531 csect = csect->sy_tc.next;
4533 if (csect != (symbolS *) NULL)
4535 while (csect->sy_tc.next != (symbolS *) NULL
4536 && (csect->sy_tc.next->sy_frag->fr_address
4537 <= fix->fx_addsy->sy_frag->fr_address))
4539 /* If the csect address equals the symbol value, then we
4540 have to look through the full symbol table to see
4541 whether this is the csect we want. Note that we will
4542 only get here if the csect has zero length. */
4543 if ((csect->sy_frag->fr_address
4544 == fix->fx_addsy->sy_frag->fr_address)
4545 && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy))
4549 for (scan = csect->sy_next;
4551 scan = scan->sy_next)
4553 if (scan->sy_tc.subseg != 0)
4555 if (scan == fix->fx_addsy)
4559 /* If we found the symbol before the next csect
4560 symbol, then this is the csect we want. */
4561 if (scan == fix->fx_addsy)
4565 csect = csect->sy_tc.next;
4568 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4569 - csect->sy_frag->fr_address);
4570 fix->fx_addsy = csect;
4574 /* Adjust a reloc against a .lcomm symbol to be against the base
4576 if (fix->fx_addsy != (symbolS *) NULL
4577 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
4578 && ! S_IS_EXTERNAL (fix->fx_addsy))
4580 resolve_symbol_value (fix->fx_addsy->sy_frag->fr_symbol, 1);
4581 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4582 - S_GET_VALUE (fix->fx_addsy->sy_frag->fr_symbol));
4583 fix->fx_addsy = fix->fx_addsy->sy_frag->fr_symbol;
4589 /* A reloc from one csect to another must be kept. The assembler
4590 will, of course, keep relocs between sections, and it will keep
4591 absolute relocs, but we need to force it to keep PC relative relocs
4592 between two csects in the same section. */
4595 ppc_force_relocation (fix)
4598 /* At this point fix->fx_addsy should already have been converted to
4599 a csect symbol. If the csect does not include the fragment, then
4600 we need to force the relocation. */
4602 && fix->fx_addsy != NULL
4603 && fix->fx_addsy->sy_tc.subseg != 0
4604 && (fix->fx_addsy->sy_frag->fr_address > fix->fx_frag->fr_address
4605 || (fix->fx_addsy->sy_tc.next != NULL
4606 && (fix->fx_addsy->sy_tc.next->sy_frag->fr_address
4607 <= fix->fx_frag->fr_address))))
4613 #endif /* OBJ_XCOFF */
4615 /* See whether a symbol is in the TOC section. */
4618 ppc_is_toc_sym (sym)
4622 return sym->sy_tc.class == XMC_TC;
4624 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
4628 /* Apply a fixup to the object code. This is called for all the
4629 fixups we generated by the call to fix_new_exp, above. In the call
4630 above we used a reloc code which was the largest legal reloc code
4631 plus the operand index. Here we undo that to recover the operand
4632 index. At this point all symbol values should be fully resolved,
4633 and we attempt to completely resolve the reloc. If we can not do
4634 that, we determine the correct reloc code and put it back in the
4638 md_apply_fix3 (fixp, valuep, seg)
4647 if (fixp->fx_addsy != NULL)
4649 /* `*valuep' may contain the value of the symbol on which the reloc
4650 will be based; we have to remove it. */
4651 if (fixp->fx_addsy->sy_used_in_reloc
4652 && S_GET_SEGMENT (fixp->fx_addsy) != absolute_section
4653 && S_GET_SEGMENT (fixp->fx_addsy) != undefined_section
4654 && ! bfd_is_com_section (S_GET_SEGMENT (fixp->fx_addsy)))
4655 value -= S_GET_VALUE (fixp->fx_addsy);
4657 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4658 supposed to be? I think this is related to various similar
4659 FIXMEs in tc-i386.c and tc-sparc.c. */
4661 value += fixp->fx_frag->fr_address + fixp->fx_where;
4668 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4669 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4670 doing this relocation the code in write.c is going to call
4671 bfd_install_relocation, which is also going to use the symbol
4672 value. That means that if the reloc is fully resolved we want to
4673 use *valuep since bfd_install_relocation is not being used.
4674 However, if the reloc is not fully resolved we do not want to use
4675 *valuep, and must use fx_offset instead. However, if the reloc
4676 is PC relative, we do want to use *valuep since it includes the
4677 result of md_pcrel_from. This is confusing. */
4678 if (fixp->fx_addsy == (symbolS *) NULL)
4683 else if (fixp->fx_pcrel)
4687 value = fixp->fx_offset;
4688 if (fixp->fx_subsy != (symbolS *) NULL)
4690 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
4691 value -= S_GET_VALUE (fixp->fx_subsy);
4694 /* We can't actually support subtracting a symbol. */
4695 as_bad_where (fixp->fx_file, fixp->fx_line,
4696 _("expression too complex"));
4702 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
4705 const struct powerpc_operand *operand;
4709 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
4711 operand = &powerpc_operands[opindex];
4714 /* It appears that an instruction like
4716 when LC..1 is not a TOC symbol does not generate a reloc. It
4717 uses the offset of LC..1 within its csect. However, .long
4718 LC..1 will generate a reloc. I can't find any documentation
4719 on how these cases are to be distinguished, so this is a wild
4720 guess. These cases are generated by gcc -mminimal-toc. */
4721 if ((operand->flags & PPC_OPERAND_PARENS) != 0
4722 && operand->bits == 16
4723 && operand->shift == 0
4724 && operand->insert == NULL
4725 && fixp->fx_addsy != NULL
4726 && fixp->fx_addsy->sy_tc.subseg != 0
4727 && fixp->fx_addsy->sy_tc.class != XMC_TC
4728 && fixp->fx_addsy->sy_tc.class != XMC_TC0
4729 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
4731 value = fixp->fx_offset;
4736 /* Fetch the instruction, insert the fully resolved operand
4737 value, and stuff the instruction back again. */
4738 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4739 if (target_big_endian)
4740 insn = bfd_getb32 ((unsigned char *) where);
4742 insn = bfd_getl32 ((unsigned char *) where);
4743 insn = ppc_insert_operand (insn, operand, (offsetT) value,
4744 fixp->fx_file, fixp->fx_line);
4745 if (target_big_endian)
4746 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4748 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4752 /* Nothing else to do here. */
4756 /* Determine a BFD reloc value based on the operand information.
4757 We are only prepared to turn a few of the operands into
4759 FIXME: We need to handle the DS field at the very least.
4760 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4761 there should be a new field in the operand table. */
4762 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4763 && operand->bits == 26
4764 && operand->shift == 0)
4765 fixp->fx_r_type = BFD_RELOC_PPC_B26;
4766 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4767 && operand->bits == 16
4768 && operand->shift == 0)
4769 fixp->fx_r_type = BFD_RELOC_PPC_B16;
4770 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4771 && operand->bits == 26
4772 && operand->shift == 0)
4773 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4774 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4775 && operand->bits == 16
4776 && operand->shift == 0)
4777 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4778 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4779 && operand->bits == 16
4780 && operand->shift == 0
4781 && operand->insert == NULL
4782 && fixp->fx_addsy != NULL
4783 && ppc_is_toc_sym (fixp->fx_addsy))
4786 if (target_big_endian)
4787 fixp->fx_where += 2;
4788 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4795 /* Use expr_symbol_where to see if this is an expression
4797 if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline))
4798 as_bad_where (fixp->fx_file, fixp->fx_line,
4799 _("unresolved expression that must be resolved"));
4801 as_bad_where (fixp->fx_file, fixp->fx_line,
4802 _("unsupported relocation type"));
4810 ppc_elf_validate_fix (fixp, seg);
4812 switch (fixp->fx_r_type)
4815 case BFD_RELOC_CTOR:
4817 fixp->fx_r_type = BFD_RELOC_32_PCREL;
4821 case BFD_RELOC_32_PCREL:
4822 case BFD_RELOC_32_BASEREL:
4823 case BFD_RELOC_PPC_EMB_NADDR32:
4824 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4828 case BFD_RELOC_LO16:
4830 case BFD_RELOC_GPREL16:
4831 case BFD_RELOC_16_GOT_PCREL:
4832 case BFD_RELOC_16_GOTOFF:
4833 case BFD_RELOC_LO16_GOTOFF:
4834 case BFD_RELOC_HI16_GOTOFF:
4835 case BFD_RELOC_HI16_S_GOTOFF:
4836 case BFD_RELOC_LO16_BASEREL:
4837 case BFD_RELOC_HI16_BASEREL:
4838 case BFD_RELOC_HI16_S_BASEREL:
4839 case BFD_RELOC_PPC_EMB_NADDR16:
4840 case BFD_RELOC_PPC_EMB_NADDR16_LO:
4841 case BFD_RELOC_PPC_EMB_NADDR16_HI:
4842 case BFD_RELOC_PPC_EMB_NADDR16_HA:
4843 case BFD_RELOC_PPC_EMB_SDAI16:
4844 case BFD_RELOC_PPC_EMB_SDA2REL:
4845 case BFD_RELOC_PPC_EMB_SDA2I16:
4846 case BFD_RELOC_PPC_EMB_RELSEC16:
4847 case BFD_RELOC_PPC_EMB_RELST_LO:
4848 case BFD_RELOC_PPC_EMB_RELST_HI:
4849 case BFD_RELOC_PPC_EMB_RELST_HA:
4850 case BFD_RELOC_PPC_EMB_RELSDA:
4851 case BFD_RELOC_PPC_TOC16:
4854 if (fixp->fx_addsy != NULL)
4855 as_bad_where (fixp->fx_file, fixp->fx_line,
4856 _("cannot emit PC relative %s relocation against %s"),
4857 bfd_get_reloc_code_name (fixp->fx_r_type),
4858 S_GET_NAME (fixp->fx_addsy));
4860 as_bad_where (fixp->fx_file, fixp->fx_line,
4861 _("cannot emit PC relative %s relocation")
4862 bfd_get_reloc_code_name (fixp->fx_r_type));
4865 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4869 /* This case happens when you write, for example,
4871 where L1 and L2 are defined later. */
4872 case BFD_RELOC_HI16:
4875 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4878 case BFD_RELOC_HI16_S:
4881 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4882 value + 0x8000 >> 16, 2);
4885 /* Because SDA21 modifies the register field, the size is set to 4
4886 bytes, rather than 2, so offset it here appropriately */
4887 case BFD_RELOC_PPC_EMB_SDA21:
4891 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where
4892 + ((target_big_endian) ? 2 : 0),
4900 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4904 case BFD_RELOC_24_PLT_PCREL:
4905 case BFD_RELOC_PPC_LOCAL24PC:
4906 if (!fixp->fx_pcrel && !fixp->fx_done)
4914 /* Fetch the instruction, insert the fully resolved operand
4915 value, and stuff the instruction back again. */
4916 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4917 if (target_big_endian)
4918 insn = bfd_getb32 ((unsigned char *) where);
4920 insn = bfd_getl32 ((unsigned char *) where);
4921 if ((value & 3) != 0)
4922 as_bad_where (fixp->fx_file, fixp->fx_line,
4923 _("must branch to an address a multiple of 4"));
4924 if ((offsetT) value < -0x40000000
4925 || (offsetT) value >= 0x40000000)
4926 as_bad_where (fixp->fx_file, fixp->fx_line,
4927 _("@local or @plt branch destination is too far "
4930 insn = insn | (value & 0x03fffffc);
4931 if (target_big_endian)
4932 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4934 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4940 _("Gas failure, reloc value %d\n"), fixp->fx_r_type);
4947 fixp->fx_addnumber = value;
4949 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
4950 fixp->fx_addnumber = 0;
4954 fixp->fx_addnumber = 0;
4956 /* We want to use the offset within the data segment of the
4957 symbol, not the actual VMA of the symbol. */
4958 fixp->fx_addnumber =
4959 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
4967 /* Generate a reloc for a fixup. */
4970 tc_gen_reloc (seg, fixp)
4976 reloc = (arelent *) xmalloc (sizeof (arelent));
4978 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
4979 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4980 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
4981 if (reloc->howto == (reloc_howto_type *) NULL)
4983 as_bad_where (fixp->fx_file, fixp->fx_line,
4984 _("reloc %d not supported by object file format"), (int)fixp->fx_r_type);
4987 reloc->addend = fixp->fx_addnumber;