1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #include "opcode/ppc.h"
38 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
40 /* Tell the main code what the endianness is. */
41 extern int target_big_endian;
43 /* Whether or not, we've set target_big_endian. */
44 static int set_target_endian = 0;
46 /* Whether to use user friendly register names. */
47 #ifndef TARGET_REG_NAMES_P
49 #define TARGET_REG_NAMES_P true
51 #define TARGET_REG_NAMES_P false
55 static boolean reg_names_p = TARGET_REG_NAMES_P;
57 static boolean register_name PARAMS ((expressionS *));
58 static void ppc_set_cpu PARAMS ((void));
59 static unsigned long ppc_insert_operand
60 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
61 offsetT val, char *file, unsigned int line));
62 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
63 static void ppc_byte PARAMS ((int));
64 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
65 static void ppc_tc PARAMS ((int));
68 static void ppc_comm PARAMS ((int));
69 static void ppc_bb PARAMS ((int));
70 static void ppc_bc PARAMS ((int));
71 static void ppc_bf PARAMS ((int));
72 static void ppc_biei PARAMS ((int));
73 static void ppc_bs PARAMS ((int));
74 static void ppc_eb PARAMS ((int));
75 static void ppc_ec PARAMS ((int));
76 static void ppc_ef PARAMS ((int));
77 static void ppc_es PARAMS ((int));
78 static void ppc_csect PARAMS ((int));
79 static void ppc_change_csect PARAMS ((symbolS *));
80 static void ppc_function PARAMS ((int));
81 static void ppc_extern PARAMS ((int));
82 static void ppc_lglobl PARAMS ((int));
83 static void ppc_section PARAMS ((int));
84 static void ppc_named_section PARAMS ((int));
85 static void ppc_stabx PARAMS ((int));
86 static void ppc_rename PARAMS ((int));
87 static void ppc_toc PARAMS ((int));
88 static void ppc_xcoff_cons PARAMS ((int));
89 static void ppc_vbyte PARAMS ((int));
93 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
94 static void ppc_elf_cons PARAMS ((int));
95 static void ppc_elf_rdata PARAMS ((int));
96 static void ppc_elf_lcomm PARAMS ((int));
97 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
101 static void ppc_set_current_section PARAMS ((segT));
102 static void ppc_previous PARAMS ((int));
103 static void ppc_pdata PARAMS ((int));
104 static void ppc_ydata PARAMS ((int));
105 static void ppc_reldata PARAMS ((int));
106 static void ppc_rdata PARAMS ((int));
107 static void ppc_ualong PARAMS ((int));
108 static void ppc_znop PARAMS ((int));
109 static void ppc_pe_comm PARAMS ((int));
110 static void ppc_pe_section PARAMS ((int));
111 static void ppc_pe_function PARAMS ((int));
112 static void ppc_pe_tocd PARAMS ((int));
115 /* Generic assembler global variables which must be defined by all
119 /* This string holds the chars that always start a comment. If the
120 pre-processor is disabled, these aren't very useful. The macro
121 tc_comment_chars points to this. We use this, rather than the
122 usual comment_chars, so that we can switch for Solaris conventions. */
123 static const char ppc_solaris_comment_chars[] = "#!";
124 static const char ppc_eabi_comment_chars[] = "#";
126 #ifdef TARGET_SOLARIS_COMMENT
127 const char *ppc_comment_chars = ppc_solaris_comment_chars;
129 const char *ppc_comment_chars = ppc_eabi_comment_chars;
132 const char comment_chars[] = "#";
135 /* Characters which start a comment at the beginning of a line. */
136 const char line_comment_chars[] = "#";
138 /* Characters which may be used to separate multiple commands on a
140 const char line_separator_chars[] = ";";
142 /* Characters which are used to indicate an exponent in a floating
144 const char EXP_CHARS[] = "eE";
146 /* Characters which mean that a number is a floating point constant,
148 const char FLT_CHARS[] = "dD";
150 /* The target specific pseudo-ops which we support. */
152 const pseudo_typeS md_pseudo_table[] =
154 /* Pseudo-ops which must be overridden. */
155 { "byte", ppc_byte, 0 },
158 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
159 legitimately belong in the obj-*.c file. However, XCOFF is based
160 on COFF, and is only implemented for the RS/6000. We just use
161 obj-coff.c, and add what we need here. */
162 { "comm", ppc_comm, 0 },
163 { "lcomm", ppc_comm, 1 },
167 { "bi", ppc_biei, 0 },
169 { "csect", ppc_csect, 0 },
170 { "data", ppc_section, 'd' },
174 { "ei", ppc_biei, 1 },
176 { "extern", ppc_extern, 0 },
177 { "function", ppc_function, 0 },
178 { "lglobl", ppc_lglobl, 0 },
179 { "rename", ppc_rename, 0 },
180 { "section", ppc_named_section, 0 },
181 { "stabx", ppc_stabx, 0 },
182 { "text", ppc_section, 't' },
183 { "toc", ppc_toc, 0 },
184 { "long", ppc_xcoff_cons, 2 },
185 { "word", ppc_xcoff_cons, 1 },
186 { "short", ppc_xcoff_cons, 1 },
187 { "vbyte", ppc_vbyte, 0 },
191 { "long", ppc_elf_cons, 4 },
192 { "word", ppc_elf_cons, 2 },
193 { "short", ppc_elf_cons, 2 },
194 { "rdata", ppc_elf_rdata, 0 },
195 { "rodata", ppc_elf_rdata, 0 },
196 { "lcomm", ppc_elf_lcomm, 0 },
200 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
201 { "previous", ppc_previous, 0 },
202 { "pdata", ppc_pdata, 0 },
203 { "ydata", ppc_ydata, 0 },
204 { "reldata", ppc_reldata, 0 },
205 { "rdata", ppc_rdata, 0 },
206 { "ualong", ppc_ualong, 0 },
207 { "znop", ppc_znop, 0 },
208 { "comm", ppc_pe_comm, 0 },
209 { "lcomm", ppc_pe_comm, 1 },
210 { "section", ppc_pe_section, 0 },
211 { "function", ppc_pe_function,0 },
212 { "tocd", ppc_pe_tocd, 0 },
215 /* This pseudo-op is used even when not generating XCOFF output. */
222 /* Predefined register names if -mregnames (or default for Windows NT). */
223 /* In general, there are lots of them, in an attempt to be compatible */
224 /* with a number of other Windows NT assemblers. */
226 /* Structure to hold information about predefined registers. */
233 /* List of registers that are pre-defined:
235 Each general register has predefined names of the form:
236 1. r<reg_num> which has the value <reg_num>.
237 2. r.<reg_num> which has the value <reg_num>.
240 Each floating point register has predefined names of the form:
241 1. f<reg_num> which has the value <reg_num>.
242 2. f.<reg_num> which has the value <reg_num>.
244 Each condition register has predefined names of the form:
245 1. cr<reg_num> which has the value <reg_num>.
246 2. cr.<reg_num> which has the value <reg_num>.
248 There are individual registers as well:
249 sp or r.sp has the value 1
250 rtoc or r.toc has the value 2
251 fpscr has the value 0
257 dsisr has the value 18
259 sdr1 has the value 25
260 srr0 has the value 26
261 srr1 has the value 27
263 The table is sorted. Suitable for searching by a binary search. */
265 static const struct pd_reg pre_defined_registers[] =
267 { "cr.0", 0 }, /* Condition Registers */
287 { "dar", 19 }, /* Data Access Register */
288 { "dec", 22 }, /* Decrementer */
289 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
291 { "f.0", 0 }, /* Floating point registers */
359 { "lr", 8 }, /* Link Register */
363 { "r.0", 0 }, /* General Purpose Registers */
396 { "r.sp", 1 }, /* Stack Pointer */
398 { "r.toc", 2 }, /* Pointer to the table of contents */
400 { "r0", 0 }, /* More general purpose registers */
433 { "rtoc", 2 }, /* Table of contents */
435 { "sdr1", 25 }, /* Storage Description Register 1 */
439 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
440 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
446 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
448 /* Given NAME, find the register number associated with that name, return
449 the integer value associated with the given name or -1 on failure. */
451 static int reg_name_search
452 PARAMS ((const struct pd_reg *, int, const char * name));
455 reg_name_search (regs, regcount, name)
456 const struct pd_reg *regs;
460 int middle, low, high;
468 middle = (low + high) / 2;
469 cmp = strcasecmp (name, regs[middle].name);
475 return regs[middle].value;
483 * Summary of register_name().
485 * in: Input_line_pointer points to 1st char of operand.
487 * out: A expressionS.
488 * The operand may have been a register: in this case, X_op == O_register,
489 * X_add_number is set to the register number, and truth is returned.
490 * Input_line_pointer->(next non-blank) char after operand, or is in its
495 register_name (expressionP)
496 expressionS *expressionP;
503 /* Find the spelling of the operand */
504 start = name = input_line_pointer;
505 if (name[0] == '%' && isalpha (name[1]))
506 name = ++input_line_pointer;
508 else if (!reg_names_p || !isalpha (name[0]))
511 c = get_symbol_end ();
512 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
514 /* look to see if it's in the register table */
517 expressionP->X_op = O_register;
518 expressionP->X_add_number = reg_number;
520 /* make the rest nice */
521 expressionP->X_add_symbol = NULL;
522 expressionP->X_op_symbol = NULL;
523 *input_line_pointer = c; /* put back the delimiting char */
528 /* reset the line as if we had not done anything */
529 *input_line_pointer = c; /* put back the delimiting char */
530 input_line_pointer = start; /* reset input_line pointer */
535 /* This function is called for each symbol seen in an expression. It
536 handles the special parsing which PowerPC assemblers are supposed
537 to use for condition codes. */
539 /* Whether to do the special parsing. */
540 static boolean cr_operand;
542 /* Names to recognize in a condition code. This table is sorted. */
543 static const struct pd_reg cr_names[] =
560 /* Parsing function. This returns non-zero if it recognized an
564 ppc_parse_name (name, expr)
573 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
578 expr->X_op = O_constant;
579 expr->X_add_number = val;
584 /* Local variables. */
586 /* The type of processor we are assembling for. This is one or more
587 of the PPC_OPCODE flags defined in opcode/ppc.h. */
588 static int ppc_cpu = 0;
590 /* The size of the processor we are assembling for. This is either
591 PPC_OPCODE_32 or PPC_OPCODE_64. */
592 static int ppc_size = PPC_OPCODE_32;
594 /* Opcode hash table. */
595 static struct hash_control *ppc_hash;
597 /* Macro hash table. */
598 static struct hash_control *ppc_macro_hash;
601 /* What type of shared library support to use */
602 static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
604 /* Flags to set in the elf header */
605 static flagword ppc_flags = 0;
607 /* Whether this is Solaris or not. */
608 #ifdef TARGET_SOLARIS_COMMENT
609 #define SOLARIS_P true
611 #define SOLARIS_P false
614 static boolean msolaris = SOLARIS_P;
619 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
620 using a bunch of different sections. These assembler sections,
621 however, are all encompassed within the .text or .data sections of
622 the final output file. We handle this by using different
623 subsegments within these main segments. */
625 /* Next subsegment to allocate within the .text segment. */
626 static subsegT ppc_text_subsegment = 2;
628 /* Linked list of csects in the text section. */
629 static symbolS *ppc_text_csects;
631 /* Next subsegment to allocate within the .data segment. */
632 static subsegT ppc_data_subsegment = 2;
634 /* Linked list of csects in the data section. */
635 static symbolS *ppc_data_csects;
637 /* The current csect. */
638 static symbolS *ppc_current_csect;
640 /* The RS/6000 assembler uses a TOC which holds addresses of functions
641 and variables. Symbols are put in the TOC with the .tc pseudo-op.
642 A special relocation is used when accessing TOC entries. We handle
643 the TOC as a subsegment within the .data segment. We set it up if
644 we see a .toc pseudo-op, and save the csect symbol here. */
645 static symbolS *ppc_toc_csect;
647 /* The first frag in the TOC subsegment. */
648 static fragS *ppc_toc_frag;
650 /* The first frag in the first subsegment after the TOC in the .data
651 segment. NULL if there are no subsegments after the TOC. */
652 static fragS *ppc_after_toc_frag;
654 /* The current static block. */
655 static symbolS *ppc_current_block;
657 /* The COFF debugging section; set by md_begin. This is not the
658 .debug section, but is instead the secret BFD section which will
659 cause BFD to set the section number of a symbol to N_DEBUG. */
660 static asection *ppc_coff_debug_section;
662 #endif /* OBJ_XCOFF */
666 /* Various sections that we need for PE coff support. */
667 static segT ydata_section;
668 static segT pdata_section;
669 static segT reldata_section;
670 static segT rdata_section;
671 static segT tocdata_section;
673 /* The current section and the previous section. See ppc_previous. */
674 static segT ppc_previous_section;
675 static segT ppc_current_section;
680 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
684 CONST char *md_shortopts = "b:l:usm:K:VQ:";
686 CONST char *md_shortopts = "um:";
688 struct option md_longopts[] = {
689 {NULL, no_argument, NULL, 0}
691 size_t md_longopts_size = sizeof(md_longopts);
694 md_parse_option (c, arg)
701 /* -u means that any undefined symbols should be treated as
702 external, which is the default for gas anyhow. */
707 /* Solaris as takes -le (presumably for little endian). For completeness
708 sake, recognize -be also. */
709 if (strcmp (arg, "e") == 0)
711 target_big_endian = 0;
712 set_target_endian = 1;
720 if (strcmp (arg, "e") == 0)
722 target_big_endian = 1;
723 set_target_endian = 1;
731 /* Recognize -K PIC */
732 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
735 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
744 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
746 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
747 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
748 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
749 else if (strcmp (arg, "pwr") == 0)
750 ppc_cpu = PPC_OPCODE_POWER;
751 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
752 instructions that are holdovers from the Power. */
753 else if (strcmp (arg, "601") == 0)
754 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
755 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
756 Motorola PowerPC 603/604. */
757 else if (strcmp (arg, "ppc") == 0
758 || strcmp (arg, "ppc32") == 0
759 || strcmp (arg, "403") == 0
760 || strcmp (arg, "603") == 0
761 || strcmp (arg, "604") == 0)
762 ppc_cpu = PPC_OPCODE_PPC;
763 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
765 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
767 ppc_cpu = PPC_OPCODE_PPC;
768 ppc_size = PPC_OPCODE_64;
770 else if (strcmp (arg, "ppc64bridge") == 0)
772 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64_BRIDGE;
773 ppc_size = PPC_OPCODE_64;
775 /* -mcom means assemble for the common intersection between Power
776 and PowerPC. At present, we just allow the union, rather
777 than the intersection. */
778 else if (strcmp (arg, "com") == 0)
779 ppc_cpu = PPC_OPCODE_COMMON;
780 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
781 else if (strcmp (arg, "any") == 0)
782 ppc_cpu = PPC_OPCODE_ANY;
784 else if (strcmp (arg, "regnames") == 0)
787 else if (strcmp (arg, "no-regnames") == 0)
791 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
792 else if (strcmp (arg, "relocatable") == 0)
794 shlib = SHILB_MRELOCATABLE;
795 ppc_flags |= EF_PPC_RELOCATABLE;
798 else if (strcmp (arg, "relocatable-lib") == 0)
800 shlib = SHILB_MRELOCATABLE;
801 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
804 /* -memb, set embedded bit */
805 else if (strcmp (arg, "emb") == 0)
806 ppc_flags |= EF_PPC_EMB;
808 /* -mlittle/-mbig set the endianess */
809 else if (strcmp (arg, "little") == 0 || strcmp (arg, "little-endian") == 0)
811 target_big_endian = 0;
812 set_target_endian = 1;
815 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
817 target_big_endian = 1;
818 set_target_endian = 1;
821 else if (strcmp (arg, "solaris") == 0)
824 ppc_comment_chars = ppc_solaris_comment_chars;
827 else if (strcmp (arg, "no-solaris") == 0)
830 ppc_comment_chars = ppc_eabi_comment_chars;
835 as_bad (_("invalid switch -m%s"), arg);
841 /* -V: SVR4 argument to print version ID. */
846 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
847 should be emitted or not. FIXME: Not implemented. */
851 /* Solaris takes -s to specify that .stabs go in a .stabs section,
852 rather than .stabs.excl, which is ignored by the linker.
853 FIXME: Not implemented. */
869 md_show_usage (stream)
875 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
876 -mpwr generate code for IBM POWER (RIOS1)\n\
877 -m601 generate code for Motorola PowerPC 601\n\
878 -mppc, -mppc32, -m403, -m603, -m604\n\
879 generate code for Motorola PowerPC 603/604\n\
880 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
881 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
882 -mcom generate code Power/PowerPC common instructions\n\
883 -many generate code for any architecture (PWR/PWRX/PPC)\n\
884 -mregnames Allow symbolic names for registers\n\
885 -mno-regnames Do not allow symbolic names for registers\n"));
888 -mrelocatable support for GCC's -mrelocatble option\n\
889 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
890 -memb set PPC_EMB bit in ELF flags\n\
891 -mlittle, -mlittle-endian\n\
892 generate code for a little endian machine\n\
893 -mbig, -mbig-endian generate code for a big endian machine\n\
894 -msolaris generate code for Solaris\n\
895 -mno-solaris do not generate code for Solaris\n\
896 -V print assembler version number\n\
897 -Qy, -Qn ignored\n"));
901 /* Set ppc_cpu if it is not already set. */
906 const char *default_os = TARGET_OS;
907 const char *default_cpu = TARGET_CPU;
911 if (strncmp (default_os, "aix", 3) == 0
912 && default_os[3] >= '4' && default_os[3] <= '9')
913 ppc_cpu = PPC_OPCODE_COMMON;
914 else if (strncmp (default_os, "aix3", 4) == 0)
915 ppc_cpu = PPC_OPCODE_POWER;
916 else if (strcmp (default_cpu, "rs6000") == 0)
917 ppc_cpu = PPC_OPCODE_POWER;
918 else if (strcmp (default_cpu, "powerpc") == 0
919 || strcmp (default_cpu, "powerpcle") == 0)
920 ppc_cpu = PPC_OPCODE_PPC;
922 as_fatal (_("Unknown default cpu = %s, os = %s"), default_cpu, default_os);
926 /* Figure out the BFD architecture to use. */
928 enum bfd_architecture
931 const char *default_cpu = TARGET_CPU;
934 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
935 return bfd_arch_powerpc;
936 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
937 return bfd_arch_rs6000;
938 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
940 if (strcmp (default_cpu, "rs6000") == 0)
941 return bfd_arch_rs6000;
942 else if (strcmp (default_cpu, "powerpc") == 0
943 || strcmp (default_cpu, "powerpcle") == 0)
944 return bfd_arch_powerpc;
947 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
948 return bfd_arch_unknown;
951 /* This function is called when the assembler starts up. It is called
952 after the options have been parsed and the output file has been
958 register const struct powerpc_opcode *op;
959 const struct powerpc_opcode *op_end;
960 const struct powerpc_macro *macro;
961 const struct powerpc_macro *macro_end;
962 boolean dup_insn = false;
967 /* Set the ELF flags if desired. */
968 if (ppc_flags && !msolaris)
969 bfd_set_private_flags (stdoutput, ppc_flags);
972 /* Insert the opcodes into a hash table. */
973 ppc_hash = hash_new ();
975 op_end = powerpc_opcodes + powerpc_num_opcodes;
976 for (op = powerpc_opcodes; op < op_end; op++)
978 know ((op->opcode & op->mask) == op->opcode);
980 if ((op->flags & ppc_cpu) != 0
981 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
982 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size
983 || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0))
987 retval = hash_insert (ppc_hash, op->name, (PTR) op);
988 if (retval != (const char *) NULL)
990 /* Ignore Power duplicates for -m601 */
991 if ((ppc_cpu & PPC_OPCODE_601) != 0
992 && (op->flags & PPC_OPCODE_POWER) != 0)
995 as_bad (_("Internal assembler error for instruction %s"), op->name);
1001 /* Insert the macros into a hash table. */
1002 ppc_macro_hash = hash_new ();
1004 macro_end = powerpc_macros + powerpc_num_macros;
1005 for (macro = powerpc_macros; macro < macro_end; macro++)
1007 if ((macro->flags & ppc_cpu) != 0)
1011 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1012 if (retval != (const char *) NULL)
1014 as_bad (_("Internal assembler error for macro %s"), macro->name);
1023 /* Tell the main code what the endianness is if it is not overidden by the user. */
1024 if (!set_target_endian)
1026 set_target_endian = 1;
1027 target_big_endian = PPC_BIG_ENDIAN;
1031 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1033 /* Create dummy symbols to serve as initial csects. This forces the
1034 text csects to precede the data csects. These symbols will not
1036 ppc_text_csects = symbol_make ("dummy\001");
1037 symbol_get_tc (ppc_text_csects)->within = ppc_text_csects;
1038 ppc_data_csects = symbol_make ("dummy\001");
1039 symbol_get_tc (ppc_data_csects)->within = ppc_data_csects;
1044 ppc_current_section = text_section;
1045 ppc_previous_section = 0;
1050 /* Insert an operand value into an instruction. */
1052 static unsigned long
1053 ppc_insert_operand (insn, operand, val, file, line)
1055 const struct powerpc_operand *operand;
1060 if (operand->bits != 32)
1065 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1067 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0)
1068 max = (1 << operand->bits) - 1;
1070 max = (1 << (operand->bits - 1)) - 1;
1071 min = - (1 << (operand->bits - 1));
1073 if (ppc_size == PPC_OPCODE_32)
1075 /* Some people write 32 bit hex constants with the sign
1076 extension done by hand. This shouldn't really be
1077 valid, but, to permit this code to assemble on a 64
1078 bit host, we sign extend the 32 bit value. */
1080 && (val & 0x80000000) != 0
1081 && (val & 0xffffffff) == val)
1090 max = (1 << operand->bits) - 1;
1094 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1099 if (test < (offsetT) min || test > (offsetT) max)
1102 _("operand out of range (%s not between %ld and %ld)");
1105 sprint_value (buf, test);
1106 if (file == (char *) NULL)
1107 as_bad (err, buf, min, max);
1109 as_bad_where (file, line, err, buf, min, max);
1113 if (operand->insert)
1118 insn = (*operand->insert) (insn, (long) val, &errmsg);
1119 if (errmsg != (const char *) NULL)
1123 insn |= (((long) val & ((1 << operand->bits) - 1))
1131 /* Parse @got, etc. and return the desired relocation. */
1132 static bfd_reloc_code_real_type
1133 ppc_elf_suffix (str_p, exp_p)
1140 bfd_reloc_code_real_type reloc;
1148 struct map_bfd *ptr;
1150 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1152 static struct map_bfd mapping[] = {
1153 MAP ("l", BFD_RELOC_LO16),
1154 MAP ("h", BFD_RELOC_HI16),
1155 MAP ("ha", BFD_RELOC_HI16_S),
1156 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1157 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1158 MAP ("got", BFD_RELOC_16_GOTOFF),
1159 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1160 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1161 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1162 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
1163 MAP ("plt", BFD_RELOC_24_PLT_PCREL),
1164 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1165 MAP ("copy", BFD_RELOC_PPC_COPY),
1166 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1167 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1168 MAP ("local", BFD_RELOC_PPC_LOCAL24PC),
1169 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
1170 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1171 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1172 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1173 MAP ("sdarel", BFD_RELOC_GPREL16),
1174 MAP ("sectoff", BFD_RELOC_32_BASEREL),
1175 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1176 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1177 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1178 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1179 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1180 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1181 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1182 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1183 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1184 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1185 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1186 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1187 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1188 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1189 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1190 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1191 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1192 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1193 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1194 MAP ("xgot", BFD_RELOC_PPC_TOC16),
1196 { (char *)0, 0, BFD_RELOC_UNUSED }
1200 return BFD_RELOC_UNUSED;
1202 for (ch = *str, str2 = ident;
1203 (str2 < ident + sizeof (ident) - 1
1204 && (isalnum (ch) || ch == '@'));
1207 *str2++ = (islower (ch)) ? ch : tolower (ch);
1214 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1215 if (ch == ptr->string[0]
1216 && len == ptr->length
1217 && memcmp (ident, ptr->string, ptr->length) == 0)
1219 if (exp_p->X_add_number != 0
1220 && (ptr->reloc == BFD_RELOC_16_GOTOFF
1221 || ptr->reloc == BFD_RELOC_LO16_GOTOFF
1222 || ptr->reloc == BFD_RELOC_HI16_GOTOFF
1223 || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
1224 as_warn (_("identifier+constant@got means identifier@got+constant"));
1226 /* Now check for identifier@suffix+constant */
1227 if (*str == '-' || *str == '+')
1229 char *orig_line = input_line_pointer;
1230 expressionS new_exp;
1232 input_line_pointer = str;
1233 expression (&new_exp);
1234 if (new_exp.X_op == O_constant)
1236 exp_p->X_add_number += new_exp.X_add_number;
1237 str = input_line_pointer;
1240 if (&input_line_pointer != str_p)
1241 input_line_pointer = orig_line;
1248 return BFD_RELOC_UNUSED;
1251 /* Like normal .long/.short/.word, except support @got, etc. */
1252 /* clobbers input_line_pointer, checks */
1255 ppc_elf_cons (nbytes)
1256 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1259 bfd_reloc_code_real_type reloc;
1261 if (is_it_end_of_statement ())
1263 demand_empty_rest_of_line ();
1270 if (exp.X_op == O_symbol
1271 && *input_line_pointer == '@'
1272 && (reloc = ppc_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
1274 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1275 int size = bfd_get_reloc_size (reloc_howto);
1278 as_bad (_("%s relocations do not fit in %d bytes\n"), reloc_howto->name, nbytes);
1282 register char *p = frag_more ((int) nbytes);
1283 int offset = nbytes - size;
1285 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
1289 emit_expr (&exp, (unsigned int) nbytes);
1291 while (*input_line_pointer++ == ',');
1293 input_line_pointer--; /* Put terminator back into stream. */
1294 demand_empty_rest_of_line ();
1297 /* Solaris pseduo op to change to the .rodata section. */
1302 char *save_line = input_line_pointer;
1303 static char section[] = ".rodata\n";
1305 /* Just pretend this is .section .rodata */
1306 input_line_pointer = section;
1307 obj_elf_section (xxx);
1309 input_line_pointer = save_line;
1312 /* Pseudo op to make file scope bss items */
1317 register char *name;
1321 register symbolS *symbolP;
1328 name = input_line_pointer;
1329 c = get_symbol_end ();
1331 /* just after name is now '\0' */
1332 p = input_line_pointer;
1335 if (*input_line_pointer != ',')
1337 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1338 ignore_rest_of_line ();
1342 input_line_pointer++; /* skip ',' */
1343 if ((size = get_absolute_expression ()) < 0)
1345 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
1346 ignore_rest_of_line ();
1350 /* The third argument to .lcomm is the alignment. */
1351 if (*input_line_pointer != ',')
1355 ++input_line_pointer;
1356 align = get_absolute_expression ();
1359 as_warn (_("ignoring bad alignment"));
1365 symbolP = symbol_find_or_make (name);
1368 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1370 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1371 S_GET_NAME (symbolP));
1372 ignore_rest_of_line ();
1376 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1378 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1379 S_GET_NAME (symbolP),
1380 (long) S_GET_VALUE (symbolP),
1383 ignore_rest_of_line ();
1389 old_subsec = now_subseg;
1392 /* convert to a power of 2 alignment */
1393 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1396 as_bad (_("Common alignment not a power of 2"));
1397 ignore_rest_of_line ();
1404 record_alignment (bss_section, align2);
1405 subseg_set (bss_section, 0);
1407 frag_align (align2, 0, 0);
1408 if (S_GET_SEGMENT (symbolP) == bss_section)
1409 symbol_get_frag (symbolP)->fr_symbol = 0;
1410 symbol_set_frag (symbolP, frag_now);
1411 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1414 S_SET_SIZE (symbolP, size);
1415 S_SET_SEGMENT (symbolP, bss_section);
1416 subseg_set (old_sec, old_subsec);
1417 demand_empty_rest_of_line ();
1420 /* Validate any relocations emitted for -mrelocatable, possibly adding
1421 fixups for word relocations in writable segments, so we can adjust
1424 ppc_elf_validate_fix (fixp, seg)
1428 if (fixp->fx_done || fixp->fx_pcrel)
1437 case SHILB_MRELOCATABLE:
1438 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1439 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1440 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1441 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1442 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1443 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1444 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1445 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1446 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1447 && strcmp (segment_name (seg), ".got2") != 0
1448 && strcmp (segment_name (seg), ".dtors") != 0
1449 && strcmp (segment_name (seg), ".ctors") != 0
1450 && strcmp (segment_name (seg), ".fixup") != 0
1451 && strcmp (segment_name (seg), ".stab") != 0
1452 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1453 && strcmp (segment_name (seg), ".eh_frame") != 0
1454 && strcmp (segment_name (seg), ".ex_shared") != 0)
1456 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1457 || fixp->fx_r_type != BFD_RELOC_CTOR)
1459 as_bad_where (fixp->fx_file, fixp->fx_line,
1460 _("Relocation cannot be done when using -mrelocatable"));
1466 #endif /* OBJ_ELF */
1471 * Summary of parse_toc_entry().
1473 * in: Input_line_pointer points to the '[' in one of:
1475 * [toc] [tocv] [toc32] [toc64]
1477 * Anything else is an error of one kind or another.
1480 * return value: success or failure
1481 * toc_kind: kind of toc reference
1482 * input_line_pointer:
1483 * success: first char after the ']'
1484 * failure: unchanged
1488 * [toc] - rv == success, toc_kind = default_toc
1489 * [tocv] - rv == success, toc_kind = data_in_toc
1490 * [toc32] - rv == success, toc_kind = must_be_32
1491 * [toc64] - rv == success, toc_kind = must_be_64
1495 enum toc_size_qualifier
1497 default_toc, /* The toc cell constructed should be the system default size */
1498 data_in_toc, /* This is a direct reference to a toc cell */
1499 must_be_32, /* The toc cell constructed must be 32 bits wide */
1500 must_be_64 /* The toc cell constructed must be 64 bits wide */
1504 parse_toc_entry(toc_kind)
1505 enum toc_size_qualifier *toc_kind;
1510 enum toc_size_qualifier t;
1512 /* save the input_line_pointer */
1513 start = input_line_pointer;
1515 /* skip over the '[' , and whitespace */
1516 ++input_line_pointer;
1519 /* find the spelling of the operand */
1520 toc_spec = input_line_pointer;
1521 c = get_symbol_end ();
1523 if (strcmp(toc_spec, "toc") == 0)
1527 else if (strcmp(toc_spec, "tocv") == 0)
1531 else if (strcmp(toc_spec, "toc32") == 0)
1535 else if (strcmp(toc_spec, "toc64") == 0)
1541 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
1542 *input_line_pointer = c; /* put back the delimiting char */
1543 input_line_pointer = start; /* reset input_line pointer */
1547 /* now find the ']' */
1548 *input_line_pointer = c; /* put back the delimiting char */
1550 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1551 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1555 as_bad (_("syntax error: expected `]', found `%c'"), c);
1556 input_line_pointer = start; /* reset input_line pointer */
1560 *toc_kind = t; /* set return value */
1566 /* We need to keep a list of fixups. We can't simply generate them as
1567 we go, because that would require us to first create the frag, and
1568 that would screw up references to ``.''. */
1574 bfd_reloc_code_real_type reloc;
1577 #define MAX_INSN_FIXUPS (5)
1579 /* This routine is called for each instruction to be assembled. */
1586 const struct powerpc_opcode *opcode;
1588 const unsigned char *opindex_ptr;
1592 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1597 bfd_reloc_code_real_type reloc;
1600 /* Get the opcode. */
1601 for (s = str; *s != '\0' && ! isspace (*s); s++)
1606 /* Look up the opcode in the hash table. */
1607 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1608 if (opcode == (const struct powerpc_opcode *) NULL)
1610 const struct powerpc_macro *macro;
1612 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1613 if (macro == (const struct powerpc_macro *) NULL)
1614 as_bad (_("Unrecognized opcode: `%s'"), str);
1616 ppc_macro (s, macro);
1621 insn = opcode->opcode;
1624 while (isspace (*str))
1627 /* PowerPC operands are just expressions. The only real issue is
1628 that a few operand types are optional. All cases which might use
1629 an optional operand separate the operands only with commas (in
1630 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1631 cases never have optional operands). There is never more than
1632 one optional operand for an instruction. So, before we start
1633 seriously parsing the operands, we check to see if we have an
1634 optional operand, and, if we do, we count the number of commas to
1635 see whether the operand should be omitted. */
1637 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1639 const struct powerpc_operand *operand;
1641 operand = &powerpc_operands[*opindex_ptr];
1642 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1644 unsigned int opcount;
1646 /* There is an optional operand. Count the number of
1647 commas in the input line. */
1654 while ((s = strchr (s, ',')) != (char *) NULL)
1661 /* If there are fewer operands in the line then are called
1662 for by the instruction, we want to skip the optional
1664 if (opcount < strlen (opcode->operands))
1671 /* Gather the operands. */
1675 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1677 const struct powerpc_operand *operand;
1683 if (next_opindex == 0)
1684 operand = &powerpc_operands[*opindex_ptr];
1687 operand = &powerpc_operands[next_opindex];
1693 /* If this is a fake operand, then we do not expect anything
1695 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1697 insn = (*operand->insert) (insn, 0L, &errmsg);
1698 if (errmsg != (const char *) NULL)
1703 /* If this is an optional operand, and we are skipping it, just
1705 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1708 if (operand->insert)
1710 insn = (*operand->insert) (insn, 0L, &errmsg);
1711 if (errmsg != (const char *) NULL)
1714 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1715 next_opindex = *opindex_ptr + 1;
1719 /* Gather the operand. */
1720 hold = input_line_pointer;
1721 input_line_pointer = str;
1724 if (*input_line_pointer == '[')
1726 /* We are expecting something like the second argument here:
1728 lwz r4,[toc].GS.0.static_int(rtoc)
1729 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1730 The argument following the `]' must be a symbol name, and the
1731 register must be the toc register: 'rtoc' or '2'
1733 The effect is to 0 as the displacement field
1734 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1735 the appropriate variation) reloc against it based on the symbol.
1736 The linker will build the toc, and insert the resolved toc offset.
1739 o The size of the toc entry is currently assumed to be
1740 32 bits. This should not be assumed to be a hard coded
1742 o In an effort to cope with a change from 32 to 64 bits,
1743 there are also toc entries that are specified to be
1744 either 32 or 64 bits:
1745 lwz r4,[toc32].GS.0.static_int(rtoc)
1746 lwz r4,[toc64].GS.0.static_int(rtoc)
1747 These demand toc entries of the specified size, and the
1748 instruction probably requires it.
1752 enum toc_size_qualifier toc_kind;
1753 bfd_reloc_code_real_type toc_reloc;
1755 /* go parse off the [tocXX] part */
1756 valid_toc = parse_toc_entry(&toc_kind);
1760 /* Note: message has already been issued. */
1761 /* FIXME: what sort of recovery should we do? */
1762 /* demand_rest_of_line(); return; ? */
1765 /* Now get the symbol following the ']' */
1771 /* In this case, we may not have seen the symbol yet, since */
1772 /* it is allowed to appear on a .extern or .globl or just be */
1773 /* a label in the .data section. */
1774 toc_reloc = BFD_RELOC_PPC_TOC16;
1777 /* 1. The symbol must be defined and either in the toc */
1778 /* section, or a global. */
1779 /* 2. The reloc generated must have the TOCDEFN flag set in */
1780 /* upper bit mess of the reloc type. */
1781 /* FIXME: It's a little confusing what the tocv qualifier can */
1782 /* be used for. At the very least, I've seen three */
1783 /* uses, only one of which I'm sure I can explain. */
1784 if (ex.X_op == O_symbol)
1786 assert (ex.X_add_symbol != NULL);
1787 if (symbol_get_bfdsym (ex.X_add_symbol)->section
1790 as_bad(_("[tocv] symbol is not a toc symbol"));
1794 toc_reloc = BFD_RELOC_PPC_TOC16;
1797 /* FIXME: these next two specifically specify 32/64 bit toc */
1798 /* entries. We don't support them today. Is this the */
1799 /* right way to say that? */
1800 toc_reloc = BFD_RELOC_UNUSED;
1801 as_bad (_("Unimplemented toc32 expression modifier"));
1804 /* FIXME: see above */
1805 toc_reloc = BFD_RELOC_UNUSED;
1806 as_bad (_("Unimplemented toc64 expression modifier"));
1810 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1816 /* We need to generate a fixup for this expression. */
1817 if (fc >= MAX_INSN_FIXUPS)
1818 as_fatal (_("too many fixups"));
1820 fixups[fc].reloc = toc_reloc;
1821 fixups[fc].exp = ex;
1822 fixups[fc].opindex = *opindex_ptr;
1825 /* Ok. We've set up the fixup for the instruction. Now make it
1826 look like the constant 0 was found here */
1828 ex.X_op = O_constant;
1829 ex.X_add_number = 0;
1830 ex.X_add_symbol = NULL;
1831 ex.X_op_symbol = NULL;
1837 if (! register_name (&ex))
1839 if ((operand->flags & PPC_OPERAND_CR) != 0)
1846 str = input_line_pointer;
1847 input_line_pointer = hold;
1849 if (ex.X_op == O_illegal)
1850 as_bad (_("illegal operand"));
1851 else if (ex.X_op == O_absent)
1852 as_bad (_("missing operand"));
1853 else if (ex.X_op == O_register)
1855 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1858 else if (ex.X_op == O_constant)
1861 /* Allow @HA, @L, @H on constants. */
1862 char *orig_str = str;
1864 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
1871 case BFD_RELOC_LO16:
1872 /* X_unsigned is the default, so if the user has done
1873 something which cleared it, we always produce a
1876 && (operand->flags & PPC_OPERAND_SIGNED) == 0)
1877 ex.X_add_number &= 0xffff;
1879 ex.X_add_number = (((ex.X_add_number & 0xffff)
1884 case BFD_RELOC_HI16:
1885 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
1888 case BFD_RELOC_HI16_S:
1889 ex.X_add_number = ((((ex.X_add_number >> 16) & 0xffff)
1890 + ((ex.X_add_number >> 15) & 1))
1895 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1899 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
1901 /* For the absoulte forms of branchs, convert the PC relative form back into
1903 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
1907 case BFD_RELOC_PPC_B26:
1908 reloc = BFD_RELOC_PPC_BA26;
1910 case BFD_RELOC_PPC_B16:
1911 reloc = BFD_RELOC_PPC_BA16;
1913 case BFD_RELOC_PPC_B16_BRTAKEN:
1914 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
1916 case BFD_RELOC_PPC_B16_BRNTAKEN:
1917 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
1924 /* We need to generate a fixup for this expression. */
1925 if (fc >= MAX_INSN_FIXUPS)
1926 as_fatal (_("too many fixups"));
1927 fixups[fc].exp = ex;
1928 fixups[fc].opindex = 0;
1929 fixups[fc].reloc = reloc;
1932 #endif /* OBJ_ELF */
1936 /* We need to generate a fixup for this expression. */
1937 if (fc >= MAX_INSN_FIXUPS)
1938 as_fatal (_("too many fixups"));
1939 fixups[fc].exp = ex;
1940 fixups[fc].opindex = *opindex_ptr;
1941 fixups[fc].reloc = BFD_RELOC_UNUSED;
1950 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
1958 /* The call to expression should have advanced str past any
1961 && (endc != ',' || *str != '\0'))
1963 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
1971 while (isspace (*str))
1975 as_bad (_("junk at end of line: `%s'"), str);
1977 /* Write out the instruction. */
1979 md_number_to_chars (f, insn, 4);
1981 /* Create any fixups. At this point we do not use a
1982 bfd_reloc_code_real_type, but instead just use the
1983 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1984 handle fixups for any operand type, although that is admittedly
1985 not a very exciting feature. We pick a BFD reloc type in
1987 for (i = 0; i < fc; i++)
1989 const struct powerpc_operand *operand;
1991 operand = &powerpc_operands[fixups[i].opindex];
1992 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1994 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2002 size = bfd_get_reloc_size (reloc_howto);
2003 offset = target_big_endian ? (4 - size) : 0;
2005 if (size < 1 || size > 4)
2008 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, size,
2009 &fixups[i].exp, reloc_howto->pc_relative,
2012 /* Turn off complaints that the addend is too large for things like
2014 switch (fixups[i].reloc)
2016 case BFD_RELOC_16_GOTOFF:
2017 case BFD_RELOC_PPC_TOC16:
2018 case BFD_RELOC_LO16:
2019 case BFD_RELOC_HI16:
2020 case BFD_RELOC_HI16_S:
2021 fixP->fx_no_overflow = 1;
2028 fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
2030 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2031 ((bfd_reloc_code_real_type)
2032 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2036 /* Handle a macro. Gather all the operands, transform them as
2037 described by the macro, and call md_assemble recursively. All the
2038 operands are separated by commas; we don't accept parentheses
2039 around operands here. */
2042 ppc_macro (str, macro)
2044 const struct powerpc_macro *macro;
2055 /* Gather the users operands into the operands array. */
2060 if (count >= sizeof operands / sizeof operands[0])
2062 operands[count++] = s;
2063 s = strchr (s, ',');
2064 if (s == (char *) NULL)
2069 if (count != macro->operands)
2071 as_bad (_("wrong number of operands"));
2075 /* Work out how large the string must be (the size is unbounded
2076 because it includes user input). */
2078 format = macro->format;
2079 while (*format != '\0')
2088 arg = strtol (format + 1, &send, 10);
2089 know (send != format && arg >= 0 && arg < count);
2090 len += strlen (operands[arg]);
2095 /* Put the string together. */
2096 complete = s = (char *) alloca (len + 1);
2097 format = macro->format;
2098 while (*format != '\0')
2104 arg = strtol (format + 1, &send, 10);
2105 strcpy (s, operands[arg]);
2112 /* Assemble the constructed instruction. */
2113 md_assemble (complete);
2117 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2120 ppc_section_letter (letter, ptr_msg)
2127 *ptr_msg = _("Bad .section directive: want a,w,x,e in string");
2132 ppc_section_word (str, len)
2136 if (len == 7 && strncmp (str, "exclude", 7) == 0)
2143 ppc_section_type (str, len)
2147 if (len == 7 && strncmp (str, "ordered", 7) == 0)
2154 ppc_section_flags (flags, attr, type)
2159 if (type == SHT_ORDERED)
2160 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2162 if (attr & SHF_EXCLUDE)
2163 flags |= SEC_EXCLUDE;
2167 #endif /* OBJ_ELF */
2170 /* Pseudo-op handling. */
2172 /* The .byte pseudo-op. This is similar to the normal .byte
2173 pseudo-op, but it can also take a single ASCII string. */
2179 if (*input_line_pointer != '\"')
2185 /* Gather characters. A real double quote is doubled. Unusual
2186 characters are not permitted. */
2187 ++input_line_pointer;
2192 c = *input_line_pointer++;
2196 if (*input_line_pointer != '\"')
2198 ++input_line_pointer;
2201 FRAG_APPEND_1_CHAR (c);
2204 demand_empty_rest_of_line ();
2209 /* XCOFF specific pseudo-op handling. */
2211 /* This is set if we are creating a .stabx symbol, since we don't want
2212 to handle symbol suffixes for such symbols. */
2213 static boolean ppc_stab_symbol;
2215 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2216 symbols in the .bss segment as though they were local common
2217 symbols, and uses a different smclas. */
2223 asection *current_seg = now_seg;
2224 subsegT current_subseg = now_subseg;
2230 symbolS *lcomm_sym = NULL;
2234 name = input_line_pointer;
2235 endc = get_symbol_end ();
2236 end_name = input_line_pointer;
2239 if (*input_line_pointer != ',')
2241 as_bad (_("missing size"));
2242 ignore_rest_of_line ();
2245 ++input_line_pointer;
2247 size = get_absolute_expression ();
2250 as_bad (_("negative size"));
2251 ignore_rest_of_line ();
2257 /* The third argument to .comm is the alignment. */
2258 if (*input_line_pointer != ',')
2262 ++input_line_pointer;
2263 align = get_absolute_expression ();
2266 as_warn (_("ignoring bad alignment"));
2285 /* The third argument to .lcomm appears to be the real local
2286 common symbol to create. References to the symbol named in
2287 the first argument are turned into references to the third
2289 if (*input_line_pointer != ',')
2291 as_bad (_("missing real symbol name"));
2292 ignore_rest_of_line ();
2295 ++input_line_pointer;
2297 lcomm_name = input_line_pointer;
2298 lcomm_endc = get_symbol_end ();
2300 lcomm_sym = symbol_find_or_make (lcomm_name);
2302 *input_line_pointer = lcomm_endc;
2306 sym = symbol_find_or_make (name);
2309 if (S_IS_DEFINED (sym)
2310 || S_GET_VALUE (sym) != 0)
2312 as_bad (_("attempt to redefine symbol"));
2313 ignore_rest_of_line ();
2317 record_alignment (bss_section, align);
2320 || ! S_IS_DEFINED (lcomm_sym))
2329 S_SET_EXTERNAL (sym);
2333 symbol_get_tc (lcomm_sym)->output = 1;
2334 def_sym = lcomm_sym;
2338 subseg_set (bss_section, 1);
2339 frag_align (align, 0, 0);
2341 symbol_set_frag (def_sym, frag_now);
2342 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2343 def_size, (char *) NULL);
2345 S_SET_SEGMENT (def_sym, bss_section);
2346 symbol_get_tc (def_sym)->align = align;
2350 /* Align the size of lcomm_sym. */
2351 symbol_get_frag (lcomm_sym)->fr_offset =
2352 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
2353 &~ ((1 << align) - 1));
2354 if (align > symbol_get_tc (lcomm_sym)->align)
2355 symbol_get_tc (lcomm_sym)->align = align;
2360 /* Make sym an offset from lcomm_sym. */
2361 S_SET_SEGMENT (sym, bss_section);
2362 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
2363 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
2364 symbol_get_frag (lcomm_sym)->fr_offset += size;
2367 subseg_set (current_seg, current_subseg);
2369 demand_empty_rest_of_line ();
2372 /* The .csect pseudo-op. This switches us into a different
2373 subsegment. The first argument is a symbol whose value is the
2374 start of the .csect. In COFF, csect symbols get special aux
2375 entries defined by the x_csect field of union internal_auxent. The
2376 optional second argument is the alignment (the default is 2). */
2386 name = input_line_pointer;
2387 endc = get_symbol_end ();
2389 sym = symbol_find_or_make (name);
2391 *input_line_pointer = endc;
2393 if (S_GET_NAME (sym)[0] == '\0')
2395 /* An unnamed csect is assumed to be [PR]. */
2396 symbol_get_tc (sym)->class = XMC_PR;
2399 ppc_change_csect (sym);
2401 if (*input_line_pointer == ',')
2403 ++input_line_pointer;
2404 symbol_get_tc (sym)->align = get_absolute_expression ();
2407 demand_empty_rest_of_line ();
2410 /* Change to a different csect. */
2413 ppc_change_csect (sym)
2416 if (S_IS_DEFINED (sym))
2417 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
2425 /* This is a new csect. We need to look at the symbol class to
2426 figure out whether it should go in the text section or the
2429 switch (symbol_get_tc (sym)->class)
2439 S_SET_SEGMENT (sym, text_section);
2440 symbol_get_tc (sym)->subseg = ppc_text_subsegment;
2441 ++ppc_text_subsegment;
2442 list_ptr = &ppc_text_csects;
2451 if (ppc_toc_csect != NULL
2452 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
2453 == ppc_data_subsegment))
2455 S_SET_SEGMENT (sym, data_section);
2456 symbol_get_tc (sym)->subseg = ppc_data_subsegment;
2457 ++ppc_data_subsegment;
2458 list_ptr = &ppc_data_csects;
2464 /* We set the obstack chunk size to a small value before
2465 changing subsegments, so that we don't use a lot of memory
2466 space for what may be a small section. */
2467 hold_chunksize = chunksize;
2470 subseg_new (segment_name (S_GET_SEGMENT (sym)),
2471 symbol_get_tc (sym)->subseg);
2473 chunksize = hold_chunksize;
2476 ppc_after_toc_frag = frag_now;
2478 symbol_set_frag (sym, frag_now);
2479 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2481 symbol_get_tc (sym)->align = 2;
2482 symbol_get_tc (sym)->output = 1;
2483 symbol_get_tc (sym)->within = sym;
2485 for (list = *list_ptr;
2486 symbol_get_tc (list)->next != (symbolS *) NULL;
2487 list = symbol_get_tc (list)->next)
2489 symbol_get_tc (list)->next = sym;
2491 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2492 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
2496 ppc_current_csect = sym;
2499 /* This function handles the .text and .data pseudo-ops. These
2500 pseudo-ops aren't really used by XCOFF; we implement them for the
2501 convenience of people who aren't used to XCOFF. */
2512 else if (type == 'd')
2517 sym = symbol_find_or_make (name);
2519 ppc_change_csect (sym);
2521 demand_empty_rest_of_line ();
2524 /* This function handles the .section pseudo-op. This is mostly to
2525 give an error, since XCOFF only supports .text, .data and .bss, but
2526 we do permit the user to name the text or data section. */
2529 ppc_named_section (ignore)
2533 const char *real_name;
2537 user_name = input_line_pointer;
2538 c = get_symbol_end ();
2540 if (strcmp (user_name, ".text") == 0)
2541 real_name = ".text[PR]";
2542 else if (strcmp (user_name, ".data") == 0)
2543 real_name = ".data[RW]";
2546 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2547 *input_line_pointer = c;
2548 ignore_rest_of_line ();
2552 *input_line_pointer = c;
2554 sym = symbol_find_or_make (real_name);
2556 ppc_change_csect (sym);
2558 demand_empty_rest_of_line ();
2561 /* The .extern pseudo-op. We create an undefined symbol. */
2570 name = input_line_pointer;
2571 endc = get_symbol_end ();
2573 (void) symbol_find_or_make (name);
2575 *input_line_pointer = endc;
2577 demand_empty_rest_of_line ();
2580 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2590 name = input_line_pointer;
2591 endc = get_symbol_end ();
2593 sym = symbol_find_or_make (name);
2595 *input_line_pointer = endc;
2597 symbol_get_tc (sym)->output = 1;
2599 demand_empty_rest_of_line ();
2602 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2603 although I don't know why it bothers. */
2614 name = input_line_pointer;
2615 endc = get_symbol_end ();
2617 sym = symbol_find_or_make (name);
2619 *input_line_pointer = endc;
2621 if (*input_line_pointer != ',')
2623 as_bad (_("missing rename string"));
2624 ignore_rest_of_line ();
2627 ++input_line_pointer;
2629 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
2631 demand_empty_rest_of_line ();
2634 /* The .stabx pseudo-op. This is similar to a normal .stabs
2635 pseudo-op, but slightly different. A sample is
2636 .stabx "main:F-1",.main,142,0
2637 The first argument is the symbol name to create. The second is the
2638 value, and the third is the storage class. The fourth seems to be
2639 always zero, and I am assuming it is the type. */
2650 name = demand_copy_C_string (&len);
2652 if (*input_line_pointer != ',')
2654 as_bad (_("missing value"));
2657 ++input_line_pointer;
2659 ppc_stab_symbol = true;
2660 sym = symbol_make (name);
2661 ppc_stab_symbol = false;
2663 symbol_get_tc (sym)->real_name = name;
2665 (void) expression (&exp);
2672 as_bad (_("illegal .stabx expression; zero assumed"));
2673 exp.X_add_number = 0;
2676 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2677 symbol_set_frag (sym, &zero_address_frag);
2681 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2682 symbol_set_value_expression (sym, &exp);
2686 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2687 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
2692 /* The value is some complex expression. This will probably
2693 fail at some later point, but this is probably the right
2694 thing to do here. */
2695 symbol_set_value_expression (sym, &exp);
2699 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2700 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
2702 if (*input_line_pointer != ',')
2704 as_bad (_("missing class"));
2707 ++input_line_pointer;
2709 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2711 if (*input_line_pointer != ',')
2713 as_bad (_("missing type"));
2716 ++input_line_pointer;
2718 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2720 symbol_get_tc (sym)->output = 1;
2722 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
2723 symbol_get_tc (sym)->within = ppc_current_block;
2725 if (exp.X_op != O_symbol
2726 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2727 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2728 ppc_frob_label (sym);
2731 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2732 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2733 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
2734 symbol_get_tc (ppc_current_csect)->within = sym;
2737 demand_empty_rest_of_line ();
2740 /* The .function pseudo-op. This takes several arguments. The first
2741 argument seems to be the external name of the symbol. The second
2742 argment seems to be the label for the start of the function. gcc
2743 uses the same name for both. I have no idea what the third and
2744 fourth arguments are meant to be. The optional fifth argument is
2745 an expression for the size of the function. In COFF this symbol
2746 gets an aux entry like that used for a csect. */
2749 ppc_function (ignore)
2758 name = input_line_pointer;
2759 endc = get_symbol_end ();
2761 /* Ignore any [PR] suffix. */
2762 name = ppc_canonicalize_symbol_name (name);
2763 s = strchr (name, '[');
2764 if (s != (char *) NULL
2765 && strcmp (s + 1, "PR]") == 0)
2768 ext_sym = symbol_find_or_make (name);
2770 *input_line_pointer = endc;
2772 if (*input_line_pointer != ',')
2774 as_bad (_("missing symbol name"));
2775 ignore_rest_of_line ();
2778 ++input_line_pointer;
2780 name = input_line_pointer;
2781 endc = get_symbol_end ();
2783 lab_sym = symbol_find_or_make (name);
2785 *input_line_pointer = endc;
2787 if (ext_sym != lab_sym)
2791 exp.X_op = O_symbol;
2792 exp.X_add_symbol = lab_sym;
2793 exp.X_op_symbol = NULL;
2794 exp.X_add_number = 0;
2796 symbol_set_value_expression (ext_sym, &exp);
2799 if (symbol_get_tc (ext_sym)->class == -1)
2800 symbol_get_tc (ext_sym)->class = XMC_PR;
2801 symbol_get_tc (ext_sym)->output = 1;
2803 if (*input_line_pointer == ',')
2807 /* Ignore the third argument. */
2808 ++input_line_pointer;
2809 expression (&ignore);
2810 if (*input_line_pointer == ',')
2812 /* Ignore the fourth argument. */
2813 ++input_line_pointer;
2814 expression (&ignore);
2815 if (*input_line_pointer == ',')
2817 /* The fifth argument is the function size. */
2818 ++input_line_pointer;
2819 symbol_get_tc (ext_sym)->size = symbol_new ("L0\001",
2822 &zero_address_frag);
2823 pseudo_set (symbol_get_tc (ext_sym)->size);
2828 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2829 SF_SET_FUNCTION (ext_sym);
2830 SF_SET_PROCESS (ext_sym);
2831 coff_add_linesym (ext_sym);
2833 demand_empty_rest_of_line ();
2836 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2845 sym = symbol_make (".bf");
2846 S_SET_SEGMENT (sym, text_section);
2847 symbol_set_frag (sym, frag_now);
2848 S_SET_VALUE (sym, frag_now_fix ());
2849 S_SET_STORAGE_CLASS (sym, C_FCN);
2851 coff_line_base = get_absolute_expression ();
2853 S_SET_NUMBER_AUXILIARY (sym, 1);
2854 SA_SET_SYM_LNNO (sym, coff_line_base);
2856 symbol_get_tc (sym)->output = 1;
2858 ppc_frob_label (sym);
2860 demand_empty_rest_of_line ();
2863 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2864 ".ef", except that the line number is absolute, not relative to the
2865 most recent ".bf" symbol. */
2873 sym = symbol_make (".ef");
2874 S_SET_SEGMENT (sym, text_section);
2875 symbol_set_frag (sym, frag_now);
2876 S_SET_VALUE (sym, frag_now_fix ());
2877 S_SET_STORAGE_CLASS (sym, C_FCN);
2878 S_SET_NUMBER_AUXILIARY (sym, 1);
2879 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2880 symbol_get_tc (sym)->output = 1;
2882 ppc_frob_label (sym);
2884 demand_empty_rest_of_line ();
2887 /* The .bi and .ei pseudo-ops. These take a string argument and
2888 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2895 static symbolS *last_biei;
2902 name = demand_copy_C_string (&len);
2904 /* The value of these symbols is actually file offset. Here we set
2905 the value to the index into the line number entries. In
2906 ppc_frob_symbols we set the fix_line field, which will cause BFD
2907 to do the right thing. */
2909 sym = symbol_make (name);
2910 /* obj-coff.c currently only handles line numbers correctly in the
2912 S_SET_SEGMENT (sym, text_section);
2913 S_SET_VALUE (sym, coff_n_line_nos);
2914 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
2916 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
2917 symbol_get_tc (sym)->output = 1;
2919 for (look = last_biei ? last_biei : symbol_rootP;
2920 (look != (symbolS *) NULL
2921 && (S_GET_STORAGE_CLASS (look) == C_FILE
2922 || S_GET_STORAGE_CLASS (look) == C_BINCL
2923 || S_GET_STORAGE_CLASS (look) == C_EINCL));
2924 look = symbol_next (look))
2926 if (look != (symbolS *) NULL)
2928 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2929 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
2933 demand_empty_rest_of_line ();
2936 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2937 There is one argument, which is a csect symbol. The value of the
2938 .bs symbol is the index of this csect symbol. */
2949 if (ppc_current_block != NULL)
2950 as_bad (_("nested .bs blocks"));
2952 name = input_line_pointer;
2953 endc = get_symbol_end ();
2955 csect = symbol_find_or_make (name);
2957 *input_line_pointer = endc;
2959 sym = symbol_make (".bs");
2960 S_SET_SEGMENT (sym, now_seg);
2961 S_SET_STORAGE_CLASS (sym, C_BSTAT);
2962 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
2963 symbol_get_tc (sym)->output = 1;
2965 symbol_get_tc (sym)->within = csect;
2967 ppc_frob_label (sym);
2969 ppc_current_block = sym;
2971 demand_empty_rest_of_line ();
2974 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2982 if (ppc_current_block == NULL)
2983 as_bad (_(".es without preceding .bs"));
2985 sym = symbol_make (".es");
2986 S_SET_SEGMENT (sym, now_seg);
2987 S_SET_STORAGE_CLASS (sym, C_ESTAT);
2988 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
2989 symbol_get_tc (sym)->output = 1;
2991 ppc_frob_label (sym);
2993 ppc_current_block = NULL;
2995 demand_empty_rest_of_line ();
2998 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3007 sym = symbol_make (".bb");
3008 S_SET_SEGMENT (sym, text_section);
3009 symbol_set_frag (sym, frag_now);
3010 S_SET_VALUE (sym, frag_now_fix ());
3011 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3013 S_SET_NUMBER_AUXILIARY (sym, 1);
3014 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3016 symbol_get_tc (sym)->output = 1;
3018 SF_SET_PROCESS (sym);
3020 ppc_frob_label (sym);
3022 demand_empty_rest_of_line ();
3025 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3034 sym = symbol_make (".eb");
3035 S_SET_SEGMENT (sym, text_section);
3036 symbol_set_frag (sym, frag_now);
3037 S_SET_VALUE (sym, frag_now_fix ());
3038 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3039 S_SET_NUMBER_AUXILIARY (sym, 1);
3040 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3041 symbol_get_tc (sym)->output = 1;
3043 SF_SET_PROCESS (sym);
3045 ppc_frob_label (sym);
3047 demand_empty_rest_of_line ();
3050 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3061 name = demand_copy_C_string (&len);
3062 sym = symbol_make (name);
3063 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3064 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3065 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3066 S_SET_VALUE (sym, 0);
3067 symbol_get_tc (sym)->output = 1;
3069 ppc_frob_label (sym);
3071 demand_empty_rest_of_line ();
3074 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3082 sym = symbol_make (".ec");
3083 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3084 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3085 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3086 S_SET_VALUE (sym, 0);
3087 symbol_get_tc (sym)->output = 1;
3089 ppc_frob_label (sym);
3091 demand_empty_rest_of_line ();
3094 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3100 if (ppc_toc_csect != (symbolS *) NULL)
3101 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
3108 subseg = ppc_data_subsegment;
3109 ++ppc_data_subsegment;
3111 subseg_new (segment_name (data_section), subseg);
3112 ppc_toc_frag = frag_now;
3114 sym = symbol_find_or_make ("TOC[TC0]");
3115 symbol_set_frag (sym, frag_now);
3116 S_SET_SEGMENT (sym, data_section);
3117 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3118 symbol_get_tc (sym)->subseg = subseg;
3119 symbol_get_tc (sym)->output = 1;
3120 symbol_get_tc (sym)->within = sym;
3122 ppc_toc_csect = sym;
3124 for (list = ppc_data_csects;
3125 symbol_get_tc (list)->next != (symbolS *) NULL;
3126 list = symbol_get_tc (list)->next)
3128 symbol_get_tc (list)->next = sym;
3130 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3131 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3135 ppc_current_csect = ppc_toc_csect;
3137 demand_empty_rest_of_line ();
3140 /* The AIX assembler automatically aligns the operands of a .long or
3141 .short pseudo-op, and we want to be compatible. */
3144 ppc_xcoff_cons (log_size)
3147 frag_align (log_size, 0, 0);
3148 record_alignment (now_seg, log_size);
3149 cons (1 << log_size);
3159 (void) expression (&exp);
3161 if (exp.X_op != O_constant)
3163 as_bad (_("non-constant byte count"));
3167 byte_count = exp.X_add_number;
3169 if (*input_line_pointer != ',')
3171 as_bad (_("missing value"));
3175 ++input_line_pointer;
3179 #endif /* OBJ_XCOFF */
3181 /* The .tc pseudo-op. This is used when generating either XCOFF or
3182 ELF. This takes two or more arguments.
3184 When generating XCOFF output, the first argument is the name to
3185 give to this location in the toc; this will be a symbol with class
3186 TC. The rest of the arguments are 4 byte values to actually put at
3187 this location in the TOC; often there is just one more argument, a
3188 relocateable symbol reference.
3190 When not generating XCOFF output, the arguments are the same, but
3191 the first argument is simply ignored. */
3199 /* Define the TOC symbol name. */
3205 if (ppc_toc_csect == (symbolS *) NULL
3206 || ppc_toc_csect != ppc_current_csect)
3208 as_bad (_(".tc not in .toc section"));
3209 ignore_rest_of_line ();
3213 name = input_line_pointer;
3214 endc = get_symbol_end ();
3216 sym = symbol_find_or_make (name);
3218 *input_line_pointer = endc;
3220 if (S_IS_DEFINED (sym))
3224 label = symbol_get_tc (ppc_current_csect)->within;
3225 if (symbol_get_tc (label)->class != XMC_TC0)
3227 as_bad (_(".tc with no label"));
3228 ignore_rest_of_line ();
3232 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3233 symbol_set_frag (label, symbol_get_frag (sym));
3234 S_SET_VALUE (label, S_GET_VALUE (sym));
3236 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3237 ++input_line_pointer;
3242 S_SET_SEGMENT (sym, now_seg);
3243 symbol_set_frag (sym, frag_now);
3244 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3245 symbol_get_tc (sym)->class = XMC_TC;
3246 symbol_get_tc (sym)->output = 1;
3248 ppc_frob_label (sym);
3251 #else /* ! defined (OBJ_XCOFF) */
3253 /* Skip the TOC symbol name. */
3254 while (is_part_of_name (*input_line_pointer)
3255 || *input_line_pointer == '['
3256 || *input_line_pointer == ']'
3257 || *input_line_pointer == '{'
3258 || *input_line_pointer == '}')
3259 ++input_line_pointer;
3261 /* Align to a four byte boundary. */
3262 frag_align (2, 0, 0);
3263 record_alignment (now_seg, 2);
3265 #endif /* ! defined (OBJ_XCOFF) */
3267 if (*input_line_pointer != ',')
3268 demand_empty_rest_of_line ();
3271 ++input_line_pointer;
3278 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3280 /* Set the current section. */
3282 ppc_set_current_section (new)
3285 ppc_previous_section = ppc_current_section;
3286 ppc_current_section = new;
3289 /* pseudo-op: .previous
3290 behaviour: toggles the current section with the previous section.
3292 warnings: "No previous section"
3295 ppc_previous(ignore)
3300 if (ppc_previous_section == NULL)
3302 as_warn(_("No previous section to return to. Directive ignored."));
3306 subseg_set(ppc_previous_section, 0);
3308 ppc_set_current_section(ppc_previous_section);
3311 /* pseudo-op: .pdata
3312 behaviour: predefined read only data section
3316 initial: .section .pdata "adr3"
3317 a - don't know -- maybe a misprint
3318 d - initialized data
3320 3 - double word aligned (that would be 4 byte boundary)
3323 Tag index tables (also known as the function table) for exception
3324 handling, debugging, etc.
3331 if (pdata_section == 0)
3333 pdata_section = subseg_new (".pdata", 0);
3335 bfd_set_section_flags (stdoutput, pdata_section,
3336 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3337 | SEC_READONLY | SEC_DATA ));
3339 bfd_set_section_alignment (stdoutput, pdata_section, 2);
3343 pdata_section = subseg_new(".pdata", 0);
3345 ppc_set_current_section(pdata_section);
3348 /* pseudo-op: .ydata
3349 behaviour: predefined read only data section
3353 initial: .section .ydata "drw3"
3354 a - don't know -- maybe a misprint
3355 d - initialized data
3357 3 - double word aligned (that would be 4 byte boundary)
3359 Tag tables (also known as the scope table) for exception handling,
3366 if (ydata_section == 0)
3368 ydata_section = subseg_new (".ydata", 0);
3369 bfd_set_section_flags (stdoutput, ydata_section,
3370 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3371 | SEC_READONLY | SEC_DATA ));
3373 bfd_set_section_alignment (stdoutput, ydata_section, 3);
3377 ydata_section = subseg_new (".ydata", 0);
3379 ppc_set_current_section(ydata_section);
3382 /* pseudo-op: .reldata
3383 behaviour: predefined read write data section
3384 double word aligned (4-byte)
3385 FIXME: relocation is applied to it
3386 FIXME: what's the difference between this and .data?
3389 initial: .section .reldata "drw3"
3390 d - initialized data
3393 3 - double word aligned (that would be 8 byte boundary)
3396 Like .data, but intended to hold data subject to relocation, such as
3397 function descriptors, etc.
3403 if (reldata_section == 0)
3405 reldata_section = subseg_new (".reldata", 0);
3407 bfd_set_section_flags (stdoutput, reldata_section,
3408 ( SEC_ALLOC | SEC_LOAD | SEC_RELOC
3411 bfd_set_section_alignment (stdoutput, reldata_section, 2);
3415 reldata_section = subseg_new (".reldata", 0);
3417 ppc_set_current_section(reldata_section);
3420 /* pseudo-op: .rdata
3421 behaviour: predefined read only data section
3425 initial: .section .rdata "dr3"
3426 d - initialized data
3428 3 - double word aligned (that would be 4 byte boundary)
3434 if (rdata_section == 0)
3436 rdata_section = subseg_new (".rdata", 0);
3437 bfd_set_section_flags (stdoutput, rdata_section,
3438 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3439 | SEC_READONLY | SEC_DATA ));
3441 bfd_set_section_alignment (stdoutput, rdata_section, 2);
3445 rdata_section = subseg_new (".rdata", 0);
3447 ppc_set_current_section(rdata_section);
3450 /* pseudo-op: .ualong
3451 behaviour: much like .int, with the exception that no alignment is
3453 FIXME: test the alignment statement
3465 /* pseudo-op: .znop <symbol name>
3466 behaviour: Issue a nop instruction
3467 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3468 the supplied symbol name.
3470 warnings: Missing symbol name
3477 const struct powerpc_opcode *opcode;
3483 /* Strip out the symbol name */
3491 symbol_name = input_line_pointer;
3492 c = get_symbol_end ();
3494 name = xmalloc (input_line_pointer - symbol_name + 1);
3495 strcpy (name, symbol_name);
3497 sym = symbol_find_or_make (name);
3499 *input_line_pointer = c;
3503 /* Look up the opcode in the hash table. */
3504 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3506 /* stick in the nop */
3507 insn = opcode->opcode;
3509 /* Write out the instruction. */
3511 md_number_to_chars (f, insn, 4);
3513 f - frag_now->fr_literal,
3518 BFD_RELOC_16_GOT_PCREL);
3531 register char *name;
3535 register symbolS *symbolP;
3538 name = input_line_pointer;
3539 c = get_symbol_end ();
3541 /* just after name is now '\0' */
3542 p = input_line_pointer;
3545 if (*input_line_pointer != ',')
3547 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3548 ignore_rest_of_line ();
3552 input_line_pointer++; /* skip ',' */
3553 if ((temp = get_absolute_expression ()) < 0)
3555 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
3556 ignore_rest_of_line ();
3562 /* The third argument to .comm is the alignment. */
3563 if (*input_line_pointer != ',')
3567 ++input_line_pointer;
3568 align = get_absolute_expression ();
3571 as_warn (_("ignoring bad alignment"));
3578 symbolP = symbol_find_or_make (name);
3581 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
3583 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3584 S_GET_NAME (symbolP));
3585 ignore_rest_of_line ();
3589 if (S_GET_VALUE (symbolP))
3591 if (S_GET_VALUE (symbolP) != (valueT) temp)
3592 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3593 S_GET_NAME (symbolP),
3594 (long) S_GET_VALUE (symbolP),
3599 S_SET_VALUE (symbolP, (valueT) temp);
3600 S_SET_EXTERNAL (symbolP);
3603 demand_empty_rest_of_line ();
3607 * implement the .section pseudo op:
3608 * .section name {, "flags"}
3610 * | +--- optional flags: 'b' for bss
3612 * +-- section name 'l' for lib
3616 * 'd' (apparently m88k for data)
3618 * But if the argument is not a quoted string, treat it as a
3619 * subsegment number.
3621 * FIXME: this is a copy of the section processing from obj-coff.c, with
3622 * additions/changes for the moto-pas assembler support. There are three
3625 * FIXME: I just noticed this. This doesn't work at all really. It it
3626 * setting bits that bfd probably neither understands or uses. The
3627 * correct approach (?) will have to incorporate extra fields attached
3628 * to the section to hold the system specific stuff. (krk)
3631 * 'a' - unknown - referred to in documentation, but no definition supplied
3632 * 'c' - section has code
3633 * 'd' - section has initialized data
3634 * 'u' - section has uninitialized data
3635 * 'i' - section contains directives (info)
3636 * 'n' - section can be discarded
3637 * 'R' - remove section at link time
3639 * Section Protection:
3640 * 'r' - section is readable
3641 * 'w' - section is writeable
3642 * 'x' - section is executable
3643 * 's' - section is sharable
3645 * Section Alignment:
3646 * '0' - align to byte boundary
3647 * '1' - align to halfword undary
3648 * '2' - align to word boundary
3649 * '3' - align to doubleword boundary
3650 * '4' - align to quadword boundary
3651 * '5' - align to 32 byte boundary
3652 * '6' - align to 64 byte boundary
3657 ppc_pe_section (ignore)
3660 /* Strip out the section name */
3669 section_name = input_line_pointer;
3670 c = get_symbol_end ();
3672 name = xmalloc (input_line_pointer - section_name + 1);
3673 strcpy (name, section_name);
3675 *input_line_pointer = c;
3680 flags = SEC_NO_FLAGS;
3682 if (strcmp (name, ".idata$2") == 0)
3686 else if (strcmp (name, ".idata$3") == 0)
3690 else if (strcmp (name, ".idata$4") == 0)
3694 else if (strcmp (name, ".idata$5") == 0)
3698 else if (strcmp (name, ".idata$6") == 0)
3703 align = 4; /* default alignment to 16 byte boundary */
3705 if (*input_line_pointer == ',')
3707 ++input_line_pointer;
3709 if (*input_line_pointer != '"')
3710 exp = get_absolute_expression ();
3713 ++input_line_pointer;
3714 while (*input_line_pointer != '"'
3715 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3717 switch (*input_line_pointer)
3719 /* Section Contents */
3720 case 'a': /* unknown */
3721 as_bad (_("Unsupported section attribute -- 'a'"));
3723 case 'c': /* code section */
3726 case 'd': /* section has initialized data */
3729 case 'u': /* section has uninitialized data */
3730 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3734 case 'i': /* section contains directives (info) */
3735 /* FIXME: This is IMAGE_SCN_LNK_INFO
3737 flags |= SEC_HAS_CONTENTS;
3739 case 'n': /* section can be discarded */
3742 case 'R': /* Remove section at link time */
3743 flags |= SEC_NEVER_LOAD;
3746 /* Section Protection */
3747 case 'r': /* section is readable */
3748 flags |= IMAGE_SCN_MEM_READ;
3750 case 'w': /* section is writeable */
3751 flags |= IMAGE_SCN_MEM_WRITE;
3753 case 'x': /* section is executable */
3754 flags |= IMAGE_SCN_MEM_EXECUTE;
3756 case 's': /* section is sharable */
3757 flags |= IMAGE_SCN_MEM_SHARED;
3760 /* Section Alignment */
3761 case '0': /* align to byte boundary */
3762 flags |= IMAGE_SCN_ALIGN_1BYTES;
3765 case '1': /* align to halfword boundary */
3766 flags |= IMAGE_SCN_ALIGN_2BYTES;
3769 case '2': /* align to word boundary */
3770 flags |= IMAGE_SCN_ALIGN_4BYTES;
3773 case '3': /* align to doubleword boundary */
3774 flags |= IMAGE_SCN_ALIGN_8BYTES;
3777 case '4': /* align to quadword boundary */
3778 flags |= IMAGE_SCN_ALIGN_16BYTES;
3781 case '5': /* align to 32 byte boundary */
3782 flags |= IMAGE_SCN_ALIGN_32BYTES;
3785 case '6': /* align to 64 byte boundary */
3786 flags |= IMAGE_SCN_ALIGN_64BYTES;
3791 as_bad(_("unknown section attribute '%c'"),
3792 *input_line_pointer);
3795 ++input_line_pointer;
3797 if (*input_line_pointer == '"')
3798 ++input_line_pointer;
3802 sec = subseg_new (name, (subsegT) exp);
3804 ppc_set_current_section(sec);
3806 if (flags != SEC_NO_FLAGS)
3808 if (! bfd_set_section_flags (stdoutput, sec, flags))
3809 as_bad (_("error setting flags for \"%s\": %s"),
3810 bfd_section_name (stdoutput, sec),
3811 bfd_errmsg (bfd_get_error ()));
3814 bfd_set_section_alignment(stdoutput, sec, align);
3819 ppc_pe_function (ignore)
3826 name = input_line_pointer;
3827 endc = get_symbol_end ();
3829 ext_sym = symbol_find_or_make (name);
3831 *input_line_pointer = endc;
3833 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3834 SF_SET_FUNCTION (ext_sym);
3835 SF_SET_PROCESS (ext_sym);
3836 coff_add_linesym (ext_sym);
3838 demand_empty_rest_of_line ();
3842 ppc_pe_tocd (ignore)
3845 if (tocdata_section == 0)
3847 tocdata_section = subseg_new (".tocd", 0);
3848 /* FIXME: section flags won't work */
3849 bfd_set_section_flags (stdoutput, tocdata_section,
3850 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3851 | SEC_READONLY | SEC_DATA ));
3853 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
3857 rdata_section = subseg_new (".tocd", 0);
3860 ppc_set_current_section(tocdata_section);
3862 demand_empty_rest_of_line ();
3865 /* Don't adjust TOC relocs to use the section symbol. */
3868 ppc_pe_fix_adjustable (fix)
3871 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
3878 /* XCOFF specific symbol and file handling. */
3880 /* Canonicalize the symbol name. We use the to force the suffix, if
3881 any, to use square brackets, and to be in upper case. */
3884 ppc_canonicalize_symbol_name (name)
3889 if (ppc_stab_symbol)
3892 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
3906 for (s++; *s != '\0' && *s != brac; s++)
3910 if (*s == '\0' || s[1] != '\0')
3911 as_bad (_("bad symbol suffix"));
3919 /* Set the class of a symbol based on the suffix, if any. This is
3920 called whenever a new symbol is created. */
3923 ppc_symbol_new_hook (sym)
3926 struct ppc_tc_sy *tc;
3929 tc = symbol_get_tc (sym);
3933 tc->real_name = NULL;
3939 if (ppc_stab_symbol)
3942 s = strchr (S_GET_NAME (sym), '[');
3943 if (s == (const char *) NULL)
3945 /* There is no suffix. */
3954 if (strcmp (s, "BS]") == 0)
3958 if (strcmp (s, "DB]") == 0)
3960 else if (strcmp (s, "DS]") == 0)
3964 if (strcmp (s, "GL]") == 0)
3968 if (strcmp (s, "PR]") == 0)
3972 if (strcmp (s, "RO]") == 0)
3974 else if (strcmp (s, "RW]") == 0)
3978 if (strcmp (s, "SV]") == 0)
3982 if (strcmp (s, "TC]") == 0)
3984 else if (strcmp (s, "TI]") == 0)
3986 else if (strcmp (s, "TB]") == 0)
3988 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
3989 tc->class = XMC_TC0;
3992 if (strcmp (s, "UA]") == 0)
3994 else if (strcmp (s, "UC]") == 0)
3998 if (strcmp (s, "XO]") == 0)
4003 if (tc->class == -1)
4004 as_bad (_("Unrecognized symbol suffix"));
4007 /* Set the class of a label based on where it is defined. This
4008 handles symbols without suffixes. Also, move the symbol so that it
4009 follows the csect symbol. */
4012 ppc_frob_label (sym)
4015 if (ppc_current_csect != (symbolS *) NULL)
4017 if (symbol_get_tc (sym)->class == -1)
4018 symbol_get_tc (sym)->class = symbol_get_tc (ppc_current_csect)->class;
4020 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4021 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
4022 &symbol_rootP, &symbol_lastP);
4023 symbol_get_tc (ppc_current_csect)->within = sym;
4027 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4028 seen. It tells ppc_adjust_symtab whether it needs to look through
4031 static boolean ppc_saw_abs;
4033 /* Change the name of a symbol just before writing it out. Set the
4034 real name if the .rename pseudo-op was used. Otherwise, remove any
4035 class suffix. Return 1 if the symbol should not be included in the
4039 ppc_frob_symbol (sym)
4042 static symbolS *ppc_last_function;
4043 static symbolS *set_end;
4045 /* Discard symbols that should not be included in the output symbol
4047 if (! symbol_used_in_reloc_p (sym)
4048 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
4049 || (! S_IS_EXTERNAL (sym)
4050 && ! symbol_get_tc (sym)->output
4051 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
4054 if (symbol_get_tc (sym)->real_name != (char *) NULL)
4055 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
4061 name = S_GET_NAME (sym);
4062 s = strchr (name, '[');
4063 if (s != (char *) NULL)
4069 snew = xmalloc (len + 1);
4070 memcpy (snew, name, len);
4073 S_SET_NAME (sym, snew);
4077 if (set_end != (symbolS *) NULL)
4079 SA_SET_SYM_ENDNDX (set_end, sym);
4083 if (SF_GET_FUNCTION (sym))
4085 if (ppc_last_function != (symbolS *) NULL)
4086 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4087 ppc_last_function = sym;
4088 if (symbol_get_tc (sym)->size != (symbolS *) NULL)
4090 resolve_symbol_value (symbol_get_tc (sym)->size, 1);
4091 SA_SET_SYM_FSIZE (sym,
4092 (long) S_GET_VALUE (symbol_get_tc (sym)->size));
4095 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4096 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4098 if (ppc_last_function == (symbolS *) NULL)
4099 as_bad (_(".ef with no preceding .function"));
4102 set_end = ppc_last_function;
4103 ppc_last_function = NULL;
4105 /* We don't have a C_EFCN symbol, but we need to force the
4106 COFF backend to believe that it has seen one. */
4107 coff_last_function = NULL;
4111 if (! S_IS_EXTERNAL (sym)
4112 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
4113 && S_GET_STORAGE_CLASS (sym) != C_FILE
4114 && S_GET_STORAGE_CLASS (sym) != C_FCN
4115 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4116 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4117 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4118 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4119 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4120 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4121 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4123 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4124 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4127 union internal_auxent *a;
4129 /* Create a csect aux. */
4130 i = S_GET_NUMBER_AUXILIARY (sym);
4131 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4132 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
4133 if (symbol_get_tc (sym)->class == XMC_TC0)
4135 /* This is the TOC table. */
4136 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4137 a->x_csect.x_scnlen.l = 0;
4138 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4140 else if (symbol_get_tc (sym)->subseg != 0)
4142 /* This is a csect symbol. x_scnlen is the size of the
4144 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
4145 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4146 S_GET_SEGMENT (sym))
4147 - S_GET_VALUE (sym));
4150 resolve_symbol_value (symbol_get_tc (sym)->next, 1);
4151 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
4152 - S_GET_VALUE (sym));
4154 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
4156 else if (S_GET_SEGMENT (sym) == bss_section)
4158 /* This is a common symbol. */
4159 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
4160 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
4161 if (S_IS_EXTERNAL (sym))
4162 symbol_get_tc (sym)->class = XMC_RW;
4164 symbol_get_tc (sym)->class = XMC_BS;
4166 else if (S_GET_SEGMENT (sym) == absolute_section)
4168 /* This is an absolute symbol. The csect will be created by
4169 ppc_adjust_symtab. */
4171 a->x_csect.x_smtyp = XTY_LD;
4172 if (symbol_get_tc (sym)->class == -1)
4173 symbol_get_tc (sym)->class = XMC_XO;
4175 else if (! S_IS_DEFINED (sym))
4177 /* This is an external symbol. */
4178 a->x_csect.x_scnlen.l = 0;
4179 a->x_csect.x_smtyp = XTY_ER;
4181 else if (symbol_get_tc (sym)->class == XMC_TC)
4185 /* This is a TOC definition. x_scnlen is the size of the
4187 next = symbol_next (sym);
4188 while (symbol_get_tc (next)->class == XMC_TC0)
4189 next = symbol_next (next);
4190 if (next == (symbolS *) NULL
4191 || symbol_get_tc (next)->class != XMC_TC)
4193 if (ppc_after_toc_frag == (fragS *) NULL)
4194 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4196 - S_GET_VALUE (sym));
4198 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
4199 - S_GET_VALUE (sym));
4203 resolve_symbol_value (next, 1);
4204 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
4205 - S_GET_VALUE (sym));
4207 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4213 /* This is a normal symbol definition. x_scnlen is the
4214 symbol index of the containing csect. */
4215 if (S_GET_SEGMENT (sym) == text_section)
4216 csect = ppc_text_csects;
4217 else if (S_GET_SEGMENT (sym) == data_section)
4218 csect = ppc_data_csects;
4222 /* Skip the initial dummy symbol. */
4223 csect = symbol_get_tc (csect)->next;
4225 if (csect == (symbolS *) NULL)
4227 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
4228 a->x_csect.x_scnlen.l = 0;
4232 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
4234 resolve_symbol_value (symbol_get_tc (csect)->next, 1);
4235 if (S_GET_VALUE (symbol_get_tc (csect)->next)
4236 > S_GET_VALUE (sym))
4238 csect = symbol_get_tc (csect)->next;
4241 a->x_csect.x_scnlen.p =
4242 coffsymbol (symbol_get_bfdsym (csect))->native;
4243 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
4246 a->x_csect.x_smtyp = XTY_LD;
4249 a->x_csect.x_parmhash = 0;
4250 a->x_csect.x_snhash = 0;
4251 if (symbol_get_tc (sym)->class == -1)
4252 a->x_csect.x_smclas = XMC_PR;
4254 a->x_csect.x_smclas = symbol_get_tc (sym)->class;
4255 a->x_csect.x_stab = 0;
4256 a->x_csect.x_snstab = 0;
4258 /* Don't let the COFF backend resort these symbols. */
4259 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
4261 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4263 /* We want the value to be the symbol index of the referenced
4264 csect symbol. BFD will do that for us if we set the right
4268 coffsymbol (symbol_get_bfdsym
4269 (symbol_get_tc (sym)->within))->native));
4270 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
4272 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4277 /* The value is the offset from the enclosing csect. */
4278 block = symbol_get_tc (sym)->within;
4279 csect = symbol_get_tc (block)->within;
4280 resolve_symbol_value (csect, 1);
4281 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
4283 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
4284 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
4286 /* We want the value to be a file offset into the line numbers.
4287 BFD will do that for us if we set the right flags. We have
4288 already set the value correctly. */
4289 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
4295 /* Adjust the symbol table. This creates csect symbols for all
4296 absolute symbols. */
4299 ppc_adjust_symtab ()
4306 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4310 union internal_auxent *a;
4312 if (S_GET_SEGMENT (sym) != absolute_section)
4315 csect = symbol_create (".abs[XO]", absolute_section,
4316 S_GET_VALUE (sym), &zero_address_frag);
4317 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
4318 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
4319 i = S_GET_NUMBER_AUXILIARY (csect);
4320 S_SET_NUMBER_AUXILIARY (csect, i + 1);
4321 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
4322 a->x_csect.x_scnlen.l = 0;
4323 a->x_csect.x_smtyp = XTY_SD;
4324 a->x_csect.x_parmhash = 0;
4325 a->x_csect.x_snhash = 0;
4326 a->x_csect.x_smclas = XMC_XO;
4327 a->x_csect.x_stab = 0;
4328 a->x_csect.x_snstab = 0;
4330 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
4332 i = S_GET_NUMBER_AUXILIARY (sym);
4333 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
4334 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
4335 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
4338 ppc_saw_abs = false;
4341 /* Set the VMA for a section. This is called on all the sections in
4345 ppc_frob_section (sec)
4348 static bfd_size_type vma = 0;
4350 bfd_set_section_vma (stdoutput, sec, vma);
4351 vma += bfd_section_size (stdoutput, sec);
4354 #endif /* OBJ_XCOFF */
4356 /* Turn a string in input_line_pointer into a floating point constant
4357 of type type, and store the appropriate bytes in *litp. The number
4358 of LITTLENUMS emitted is stored in *sizep . An error message is
4359 returned, or NULL on OK. */
4362 md_atof (type, litp, sizep)
4368 LITTLENUM_TYPE words[4];
4384 return _("bad call to md_atof");
4387 t = atof_ieee (input_line_pointer, type, words);
4389 input_line_pointer = t;
4393 if (target_big_endian)
4395 for (i = 0; i < prec; i++)
4397 md_number_to_chars (litp, (valueT) words[i], 2);
4403 for (i = prec - 1; i >= 0; i--)
4405 md_number_to_chars (litp, (valueT) words[i], 2);
4413 /* Write a value out to the object file, using the appropriate
4417 md_number_to_chars (buf, val, n)
4422 if (target_big_endian)
4423 number_to_chars_bigendian (buf, val, n);
4425 number_to_chars_littleendian (buf, val, n);
4428 /* Align a section (I don't know why this is machine dependent). */
4431 md_section_align (seg, addr)
4435 int align = bfd_get_section_alignment (stdoutput, seg);
4437 return ((addr + (1 << align) - 1) & (-1 << align));
4440 /* We don't have any form of relaxing. */
4443 md_estimate_size_before_relax (fragp, seg)
4451 /* Convert a machine dependent frag. We never generate these. */
4454 md_convert_frag (abfd, sec, fragp)
4462 /* We have no need to default values of symbols. */
4466 md_undefined_symbol (name)
4472 /* Functions concerning relocs. */
4474 /* The location from which a PC relative jump should be calculated,
4475 given a PC relative reloc. */
4478 md_pcrel_from_section (fixp, sec)
4482 return fixp->fx_frag->fr_address + fixp->fx_where;
4487 /* This is called to see whether a fixup should be adjusted to use a
4488 section symbol. We take the opportunity to change a fixup against
4489 a symbol in the TOC subsegment into a reloc against the
4490 corresponding .tc symbol. */
4493 ppc_fix_adjustable (fix)
4498 resolve_symbol_value (fix->fx_addsy, 1);
4499 val = S_GET_VALUE (fix->fx_addsy);
4500 if (ppc_toc_csect != (symbolS *) NULL
4501 && fix->fx_addsy != (symbolS *) NULL
4502 && fix->fx_addsy != ppc_toc_csect
4503 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4504 && val >= ppc_toc_frag->fr_address
4505 && (ppc_after_toc_frag == (fragS *) NULL
4506 || val < ppc_after_toc_frag->fr_address))
4510 for (sy = symbol_next (ppc_toc_csect);
4511 sy != (symbolS *) NULL;
4512 sy = symbol_next (sy))
4514 if (symbol_get_tc (sy)->class == XMC_TC0)
4516 if (symbol_get_tc (sy)->class != XMC_TC)
4518 resolve_symbol_value (sy, 1);
4519 if (val == S_GET_VALUE (sy))
4522 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4527 as_bad_where (fix->fx_file, fix->fx_line,
4528 _("symbol in .toc does not match any .tc"));
4531 /* Possibly adjust the reloc to be against the csect. */
4532 if (fix->fx_addsy != (symbolS *) NULL
4533 && symbol_get_tc (fix->fx_addsy)->subseg == 0
4534 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC0
4535 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC
4536 && S_GET_SEGMENT (fix->fx_addsy) != bss_section
4537 /* Don't adjust if this is a reloc in the toc section. */
4538 && (S_GET_SEGMENT (fix->fx_addsy) != data_section
4539 || ppc_toc_csect == NULL
4540 || val < ppc_toc_frag->fr_address
4541 || (ppc_after_toc_frag != NULL
4542 && val >= ppc_after_toc_frag->fr_address)))
4546 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4547 csect = ppc_text_csects;
4548 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4549 csect = ppc_data_csects;
4553 /* Skip the initial dummy symbol. */
4554 csect = symbol_get_tc (csect)->next;
4556 if (csect != (symbolS *) NULL)
4558 while (symbol_get_tc (csect)->next != (symbolS *) NULL
4559 && (symbol_get_frag (symbol_get_tc (csect)->next)->fr_address
4562 /* If the csect address equals the symbol value, then we
4563 have to look through the full symbol table to see
4564 whether this is the csect we want. Note that we will
4565 only get here if the csect has zero length. */
4566 if ((symbol_get_frag (csect)->fr_address == val)
4567 && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy))
4571 for (scan = symbol_next (csect);
4573 scan = symbol_next (scan))
4575 if (symbol_get_tc (scan)->subseg != 0)
4577 if (scan == fix->fx_addsy)
4581 /* If we found the symbol before the next csect
4582 symbol, then this is the csect we want. */
4583 if (scan == fix->fx_addsy)
4587 csect = symbol_get_tc (csect)->next;
4590 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4591 - symbol_get_frag (csect)->fr_address);
4592 fix->fx_addsy = csect;
4596 /* Adjust a reloc against a .lcomm symbol to be against the base
4598 if (fix->fx_addsy != (symbolS *) NULL
4599 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
4600 && ! S_IS_EXTERNAL (fix->fx_addsy))
4602 resolve_symbol_value (symbol_get_frag (fix->fx_addsy)->fr_symbol, 1);
4604 (S_GET_VALUE (fix->fx_addsy)
4605 - S_GET_VALUE (symbol_get_frag (fix->fx_addsy)->fr_symbol));
4606 fix->fx_addsy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
4612 /* A reloc from one csect to another must be kept. The assembler
4613 will, of course, keep relocs between sections, and it will keep
4614 absolute relocs, but we need to force it to keep PC relative relocs
4615 between two csects in the same section. */
4618 ppc_force_relocation (fix)
4621 /* At this point fix->fx_addsy should already have been converted to
4622 a csect symbol. If the csect does not include the fragment, then
4623 we need to force the relocation. */
4625 && fix->fx_addsy != NULL
4626 && symbol_get_tc (fix->fx_addsy)->subseg != 0
4627 && ((symbol_get_frag (fix->fx_addsy)->fr_address
4628 > fix->fx_frag->fr_address)
4629 || (symbol_get_tc (fix->fx_addsy)->next != NULL
4630 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
4631 <= fix->fx_frag->fr_address))))
4637 #endif /* OBJ_XCOFF */
4639 /* See whether a symbol is in the TOC section. */
4642 ppc_is_toc_sym (sym)
4646 return symbol_get_tc (sym)->class == XMC_TC;
4648 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
4652 /* Apply a fixup to the object code. This is called for all the
4653 fixups we generated by the call to fix_new_exp, above. In the call
4654 above we used a reloc code which was the largest legal reloc code
4655 plus the operand index. Here we undo that to recover the operand
4656 index. At this point all symbol values should be fully resolved,
4657 and we attempt to completely resolve the reloc. If we can not do
4658 that, we determine the correct reloc code and put it back in the
4662 md_apply_fix3 (fixp, valuep, seg)
4671 if (fixp->fx_addsy != NULL)
4673 /* `*valuep' may contain the value of the symbol on which the reloc
4674 will be based; we have to remove it. */
4675 if (symbol_used_in_reloc_p (fixp->fx_addsy)
4676 && S_GET_SEGMENT (fixp->fx_addsy) != absolute_section
4677 && S_GET_SEGMENT (fixp->fx_addsy) != undefined_section
4678 && ! bfd_is_com_section (S_GET_SEGMENT (fixp->fx_addsy)))
4679 value -= S_GET_VALUE (fixp->fx_addsy);
4681 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4682 supposed to be? I think this is related to various similar
4683 FIXMEs in tc-i386.c and tc-sparc.c. */
4685 value += fixp->fx_frag->fr_address + fixp->fx_where;
4692 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4693 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4694 doing this relocation the code in write.c is going to call
4695 bfd_install_relocation, which is also going to use the symbol
4696 value. That means that if the reloc is fully resolved we want to
4697 use *valuep since bfd_install_relocation is not being used.
4698 However, if the reloc is not fully resolved we do not want to use
4699 *valuep, and must use fx_offset instead. However, if the reloc
4700 is PC relative, we do want to use *valuep since it includes the
4701 result of md_pcrel_from. This is confusing. */
4702 if (fixp->fx_addsy == (symbolS *) NULL)
4707 else if (fixp->fx_pcrel)
4711 value = fixp->fx_offset;
4712 if (fixp->fx_subsy != (symbolS *) NULL)
4714 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
4715 value -= S_GET_VALUE (fixp->fx_subsy);
4718 /* We can't actually support subtracting a symbol. */
4719 as_bad_where (fixp->fx_file, fixp->fx_line,
4720 _("expression too complex"));
4726 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
4729 const struct powerpc_operand *operand;
4733 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
4735 operand = &powerpc_operands[opindex];
4738 /* It appears that an instruction like
4740 when LC..1 is not a TOC symbol does not generate a reloc. It
4741 uses the offset of LC..1 within its csect. However, .long
4742 LC..1 will generate a reloc. I can't find any documentation
4743 on how these cases are to be distinguished, so this is a wild
4744 guess. These cases are generated by gcc -mminimal-toc. */
4745 if ((operand->flags & PPC_OPERAND_PARENS) != 0
4746 && operand->bits == 16
4747 && operand->shift == 0
4748 && operand->insert == NULL
4749 && fixp->fx_addsy != NULL
4750 && symbol_get_tc (fixp->fx_addsy)->subseg != 0
4751 && symbol_get_tc (fixp->fx_addsy)->class != XMC_TC
4752 && symbol_get_tc (fixp->fx_addsy)->class != XMC_TC0
4753 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
4755 value = fixp->fx_offset;
4760 /* Fetch the instruction, insert the fully resolved operand
4761 value, and stuff the instruction back again. */
4762 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4763 if (target_big_endian)
4764 insn = bfd_getb32 ((unsigned char *) where);
4766 insn = bfd_getl32 ((unsigned char *) where);
4767 insn = ppc_insert_operand (insn, operand, (offsetT) value,
4768 fixp->fx_file, fixp->fx_line);
4769 if (target_big_endian)
4770 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4772 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4776 /* Nothing else to do here. */
4780 /* Determine a BFD reloc value based on the operand information.
4781 We are only prepared to turn a few of the operands into
4783 FIXME: We need to handle the DS field at the very least.
4784 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4785 there should be a new field in the operand table. */
4786 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4787 && operand->bits == 26
4788 && operand->shift == 0)
4789 fixp->fx_r_type = BFD_RELOC_PPC_B26;
4790 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4791 && operand->bits == 16
4792 && operand->shift == 0)
4793 fixp->fx_r_type = BFD_RELOC_PPC_B16;
4794 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4795 && operand->bits == 26
4796 && operand->shift == 0)
4797 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4798 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4799 && operand->bits == 16
4800 && operand->shift == 0)
4801 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4802 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4803 && operand->bits == 16
4804 && operand->shift == 0
4805 && operand->insert == NULL
4806 && fixp->fx_addsy != NULL
4807 && ppc_is_toc_sym (fixp->fx_addsy))
4810 if (target_big_endian)
4811 fixp->fx_where += 2;
4812 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4819 /* Use expr_symbol_where to see if this is an expression
4821 if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline))
4822 as_bad_where (fixp->fx_file, fixp->fx_line,
4823 _("unresolved expression that must be resolved"));
4825 as_bad_where (fixp->fx_file, fixp->fx_line,
4826 _("unsupported relocation type"));
4834 ppc_elf_validate_fix (fixp, seg);
4836 switch (fixp->fx_r_type)
4839 case BFD_RELOC_CTOR:
4841 fixp->fx_r_type = BFD_RELOC_32_PCREL;
4845 case BFD_RELOC_32_PCREL:
4846 case BFD_RELOC_32_BASEREL:
4847 case BFD_RELOC_PPC_EMB_NADDR32:
4848 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4852 case BFD_RELOC_LO16:
4854 case BFD_RELOC_GPREL16:
4855 case BFD_RELOC_16_GOT_PCREL:
4856 case BFD_RELOC_16_GOTOFF:
4857 case BFD_RELOC_LO16_GOTOFF:
4858 case BFD_RELOC_HI16_GOTOFF:
4859 case BFD_RELOC_HI16_S_GOTOFF:
4860 case BFD_RELOC_LO16_BASEREL:
4861 case BFD_RELOC_HI16_BASEREL:
4862 case BFD_RELOC_HI16_S_BASEREL:
4863 case BFD_RELOC_PPC_EMB_NADDR16:
4864 case BFD_RELOC_PPC_EMB_NADDR16_LO:
4865 case BFD_RELOC_PPC_EMB_NADDR16_HI:
4866 case BFD_RELOC_PPC_EMB_NADDR16_HA:
4867 case BFD_RELOC_PPC_EMB_SDAI16:
4868 case BFD_RELOC_PPC_EMB_SDA2REL:
4869 case BFD_RELOC_PPC_EMB_SDA2I16:
4870 case BFD_RELOC_PPC_EMB_RELSEC16:
4871 case BFD_RELOC_PPC_EMB_RELST_LO:
4872 case BFD_RELOC_PPC_EMB_RELST_HI:
4873 case BFD_RELOC_PPC_EMB_RELST_HA:
4874 case BFD_RELOC_PPC_EMB_RELSDA:
4875 case BFD_RELOC_PPC_TOC16:
4878 if (fixp->fx_addsy != NULL)
4879 as_bad_where (fixp->fx_file, fixp->fx_line,
4880 _("cannot emit PC relative %s relocation against %s"),
4881 bfd_get_reloc_code_name (fixp->fx_r_type),
4882 S_GET_NAME (fixp->fx_addsy));
4884 as_bad_where (fixp->fx_file, fixp->fx_line,
4885 _("cannot emit PC relative %s relocation"),
4886 bfd_get_reloc_code_name (fixp->fx_r_type));
4889 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4893 /* This case happens when you write, for example,
4895 where L1 and L2 are defined later. */
4896 case BFD_RELOC_HI16:
4899 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4902 case BFD_RELOC_HI16_S:
4905 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4906 (value + 0x8000) >> 16, 2);
4909 /* Because SDA21 modifies the register field, the size is set to 4
4910 bytes, rather than 2, so offset it here appropriately */
4911 case BFD_RELOC_PPC_EMB_SDA21:
4915 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where
4916 + ((target_big_endian) ? 2 : 0),
4924 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4928 case BFD_RELOC_24_PLT_PCREL:
4929 case BFD_RELOC_PPC_LOCAL24PC:
4930 if (!fixp->fx_pcrel && !fixp->fx_done)
4938 /* Fetch the instruction, insert the fully resolved operand
4939 value, and stuff the instruction back again. */
4940 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4941 if (target_big_endian)
4942 insn = bfd_getb32 ((unsigned char *) where);
4944 insn = bfd_getl32 ((unsigned char *) where);
4945 if ((value & 3) != 0)
4946 as_bad_where (fixp->fx_file, fixp->fx_line,
4947 _("must branch to an address a multiple of 4"));
4948 if ((offsetT) value < -0x40000000
4949 || (offsetT) value >= 0x40000000)
4950 as_bad_where (fixp->fx_file, fixp->fx_line,
4951 _("@local or @plt branch destination is too far away, %ld bytes"),
4953 insn = insn | (value & 0x03fffffc);
4954 if (target_big_endian)
4955 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4957 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4961 case BFD_RELOC_VTABLE_INHERIT:
4964 && !S_IS_DEFINED (fixp->fx_addsy)
4965 && !S_IS_WEAK (fixp->fx_addsy))
4966 S_SET_WEAK (fixp->fx_addsy);
4969 case BFD_RELOC_VTABLE_ENTRY:
4975 _("Gas failure, reloc value %d\n"), fixp->fx_r_type);
4982 fixp->fx_addnumber = value;
4984 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
4985 fixp->fx_addnumber = 0;
4989 fixp->fx_addnumber = 0;
4991 /* We want to use the offset within the data segment of the
4992 symbol, not the actual VMA of the symbol. */
4993 fixp->fx_addnumber =
4994 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
5002 /* Generate a reloc for a fixup. */
5005 tc_gen_reloc (seg, fixp)
5011 reloc = (arelent *) xmalloc (sizeof (arelent));
5013 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
5014 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
5015 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
5016 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
5017 if (reloc->howto == (reloc_howto_type *) NULL)
5019 as_bad_where (fixp->fx_file, fixp->fx_line,
5020 _("reloc %d not supported by object file format"), (int)fixp->fx_r_type);
5023 reloc->addend = fixp->fx_addnumber;