1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/ppc.h"
37 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
39 /* Tell the main code what the endianness is. */
40 extern int target_big_endian
;
42 /* Whether or not, we've set target_big_endian. */
43 static int set_target_endian
= 0;
45 /* Whether to use user friendly register names. */
46 #ifndef TARGET_REG_NAMES_P
48 #define TARGET_REG_NAMES_P true
50 #define TARGET_REG_NAMES_P false
54 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
56 static void ppc_set_cpu
PARAMS ((void));
57 static unsigned long ppc_insert_operand
58 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
59 offsetT val
, char *file
, unsigned int line
));
60 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
61 static void ppc_byte
PARAMS ((int));
62 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
63 static void ppc_tc
PARAMS ((int));
66 static void ppc_comm
PARAMS ((int));
67 static void ppc_bb
PARAMS ((int));
68 static void ppc_bc
PARAMS ((int));
69 static void ppc_bf
PARAMS ((int));
70 static void ppc_biei
PARAMS ((int));
71 static void ppc_bs
PARAMS ((int));
72 static void ppc_eb
PARAMS ((int));
73 static void ppc_ec
PARAMS ((int));
74 static void ppc_ef
PARAMS ((int));
75 static void ppc_es
PARAMS ((int));
76 static void ppc_csect
PARAMS ((int));
77 static void ppc_change_csect
PARAMS ((symbolS
*));
78 static void ppc_function
PARAMS ((int));
79 static void ppc_extern
PARAMS ((int));
80 static void ppc_lglobl
PARAMS ((int));
81 static void ppc_section
PARAMS ((int));
82 static void ppc_stabx
PARAMS ((int));
83 static void ppc_rename
PARAMS ((int));
84 static void ppc_toc
PARAMS ((int));
88 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
89 static void ppc_elf_cons
PARAMS ((int));
90 static void ppc_elf_rdata
PARAMS ((int));
91 static void ppc_elf_lcomm
PARAMS ((int));
92 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
96 static void ppc_set_current_section
PARAMS ((segT
));
97 static void ppc_previous
PARAMS ((int));
98 static void ppc_pdata
PARAMS ((int));
99 static void ppc_ydata
PARAMS ((int));
100 static void ppc_reldata
PARAMS ((int));
101 static void ppc_rdata
PARAMS ((int));
102 static void ppc_ualong
PARAMS ((int));
103 static void ppc_znop
PARAMS ((int));
104 static void ppc_pe_comm
PARAMS ((int));
105 static void ppc_pe_section
PARAMS ((int));
106 static void ppc_pe_function
PARAMS ((int));
107 static void ppc_pe_tocd
PARAMS ((int));
110 /* Generic assembler global variables which must be defined by all
113 /* This string holds the chars that always start a comment. If the
114 pre-processor is disabled, these aren't very useful. The macro
115 tc_comment_chars points to this. We use this, rather than the
116 usual comment_chars, so that we can switch for Solaris conventions. */
117 static const char ppc_solaris_comment_chars
[] = "#!";
118 static const char ppc_eabi_comment_chars
[] = "#";
120 #ifdef TARGET_SOLARIS_COMMENT
121 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
123 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
126 /* Characters which start a comment at the beginning of a line. */
127 const char line_comment_chars
[] = "#";
129 /* Characters which may be used to separate multiple commands on a
131 const char line_separator_chars
[] = ";";
133 /* Characters which are used to indicate an exponent in a floating
135 const char EXP_CHARS
[] = "eE";
137 /* Characters which mean that a number is a floating point constant,
139 const char FLT_CHARS
[] = "dD";
141 /* The target specific pseudo-ops which we support. */
143 const pseudo_typeS md_pseudo_table
[] =
145 /* Pseudo-ops which must be overridden. */
146 { "byte", ppc_byte
, 0 },
149 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
150 legitimately belong in the obj-*.c file. However, XCOFF is based
151 on COFF, and is only implemented for the RS/6000. We just use
152 obj-coff.c, and add what we need here. */
153 { "comm", ppc_comm
, 0 },
154 { "lcomm", ppc_comm
, 1 },
158 { "bi", ppc_biei
, 0 },
160 { "csect", ppc_csect
, 0 },
161 { "data", ppc_section
, 'd' },
165 { "ei", ppc_biei
, 1 },
167 { "extern", ppc_extern
, 0 },
168 { "function", ppc_function
, 0 },
169 { "lglobl", ppc_lglobl
, 0 },
170 { "rename", ppc_rename
, 0 },
171 { "stabx", ppc_stabx
, 0 },
172 { "text", ppc_section
, 't' },
173 { "toc", ppc_toc
, 0 },
177 { "long", ppc_elf_cons
, 4 },
178 { "word", ppc_elf_cons
, 2 },
179 { "short", ppc_elf_cons
, 2 },
180 { "rdata", ppc_elf_rdata
, 0 },
181 { "rodata", ppc_elf_rdata
, 0 },
182 { "lcomm", ppc_elf_lcomm
, 0 },
186 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
187 { "previous", ppc_previous
, 0 },
188 { "pdata", ppc_pdata
, 0 },
189 { "ydata", ppc_ydata
, 0 },
190 { "reldata", ppc_reldata
, 0 },
191 { "rdata", ppc_rdata
, 0 },
192 { "ualong", ppc_ualong
, 0 },
193 { "znop", ppc_znop
, 0 },
194 { "comm", ppc_pe_comm
, 0 },
195 { "lcomm", ppc_pe_comm
, 1 },
196 { "section", ppc_pe_section
, 0 },
197 { "function", ppc_pe_function
,0 },
198 { "tocd", ppc_pe_tocd
, 0 },
201 /* This pseudo-op is used even when not generating XCOFF output. */
208 /* Predefined register names if -mregnames (or default for Windows NT). */
209 /* In general, there are lots of them, in an attempt to be compatible */
210 /* with a number of other Windows NT assemblers. */
212 /* Structure to hold information about predefined registers. */
219 /* List of registers that are pre-defined:
221 Each general register has predefined names of the form:
222 1. r<reg_num> which has the value <reg_num>.
223 2. r.<reg_num> which has the value <reg_num>.
226 Each floating point register has predefined names of the form:
227 1. f<reg_num> which has the value <reg_num>.
228 2. f.<reg_num> which has the value <reg_num>.
230 Each condition register has predefined names of the form:
231 1. cr<reg_num> which has the value <reg_num>.
232 2. cr.<reg_num> which has the value <reg_num>.
234 There are individual registers as well:
235 sp or r.sp has the value 1
236 rtoc or r.toc has the value 2
237 fpscr has the value 0
243 dsisr has the value 18
245 sdr1 has the value 25
246 srr0 has the value 26
247 srr1 has the value 27
249 The table is sorted. Suitable for searching by a binary search. */
251 static const struct pd_reg pre_defined_registers
[] =
253 { "cr.0", 0 }, /* Condition Registers */
273 { "dar", 19 }, /* Data Access Register */
274 { "dec", 22 }, /* Decrementer */
275 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
277 { "f.0", 0 }, /* Floating point registers */
345 { "lr", 8 }, /* Link Register */
349 { "r.0", 0 }, /* General Purpose Registers */
382 { "r.sp", 1 }, /* Stack Pointer */
384 { "r.toc", 2 }, /* Pointer to the table of contents */
386 { "r0", 0 }, /* More general purpose registers */
419 { "rtoc", 2 }, /* Table of contents */
421 { "sdr1", 25 }, /* Storage Description Register 1 */
425 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
426 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
432 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
434 /* Given NAME, find the register number associated with that name, return
435 the integer value associated with the given name or -1 on failure. */
437 static int reg_name_search
438 PARAMS ((const struct pd_reg
*, int, const char * name
));
441 reg_name_search (regs
, regcount
, name
)
442 const struct pd_reg
*regs
;
446 int middle
, low
, high
;
454 middle
= (low
+ high
) / 2;
455 cmp
= strcasecmp (name
, regs
[middle
].name
);
461 return regs
[middle
].value
;
469 * Summary of register_name().
471 * in: Input_line_pointer points to 1st char of operand.
473 * out: A expressionS.
474 * The operand may have been a register: in this case, X_op == O_register,
475 * X_add_number is set to the register number, and truth is returned.
476 * Input_line_pointer->(next non-blank) char after operand, or is in its
481 register_name (expressionP
)
482 expressionS
*expressionP
;
489 /* Find the spelling of the operand */
490 start
= name
= input_line_pointer
;
491 if (name
[0] == '%' && isalpha (name
[1]))
492 name
= ++input_line_pointer
;
494 else if (!reg_names_p
|| !isalpha (name
[0]))
497 c
= get_symbol_end ();
498 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
500 /* look to see if it's in the register table */
503 expressionP
->X_op
= O_register
;
504 expressionP
->X_add_number
= reg_number
;
506 /* make the rest nice */
507 expressionP
->X_add_symbol
= NULL
;
508 expressionP
->X_op_symbol
= NULL
;
509 *input_line_pointer
= c
; /* put back the delimiting char */
514 /* reset the line as if we had not done anything */
515 *input_line_pointer
= c
; /* put back the delimiting char */
516 input_line_pointer
= start
; /* reset input_line pointer */
521 /* This function is called for each symbol seen in an expression. It
522 handles the special parsing which PowerPC assemblers are supposed
523 to use for condition codes. */
525 /* Whether to do the special parsing. */
526 static boolean cr_operand
;
528 /* Names to recognize in a condition code. This table is sorted. */
529 static const struct pd_reg cr_names
[] =
546 /* Parsing function. This returns non-zero if it recognized an
550 ppc_parse_name (name
, expr
)
559 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
564 expr
->X_op
= O_constant
;
565 expr
->X_add_number
= val
;
570 /* Local variables. */
572 /* The type of processor we are assembling for. This is one or more
573 of the PPC_OPCODE flags defined in opcode/ppc.h. */
574 static int ppc_cpu
= 0;
576 /* The size of the processor we are assembling for. This is either
577 PPC_OPCODE_32 or PPC_OPCODE_64. */
578 static int ppc_size
= PPC_OPCODE_32
;
580 /* Opcode hash table. */
581 static struct hash_control
*ppc_hash
;
583 /* Macro hash table. */
584 static struct hash_control
*ppc_macro_hash
;
587 /* What type of shared library support to use */
588 static enum { SHLIB_NONE
, SHLIB_PIC
, SHILB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
590 /* Flags to set in the elf header */
591 static flagword ppc_flags
= 0;
593 /* Whether this is Solaris or not. */
594 #ifdef TARGET_SOLARIS_COMMENT
595 #define SOLARIS_P true
597 #define SOLARIS_P false
600 static boolean msolaris
= SOLARIS_P
;
605 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
606 using a bunch of different sections. These assembler sections,
607 however, are all encompassed within the .text or .data sections of
608 the final output file. We handle this by using different
609 subsegments within these main segments. */
611 /* Next subsegment to allocate within the .text segment. */
612 static subsegT ppc_text_subsegment
= 2;
614 /* Linked list of csects in the text section. */
615 static symbolS
*ppc_text_csects
;
617 /* Next subsegment to allocate within the .data segment. */
618 static subsegT ppc_data_subsegment
= 2;
620 /* Linked list of csects in the data section. */
621 static symbolS
*ppc_data_csects
;
623 /* The current csect. */
624 static symbolS
*ppc_current_csect
;
626 /* The RS/6000 assembler uses a TOC which holds addresses of functions
627 and variables. Symbols are put in the TOC with the .tc pseudo-op.
628 A special relocation is used when accessing TOC entries. We handle
629 the TOC as a subsegment within the .data segment. We set it up if
630 we see a .toc pseudo-op, and save the csect symbol here. */
631 static symbolS
*ppc_toc_csect
;
633 /* The first frag in the TOC subsegment. */
634 static fragS
*ppc_toc_frag
;
636 /* The first frag in the first subsegment after the TOC in the .data
637 segment. NULL if there are no subsegments after the TOC. */
638 static fragS
*ppc_after_toc_frag
;
640 /* The current static block. */
641 static symbolS
*ppc_current_block
;
643 /* The COFF debugging section; set by md_begin. This is not the
644 .debug section, but is instead the secret BFD section which will
645 cause BFD to set the section number of a symbol to N_DEBUG. */
646 static asection
*ppc_coff_debug_section
;
648 #endif /* OBJ_XCOFF */
652 /* Various sections that we need for PE coff support. */
653 static segT ydata_section
;
654 static segT pdata_section
;
655 static segT reldata_section
;
656 static segT rdata_section
;
657 static segT tocdata_section
;
659 /* The current section and the previous section. See ppc_previous. */
660 static segT ppc_previous_section
;
661 static segT ppc_current_section
;
666 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
669 #ifndef WORKING_DOT_WORD
670 const int md_short_jump_size
= 4;
671 const int md_long_jump_size
= 4;
675 CONST
char *md_shortopts
= "b:l:usm:K:VQ:";
677 CONST
char *md_shortopts
= "um:";
679 struct option md_longopts
[] = {
680 {NULL
, no_argument
, NULL
, 0}
682 size_t md_longopts_size
= sizeof(md_longopts
);
685 md_parse_option (c
, arg
)
692 /* -u means that any undefined symbols should be treated as
693 external, which is the default for gas anyhow. */
698 /* Solaris as takes -le (presumably for little endian). For completeness
699 sake, recognize -be also. */
700 if (strcmp (arg
, "e") == 0)
702 target_big_endian
= 0;
703 set_target_endian
= 1;
711 if (strcmp (arg
, "e") == 0)
713 target_big_endian
= 1;
714 set_target_endian
= 1;
722 /* Recognize -K PIC */
723 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
726 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
735 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
737 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
738 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
739 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
740 else if (strcmp (arg
, "pwr") == 0)
741 ppc_cpu
= PPC_OPCODE_POWER
;
742 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
743 instructions that are holdovers from the Power. */
744 else if (strcmp (arg
, "601") == 0)
745 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
746 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
747 Motorola PowerPC 603/604. */
748 else if (strcmp (arg
, "ppc") == 0
749 || strcmp (arg
, "ppc32") == 0
750 || strcmp (arg
, "403") == 0
751 || strcmp (arg
, "603") == 0
752 || strcmp (arg
, "604") == 0)
753 ppc_cpu
= PPC_OPCODE_PPC
;
754 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
756 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
758 ppc_cpu
= PPC_OPCODE_PPC
;
759 ppc_size
= PPC_OPCODE_64
;
761 /* -mcom means assemble for the common intersection between Power
762 and PowerPC. At present, we just allow the union, rather
763 than the intersection. */
764 else if (strcmp (arg
, "com") == 0)
765 ppc_cpu
= PPC_OPCODE_COMMON
;
766 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
767 else if (strcmp (arg
, "any") == 0)
768 ppc_cpu
= PPC_OPCODE_ANY
;
770 else if (strcmp (arg
, "regnames") == 0)
773 else if (strcmp (arg
, "no-regnames") == 0)
777 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
778 else if (strcmp (arg
, "relocatable") == 0)
780 shlib
= SHILB_MRELOCATABLE
;
781 ppc_flags
|= EF_PPC_RELOCATABLE
;
784 else if (strcmp (arg
, "relocatable-lib") == 0)
786 shlib
= SHILB_MRELOCATABLE
;
787 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
790 /* -memb, set embedded bit */
791 else if (strcmp (arg
, "emb") == 0)
792 ppc_flags
|= EF_PPC_EMB
;
794 /* -mlittle/-mbig set the endianess */
795 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
797 target_big_endian
= 0;
798 set_target_endian
= 1;
801 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
803 target_big_endian
= 1;
804 set_target_endian
= 1;
807 else if (strcmp (arg
, "solaris") == 0)
810 ppc_comment_chars
= ppc_solaris_comment_chars
;
813 else if (strcmp (arg
, "no-solaris") == 0)
816 ppc_comment_chars
= ppc_eabi_comment_chars
;
821 as_bad ("invalid switch -m%s", arg
);
827 /* -V: SVR4 argument to print version ID. */
832 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
833 should be emitted or not. FIXME: Not implemented. */
837 /* Solaris takes -s to specify that .stabs go in a .stabs section,
838 rather than .stabs.excl, which is ignored by the linker.
839 FIXME: Not implemented. */
855 md_show_usage (stream
)
861 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
862 -mpwr generate code for IBM POWER (RIOS1)\n\
863 -m601 generate code for Motorola PowerPC 601\n\
864 -mppc, -mppc32, -m403, -m603, -m604\n\
865 generate code for Motorola PowerPC 603/604\n\
866 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
867 -mcom generate code Power/PowerPC common instructions\n\
868 -many generate code for any architecture (PWR/PWRX/PPC)\n\
869 -mregnames Allow symbolic names for registers\n\
870 -mno-regnames Do not allow symbolic names for registers\n");
873 -mrelocatable support for GCC's -mrelocatble option\n\
874 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
875 -memb set PPC_EMB bit in ELF flags\n\
876 -mlittle, -mlittle-endian\n\
877 generate code for a little endian machine\n\
878 -mbig, -mbig-endian generate code for a big endian machine\n\
879 -msolaris generate code for Solaris\n\
880 -mno-solaris do not generate code for Solaris\n\
881 -V print assembler version number\n\
882 -Qy, -Qn ignored\n");
886 /* Set ppc_cpu if it is not already set. */
891 const char *default_os
= TARGET_OS
;
892 const char *default_cpu
= TARGET_CPU
;
896 if (strncmp (default_os
, "aix", 3) == 0
897 && default_os
[3] >= '4' && default_os
[3] <= '9')
898 ppc_cpu
= PPC_OPCODE_COMMON
;
899 else if (strncmp (default_os
, "aix3", 4) == 0)
900 ppc_cpu
= PPC_OPCODE_POWER
;
901 else if (strcmp (default_cpu
, "rs6000") == 0)
902 ppc_cpu
= PPC_OPCODE_POWER
;
903 else if (strcmp (default_cpu
, "powerpc") == 0
904 || strcmp (default_cpu
, "powerpcle") == 0)
905 ppc_cpu
= PPC_OPCODE_PPC
;
907 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu
, default_os
);
911 /* Figure out the BFD architecture to use. */
913 enum bfd_architecture
916 const char *default_cpu
= TARGET_CPU
;
919 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
920 return bfd_arch_powerpc
;
921 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
922 return bfd_arch_rs6000
;
923 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
925 if (strcmp (default_cpu
, "rs6000") == 0)
926 return bfd_arch_rs6000
;
927 else if (strcmp (default_cpu
, "powerpc") == 0
928 || strcmp (default_cpu
, "powerpcle") == 0)
929 return bfd_arch_powerpc
;
932 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
933 return bfd_arch_unknown
;
936 /* This function is called when the assembler starts up. It is called
937 after the options have been parsed and the output file has been
943 register const struct powerpc_opcode
*op
;
944 const struct powerpc_opcode
*op_end
;
945 const struct powerpc_macro
*macro
;
946 const struct powerpc_macro
*macro_end
;
947 boolean dup_insn
= false;
952 /* Set the ELF flags if desired. */
953 if (ppc_flags
&& !msolaris
)
954 bfd_set_private_flags (stdoutput
, ppc_flags
);
957 /* Insert the opcodes into a hash table. */
958 ppc_hash
= hash_new ();
960 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
961 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
963 know ((op
->opcode
& op
->mask
) == op
->opcode
);
965 if ((op
->flags
& ppc_cpu
) != 0
966 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
967 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
971 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
972 if (retval
!= (const char *) NULL
)
974 /* Ignore Power duplicates for -m601 */
975 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
976 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
979 as_bad ("Internal assembler error for instruction %s", op
->name
);
985 /* Insert the macros into a hash table. */
986 ppc_macro_hash
= hash_new ();
988 macro_end
= powerpc_macros
+ powerpc_num_macros
;
989 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
991 if ((macro
->flags
& ppc_cpu
) != 0)
995 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
996 if (retval
!= (const char *) NULL
)
998 as_bad ("Internal assembler error for macro %s", macro
->name
);
1007 /* Tell the main code what the endianness is if it is not overidden by the user. */
1008 if (!set_target_endian
)
1010 set_target_endian
= 1;
1011 target_big_endian
= PPC_BIG_ENDIAN
;
1015 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1017 /* Create dummy symbols to serve as initial csects. This forces the
1018 text csects to precede the data csects. These symbols will not
1020 ppc_text_csects
= symbol_make ("dummy\001");
1021 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
1022 ppc_data_csects
= symbol_make ("dummy\001");
1023 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
1028 ppc_current_section
= text_section
;
1029 ppc_previous_section
= 0;
1034 /* Insert an operand value into an instruction. */
1036 static unsigned long
1037 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1039 const struct powerpc_operand
*operand
;
1044 if (operand
->bits
!= 32)
1049 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1051 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
1052 && ppc_size
== PPC_OPCODE_32
)
1053 max
= (1 << operand
->bits
) - 1;
1055 max
= (1 << (operand
->bits
- 1)) - 1;
1056 min
= - (1 << (operand
->bits
- 1));
1060 max
= (1 << operand
->bits
) - 1;
1064 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1069 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1072 "operand out of range (%s not between %ld and %ld)";
1075 sprint_value (buf
, test
);
1076 if (file
== (char *) NULL
)
1077 as_bad (err
, buf
, min
, max
);
1079 as_bad_where (file
, line
, err
, buf
, min
, max
);
1083 if (operand
->insert
)
1088 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1089 if (errmsg
!= (const char *) NULL
)
1093 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1101 /* Parse @got, etc. and return the desired relocation. */
1102 static bfd_reloc_code_real_type
1103 ppc_elf_suffix (str_p
, exp_p
)
1110 bfd_reloc_code_real_type reloc
;
1118 struct map_bfd
*ptr
;
1120 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1122 static struct map_bfd mapping
[] = {
1123 MAP ("l", BFD_RELOC_LO16
),
1124 MAP ("h", BFD_RELOC_HI16
),
1125 MAP ("ha", BFD_RELOC_HI16_S
),
1126 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1127 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1128 MAP ("got", BFD_RELOC_16_GOTOFF
),
1129 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1130 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1131 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1132 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1133 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1134 MAP ("copy", BFD_RELOC_PPC_COPY
),
1135 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1136 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1137 MAP ("local", BFD_RELOC_PPC_LOCAL24PC
),
1138 MAP ("plt", BFD_RELOC_32_PLTOFF
),
1139 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1140 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1141 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1142 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1143 MAP ("sdarel", BFD_RELOC_GPREL16
),
1144 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1145 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1146 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1147 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1148 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1149 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1150 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1151 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1152 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1153 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1154 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1155 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1156 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1157 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1158 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1159 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1160 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1161 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1162 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1163 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1164 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1166 { (char *)0, 0, BFD_RELOC_UNUSED
}
1170 return BFD_RELOC_UNUSED
;
1172 for (ch
= *str
, str2
= ident
;
1173 (str2
< ident
+ sizeof (ident
) - 1
1174 && (isalnum (ch
) || ch
== '@'));
1177 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1184 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1185 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1187 /* Now check for identifier@suffix+constant */
1188 if (*str
== '-' || *str
== '+')
1190 char *orig_line
= input_line_pointer
;
1191 expressionS new_exp
;
1193 input_line_pointer
= str
;
1194 expression (&new_exp
);
1195 if (new_exp
.X_op
== O_constant
)
1197 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1198 str
= input_line_pointer
;
1201 if (&input_line_pointer
!= str_p
)
1202 input_line_pointer
= orig_line
;
1209 return BFD_RELOC_UNUSED
;
1212 /* Like normal .long/.short/.word, except support @got, etc. */
1213 /* clobbers input_line_pointer, checks */
1216 ppc_elf_cons (nbytes
)
1217 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1220 bfd_reloc_code_real_type reloc
;
1222 if (is_it_end_of_statement ())
1224 demand_empty_rest_of_line ();
1231 if (exp
.X_op
== O_symbol
1232 && *input_line_pointer
== '@'
1233 && (reloc
= ppc_elf_suffix (&input_line_pointer
, &exp
)) != BFD_RELOC_UNUSED
)
1235 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1236 int size
= bfd_get_reloc_size (reloc_howto
);
1239 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
1243 register char *p
= frag_more ((int) nbytes
);
1244 int offset
= nbytes
- size
;
1246 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1250 emit_expr (&exp
, (unsigned int) nbytes
);
1252 while (*input_line_pointer
++ == ',');
1254 input_line_pointer
--; /* Put terminator back into stream. */
1255 demand_empty_rest_of_line ();
1258 /* Solaris pseduo op to change to the .rodata section. */
1263 char *save_line
= input_line_pointer
;
1264 static char section
[] = ".rodata\n";
1266 /* Just pretend this is .section .rodata */
1267 input_line_pointer
= section
;
1268 obj_elf_section (xxx
);
1270 input_line_pointer
= save_line
;
1273 /* Pseudo op to make file scope bss items */
1278 register char *name
;
1282 register symbolS
*symbolP
;
1289 name
= input_line_pointer
;
1290 c
= get_symbol_end ();
1292 /* just after name is now '\0' */
1293 p
= input_line_pointer
;
1296 if (*input_line_pointer
!= ',')
1298 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1299 ignore_rest_of_line ();
1303 input_line_pointer
++; /* skip ',' */
1304 if ((size
= get_absolute_expression ()) < 0)
1306 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size
);
1307 ignore_rest_of_line ();
1311 /* The third argument to .lcomm is the alignment. */
1312 if (*input_line_pointer
!= ',')
1316 ++input_line_pointer
;
1317 align
= get_absolute_expression ();
1320 as_warn ("ignoring bad alignment");
1326 symbolP
= symbol_find_or_make (name
);
1329 if (S_IS_DEFINED (symbolP
))
1331 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1332 S_GET_NAME (symbolP
));
1333 ignore_rest_of_line ();
1337 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1339 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1340 S_GET_NAME (symbolP
),
1341 (long) S_GET_VALUE (symbolP
),
1344 ignore_rest_of_line ();
1350 old_subsec
= now_subseg
;
1353 /* convert to a power of 2 alignment */
1354 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1357 as_bad ("Common alignment not a power of 2");
1358 ignore_rest_of_line ();
1365 record_alignment (bss_section
, align2
);
1366 subseg_set (bss_section
, 0);
1368 frag_align (align2
, 0);
1369 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1370 symbolP
->sy_frag
->fr_symbol
= 0;
1371 symbolP
->sy_frag
= frag_now
;
1372 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1375 S_SET_SIZE (symbolP
, size
);
1376 S_SET_SEGMENT (symbolP
, bss_section
);
1377 S_CLEAR_EXTERNAL (symbolP
);
1378 subseg_set (old_sec
, old_subsec
);
1379 demand_empty_rest_of_line ();
1382 /* Validate any relocations emitted for -mrelocatable, possibly adding
1383 fixups for word relocations in writable segments, so we can adjust
1386 ppc_elf_validate_fix (fixp
, seg
)
1390 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1399 case SHILB_MRELOCATABLE
:
1400 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1401 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1402 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1403 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1404 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1405 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1406 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1407 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1408 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1409 && strcmp (segment_name (seg
), ".got2") != 0
1410 && strcmp (segment_name (seg
), ".dtors") != 0
1411 && strcmp (segment_name (seg
), ".ctors") != 0
1412 && strcmp (segment_name (seg
), ".fixup") != 0
1413 && strcmp (segment_name (seg
), ".stab") != 0
1414 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1415 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1417 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1418 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1420 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1421 "Relocation cannot be done when using -mrelocatable");
1427 #endif /* OBJ_ELF */
1432 * Summary of parse_toc_entry().
1434 * in: Input_line_pointer points to the '[' in one of:
1436 * [toc] [tocv] [toc32] [toc64]
1438 * Anything else is an error of one kind or another.
1441 * return value: success or failure
1442 * toc_kind: kind of toc reference
1443 * input_line_pointer:
1444 * success: first char after the ']'
1445 * failure: unchanged
1449 * [toc] - rv == success, toc_kind = default_toc
1450 * [tocv] - rv == success, toc_kind = data_in_toc
1451 * [toc32] - rv == success, toc_kind = must_be_32
1452 * [toc64] - rv == success, toc_kind = must_be_64
1456 enum toc_size_qualifier
1458 default_toc
, /* The toc cell constructed should be the system default size */
1459 data_in_toc
, /* This is a direct reference to a toc cell */
1460 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1461 must_be_64
/* The toc cell constructed must be 64 bits wide */
1465 parse_toc_entry(toc_kind
)
1466 enum toc_size_qualifier
*toc_kind
;
1471 enum toc_size_qualifier t
;
1473 /* save the input_line_pointer */
1474 start
= input_line_pointer
;
1476 /* skip over the '[' , and whitespace */
1477 ++input_line_pointer
;
1480 /* find the spelling of the operand */
1481 toc_spec
= input_line_pointer
;
1482 c
= get_symbol_end ();
1484 if (strcmp(toc_spec
, "toc") == 0)
1488 else if (strcmp(toc_spec
, "tocv") == 0)
1492 else if (strcmp(toc_spec
, "toc32") == 0)
1496 else if (strcmp(toc_spec
, "toc64") == 0)
1502 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1503 *input_line_pointer
= c
; /* put back the delimiting char */
1504 input_line_pointer
= start
; /* reset input_line pointer */
1508 /* now find the ']' */
1509 *input_line_pointer
= c
; /* put back the delimiting char */
1511 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1512 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1516 as_bad ("syntax error: expected `]', found `%c'", c
);
1517 input_line_pointer
= start
; /* reset input_line pointer */
1521 *toc_kind
= t
; /* set return value */
1527 /* We need to keep a list of fixups. We can't simply generate them as
1528 we go, because that would require us to first create the frag, and
1529 that would screw up references to ``.''. */
1535 bfd_reloc_code_real_type reloc
;
1538 #define MAX_INSN_FIXUPS (5)
1540 /* This routine is called for each instruction to be assembled. */
1547 const struct powerpc_opcode
*opcode
;
1549 const unsigned char *opindex_ptr
;
1553 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1558 bfd_reloc_code_real_type reloc
;
1561 /* Get the opcode. */
1562 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1567 /* Look up the opcode in the hash table. */
1568 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1569 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1571 const struct powerpc_macro
*macro
;
1573 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1574 if (macro
== (const struct powerpc_macro
*) NULL
)
1575 as_bad ("Unrecognized opcode: `%s'", str
);
1577 ppc_macro (s
, macro
);
1582 insn
= opcode
->opcode
;
1585 while (isspace (*str
))
1588 /* PowerPC operands are just expressions. The only real issue is
1589 that a few operand types are optional. All cases which might use
1590 an optional operand separate the operands only with commas (in
1591 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1592 cases never have optional operands). There is never more than
1593 one optional operand for an instruction. So, before we start
1594 seriously parsing the operands, we check to see if we have an
1595 optional operand, and, if we do, we count the number of commas to
1596 see whether the operand should be omitted. */
1598 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1600 const struct powerpc_operand
*operand
;
1602 operand
= &powerpc_operands
[*opindex_ptr
];
1603 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1605 unsigned int opcount
;
1607 /* There is an optional operand. Count the number of
1608 commas in the input line. */
1615 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1622 /* If there are fewer operands in the line then are called
1623 for by the instruction, we want to skip the optional
1625 if (opcount
< strlen (opcode
->operands
))
1632 /* Gather the operands. */
1636 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1638 const struct powerpc_operand
*operand
;
1644 if (next_opindex
== 0)
1645 operand
= &powerpc_operands
[*opindex_ptr
];
1648 operand
= &powerpc_operands
[next_opindex
];
1654 /* If this is a fake operand, then we do not expect anything
1656 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1658 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1659 if (errmsg
!= (const char *) NULL
)
1664 /* If this is an optional operand, and we are skipping it, just
1666 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1669 if (operand
->insert
)
1671 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1672 if (errmsg
!= (const char *) NULL
)
1675 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1676 next_opindex
= *opindex_ptr
+ 1;
1680 /* Gather the operand. */
1681 hold
= input_line_pointer
;
1682 input_line_pointer
= str
;
1685 if (*input_line_pointer
== '[')
1687 /* We are expecting something like the second argument here:
1689 lwz r4,[toc].GS.0.static_int(rtoc)
1690 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1691 The argument following the `]' must be a symbol name, and the
1692 register must be the toc register: 'rtoc' or '2'
1694 The effect is to 0 as the displacement field
1695 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1696 the appropriate variation) reloc against it based on the symbol.
1697 The linker will build the toc, and insert the resolved toc offset.
1700 o The size of the toc entry is currently assumed to be
1701 32 bits. This should not be assumed to be a hard coded
1703 o In an effort to cope with a change from 32 to 64 bits,
1704 there are also toc entries that are specified to be
1705 either 32 or 64 bits:
1706 lwz r4,[toc32].GS.0.static_int(rtoc)
1707 lwz r4,[toc64].GS.0.static_int(rtoc)
1708 These demand toc entries of the specified size, and the
1709 instruction probably requires it.
1713 enum toc_size_qualifier toc_kind
;
1714 bfd_reloc_code_real_type toc_reloc
;
1716 /* go parse off the [tocXX] part */
1717 valid_toc
= parse_toc_entry(&toc_kind
);
1721 /* Note: message has already been issued. */
1722 /* FIXME: what sort of recovery should we do? */
1723 /* demand_rest_of_line(); return; ? */
1726 /* Now get the symbol following the ']' */
1732 /* In this case, we may not have seen the symbol yet, since */
1733 /* it is allowed to appear on a .extern or .globl or just be */
1734 /* a label in the .data section. */
1735 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1738 /* 1. The symbol must be defined and either in the toc */
1739 /* section, or a global. */
1740 /* 2. The reloc generated must have the TOCDEFN flag set in */
1741 /* upper bit mess of the reloc type. */
1742 /* FIXME: It's a little confusing what the tocv qualifier can */
1743 /* be used for. At the very least, I've seen three */
1744 /* uses, only one of which I'm sure I can explain. */
1745 if (ex
.X_op
== O_symbol
)
1747 assert (ex
.X_add_symbol
!= NULL
);
1748 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1750 as_bad("[tocv] symbol is not a toc symbol");
1754 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1757 /* FIXME: these next two specifically specify 32/64 bit toc */
1758 /* entries. We don't support them today. Is this the */
1759 /* right way to say that? */
1760 toc_reloc
= BFD_RELOC_UNUSED
;
1761 as_bad ("Unimplemented toc32 expression modifier");
1764 /* FIXME: see above */
1765 toc_reloc
= BFD_RELOC_UNUSED
;
1766 as_bad ("Unimplemented toc64 expression modifier");
1770 "Unexpected return value [%d] from parse_toc_entry!\n",
1776 /* We need to generate a fixup for this expression. */
1777 if (fc
>= MAX_INSN_FIXUPS
)
1778 as_fatal ("too many fixups");
1780 fixups
[fc
].reloc
= toc_reloc
;
1781 fixups
[fc
].exp
= ex
;
1782 fixups
[fc
].opindex
= *opindex_ptr
;
1785 /* Ok. We've set up the fixup for the instruction. Now make it
1786 look like the constant 0 was found here */
1788 ex
.X_op
= O_constant
;
1789 ex
.X_add_number
= 0;
1790 ex
.X_add_symbol
= NULL
;
1791 ex
.X_op_symbol
= NULL
;
1797 if (! register_name (&ex
))
1799 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1806 str
= input_line_pointer
;
1807 input_line_pointer
= hold
;
1809 if (ex
.X_op
== O_illegal
)
1810 as_bad ("illegal operand");
1811 else if (ex
.X_op
== O_absent
)
1812 as_bad ("missing operand");
1813 else if (ex
.X_op
== O_register
)
1815 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1818 else if (ex
.X_op
== O_constant
)
1821 /* Allow @HA, @L, @H on constants. */
1822 char *orig_str
= str
;
1824 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1831 case BFD_RELOC_LO16
:
1833 ex
.X_add_number
&= 0xffff;
1835 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
1840 case BFD_RELOC_HI16
:
1841 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1844 case BFD_RELOC_HI16_S
:
1845 ex
.X_add_number
= (((ex
.X_add_number
>> 16) & 0xffff)
1846 + ((ex
.X_add_number
>> 15) & 1));
1850 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1854 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
1856 /* For the absoulte forms of branchs, convert the PC relative form back into
1858 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1862 case BFD_RELOC_PPC_B26
:
1863 reloc
= BFD_RELOC_PPC_BA26
;
1865 case BFD_RELOC_PPC_B16
:
1866 reloc
= BFD_RELOC_PPC_BA16
;
1868 case BFD_RELOC_PPC_B16_BRTAKEN
:
1869 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
1871 case BFD_RELOC_PPC_B16_BRNTAKEN
:
1872 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
1879 /* We need to generate a fixup for this expression. */
1880 if (fc
>= MAX_INSN_FIXUPS
)
1881 as_fatal ("too many fixups");
1882 fixups
[fc
].exp
= ex
;
1883 fixups
[fc
].opindex
= 0;
1884 fixups
[fc
].reloc
= reloc
;
1887 #endif /* OBJ_ELF */
1891 /* We need to generate a fixup for this expression. */
1892 if (fc
>= MAX_INSN_FIXUPS
)
1893 as_fatal ("too many fixups");
1894 fixups
[fc
].exp
= ex
;
1895 fixups
[fc
].opindex
= *opindex_ptr
;
1896 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1905 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1913 /* The call to expression should have advanced str past any
1916 && (endc
!= ',' || *str
!= '\0'))
1918 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1926 while (isspace (*str
))
1930 as_bad ("junk at end of line: `%s'", str
);
1932 /* Write out the instruction. */
1934 md_number_to_chars (f
, insn
, 4);
1936 /* Create any fixups. At this point we do not use a
1937 bfd_reloc_code_real_type, but instead just use the
1938 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1939 handle fixups for any operand type, although that is admittedly
1940 not a very exciting feature. We pick a BFD reloc type in
1942 for (i
= 0; i
< fc
; i
++)
1944 const struct powerpc_operand
*operand
;
1946 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1947 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1949 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1957 size
= bfd_get_reloc_size (reloc_howto
);
1958 offset
= target_big_endian
? (4 - size
) : 0;
1960 if (size
< 1 || size
> 4)
1963 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1964 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1967 /* Turn off complaints that the addend is too large for things like
1969 switch (fixups
[i
].reloc
)
1971 case BFD_RELOC_16_GOTOFF
:
1972 case BFD_RELOC_PPC_TOC16
:
1973 case BFD_RELOC_LO16
:
1974 case BFD_RELOC_HI16
:
1975 case BFD_RELOC_HI16_S
:
1976 fixP
->fx_no_overflow
= 1;
1983 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1985 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1986 ((bfd_reloc_code_real_type
)
1987 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1991 #ifndef WORKING_DOT_WORD
1992 /* Handle long and short jumps */
1994 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1996 addressT from_addr
, to_addr
;
2004 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2006 addressT from_addr
, to_addr
;
2014 /* Handle a macro. Gather all the operands, transform them as
2015 described by the macro, and call md_assemble recursively. All the
2016 operands are separated by commas; we don't accept parentheses
2017 around operands here. */
2020 ppc_macro (str
, macro
)
2022 const struct powerpc_macro
*macro
;
2033 /* Gather the users operands into the operands array. */
2038 if (count
>= sizeof operands
/ sizeof operands
[0])
2040 operands
[count
++] = s
;
2041 s
= strchr (s
, ',');
2042 if (s
== (char *) NULL
)
2047 if (count
!= macro
->operands
)
2049 as_bad ("wrong number of operands");
2053 /* Work out how large the string must be (the size is unbounded
2054 because it includes user input). */
2056 format
= macro
->format
;
2057 while (*format
!= '\0')
2066 arg
= strtol (format
+ 1, &send
, 10);
2067 know (send
!= format
&& arg
>= 0 && arg
< count
);
2068 len
+= strlen (operands
[arg
]);
2073 /* Put the string together. */
2074 complete
= s
= (char *) alloca (len
+ 1);
2075 format
= macro
->format
;
2076 while (*format
!= '\0')
2082 arg
= strtol (format
+ 1, &send
, 10);
2083 strcpy (s
, operands
[arg
]);
2090 /* Assemble the constructed instruction. */
2091 md_assemble (complete
);
2095 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2098 ppc_section_letter (letter
, ptr_msg
)
2105 *ptr_msg
= "Bad .section directive: want a,w,x,e in string";
2110 ppc_section_word (ptr_str
)
2113 if (strncmp (*ptr_str
, "exclude", sizeof ("exclude")-1) == 0)
2115 *ptr_str
+= sizeof ("exclude")-1;
2123 ppc_section_type (ptr_str
)
2126 if (strncmp (*ptr_str
, "ordered", sizeof ("ordered")-1) == 0)
2128 *ptr_str
+= sizeof ("ordered")-1;
2136 ppc_section_flags (flags
, attr
, type
)
2141 if (type
== SHT_ORDERED
)
2142 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2144 if (attr
& SHF_EXCLUDE
)
2145 flags
|= SEC_EXCLUDE
;
2149 #endif /* OBJ_ELF */
2152 /* Pseudo-op handling. */
2154 /* The .byte pseudo-op. This is similar to the normal .byte
2155 pseudo-op, but it can also take a single ASCII string. */
2161 if (*input_line_pointer
!= '\"')
2167 /* Gather characters. A real double quote is doubled. Unusual
2168 characters are not permitted. */
2169 ++input_line_pointer
;
2174 c
= *input_line_pointer
++;
2178 if (*input_line_pointer
!= '\"')
2180 ++input_line_pointer
;
2183 FRAG_APPEND_1_CHAR (c
);
2186 demand_empty_rest_of_line ();
2191 /* XCOFF specific pseudo-op handling. */
2193 /* This is set if we are creating a .stabx symbol, since we don't want
2194 to handle symbol suffixes for such symbols. */
2195 static boolean ppc_stab_symbol
;
2197 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2198 symbols in the .bss segment as though they were local common
2199 symbols, and uses a different smclas. */
2205 asection
*current_seg
= now_seg
;
2206 subsegT current_subseg
= now_subseg
;
2212 symbolS
*lcomm_sym
= NULL
;
2216 name
= input_line_pointer
;
2217 endc
= get_symbol_end ();
2218 end_name
= input_line_pointer
;
2221 if (*input_line_pointer
!= ',')
2223 as_bad ("missing size");
2224 ignore_rest_of_line ();
2227 ++input_line_pointer
;
2229 size
= get_absolute_expression ();
2232 as_bad ("negative size");
2233 ignore_rest_of_line ();
2239 /* The third argument to .comm is the alignment. */
2240 if (*input_line_pointer
!= ',')
2244 ++input_line_pointer
;
2245 align
= get_absolute_expression ();
2248 as_warn ("ignoring bad alignment");
2267 /* The third argument to .lcomm appears to be the real local
2268 common symbol to create. References to the symbol named in
2269 the first argument are turned into references to the third
2271 if (*input_line_pointer
!= ',')
2273 as_bad ("missing real symbol name");
2274 ignore_rest_of_line ();
2277 ++input_line_pointer
;
2279 lcomm_name
= input_line_pointer
;
2280 lcomm_endc
= get_symbol_end ();
2282 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2284 *input_line_pointer
= lcomm_endc
;
2288 sym
= symbol_find_or_make (name
);
2291 if (S_IS_DEFINED (sym
)
2292 || S_GET_VALUE (sym
) != 0)
2294 as_bad ("attempt to redefine symbol");
2295 ignore_rest_of_line ();
2299 record_alignment (bss_section
, align
);
2302 || ! S_IS_DEFINED (lcomm_sym
))
2311 S_SET_EXTERNAL (sym
);
2315 lcomm_sym
->sy_tc
.output
= 1;
2316 def_sym
= lcomm_sym
;
2320 subseg_set (bss_section
, 1);
2321 frag_align (align
, 0);
2323 def_sym
->sy_frag
= frag_now
;
2324 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2325 def_size
, (char *) NULL
);
2327 S_SET_SEGMENT (def_sym
, bss_section
);
2328 def_sym
->sy_tc
.align
= align
;
2332 /* Align the size of lcomm_sym. */
2333 lcomm_sym
->sy_frag
->fr_offset
=
2334 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
2335 &~ ((1 << align
) - 1));
2336 if (align
> lcomm_sym
->sy_tc
.align
)
2337 lcomm_sym
->sy_tc
.align
= align
;
2342 /* Make sym an offset from lcomm_sym. */
2343 S_SET_SEGMENT (sym
, bss_section
);
2344 sym
->sy_frag
= lcomm_sym
->sy_frag
;
2345 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
2346 lcomm_sym
->sy_frag
->fr_offset
+= size
;
2349 subseg_set (current_seg
, current_subseg
);
2351 demand_empty_rest_of_line ();
2354 /* The .csect pseudo-op. This switches us into a different
2355 subsegment. The first argument is a symbol whose value is the
2356 start of the .csect. In COFF, csect symbols get special aux
2357 entries defined by the x_csect field of union internal_auxent. The
2358 optional second argument is the alignment (the default is 2). */
2368 name
= input_line_pointer
;
2369 endc
= get_symbol_end ();
2371 sym
= symbol_find_or_make (name
);
2373 *input_line_pointer
= endc
;
2375 if (S_GET_NAME (sym
)[0] == '\0')
2377 /* An unnamed csect is assumed to be [PR]. */
2378 sym
->sy_tc
.class = XMC_PR
;
2381 ppc_change_csect (sym
);
2383 if (*input_line_pointer
== ',')
2385 ++input_line_pointer
;
2386 sym
->sy_tc
.align
= get_absolute_expression ();
2389 demand_empty_rest_of_line ();
2392 /* Change to a different csect. */
2395 ppc_change_csect (sym
)
2398 if (S_IS_DEFINED (sym
))
2399 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
2406 /* This is a new csect. We need to look at the symbol class to
2407 figure out whether it should go in the text section or the
2410 switch (sym
->sy_tc
.class)
2420 S_SET_SEGMENT (sym
, text_section
);
2421 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
2422 ++ppc_text_subsegment
;
2423 list_ptr
= &ppc_text_csects
;
2432 if (ppc_toc_csect
!= NULL
2433 && ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
2435 S_SET_SEGMENT (sym
, data_section
);
2436 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
2437 ++ppc_data_subsegment
;
2438 list_ptr
= &ppc_data_csects
;
2444 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
2446 ppc_after_toc_frag
= frag_now
;
2448 sym
->sy_frag
= frag_now
;
2449 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2451 sym
->sy_tc
.align
= 2;
2452 sym
->sy_tc
.output
= 1;
2453 sym
->sy_tc
.within
= sym
;
2455 for (list
= *list_ptr
;
2456 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2457 list
= list
->sy_tc
.next
)
2459 list
->sy_tc
.next
= sym
;
2461 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2462 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2465 ppc_current_csect
= sym
;
2468 /* This function handles the .text and .data pseudo-ops. These
2469 pseudo-ops aren't really used by XCOFF; we implement them for the
2470 convenience of people who aren't used to XCOFF. */
2481 else if (type
== 'd')
2486 sym
= symbol_find_or_make (name
);
2488 ppc_change_csect (sym
);
2490 demand_empty_rest_of_line ();
2493 /* The .extern pseudo-op. We create an undefined symbol. */
2502 name
= input_line_pointer
;
2503 endc
= get_symbol_end ();
2505 (void) symbol_find_or_make (name
);
2507 *input_line_pointer
= endc
;
2509 demand_empty_rest_of_line ();
2512 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2522 name
= input_line_pointer
;
2523 endc
= get_symbol_end ();
2525 sym
= symbol_find_or_make (name
);
2527 *input_line_pointer
= endc
;
2529 sym
->sy_tc
.output
= 1;
2531 demand_empty_rest_of_line ();
2534 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2535 although I don't know why it bothers. */
2546 name
= input_line_pointer
;
2547 endc
= get_symbol_end ();
2549 sym
= symbol_find_or_make (name
);
2551 *input_line_pointer
= endc
;
2553 if (*input_line_pointer
!= ',')
2555 as_bad ("missing rename string");
2556 ignore_rest_of_line ();
2559 ++input_line_pointer
;
2561 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2563 demand_empty_rest_of_line ();
2566 /* The .stabx pseudo-op. This is similar to a normal .stabs
2567 pseudo-op, but slightly different. A sample is
2568 .stabx "main:F-1",.main,142,0
2569 The first argument is the symbol name to create. The second is the
2570 value, and the third is the storage class. The fourth seems to be
2571 always zero, and I am assuming it is the type. */
2582 name
= demand_copy_C_string (&len
);
2584 if (*input_line_pointer
!= ',')
2586 as_bad ("missing value");
2589 ++input_line_pointer
;
2591 ppc_stab_symbol
= true;
2592 sym
= symbol_make (name
);
2593 ppc_stab_symbol
= false;
2595 sym
->sy_tc
.real_name
= name
;
2597 (void) expression (&exp
);
2604 as_bad ("illegal .stabx expression; zero assumed");
2605 exp
.X_add_number
= 0;
2608 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2609 sym
->sy_frag
= &zero_address_frag
;
2613 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2614 sym
->sy_value
= exp
;
2618 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2619 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2624 /* The value is some complex expression. This will probably
2625 fail at some later point, but this is probably the right
2626 thing to do here. */
2627 sym
->sy_value
= exp
;
2631 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2632 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2634 if (*input_line_pointer
!= ',')
2636 as_bad ("missing class");
2639 ++input_line_pointer
;
2641 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2643 if (*input_line_pointer
!= ',')
2645 as_bad ("missing type");
2648 ++input_line_pointer
;
2650 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2652 sym
->sy_tc
.output
= 1;
2654 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2655 sym
->sy_tc
.within
= ppc_current_block
;
2657 if (exp
.X_op
!= O_symbol
2658 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2659 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2660 ppc_frob_label (sym
);
2663 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2664 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2665 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2666 ppc_current_csect
->sy_tc
.within
= sym
;
2669 demand_empty_rest_of_line ();
2672 /* The .function pseudo-op. This takes several arguments. The first
2673 argument seems to be the external name of the symbol. The second
2674 argment seems to be the label for the start of the function. gcc
2675 uses the same name for both. I have no idea what the third and
2676 fourth arguments are meant to be. The optional fifth argument is
2677 an expression for the size of the function. In COFF this symbol
2678 gets an aux entry like that used for a csect. */
2681 ppc_function (ignore
)
2690 name
= input_line_pointer
;
2691 endc
= get_symbol_end ();
2693 /* Ignore any [PR] suffix. */
2694 name
= ppc_canonicalize_symbol_name (name
);
2695 s
= strchr (name
, '[');
2696 if (s
!= (char *) NULL
2697 && strcmp (s
+ 1, "PR]") == 0)
2700 ext_sym
= symbol_find_or_make (name
);
2702 *input_line_pointer
= endc
;
2704 if (*input_line_pointer
!= ',')
2706 as_bad ("missing symbol name");
2707 ignore_rest_of_line ();
2710 ++input_line_pointer
;
2712 name
= input_line_pointer
;
2713 endc
= get_symbol_end ();
2715 lab_sym
= symbol_find_or_make (name
);
2717 *input_line_pointer
= endc
;
2719 if (ext_sym
!= lab_sym
)
2721 ext_sym
->sy_value
.X_op
= O_symbol
;
2722 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2723 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2724 ext_sym
->sy_value
.X_add_number
= 0;
2727 if (ext_sym
->sy_tc
.class == -1)
2728 ext_sym
->sy_tc
.class = XMC_PR
;
2729 ext_sym
->sy_tc
.output
= 1;
2731 if (*input_line_pointer
== ',')
2735 /* Ignore the third argument. */
2736 ++input_line_pointer
;
2737 expression (&ignore
);
2738 if (*input_line_pointer
== ',')
2740 /* Ignore the fourth argument. */
2741 ++input_line_pointer
;
2742 expression (&ignore
);
2743 if (*input_line_pointer
== ',')
2745 /* The fifth argument is the function size. */
2746 ++input_line_pointer
;
2747 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2750 &zero_address_frag
);
2751 pseudo_set (ext_sym
->sy_tc
.size
);
2756 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2757 SF_SET_FUNCTION (ext_sym
);
2758 SF_SET_PROCESS (ext_sym
);
2759 coff_add_linesym (ext_sym
);
2761 demand_empty_rest_of_line ();
2764 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2773 sym
= symbol_make (".bf");
2774 S_SET_SEGMENT (sym
, text_section
);
2775 sym
->sy_frag
= frag_now
;
2776 S_SET_VALUE (sym
, frag_now_fix ());
2777 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2779 coff_line_base
= get_absolute_expression ();
2781 S_SET_NUMBER_AUXILIARY (sym
, 1);
2782 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2784 sym
->sy_tc
.output
= 1;
2786 ppc_frob_label (sym
);
2788 demand_empty_rest_of_line ();
2791 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2792 ".ef", except that the line number is absolute, not relative to the
2793 most recent ".bf" symbol. */
2801 sym
= symbol_make (".ef");
2802 S_SET_SEGMENT (sym
, text_section
);
2803 sym
->sy_frag
= frag_now
;
2804 S_SET_VALUE (sym
, frag_now_fix ());
2805 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2806 S_SET_NUMBER_AUXILIARY (sym
, 1);
2807 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2808 sym
->sy_tc
.output
= 1;
2810 ppc_frob_label (sym
);
2812 demand_empty_rest_of_line ();
2815 /* The .bi and .ei pseudo-ops. These take a string argument and
2816 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2828 name
= demand_copy_C_string (&len
);
2830 /* The value of these symbols is actually file offset. Here we set
2831 the value to the index into the line number entries. In
2832 ppc_frob_symbols we set the fix_line field, which will cause BFD
2833 to do the right thing. */
2835 sym
= symbol_make (name
);
2836 /* obj-coff.c currently only handles line numbers correctly in the
2838 S_SET_SEGMENT (sym
, text_section
);
2839 S_SET_VALUE (sym
, coff_n_line_nos
);
2840 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2842 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2843 sym
->sy_tc
.output
= 1;
2845 for (look
= symbol_rootP
;
2846 (look
!= (symbolS
*) NULL
2847 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2848 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2849 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2850 look
= symbol_next (look
))
2852 if (look
!= (symbolS
*) NULL
)
2854 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2855 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2858 demand_empty_rest_of_line ();
2861 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2862 There is one argument, which is a csect symbol. The value of the
2863 .bs symbol is the index of this csect symbol. */
2874 if (ppc_current_block
!= NULL
)
2875 as_bad ("nested .bs blocks");
2877 name
= input_line_pointer
;
2878 endc
= get_symbol_end ();
2880 csect
= symbol_find_or_make (name
);
2882 *input_line_pointer
= endc
;
2884 sym
= symbol_make (".bs");
2885 S_SET_SEGMENT (sym
, now_seg
);
2886 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2887 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2888 sym
->sy_tc
.output
= 1;
2890 sym
->sy_tc
.within
= csect
;
2892 ppc_frob_label (sym
);
2894 ppc_current_block
= sym
;
2896 demand_empty_rest_of_line ();
2899 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2907 if (ppc_current_block
== NULL
)
2908 as_bad (".es without preceding .bs");
2910 sym
= symbol_make (".es");
2911 S_SET_SEGMENT (sym
, now_seg
);
2912 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2913 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2914 sym
->sy_tc
.output
= 1;
2916 ppc_frob_label (sym
);
2918 ppc_current_block
= NULL
;
2920 demand_empty_rest_of_line ();
2923 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2932 sym
= symbol_make (".bb");
2933 S_SET_SEGMENT (sym
, text_section
);
2934 sym
->sy_frag
= frag_now
;
2935 S_SET_VALUE (sym
, frag_now_fix ());
2936 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2938 S_SET_NUMBER_AUXILIARY (sym
, 1);
2939 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2941 sym
->sy_tc
.output
= 1;
2943 SF_SET_PROCESS (sym
);
2945 ppc_frob_label (sym
);
2947 demand_empty_rest_of_line ();
2950 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2959 sym
= symbol_make (".eb");
2960 S_SET_SEGMENT (sym
, text_section
);
2961 sym
->sy_frag
= frag_now
;
2962 S_SET_VALUE (sym
, frag_now_fix ());
2963 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2964 S_SET_NUMBER_AUXILIARY (sym
, 1);
2965 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2966 sym
->sy_tc
.output
= 1;
2968 SF_SET_PROCESS (sym
);
2970 ppc_frob_label (sym
);
2972 demand_empty_rest_of_line ();
2975 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
2986 name
= demand_copy_C_string (&len
);
2987 sym
= symbol_make (name
);
2988 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2989 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2990 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
2991 S_SET_VALUE (sym
, 0);
2992 sym
->sy_tc
.output
= 1;
2994 ppc_frob_label (sym
);
2996 demand_empty_rest_of_line ();
2999 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3007 sym
= symbol_make (".ec");
3008 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3009 sym
->bsym
->flags
|= BSF_DEBUGGING
;
3010 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3011 S_SET_VALUE (sym
, 0);
3012 sym
->sy_tc
.output
= 1;
3014 ppc_frob_label (sym
);
3016 demand_empty_rest_of_line ();
3019 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3025 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3026 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
3033 subseg
= ppc_data_subsegment
;
3034 ++ppc_data_subsegment
;
3036 subseg_new (segment_name (data_section
), subseg
);
3037 ppc_toc_frag
= frag_now
;
3039 sym
= symbol_find_or_make ("TOC[TC0]");
3040 sym
->sy_frag
= frag_now
;
3041 S_SET_SEGMENT (sym
, data_section
);
3042 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3043 sym
->sy_tc
.subseg
= subseg
;
3044 sym
->sy_tc
.output
= 1;
3045 sym
->sy_tc
.within
= sym
;
3047 ppc_toc_csect
= sym
;
3049 for (list
= ppc_data_csects
;
3050 list
->sy_tc
.next
!= (symbolS
*) NULL
;
3051 list
= list
->sy_tc
.next
)
3053 list
->sy_tc
.next
= sym
;
3055 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3056 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
3059 ppc_current_csect
= ppc_toc_csect
;
3061 demand_empty_rest_of_line ();
3064 #endif /* OBJ_XCOFF */
3066 /* The .tc pseudo-op. This is used when generating either XCOFF or
3067 ELF. This takes two or more arguments.
3069 When generating XCOFF output, the first argument is the name to
3070 give to this location in the toc; this will be a symbol with class
3071 TC. The rest of the arguments are 4 byte values to actually put at
3072 this location in the TOC; often there is just one more argument, a
3073 relocateable symbol reference.
3075 When not generating XCOFF output, the arguments are the same, but
3076 the first argument is simply ignored. */
3084 /* Define the TOC symbol name. */
3090 if (ppc_toc_csect
== (symbolS
*) NULL
3091 || ppc_toc_csect
!= ppc_current_csect
)
3093 as_bad (".tc not in .toc section");
3094 ignore_rest_of_line ();
3098 name
= input_line_pointer
;
3099 endc
= get_symbol_end ();
3101 sym
= symbol_find_or_make (name
);
3103 *input_line_pointer
= endc
;
3105 if (S_IS_DEFINED (sym
))
3109 label
= ppc_current_csect
->sy_tc
.within
;
3110 if (label
->sy_tc
.class != XMC_TC0
)
3112 as_bad (".tc with no label");
3113 ignore_rest_of_line ();
3117 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3118 label
->sy_frag
= sym
->sy_frag
;
3119 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3121 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3122 ++input_line_pointer
;
3127 S_SET_SEGMENT (sym
, now_seg
);
3128 sym
->sy_frag
= frag_now
;
3129 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3130 sym
->sy_tc
.class = XMC_TC
;
3131 sym
->sy_tc
.output
= 1;
3133 ppc_frob_label (sym
);
3136 #else /* ! defined (OBJ_XCOFF) */
3138 /* Skip the TOC symbol name. */
3139 while (is_part_of_name (*input_line_pointer
)
3140 || *input_line_pointer
== '['
3141 || *input_line_pointer
== ']'
3142 || *input_line_pointer
== '{'
3143 || *input_line_pointer
== '}')
3144 ++input_line_pointer
;
3146 /* Align to a four byte boundary. */
3148 record_alignment (now_seg
, 2);
3150 #endif /* ! defined (OBJ_XCOFF) */
3152 if (*input_line_pointer
!= ',')
3153 demand_empty_rest_of_line ();
3156 ++input_line_pointer
;
3163 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3165 /* Set the current section. */
3167 ppc_set_current_section (new)
3170 ppc_previous_section
= ppc_current_section
;
3171 ppc_current_section
= new;
3174 /* pseudo-op: .previous
3175 behaviour: toggles the current section with the previous section.
3177 warnings: "No previous section"
3180 ppc_previous(ignore
)
3185 if (ppc_previous_section
== NULL
)
3187 as_warn("No previous section to return to. Directive ignored.");
3191 subseg_set(ppc_previous_section
, 0);
3193 ppc_set_current_section(ppc_previous_section
);
3196 /* pseudo-op: .pdata
3197 behaviour: predefined read only data section
3201 initial: .section .pdata "adr3"
3202 a - don't know -- maybe a misprint
3203 d - initialized data
3205 3 - double word aligned (that would be 4 byte boundary)
3208 Tag index tables (also known as the function table) for exception
3209 handling, debugging, etc.
3216 if (pdata_section
== 0)
3218 pdata_section
= subseg_new (".pdata", 0);
3220 bfd_set_section_flags (stdoutput
, pdata_section
,
3221 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3222 | SEC_READONLY
| SEC_DATA
));
3224 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3228 pdata_section
= subseg_new(".pdata", 0);
3230 ppc_set_current_section(pdata_section
);
3233 /* pseudo-op: .ydata
3234 behaviour: predefined read only data section
3238 initial: .section .ydata "drw3"
3239 a - don't know -- maybe a misprint
3240 d - initialized data
3242 3 - double word aligned (that would be 4 byte boundary)
3244 Tag tables (also known as the scope table) for exception handling,
3251 if (ydata_section
== 0)
3253 ydata_section
= subseg_new (".ydata", 0);
3254 bfd_set_section_flags (stdoutput
, ydata_section
,
3255 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3256 | SEC_READONLY
| SEC_DATA
));
3258 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3262 ydata_section
= subseg_new (".ydata", 0);
3264 ppc_set_current_section(ydata_section
);
3267 /* pseudo-op: .reldata
3268 behaviour: predefined read write data section
3269 double word aligned (4-byte)
3270 FIXME: relocation is applied to it
3271 FIXME: what's the difference between this and .data?
3274 initial: .section .reldata "drw3"
3275 d - initialized data
3278 3 - double word aligned (that would be 8 byte boundary)
3281 Like .data, but intended to hold data subject to relocation, such as
3282 function descriptors, etc.
3288 if (reldata_section
== 0)
3290 reldata_section
= subseg_new (".reldata", 0);
3292 bfd_set_section_flags (stdoutput
, reldata_section
,
3293 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3296 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3300 reldata_section
= subseg_new (".reldata", 0);
3302 ppc_set_current_section(reldata_section
);
3305 /* pseudo-op: .rdata
3306 behaviour: predefined read only data section
3310 initial: .section .rdata "dr3"
3311 d - initialized data
3313 3 - double word aligned (that would be 4 byte boundary)
3319 if (rdata_section
== 0)
3321 rdata_section
= subseg_new (".rdata", 0);
3322 bfd_set_section_flags (stdoutput
, rdata_section
,
3323 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3324 | SEC_READONLY
| SEC_DATA
));
3326 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3330 rdata_section
= subseg_new (".rdata", 0);
3332 ppc_set_current_section(rdata_section
);
3335 /* pseudo-op: .ualong
3336 behaviour: much like .int, with the exception that no alignment is
3338 FIXME: test the alignment statement
3350 /* pseudo-op: .znop <symbol name>
3351 behaviour: Issue a nop instruction
3352 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3353 the supplied symbol name.
3355 warnings: Missing symbol name
3362 const struct powerpc_opcode
*opcode
;
3368 /* Strip out the symbol name */
3376 symbol_name
= input_line_pointer
;
3377 c
= get_symbol_end ();
3379 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3380 strcpy (name
, symbol_name
);
3382 sym
= symbol_find_or_make (name
);
3384 *input_line_pointer
= c
;
3388 /* Look up the opcode in the hash table. */
3389 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3391 /* stick in the nop */
3392 insn
= opcode
->opcode
;
3394 /* Write out the instruction. */
3396 md_number_to_chars (f
, insn
, 4);
3398 f
- frag_now
->fr_literal
,
3403 BFD_RELOC_16_GOT_PCREL
);
3416 register char *name
;
3420 register symbolS
*symbolP
;
3423 name
= input_line_pointer
;
3424 c
= get_symbol_end ();
3426 /* just after name is now '\0' */
3427 p
= input_line_pointer
;
3430 if (*input_line_pointer
!= ',')
3432 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3433 ignore_rest_of_line ();
3437 input_line_pointer
++; /* skip ',' */
3438 if ((temp
= get_absolute_expression ()) < 0)
3440 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
3441 ignore_rest_of_line ();
3447 /* The third argument to .comm is the alignment. */
3448 if (*input_line_pointer
!= ',')
3452 ++input_line_pointer
;
3453 align
= get_absolute_expression ();
3456 as_warn ("ignoring bad alignment");
3463 symbolP
= symbol_find_or_make (name
);
3466 if (S_IS_DEFINED (symbolP
))
3468 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3469 S_GET_NAME (symbolP
));
3470 ignore_rest_of_line ();
3474 if (S_GET_VALUE (symbolP
))
3476 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3477 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3478 S_GET_NAME (symbolP
),
3479 (long) S_GET_VALUE (symbolP
),
3484 S_SET_VALUE (symbolP
, (valueT
) temp
);
3485 S_SET_EXTERNAL (symbolP
);
3488 demand_empty_rest_of_line ();
3492 * implement the .section pseudo op:
3493 * .section name {, "flags"}
3495 * | +--- optional flags: 'b' for bss
3497 * +-- section name 'l' for lib
3501 * 'd' (apparently m88k for data)
3503 * But if the argument is not a quoted string, treat it as a
3504 * subsegment number.
3506 * FIXME: this is a copy of the section processing from obj-coff.c, with
3507 * additions/changes for the moto-pas assembler support. There are three
3510 * FIXME: I just noticed this. This doesn't work at all really. It it
3511 * setting bits that bfd probably neither understands or uses. The
3512 * correct approach (?) will have to incorporate extra fields attached
3513 * to the section to hold the system specific stuff. (krk)
3516 * 'a' - unknown - referred to in documentation, but no definition supplied
3517 * 'c' - section has code
3518 * 'd' - section has initialized data
3519 * 'u' - section has uninitialized data
3520 * 'i' - section contains directives (info)
3521 * 'n' - section can be discarded
3522 * 'R' - remove section at link time
3524 * Section Protection:
3525 * 'r' - section is readable
3526 * 'w' - section is writeable
3527 * 'x' - section is executable
3528 * 's' - section is sharable
3530 * Section Alignment:
3531 * '0' - align to byte boundary
3532 * '1' - align to halfword undary
3533 * '2' - align to word boundary
3534 * '3' - align to doubleword boundary
3535 * '4' - align to quadword boundary
3536 * '5' - align to 32 byte boundary
3537 * '6' - align to 64 byte boundary
3542 ppc_pe_section (ignore
)
3545 /* Strip out the section name */
3554 section_name
= input_line_pointer
;
3555 c
= get_symbol_end ();
3557 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3558 strcpy (name
, section_name
);
3560 *input_line_pointer
= c
;
3565 flags
= SEC_NO_FLAGS
;
3567 if (strcmp (name
, ".idata$2") == 0)
3571 else if (strcmp (name
, ".idata$3") == 0)
3575 else if (strcmp (name
, ".idata$4") == 0)
3579 else if (strcmp (name
, ".idata$5") == 0)
3583 else if (strcmp (name
, ".idata$6") == 0)
3588 align
= 4; /* default alignment to 16 byte boundary */
3590 if (*input_line_pointer
== ',')
3592 ++input_line_pointer
;
3594 if (*input_line_pointer
!= '"')
3595 exp
= get_absolute_expression ();
3598 ++input_line_pointer
;
3599 while (*input_line_pointer
!= '"'
3600 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3602 switch (*input_line_pointer
)
3604 /* Section Contents */
3605 case 'a': /* unknown */
3606 as_bad ("Unsupported section attribute -- 'a'");
3608 case 'c': /* code section */
3611 case 'd': /* section has initialized data */
3614 case 'u': /* section has uninitialized data */
3615 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3619 case 'i': /* section contains directives (info) */
3620 /* FIXME: This is IMAGE_SCN_LNK_INFO
3622 flags
|= SEC_HAS_CONTENTS
;
3624 case 'n': /* section can be discarded */
3627 case 'R': /* Remove section at link time */
3628 flags
|= SEC_NEVER_LOAD
;
3631 /* Section Protection */
3632 case 'r': /* section is readable */
3633 flags
|= IMAGE_SCN_MEM_READ
;
3635 case 'w': /* section is writeable */
3636 flags
|= IMAGE_SCN_MEM_WRITE
;
3638 case 'x': /* section is executable */
3639 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3641 case 's': /* section is sharable */
3642 flags
|= IMAGE_SCN_MEM_SHARED
;
3645 /* Section Alignment */
3646 case '0': /* align to byte boundary */
3647 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3650 case '1': /* align to halfword boundary */
3651 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3654 case '2': /* align to word boundary */
3655 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3658 case '3': /* align to doubleword boundary */
3659 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3662 case '4': /* align to quadword boundary */
3663 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3666 case '5': /* align to 32 byte boundary */
3667 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3670 case '6': /* align to 64 byte boundary */
3671 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3676 as_bad("unknown section attribute '%c'",
3677 *input_line_pointer
);
3680 ++input_line_pointer
;
3682 if (*input_line_pointer
== '"')
3683 ++input_line_pointer
;
3687 sec
= subseg_new (name
, (subsegT
) exp
);
3689 ppc_set_current_section(sec
);
3691 if (flags
!= SEC_NO_FLAGS
)
3693 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3694 as_bad ("error setting flags for \"%s\": %s",
3695 bfd_section_name (stdoutput
, sec
),
3696 bfd_errmsg (bfd_get_error ()));
3699 bfd_set_section_alignment(stdoutput
, sec
, align
);
3704 ppc_pe_function (ignore
)
3711 name
= input_line_pointer
;
3712 endc
= get_symbol_end ();
3714 ext_sym
= symbol_find_or_make (name
);
3716 *input_line_pointer
= endc
;
3718 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3719 SF_SET_FUNCTION (ext_sym
);
3720 SF_SET_PROCESS (ext_sym
);
3721 coff_add_linesym (ext_sym
);
3723 demand_empty_rest_of_line ();
3727 ppc_pe_tocd (ignore
)
3730 if (tocdata_section
== 0)
3732 tocdata_section
= subseg_new (".tocd", 0);
3733 /* FIXME: section flags won't work */
3734 bfd_set_section_flags (stdoutput
, tocdata_section
,
3735 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3736 | SEC_READONLY
| SEC_DATA
));
3738 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3742 rdata_section
= subseg_new (".tocd", 0);
3745 ppc_set_current_section(tocdata_section
);
3747 demand_empty_rest_of_line ();
3750 /* Don't adjust TOC relocs to use the section symbol. */
3753 ppc_pe_fix_adjustable (fix
)
3756 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3763 /* XCOFF specific symbol and file handling. */
3765 /* Canonicalize the symbol name. We use the to force the suffix, if
3766 any, to use square brackets, and to be in upper case. */
3769 ppc_canonicalize_symbol_name (name
)
3774 if (ppc_stab_symbol
)
3777 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3791 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3795 if (*s
== '\0' || s
[1] != '\0')
3796 as_bad ("bad symbol suffix");
3804 /* Set the class of a symbol based on the suffix, if any. This is
3805 called whenever a new symbol is created. */
3808 ppc_symbol_new_hook (sym
)
3813 sym
->sy_tc
.next
= NULL
;
3814 sym
->sy_tc
.output
= 0;
3815 sym
->sy_tc
.class = -1;
3816 sym
->sy_tc
.real_name
= NULL
;
3817 sym
->sy_tc
.subseg
= 0;
3818 sym
->sy_tc
.align
= 0;
3819 sym
->sy_tc
.size
= NULL
;
3820 sym
->sy_tc
.within
= NULL
;
3822 if (ppc_stab_symbol
)
3825 s
= strchr (S_GET_NAME (sym
), '[');
3826 if (s
== (const char *) NULL
)
3828 /* There is no suffix. */
3837 if (strcmp (s
, "BS]") == 0)
3838 sym
->sy_tc
.class = XMC_BS
;
3841 if (strcmp (s
, "DB]") == 0)
3842 sym
->sy_tc
.class = XMC_DB
;
3843 else if (strcmp (s
, "DS]") == 0)
3844 sym
->sy_tc
.class = XMC_DS
;
3847 if (strcmp (s
, "GL]") == 0)
3848 sym
->sy_tc
.class = XMC_GL
;
3851 if (strcmp (s
, "PR]") == 0)
3852 sym
->sy_tc
.class = XMC_PR
;
3855 if (strcmp (s
, "RO]") == 0)
3856 sym
->sy_tc
.class = XMC_RO
;
3857 else if (strcmp (s
, "RW]") == 0)
3858 sym
->sy_tc
.class = XMC_RW
;
3861 if (strcmp (s
, "SV]") == 0)
3862 sym
->sy_tc
.class = XMC_SV
;
3865 if (strcmp (s
, "TC]") == 0)
3866 sym
->sy_tc
.class = XMC_TC
;
3867 else if (strcmp (s
, "TI]") == 0)
3868 sym
->sy_tc
.class = XMC_TI
;
3869 else if (strcmp (s
, "TB]") == 0)
3870 sym
->sy_tc
.class = XMC_TB
;
3871 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3872 sym
->sy_tc
.class = XMC_TC0
;
3875 if (strcmp (s
, "UA]") == 0)
3876 sym
->sy_tc
.class = XMC_UA
;
3877 else if (strcmp (s
, "UC]") == 0)
3878 sym
->sy_tc
.class = XMC_UC
;
3881 if (strcmp (s
, "XO]") == 0)
3882 sym
->sy_tc
.class = XMC_XO
;
3886 if (sym
->sy_tc
.class == -1)
3887 as_bad ("Unrecognized symbol suffix");
3890 /* Set the class of a label based on where it is defined. This
3891 handles symbols without suffixes. Also, move the symbol so that it
3892 follows the csect symbol. */
3895 ppc_frob_label (sym
)
3898 if (ppc_current_csect
!= (symbolS
*) NULL
)
3900 if (sym
->sy_tc
.class == -1)
3901 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3903 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3904 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3906 ppc_current_csect
->sy_tc
.within
= sym
;
3910 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3911 seen. It tells ppc_adjust_symtab whether it needs to look through
3914 static boolean ppc_saw_abs
;
3916 /* Change the name of a symbol just before writing it out. Set the
3917 real name if the .rename pseudo-op was used. Otherwise, remove any
3918 class suffix. Return 1 if the symbol should not be included in the
3922 ppc_frob_symbol (sym
)
3925 static symbolS
*ppc_last_function
;
3926 static symbolS
*set_end
;
3928 /* Discard symbols that should not be included in the output symbol
3930 if (! sym
->sy_used_in_reloc
3931 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3932 || (! S_IS_EXTERNAL (sym
)
3933 && ! sym
->sy_tc
.output
3934 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3937 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3938 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3944 name
= S_GET_NAME (sym
);
3945 s
= strchr (name
, '[');
3946 if (s
!= (char *) NULL
)
3952 snew
= xmalloc (len
+ 1);
3953 memcpy (snew
, name
, len
);
3956 S_SET_NAME (sym
, snew
);
3960 if (set_end
!= (symbolS
*) NULL
)
3962 SA_SET_SYM_ENDNDX (set_end
, sym
);
3966 if (SF_GET_FUNCTION (sym
))
3968 if (ppc_last_function
!= (symbolS
*) NULL
)
3969 as_bad ("two .function pseudo-ops with no intervening .ef");
3970 ppc_last_function
= sym
;
3971 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3973 resolve_symbol_value (sym
->sy_tc
.size
);
3974 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3977 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3978 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3980 if (ppc_last_function
== (symbolS
*) NULL
)
3981 as_bad (".ef with no preceding .function");
3984 set_end
= ppc_last_function
;
3985 ppc_last_function
= NULL
;
3987 /* We don't have a C_EFCN symbol, but we need to force the
3988 COFF backend to believe that it has seen one. */
3989 coff_last_function
= NULL
;
3993 if (! S_IS_EXTERNAL (sym
)
3994 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3995 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3996 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3997 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
3998 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3999 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4000 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4001 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4002 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4003 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4005 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4006 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4009 union internal_auxent
*a
;
4011 /* Create a csect aux. */
4012 i
= S_GET_NUMBER_AUXILIARY (sym
);
4013 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4014 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
4015 if (sym
->sy_tc
.class == XMC_TC0
)
4017 /* This is the TOC table. */
4018 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4019 a
->x_csect
.x_scnlen
.l
= 0;
4020 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4022 else if (sym
->sy_tc
.subseg
!= 0)
4024 /* This is a csect symbol. x_scnlen is the size of the
4026 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
4027 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4028 S_GET_SEGMENT (sym
))
4029 - S_GET_VALUE (sym
));
4032 resolve_symbol_value (sym
->sy_tc
.next
);
4033 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
4034 - S_GET_VALUE (sym
));
4036 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
4038 else if (S_GET_SEGMENT (sym
) == bss_section
)
4040 /* This is a common symbol. */
4041 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
4042 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
4043 if (S_IS_EXTERNAL (sym
))
4044 sym
->sy_tc
.class = XMC_RW
;
4046 sym
->sy_tc
.class = XMC_BS
;
4048 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4050 /* This is an absolute symbol. The csect will be created by
4051 ppc_adjust_symtab. */
4053 a
->x_csect
.x_smtyp
= XTY_LD
;
4054 if (sym
->sy_tc
.class == -1)
4055 sym
->sy_tc
.class = XMC_XO
;
4057 else if (! S_IS_DEFINED (sym
))
4059 /* This is an external symbol. */
4060 a
->x_csect
.x_scnlen
.l
= 0;
4061 a
->x_csect
.x_smtyp
= XTY_ER
;
4063 else if (sym
->sy_tc
.class == XMC_TC
)
4067 /* This is a TOC definition. x_scnlen is the size of the
4069 next
= symbol_next (sym
);
4070 while (next
->sy_tc
.class == XMC_TC0
)
4071 next
= symbol_next (next
);
4072 if (next
== (symbolS
*) NULL
4073 || next
->sy_tc
.class != XMC_TC
)
4075 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4076 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4078 - S_GET_VALUE (sym
));
4080 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4081 - S_GET_VALUE (sym
));
4085 resolve_symbol_value (next
);
4086 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4087 - S_GET_VALUE (sym
));
4089 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4095 /* This is a normal symbol definition. x_scnlen is the
4096 symbol index of the containing csect. */
4097 if (S_GET_SEGMENT (sym
) == text_section
)
4098 csect
= ppc_text_csects
;
4099 else if (S_GET_SEGMENT (sym
) == data_section
)
4100 csect
= ppc_data_csects
;
4104 /* Skip the initial dummy symbol. */
4105 csect
= csect
->sy_tc
.next
;
4107 if (csect
== (symbolS
*) NULL
)
4109 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym
));
4110 a
->x_csect
.x_scnlen
.l
= 0;
4114 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
4116 resolve_symbol_value (csect
->sy_tc
.next
);
4117 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
4119 csect
= csect
->sy_tc
.next
;
4122 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4123 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
4125 a
->x_csect
.x_smtyp
= XTY_LD
;
4128 a
->x_csect
.x_parmhash
= 0;
4129 a
->x_csect
.x_snhash
= 0;
4130 if (sym
->sy_tc
.class == -1)
4131 a
->x_csect
.x_smclas
= XMC_PR
;
4133 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
4134 a
->x_csect
.x_stab
= 0;
4135 a
->x_csect
.x_snstab
= 0;
4137 /* Don't let the COFF backend resort these symbols. */
4138 sym
->bsym
->flags
|= BSF_NOT_AT_END
;
4140 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4142 /* We want the value to be the symbol index of the referenced
4143 csect symbol. BFD will do that for us if we set the right
4146 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
4147 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
4149 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4154 /* The value is the offset from the enclosing csect. */
4155 block
= sym
->sy_tc
.within
;
4156 csect
= block
->sy_tc
.within
;
4157 resolve_symbol_value (csect
);
4158 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4160 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4161 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4163 /* We want the value to be a file offset into the line numbers.
4164 BFD will do that for us if we set the right flags. We have
4165 already set the value correctly. */
4166 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
4172 /* Adjust the symbol table. This creates csect symbols for all
4173 absolute symbols. */
4176 ppc_adjust_symtab ()
4183 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4187 union internal_auxent
*a
;
4189 if (S_GET_SEGMENT (sym
) != absolute_section
)
4192 csect
= symbol_create (".abs[XO]", absolute_section
,
4193 S_GET_VALUE (sym
), &zero_address_frag
);
4194 csect
->bsym
->value
= S_GET_VALUE (sym
);
4195 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4196 i
= S_GET_NUMBER_AUXILIARY (csect
);
4197 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4198 a
= &coffsymbol (csect
->bsym
)->native
[i
+ 1].u
.auxent
;
4199 a
->x_csect
.x_scnlen
.l
= 0;
4200 a
->x_csect
.x_smtyp
= XTY_SD
;
4201 a
->x_csect
.x_parmhash
= 0;
4202 a
->x_csect
.x_snhash
= 0;
4203 a
->x_csect
.x_smclas
= XMC_XO
;
4204 a
->x_csect
.x_stab
= 0;
4205 a
->x_csect
.x_snstab
= 0;
4207 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4209 i
= S_GET_NUMBER_AUXILIARY (sym
);
4210 a
= &coffsymbol (sym
->bsym
)->native
[i
].u
.auxent
;
4211 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4212 coffsymbol (sym
->bsym
)->native
[i
].fix_scnlen
= 1;
4215 ppc_saw_abs
= false;
4218 /* Set the VMA for a section. This is called on all the sections in
4222 ppc_frob_section (sec
)
4225 static bfd_size_type vma
= 0;
4227 bfd_set_section_vma (stdoutput
, sec
, vma
);
4228 vma
+= bfd_section_size (stdoutput
, sec
);
4231 #endif /* OBJ_XCOFF */
4233 /* Turn a string in input_line_pointer into a floating point constant
4234 of type type, and store the appropriate bytes in *litp. The number
4235 of LITTLENUMS emitted is stored in *sizep . An error message is
4236 returned, or NULL on OK. */
4239 md_atof (type
, litp
, sizep
)
4245 LITTLENUM_TYPE words
[4];
4261 return "bad call to md_atof";
4264 t
= atof_ieee (input_line_pointer
, type
, words
);
4266 input_line_pointer
= t
;
4270 if (target_big_endian
)
4272 for (i
= 0; i
< prec
; i
++)
4274 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4280 for (i
= prec
- 1; i
>= 0; i
--)
4282 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4290 /* Write a value out to the object file, using the appropriate
4294 md_number_to_chars (buf
, val
, n
)
4299 if (target_big_endian
)
4300 number_to_chars_bigendian (buf
, val
, n
);
4302 number_to_chars_littleendian (buf
, val
, n
);
4305 /* Align a section (I don't know why this is machine dependent). */
4308 md_section_align (seg
, addr
)
4312 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4314 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4317 /* We don't have any form of relaxing. */
4320 md_estimate_size_before_relax (fragp
, seg
)
4328 /* Convert a machine dependent frag. We never generate these. */
4331 md_convert_frag (abfd
, sec
, fragp
)
4339 /* We have no need to default values of symbols. */
4343 md_undefined_symbol (name
)
4349 /* Functions concerning relocs. */
4351 /* The location from which a PC relative jump should be calculated,
4352 given a PC relative reloc. */
4355 md_pcrel_from_section (fixp
, sec
)
4360 if (fixp
->fx_addsy
!= (symbolS
*) NULL
4361 && (! S_IS_DEFINED (fixp
->fx_addsy
)
4362 || TC_FORCE_RELOCATION_SECTION (fixp
, sec
)))
4366 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4371 /* This is called to see whether a fixup should be adjusted to use a
4372 section symbol. We take the opportunity to change a fixup against
4373 a symbol in the TOC subsegment into a reloc against the
4374 corresponding .tc symbol. */
4377 ppc_fix_adjustable (fix
)
4382 resolve_symbol_value (fix
->fx_addsy
);
4383 val
= S_GET_VALUE (fix
->fx_addsy
);
4384 if (ppc_toc_csect
!= (symbolS
*) NULL
4385 && fix
->fx_addsy
!= (symbolS
*) NULL
4386 && fix
->fx_addsy
!= ppc_toc_csect
4387 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4388 && val
>= ppc_toc_frag
->fr_address
4389 && (ppc_after_toc_frag
== (fragS
*) NULL
4390 || val
< ppc_after_toc_frag
->fr_address
))
4394 for (sy
= symbol_next (ppc_toc_csect
);
4395 sy
!= (symbolS
*) NULL
;
4396 sy
= symbol_next (sy
))
4398 if (sy
->sy_tc
.class == XMC_TC0
)
4400 if (sy
->sy_tc
.class != XMC_TC
)
4402 resolve_symbol_value (sy
);
4403 if (val
== S_GET_VALUE (sy
))
4406 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4411 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4412 "symbol in .toc does not match any .tc");
4415 /* Possibly adjust the reloc to be against the csect. */
4416 if (fix
->fx_addsy
!= (symbolS
*) NULL
4417 && fix
->fx_addsy
->sy_tc
.subseg
== 0
4418 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
4419 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
4420 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
4424 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4425 csect
= ppc_text_csects
;
4426 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4427 csect
= ppc_data_csects
;
4431 /* Skip the initial dummy symbol. */
4432 csect
= csect
->sy_tc
.next
;
4434 if (csect
!= (symbolS
*) NULL
)
4436 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
4437 && (csect
->sy_tc
.next
->sy_frag
->fr_address
4438 <= fix
->fx_addsy
->sy_frag
->fr_address
))
4439 csect
= csect
->sy_tc
.next
;
4441 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4442 - csect
->sy_frag
->fr_address
);
4443 fix
->fx_addsy
= csect
;
4447 /* Adjust a reloc against a .lcomm symbol to be against the base
4449 if (fix
->fx_addsy
!= (symbolS
*) NULL
4450 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4451 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4453 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
4454 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4455 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
4456 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
4462 /* A reloc from one csect to another must be kept. The assembler
4463 will, of course, keep relocs between sections, and it will keep
4464 absolute relocs, but we need to force it to keep PC relative relocs
4465 between two csects in the same section. */
4468 ppc_force_relocation (fix
)
4471 /* At this point fix->fx_addsy should already have been converted to
4472 a csect symbol. If the csect does not include the fragment, then
4473 we need to force the relocation. */
4475 && fix
->fx_addsy
!= NULL
4476 && fix
->fx_addsy
->sy_tc
.subseg
!= 0
4477 && (fix
->fx_addsy
->sy_frag
->fr_address
> fix
->fx_frag
->fr_address
4478 || (fix
->fx_addsy
->sy_tc
.next
!= NULL
4479 && (fix
->fx_addsy
->sy_tc
.next
->sy_frag
->fr_address
4480 <= fix
->fx_frag
->fr_address
))))
4486 #endif /* OBJ_XCOFF */
4488 /* See whether a symbol is in the TOC section. */
4491 ppc_is_toc_sym (sym
)
4495 return sym
->sy_tc
.class == XMC_TC
;
4497 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4501 /* Apply a fixup to the object code. This is called for all the
4502 fixups we generated by the call to fix_new_exp, above. In the call
4503 above we used a reloc code which was the largest legal reloc code
4504 plus the operand index. Here we undo that to recover the operand
4505 index. At this point all symbol values should be fully resolved,
4506 and we attempt to completely resolve the reloc. If we can not do
4507 that, we determine the correct reloc code and put it back in the
4511 md_apply_fix3 (fixp
, valuep
, seg
)
4518 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4519 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4520 doing this relocation the code in write.c is going to call
4521 bfd_perform_relocation, which is also going to use the symbol
4522 value. That means that if the reloc is fully resolved we want to
4523 use *valuep since bfd_perform_relocation is not being used.
4524 However, if the reloc is not fully resolved we do not want to use
4525 *valuep, and must use fx_offset instead. However, if the reloc
4526 is PC relative, we do want to use *valuep since it includes the
4527 result of md_pcrel_from. This is confusing. */
4529 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4534 else if (fixp
->fx_pcrel
)
4538 value
= fixp
->fx_offset
;
4539 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4541 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4542 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4545 /* We can't actually support subtracting a symbol. */
4546 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4547 "expression too complex");
4552 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4555 const struct powerpc_operand
*operand
;
4559 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4561 operand
= &powerpc_operands
[opindex
];
4564 /* It appears that an instruction like
4566 when LC..1 is not a TOC symbol does not generate a reloc. It
4567 uses the offset of LC..1 within its csect. However, .long
4568 LC..1 will generate a reloc. I can't find any documentation
4569 on how these cases are to be distinguished, so this is a wild
4570 guess. These cases are generated by gcc -mminimal-toc. */
4571 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4572 && operand
->bits
== 16
4573 && operand
->shift
== 0
4574 && operand
->insert
== NULL
4575 && fixp
->fx_addsy
!= NULL
4576 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
4577 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
4578 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
4579 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4581 value
= fixp
->fx_offset
;
4586 /* Fetch the instruction, insert the fully resolved operand
4587 value, and stuff the instruction back again. */
4588 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4589 if (target_big_endian
)
4590 insn
= bfd_getb32 ((unsigned char *) where
);
4592 insn
= bfd_getl32 ((unsigned char *) where
);
4593 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4594 fixp
->fx_file
, fixp
->fx_line
);
4595 if (target_big_endian
)
4596 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4598 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4602 /* Nothing else to do here. */
4606 /* Determine a BFD reloc value based on the operand information.
4607 We are only prepared to turn a few of the operands into
4609 FIXME: We need to handle the DS field at the very least.
4610 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4611 there should be a new field in the operand table. */
4612 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4613 && operand
->bits
== 26
4614 && operand
->shift
== 0)
4615 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4616 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4617 && operand
->bits
== 16
4618 && operand
->shift
== 0)
4619 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4620 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4621 && operand
->bits
== 26
4622 && operand
->shift
== 0)
4623 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4624 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4625 && operand
->bits
== 16
4626 && operand
->shift
== 0)
4627 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4628 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4629 && operand
->bits
== 16
4630 && operand
->shift
== 0
4631 && operand
->insert
== NULL
4632 && fixp
->fx_addsy
!= NULL
4633 && ppc_is_toc_sym (fixp
->fx_addsy
))
4636 if (target_big_endian
)
4637 fixp
->fx_where
+= 2;
4638 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4645 /* Use expr_symbol_where to see if this is an expression
4647 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
4648 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4649 "unresolved expression that must be resolved");
4651 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4652 "unsupported relocation type");
4660 ppc_elf_validate_fix (fixp
, seg
);
4662 switch (fixp
->fx_r_type
)
4665 case BFD_RELOC_CTOR
:
4667 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4671 case BFD_RELOC_32_PCREL
:
4672 case BFD_RELOC_32_BASEREL
:
4673 case BFD_RELOC_PPC_EMB_NADDR32
:
4674 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4678 case BFD_RELOC_LO16
:
4679 case BFD_RELOC_HI16
:
4680 case BFD_RELOC_HI16_S
:
4682 case BFD_RELOC_GPREL16
:
4683 case BFD_RELOC_16_GOT_PCREL
:
4684 case BFD_RELOC_16_GOTOFF
:
4685 case BFD_RELOC_LO16_GOTOFF
:
4686 case BFD_RELOC_HI16_GOTOFF
:
4687 case BFD_RELOC_HI16_S_GOTOFF
:
4688 case BFD_RELOC_LO16_BASEREL
:
4689 case BFD_RELOC_HI16_BASEREL
:
4690 case BFD_RELOC_HI16_S_BASEREL
:
4691 case BFD_RELOC_PPC_EMB_NADDR16
:
4692 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
4693 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
4694 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
4695 case BFD_RELOC_PPC_EMB_SDAI16
:
4696 case BFD_RELOC_PPC_EMB_SDA2REL
:
4697 case BFD_RELOC_PPC_EMB_SDA2I16
:
4698 case BFD_RELOC_PPC_EMB_RELSEC16
:
4699 case BFD_RELOC_PPC_EMB_RELST_LO
:
4700 case BFD_RELOC_PPC_EMB_RELST_HI
:
4701 case BFD_RELOC_PPC_EMB_RELST_HA
:
4702 case BFD_RELOC_PPC_EMB_RELSDA
:
4703 case BFD_RELOC_PPC_TOC16
:
4705 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4706 "cannot emit PC relative %s relocation%s%s",
4707 bfd_get_reloc_code_name (fixp
->fx_r_type
),
4708 fixp
->fx_addsy
!= NULL
? " against " : "",
4709 (fixp
->fx_addsy
!= NULL
4710 ? S_GET_NAME (fixp
->fx_addsy
)
4713 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4717 /* Because SDA21 modifies the register field, the size is set to 4
4718 bytes, rather than 2, so offset it here appropriately */
4719 case BFD_RELOC_PPC_EMB_SDA21
:
4723 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
4724 + ((target_big_endian
) ? 2 : 0),
4732 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4736 case BFD_RELOC_PPC_LOCAL24PC
:
4737 if (!fixp
->fx_pcrel
)
4744 "Gas failure, reloc value %d\n", fixp
->fx_r_type
);
4751 fixp
->fx_addnumber
= value
;
4753 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4754 fixp
->fx_addnumber
= 0;
4758 fixp
->fx_addnumber
= 0;
4760 /* We want to use the offset within the data segment of the
4761 symbol, not the actual VMA of the symbol. */
4762 fixp
->fx_addnumber
=
4763 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4771 /* Generate a reloc for a fixup. */
4774 tc_gen_reloc (seg
, fixp
)
4780 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4782 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4783 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4784 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4785 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4787 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4788 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4791 reloc
->addend
= fixp
->fx_addnumber
;