1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/ppc.h"
37 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
39 /* Tell the main code what the endianness is. */
40 extern int target_big_endian
;
42 /* Whether or not, we've set target_big_endian. */
43 static int set_target_endian
= 0;
45 /* Whether to use user friendly register names. */
46 #ifndef TARGET_REG_NAMES_P
48 #define TARGET_REG_NAMES_P true
50 #define TARGET_REG_NAMES_P false
54 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
56 static void ppc_set_cpu
PARAMS ((void));
57 static unsigned long ppc_insert_operand
58 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
59 offsetT val
, char *file
, unsigned int line
));
60 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
61 static void ppc_byte
PARAMS ((int));
62 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
63 static void ppc_tc
PARAMS ((int));
66 static void ppc_comm
PARAMS ((int));
67 static void ppc_bb
PARAMS ((int));
68 static void ppc_bc
PARAMS ((int));
69 static void ppc_bf
PARAMS ((int));
70 static void ppc_biei
PARAMS ((int));
71 static void ppc_bs
PARAMS ((int));
72 static void ppc_eb
PARAMS ((int));
73 static void ppc_ec
PARAMS ((int));
74 static void ppc_ef
PARAMS ((int));
75 static void ppc_es
PARAMS ((int));
76 static void ppc_csect
PARAMS ((int));
77 static void ppc_change_csect
PARAMS ((symbolS
*));
78 static void ppc_function
PARAMS ((int));
79 static void ppc_extern
PARAMS ((int));
80 static void ppc_lglobl
PARAMS ((int));
81 static void ppc_section
PARAMS ((int));
82 static void ppc_stabx
PARAMS ((int));
83 static void ppc_rename
PARAMS ((int));
84 static void ppc_toc
PARAMS ((int));
88 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
89 static void ppc_elf_cons
PARAMS ((int));
90 static void ppc_elf_rdata
PARAMS ((int));
91 static void ppc_elf_lcomm
PARAMS ((int));
92 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
96 static void ppc_set_current_section
PARAMS ((segT
));
97 static void ppc_previous
PARAMS ((int));
98 static void ppc_pdata
PARAMS ((int));
99 static void ppc_ydata
PARAMS ((int));
100 static void ppc_reldata
PARAMS ((int));
101 static void ppc_rdata
PARAMS ((int));
102 static void ppc_ualong
PARAMS ((int));
103 static void ppc_znop
PARAMS ((int));
104 static void ppc_pe_comm
PARAMS ((int));
105 static void ppc_pe_section
PARAMS ((int));
106 static void ppc_pe_function
PARAMS ((int));
107 static void ppc_pe_tocd
PARAMS ((int));
110 /* Generic assembler global variables which must be defined by all
113 /* 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 /* Whether to warn about non PC relative relocations that aren't
588 in the .got2 section. */
589 static boolean mrelocatable
= false;
591 /* Flags to set in the elf header */
592 static flagword ppc_flags
= 0;
594 /* Whether this is Solaris or not. */
595 #ifdef TARGET_SOLARIS_COMMENT
596 #define SOLARIS_P true
598 #define SOLARIS_P false
601 static boolean msolaris
= SOLARIS_P
;
606 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
607 using a bunch of different sections. These assembler sections,
608 however, are all encompassed within the .text or .data sections of
609 the final output file. We handle this by using different
610 subsegments within these main segments. */
612 /* Next subsegment to allocate within the .text segment. */
613 static subsegT ppc_text_subsegment
= 2;
615 /* Linked list of csects in the text section. */
616 static symbolS
*ppc_text_csects
;
618 /* Next subsegment to allocate within the .data segment. */
619 static subsegT ppc_data_subsegment
= 2;
621 /* Linked list of csects in the data section. */
622 static symbolS
*ppc_data_csects
;
624 /* The current csect. */
625 static symbolS
*ppc_current_csect
;
627 /* The RS/6000 assembler uses a TOC which holds addresses of functions
628 and variables. Symbols are put in the TOC with the .tc pseudo-op.
629 A special relocation is used when accessing TOC entries. We handle
630 the TOC as a subsegment within the .data segment. We set it up if
631 we see a .toc pseudo-op, and save the csect symbol here. */
632 static symbolS
*ppc_toc_csect
;
634 /* The first frag in the TOC subsegment. */
635 static fragS
*ppc_toc_frag
;
637 /* The first frag in the first subsegment after the TOC in the .data
638 segment. NULL if there are no subsegments after the TOC. */
639 static fragS
*ppc_after_toc_frag
;
641 /* The current static block. */
642 static symbolS
*ppc_current_block
;
644 /* The COFF debugging section; set by md_begin. This is not the
645 .debug section, but is instead the secret BFD section which will
646 cause BFD to set the section number of a symbol to N_DEBUG. */
647 static asection
*ppc_coff_debug_section
;
649 #endif /* OBJ_XCOFF */
653 /* Various sections that we need for PE coff support. */
654 static segT ydata_section
;
655 static segT pdata_section
;
656 static segT reldata_section
;
657 static segT rdata_section
;
658 static segT tocdata_section
;
660 /* The current section and the previous section. See ppc_previous. */
661 static segT ppc_previous_section
;
662 static segT ppc_current_section
;
667 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
670 #ifndef WORKING_DOT_WORD
671 const int md_short_jump_size
= 4;
672 const int md_long_jump_size
= 4;
676 CONST
char *md_shortopts
= "b:l:usm:K:VQ:";
678 CONST
char *md_shortopts
= "um:";
680 struct option md_longopts
[] = {
681 {NULL
, no_argument
, NULL
, 0}
683 size_t md_longopts_size
= sizeof(md_longopts
);
686 md_parse_option (c
, arg
)
693 /* -u means that any undefined symbols should be treated as
694 external, which is the default for gas anyhow. */
699 /* Solaris as takes -le (presumably for little endian). For completeness
700 sake, recognize -be also. */
701 if (strcmp (arg
, "e") == 0)
703 target_big_endian
= 0;
704 set_target_endian
= 1;
712 if (strcmp (arg
, "e") == 0)
714 target_big_endian
= 1;
715 set_target_endian
= 1;
723 /* Recognize -K PIC */
724 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
727 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
736 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
738 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
739 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
740 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
741 else if (strcmp (arg
, "pwr") == 0)
742 ppc_cpu
= PPC_OPCODE_POWER
;
743 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
744 instructions that are holdovers from the Power. */
745 else if (strcmp (arg
, "601") == 0)
746 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
747 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
748 Motorola PowerPC 603/604. */
749 else if (strcmp (arg
, "ppc") == 0
750 || strcmp (arg
, "ppc32") == 0
751 || strcmp (arg
, "403") == 0
752 || strcmp (arg
, "603") == 0
753 || strcmp (arg
, "604") == 0)
754 ppc_cpu
= PPC_OPCODE_PPC
;
755 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
757 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
759 ppc_cpu
= PPC_OPCODE_PPC
;
760 ppc_size
= PPC_OPCODE_64
;
762 /* -mcom means assemble for the common intersection between Power
763 and PowerPC. At present, we just allow the union, rather
764 than the intersection. */
765 else if (strcmp (arg
, "com") == 0)
766 ppc_cpu
= PPC_OPCODE_COMMON
;
767 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
768 else if (strcmp (arg
, "any") == 0)
769 ppc_cpu
= PPC_OPCODE_ANY
;
771 else if (strcmp (arg
, "regnames") == 0)
774 else if (strcmp (arg
, "no-regnames") == 0)
778 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
779 else if (strcmp (arg
, "relocatable") == 0)
782 ppc_flags
|= EF_PPC_RELOCATABLE
;
785 else if (strcmp (arg
, "relocatable-lib") == 0)
788 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
791 /* -memb, set embedded bit */
792 else if (strcmp (arg
, "emb") == 0)
793 ppc_flags
|= EF_PPC_EMB
;
795 /* -mlittle/-mbig set the endianess */
796 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
798 target_big_endian
= 0;
799 set_target_endian
= 1;
802 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
804 target_big_endian
= 1;
805 set_target_endian
= 1;
808 else if (strcmp (arg
, "solaris") == 0)
811 ppc_comment_chars
= ppc_solaris_comment_chars
;
814 else if (strcmp (arg
, "no-solaris") == 0)
817 ppc_comment_chars
= ppc_eabi_comment_chars
;
822 as_bad ("invalid switch -m%s", arg
);
828 /* -V: SVR4 argument to print version ID. */
833 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
834 should be emitted or not. FIXME: Not implemented. */
838 /* Solaris takes -s to specify that .stabs go in a .stabs section,
839 rather than .stabs.excl, which is ignored by the linker.
840 FIXME: Not implemented. */
856 md_show_usage (stream
)
862 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
863 -mpwr generate code for IBM POWER (RIOS1)\n\
864 -m601 generate code for Motorola PowerPC 601\n\
865 -mppc, -mppc32, -m403, -m603, -m604\n\
866 generate code for Motorola PowerPC 603/604\n\
867 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
868 -mcom generate code Power/PowerPC common instructions\n\
869 -many generate code for any architecture (PWR/PWRX/PPC)\n\
870 -mregnames Allow symbolic names for registers\n\
871 -mno-regnames Do not allow symbolic names for registers\n");
874 -mrelocatable support for GCC's -mrelocatble option\n\
875 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
876 -memb set PPC_EMB bit in ELF flags\n\
877 -mlittle, -mlittle-endian\n\
878 generate code for a little endian machine\n\
879 -mbig, -mbig-endian generate code for a big endian machine\n\
880 -msolaris generate code for Solaris\n\
881 -mno-solaris do not generate code for Solaris\n\
882 -V print assembler version number\n\
883 -Qy, -Qn ignored\n");
887 /* Set ppc_cpu if it is not already set. */
892 const char *default_os
= TARGET_OS
;
893 const char *default_cpu
= TARGET_CPU
;
897 if (strncmp (default_os
, "aix", 3) == 0
898 && default_os
[3] >= '4' && default_os
[3] <= '9')
899 ppc_cpu
= PPC_OPCODE_COMMON
;
900 else if (strncmp (default_os
, "aix3", 4) == 0)
901 ppc_cpu
= PPC_OPCODE_POWER
;
902 else if (strcmp (default_cpu
, "rs6000") == 0)
903 ppc_cpu
= PPC_OPCODE_POWER
;
904 else if (strcmp (default_cpu
, "powerpc") == 0
905 || strcmp (default_cpu
, "powerpcle") == 0)
906 ppc_cpu
= PPC_OPCODE_PPC
;
908 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu
, default_os
);
912 /* Figure out the BFD architecture to use. */
914 enum bfd_architecture
917 const char *default_cpu
= TARGET_CPU
;
920 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
921 return bfd_arch_powerpc
;
922 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
923 return bfd_arch_rs6000
;
924 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
926 if (strcmp (default_cpu
, "rs6000") == 0)
927 return bfd_arch_rs6000
;
928 else if (strcmp (default_cpu
, "powerpc") == 0
929 || strcmp (default_cpu
, "powerpcle") == 0)
930 return bfd_arch_powerpc
;
933 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
934 return bfd_arch_unknown
;
937 /* This function is called when the assembler starts up. It is called
938 after the options have been parsed and the output file has been
944 register const struct powerpc_opcode
*op
;
945 const struct powerpc_opcode
*op_end
;
946 const struct powerpc_macro
*macro
;
947 const struct powerpc_macro
*macro_end
;
948 boolean dup_insn
= false;
953 /* Set the ELF flags if desired. */
954 if (ppc_flags
&& !msolaris
)
955 bfd_set_private_flags (stdoutput
, ppc_flags
);
958 /* Insert the opcodes into a hash table. */
959 ppc_hash
= hash_new ();
961 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
962 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
964 know ((op
->opcode
& op
->mask
) == op
->opcode
);
966 if ((op
->flags
& ppc_cpu
) != 0
967 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
968 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
972 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
973 if (retval
!= (const char *) NULL
)
975 /* Ignore Power duplicates for -m601 */
976 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
977 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
980 as_bad ("Internal assembler error for instruction %s", op
->name
);
986 /* Insert the macros into a hash table. */
987 ppc_macro_hash
= hash_new ();
989 macro_end
= powerpc_macros
+ powerpc_num_macros
;
990 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
992 if ((macro
->flags
& ppc_cpu
) != 0)
996 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
997 if (retval
!= (const char *) NULL
)
999 as_bad ("Internal assembler error for macro %s", macro
->name
);
1008 /* Tell the main code what the endianness is if it is not overidden by the user. */
1009 if (!set_target_endian
)
1011 set_target_endian
= 1;
1012 target_big_endian
= PPC_BIG_ENDIAN
;
1016 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1018 /* Create dummy symbols to serve as initial csects. This forces the
1019 text csects to precede the data csects. These symbols will not
1021 ppc_text_csects
= symbol_make ("dummy\001");
1022 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
1023 ppc_data_csects
= symbol_make ("dummy\001");
1024 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
1029 ppc_current_section
= text_section
;
1030 ppc_previous_section
= 0;
1035 /* Insert an operand value into an instruction. */
1037 static unsigned long
1038 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1040 const struct powerpc_operand
*operand
;
1045 if (operand
->bits
!= 32)
1050 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1052 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
1053 && ppc_size
== PPC_OPCODE_32
)
1054 max
= (1 << operand
->bits
) - 1;
1056 max
= (1 << (operand
->bits
- 1)) - 1;
1057 min
= - (1 << (operand
->bits
- 1));
1061 max
= (1 << operand
->bits
) - 1;
1065 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1070 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1073 "operand out of range (%s not between %ld and %ld)";
1076 sprint_value (buf
, test
);
1077 if (file
== (char *) NULL
)
1078 as_bad (err
, buf
, min
, max
);
1080 as_bad_where (file
, line
, err
, buf
, min
, max
);
1084 if (operand
->insert
)
1089 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
1090 if (errmsg
!= (const char *) NULL
)
1094 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1102 /* Parse @got, etc. and return the desired relocation. */
1103 static bfd_reloc_code_real_type
1104 ppc_elf_suffix (str_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)
1191 return BFD_RELOC_UNUSED
;
1194 /* Like normal .long/.short/.word, except support @got, etc. */
1195 /* clobbers input_line_pointer, checks */
1198 ppc_elf_cons (nbytes
)
1199 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1202 bfd_reloc_code_real_type reloc
;
1204 if (is_it_end_of_statement ())
1206 demand_empty_rest_of_line ();
1213 if (exp
.X_op
== O_symbol
1214 && *input_line_pointer
== '@'
1215 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
1217 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1218 int size
= bfd_get_reloc_size (reloc_howto
);
1221 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
1225 register char *p
= frag_more ((int) nbytes
);
1226 int offset
= nbytes
- size
;
1228 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1232 emit_expr (&exp
, (unsigned int) nbytes
);
1234 while (*input_line_pointer
++ == ',');
1236 input_line_pointer
--; /* Put terminator back into stream. */
1237 demand_empty_rest_of_line ();
1240 /* Solaris pseduo op to change to the .rodata section. */
1245 char *save_line
= input_line_pointer
;
1246 static char section
[] = ".rodata\n";
1248 /* Just pretend this is .section .rodata */
1249 input_line_pointer
= section
;
1250 obj_elf_section (xxx
);
1252 input_line_pointer
= save_line
;
1255 /* Pseudo op to make file scope bss items */
1260 register char *name
;
1264 register symbolS
*symbolP
;
1271 name
= input_line_pointer
;
1272 c
= get_symbol_end ();
1274 /* just after name is now '\0' */
1275 p
= input_line_pointer
;
1278 if (*input_line_pointer
!= ',')
1280 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1281 ignore_rest_of_line ();
1285 input_line_pointer
++; /* skip ',' */
1286 if ((size
= get_absolute_expression ()) < 0)
1288 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size
);
1289 ignore_rest_of_line ();
1293 /* The third argument to .lcomm is the alignment. */
1294 if (*input_line_pointer
!= ',')
1298 ++input_line_pointer
;
1299 align
= get_absolute_expression ();
1302 as_warn ("ignoring bad alignment");
1308 symbolP
= symbol_find_or_make (name
);
1311 if (S_IS_DEFINED (symbolP
))
1313 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1314 S_GET_NAME (symbolP
));
1315 ignore_rest_of_line ();
1319 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1321 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1322 S_GET_NAME (symbolP
),
1323 (long) S_GET_VALUE (symbolP
),
1326 ignore_rest_of_line ();
1332 old_subsec
= now_subseg
;
1335 /* convert to a power of 2 alignment */
1336 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1339 as_bad ("Common alignment not a power of 2");
1340 ignore_rest_of_line ();
1347 record_alignment (bss_section
, align2
);
1348 subseg_set (bss_section
, 0);
1350 frag_align (align2
, 0);
1351 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1352 symbolP
->sy_frag
->fr_symbol
= 0;
1353 symbolP
->sy_frag
= frag_now
;
1354 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1357 S_SET_SIZE (symbolP
, size
);
1358 S_SET_SEGMENT (symbolP
, bss_section
);
1359 S_CLEAR_EXTERNAL (symbolP
);
1360 subseg_set (old_sec
, old_subsec
);
1361 demand_empty_rest_of_line ();
1364 /* Validate any relocations emitted for -mrelocatable, possibly adding
1365 fixups for word relocations in writable segments, so we can adjust
1368 ppc_elf_validate_fix (fixp
, seg
)
1375 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1376 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1377 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1378 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1379 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1380 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1381 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1382 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1383 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1384 && strcmp (segment_name (seg
), ".got2") != 0
1385 && strcmp (segment_name (seg
), ".dtors") != 0
1386 && strcmp (segment_name (seg
), ".ctors") != 0
1387 && strcmp (segment_name (seg
), ".fixup") != 0
1388 && strcmp (segment_name (seg
), ".stab") != 0
1389 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1390 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1392 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1393 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1395 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1396 "Relocation cannot be done when using -mrelocatable");
1400 #endif /* OBJ_ELF */
1405 * Summary of parse_toc_entry().
1407 * in: Input_line_pointer points to the '[' in one of:
1409 * [toc] [tocv] [toc32] [toc64]
1411 * Anything else is an error of one kind or another.
1414 * return value: success or failure
1415 * toc_kind: kind of toc reference
1416 * input_line_pointer:
1417 * success: first char after the ']'
1418 * failure: unchanged
1422 * [toc] - rv == success, toc_kind = default_toc
1423 * [tocv] - rv == success, toc_kind = data_in_toc
1424 * [toc32] - rv == success, toc_kind = must_be_32
1425 * [toc64] - rv == success, toc_kind = must_be_64
1429 enum toc_size_qualifier
1431 default_toc
, /* The toc cell constructed should be the system default size */
1432 data_in_toc
, /* This is a direct reference to a toc cell */
1433 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1434 must_be_64
/* The toc cell constructed must be 64 bits wide */
1438 parse_toc_entry(toc_kind
)
1439 enum toc_size_qualifier
*toc_kind
;
1444 enum toc_size_qualifier t
;
1446 /* save the input_line_pointer */
1447 start
= input_line_pointer
;
1449 /* skip over the '[' , and whitespace */
1450 ++input_line_pointer
;
1453 /* find the spelling of the operand */
1454 toc_spec
= input_line_pointer
;
1455 c
= get_symbol_end ();
1457 if (strcmp(toc_spec
, "toc") == 0)
1461 else if (strcmp(toc_spec
, "tocv") == 0)
1465 else if (strcmp(toc_spec
, "toc32") == 0)
1469 else if (strcmp(toc_spec
, "toc64") == 0)
1475 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1476 *input_line_pointer
= c
; /* put back the delimiting char */
1477 input_line_pointer
= start
; /* reset input_line pointer */
1481 /* now find the ']' */
1482 *input_line_pointer
= c
; /* put back the delimiting char */
1484 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1485 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1489 as_bad ("syntax error: expected `]', found `%c'", c
);
1490 input_line_pointer
= start
; /* reset input_line pointer */
1494 *toc_kind
= t
; /* set return value */
1500 /* We need to keep a list of fixups. We can't simply generate them as
1501 we go, because that would require us to first create the frag, and
1502 that would screw up references to ``.''. */
1508 bfd_reloc_code_real_type reloc
;
1511 #define MAX_INSN_FIXUPS (5)
1513 /* This routine is called for each instruction to be assembled. */
1520 const struct powerpc_opcode
*opcode
;
1522 const unsigned char *opindex_ptr
;
1526 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1531 bfd_reloc_code_real_type reloc
;
1534 /* Get the opcode. */
1535 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1540 /* Look up the opcode in the hash table. */
1541 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1542 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1544 const struct powerpc_macro
*macro
;
1546 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1547 if (macro
== (const struct powerpc_macro
*) NULL
)
1548 as_bad ("Unrecognized opcode: `%s'", str
);
1550 ppc_macro (s
, macro
);
1555 insn
= opcode
->opcode
;
1558 while (isspace (*str
))
1561 /* PowerPC operands are just expressions. The only real issue is
1562 that a few operand types are optional. All cases which might use
1563 an optional operand separate the operands only with commas (in
1564 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1565 cases never have optional operands). There is never more than
1566 one optional operand for an instruction. So, before we start
1567 seriously parsing the operands, we check to see if we have an
1568 optional operand, and, if we do, we count the number of commas to
1569 see whether the operand should be omitted. */
1571 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1573 const struct powerpc_operand
*operand
;
1575 operand
= &powerpc_operands
[*opindex_ptr
];
1576 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1578 unsigned int opcount
;
1580 /* There is an optional operand. Count the number of
1581 commas in the input line. */
1588 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1595 /* If there are fewer operands in the line then are called
1596 for by the instruction, we want to skip the optional
1598 if (opcount
< strlen (opcode
->operands
))
1605 /* Gather the operands. */
1609 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1611 const struct powerpc_operand
*operand
;
1617 if (next_opindex
== 0)
1618 operand
= &powerpc_operands
[*opindex_ptr
];
1621 operand
= &powerpc_operands
[next_opindex
];
1627 /* If this is a fake operand, then we do not expect anything
1629 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1631 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1632 if (errmsg
!= (const char *) NULL
)
1637 /* If this is an optional operand, and we are skipping it, just
1639 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1642 if (operand
->insert
)
1644 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1645 if (errmsg
!= (const char *) NULL
)
1648 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1649 next_opindex
= *opindex_ptr
+ 1;
1653 /* Gather the operand. */
1654 hold
= input_line_pointer
;
1655 input_line_pointer
= str
;
1658 if (*input_line_pointer
== '[')
1660 /* We are expecting something like the second argument here:
1662 lwz r4,[toc].GS.0.static_int(rtoc)
1663 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1664 The argument following the `]' must be a symbol name, and the
1665 register must be the toc register: 'rtoc' or '2'
1667 The effect is to 0 as the displacement field
1668 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1669 the appropriate variation) reloc against it based on the symbol.
1670 The linker will build the toc, and insert the resolved toc offset.
1673 o The size of the toc entry is currently assumed to be
1674 32 bits. This should not be assumed to be a hard coded
1676 o In an effort to cope with a change from 32 to 64 bits,
1677 there are also toc entries that are specified to be
1678 either 32 or 64 bits:
1679 lwz r4,[toc32].GS.0.static_int(rtoc)
1680 lwz r4,[toc64].GS.0.static_int(rtoc)
1681 These demand toc entries of the specified size, and the
1682 instruction probably requires it.
1686 enum toc_size_qualifier toc_kind
;
1687 bfd_reloc_code_real_type toc_reloc
;
1689 /* go parse off the [tocXX] part */
1690 valid_toc
= parse_toc_entry(&toc_kind
);
1694 /* Note: message has already been issued. */
1695 /* FIXME: what sort of recovery should we do? */
1696 /* demand_rest_of_line(); return; ? */
1699 /* Now get the symbol following the ']' */
1705 /* In this case, we may not have seen the symbol yet, since */
1706 /* it is allowed to appear on a .extern or .globl or just be */
1707 /* a label in the .data section. */
1708 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1711 /* 1. The symbol must be defined and either in the toc */
1712 /* section, or a global. */
1713 /* 2. The reloc generated must have the TOCDEFN flag set in */
1714 /* upper bit mess of the reloc type. */
1715 /* FIXME: It's a little confusing what the tocv qualifier can */
1716 /* be used for. At the very least, I've seen three */
1717 /* uses, only one of which I'm sure I can explain. */
1718 if (ex
.X_op
== O_symbol
)
1720 assert (ex
.X_add_symbol
!= NULL
);
1721 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1723 as_bad("[tocv] symbol is not a toc symbol");
1727 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1730 /* FIXME: these next two specifically specify 32/64 bit toc */
1731 /* entries. We don't support them today. Is this the */
1732 /* right way to say that? */
1733 toc_reloc
= BFD_RELOC_UNUSED
;
1734 as_bad ("Unimplemented toc32 expression modifier");
1737 /* FIXME: see above */
1738 toc_reloc
= BFD_RELOC_UNUSED
;
1739 as_bad ("Unimplemented toc64 expression modifier");
1743 "Unexpected return value [%d] from parse_toc_entry!\n",
1749 /* We need to generate a fixup for this expression. */
1750 if (fc
>= MAX_INSN_FIXUPS
)
1751 as_fatal ("too many fixups");
1753 fixups
[fc
].reloc
= toc_reloc
;
1754 fixups
[fc
].exp
= ex
;
1755 fixups
[fc
].opindex
= *opindex_ptr
;
1758 /* Ok. We've set up the fixup for the instruction. Now make it
1759 look like the constant 0 was found here */
1761 ex
.X_op
= O_constant
;
1762 ex
.X_add_number
= 0;
1763 ex
.X_add_symbol
= NULL
;
1764 ex
.X_op_symbol
= NULL
;
1770 if (! register_name (&ex
))
1772 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
1779 str
= input_line_pointer
;
1780 input_line_pointer
= hold
;
1782 if (ex
.X_op
== O_illegal
)
1783 as_bad ("illegal operand");
1784 else if (ex
.X_op
== O_absent
)
1785 as_bad ("missing operand");
1786 else if (ex
.X_op
== O_register
)
1788 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1791 else if (ex
.X_op
== O_constant
)
1794 /* Allow @HA, @L, @H on constants. */
1795 char *orig_str
= str
;
1797 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1804 case BFD_RELOC_LO16
:
1806 ex
.X_add_number
&= 0xffff;
1808 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
1813 case BFD_RELOC_HI16
:
1814 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1817 case BFD_RELOC_HI16_S
:
1818 ex
.X_add_number
= (((ex
.X_add_number
>> 16) & 0xffff)
1819 + ((ex
.X_add_number
>> 15) & 1));
1823 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1827 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1829 /* For the absoulte forms of branchs, convert the PC relative form back into
1831 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1835 case BFD_RELOC_PPC_B26
:
1836 reloc
= BFD_RELOC_PPC_BA26
;
1838 case BFD_RELOC_PPC_B16
:
1839 reloc
= BFD_RELOC_PPC_BA16
;
1841 case BFD_RELOC_PPC_B16_BRTAKEN
:
1842 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
1844 case BFD_RELOC_PPC_B16_BRNTAKEN
:
1845 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
1852 /* We need to generate a fixup for this expression. */
1853 if (fc
>= MAX_INSN_FIXUPS
)
1854 as_fatal ("too many fixups");
1855 fixups
[fc
].exp
= ex
;
1856 fixups
[fc
].opindex
= 0;
1857 fixups
[fc
].reloc
= reloc
;
1860 #endif /* OBJ_ELF */
1864 /* We need to generate a fixup for this expression. */
1865 if (fc
>= MAX_INSN_FIXUPS
)
1866 as_fatal ("too many fixups");
1867 fixups
[fc
].exp
= ex
;
1868 fixups
[fc
].opindex
= *opindex_ptr
;
1869 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1878 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1886 /* The call to expression should have advanced str past any
1889 && (endc
!= ',' || *str
!= '\0'))
1891 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1899 while (isspace (*str
))
1903 as_bad ("junk at end of line: `%s'", str
);
1905 /* Write out the instruction. */
1907 md_number_to_chars (f
, insn
, 4);
1909 /* Create any fixups. At this point we do not use a
1910 bfd_reloc_code_real_type, but instead just use the
1911 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1912 handle fixups for any operand type, although that is admittedly
1913 not a very exciting feature. We pick a BFD reloc type in
1915 for (i
= 0; i
< fc
; i
++)
1917 const struct powerpc_operand
*operand
;
1919 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1920 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1922 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1930 size
= bfd_get_reloc_size (reloc_howto
);
1931 offset
= target_big_endian
? (4 - size
) : 0;
1933 if (size
< 1 || size
> 4)
1936 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1937 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1940 /* Turn off complaints that the addend is too large for things like
1942 switch (fixups
[i
].reloc
)
1944 case BFD_RELOC_16_GOTOFF
:
1945 case BFD_RELOC_PPC_TOC16
:
1946 case BFD_RELOC_LO16
:
1947 case BFD_RELOC_HI16
:
1948 case BFD_RELOC_HI16_S
:
1949 fixP
->fx_no_overflow
= 1;
1956 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1958 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1959 ((bfd_reloc_code_real_type
)
1960 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1964 #ifndef WORKING_DOT_WORD
1965 /* Handle long and short jumps */
1967 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1969 addressT from_addr
, to_addr
;
1977 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1979 addressT from_addr
, to_addr
;
1987 /* Handle a macro. Gather all the operands, transform them as
1988 described by the macro, and call md_assemble recursively. All the
1989 operands are separated by commas; we don't accept parentheses
1990 around operands here. */
1993 ppc_macro (str
, macro
)
1995 const struct powerpc_macro
*macro
;
2006 /* Gather the users operands into the operands array. */
2011 if (count
>= sizeof operands
/ sizeof operands
[0])
2013 operands
[count
++] = s
;
2014 s
= strchr (s
, ',');
2015 if (s
== (char *) NULL
)
2020 if (count
!= macro
->operands
)
2022 as_bad ("wrong number of operands");
2026 /* Work out how large the string must be (the size is unbounded
2027 because it includes user input). */
2029 format
= macro
->format
;
2030 while (*format
!= '\0')
2039 arg
= strtol (format
+ 1, &send
, 10);
2040 know (send
!= format
&& arg
>= 0 && arg
< count
);
2041 len
+= strlen (operands
[arg
]);
2046 /* Put the string together. */
2047 complete
= s
= (char *) alloca (len
+ 1);
2048 format
= macro
->format
;
2049 while (*format
!= '\0')
2055 arg
= strtol (format
+ 1, &send
, 10);
2056 strcpy (s
, operands
[arg
]);
2063 /* Assemble the constructed instruction. */
2064 md_assemble (complete
);
2068 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2071 ppc_section_letter (letter
, ptr_msg
)
2078 *ptr_msg
= "Bad .section directive: want a,w,x,e in string";
2083 ppc_section_word (ptr_str
)
2086 if (strncmp (*ptr_str
, "exclude", sizeof ("exclude")-1) == 0)
2088 *ptr_str
+= sizeof ("exclude")-1;
2096 ppc_section_type (ptr_str
)
2099 if (strncmp (*ptr_str
, "ordered", sizeof ("ordered")-1) == 0)
2101 *ptr_str
+= sizeof ("ordered")-1;
2109 ppc_section_flags (flags
, attr
, type
)
2114 if (type
== SHT_ORDERED
)
2115 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2117 if (attr
& SHF_EXCLUDE
)
2118 flags
|= SEC_EXCLUDE
;
2122 #endif /* OBJ_ELF */
2125 /* Pseudo-op handling. */
2127 /* The .byte pseudo-op. This is similar to the normal .byte
2128 pseudo-op, but it can also take a single ASCII string. */
2134 if (*input_line_pointer
!= '\"')
2140 /* Gather characters. A real double quote is doubled. Unusual
2141 characters are not permitted. */
2142 ++input_line_pointer
;
2147 c
= *input_line_pointer
++;
2151 if (*input_line_pointer
!= '\"')
2153 ++input_line_pointer
;
2156 FRAG_APPEND_1_CHAR (c
);
2159 demand_empty_rest_of_line ();
2164 /* XCOFF specific pseudo-op handling. */
2166 /* This is set if we are creating a .stabx symbol, since we don't want
2167 to handle symbol suffixes for such symbols. */
2168 static boolean ppc_stab_symbol
;
2170 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2171 symbols in the .bss segment as though they were local common
2172 symbols, and uses a different smclas. */
2178 asection
*current_seg
= now_seg
;
2179 subsegT current_subseg
= now_subseg
;
2185 symbolS
*lcomm_sym
= NULL
;
2189 name
= input_line_pointer
;
2190 endc
= get_symbol_end ();
2191 end_name
= input_line_pointer
;
2194 if (*input_line_pointer
!= ',')
2196 as_bad ("missing size");
2197 ignore_rest_of_line ();
2200 ++input_line_pointer
;
2202 size
= get_absolute_expression ();
2205 as_bad ("negative size");
2206 ignore_rest_of_line ();
2212 /* The third argument to .comm is the alignment. */
2213 if (*input_line_pointer
!= ',')
2217 ++input_line_pointer
;
2218 align
= get_absolute_expression ();
2221 as_warn ("ignoring bad alignment");
2240 /* The third argument to .lcomm appears to be the real local
2241 common symbol to create. References to the symbol named in
2242 the first argument are turned into references to the third
2244 if (*input_line_pointer
!= ',')
2246 as_bad ("missing real symbol name");
2247 ignore_rest_of_line ();
2250 ++input_line_pointer
;
2252 lcomm_name
= input_line_pointer
;
2253 lcomm_endc
= get_symbol_end ();
2255 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2257 *input_line_pointer
= lcomm_endc
;
2261 sym
= symbol_find_or_make (name
);
2264 if (S_IS_DEFINED (sym
)
2265 || S_GET_VALUE (sym
) != 0)
2267 as_bad ("attempt to redefine symbol");
2268 ignore_rest_of_line ();
2272 record_alignment (bss_section
, align
);
2275 || ! S_IS_DEFINED (lcomm_sym
))
2284 S_SET_EXTERNAL (sym
);
2288 lcomm_sym
->sy_tc
.output
= 1;
2289 def_sym
= lcomm_sym
;
2293 subseg_set (bss_section
, 1);
2294 frag_align (align
, 0);
2296 def_sym
->sy_frag
= frag_now
;
2297 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2298 def_size
, (char *) NULL
);
2300 S_SET_SEGMENT (def_sym
, bss_section
);
2301 def_sym
->sy_tc
.align
= align
;
2305 /* Align the size of lcomm_sym. */
2306 lcomm_sym
->sy_frag
->fr_offset
=
2307 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
2308 &~ ((1 << align
) - 1));
2309 if (align
> lcomm_sym
->sy_tc
.align
)
2310 lcomm_sym
->sy_tc
.align
= align
;
2315 /* Make sym an offset from lcomm_sym. */
2316 S_SET_SEGMENT (sym
, bss_section
);
2317 sym
->sy_frag
= lcomm_sym
->sy_frag
;
2318 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
2319 lcomm_sym
->sy_frag
->fr_offset
+= size
;
2322 subseg_set (current_seg
, current_subseg
);
2324 demand_empty_rest_of_line ();
2327 /* The .csect pseudo-op. This switches us into a different
2328 subsegment. The first argument is a symbol whose value is the
2329 start of the .csect. In COFF, csect symbols get special aux
2330 entries defined by the x_csect field of union internal_auxent. The
2331 optional second argument is the alignment (the default is 2). */
2341 name
= input_line_pointer
;
2342 endc
= get_symbol_end ();
2344 sym
= symbol_find_or_make (name
);
2346 *input_line_pointer
= endc
;
2348 if (S_GET_NAME (sym
)[0] == '\0')
2350 /* An unnamed csect is assumed to be [PR]. */
2351 sym
->sy_tc
.class = XMC_PR
;
2354 ppc_change_csect (sym
);
2356 if (*input_line_pointer
== ',')
2358 ++input_line_pointer
;
2359 sym
->sy_tc
.align
= get_absolute_expression ();
2362 demand_empty_rest_of_line ();
2365 /* Change to a different csect. */
2368 ppc_change_csect (sym
)
2371 if (S_IS_DEFINED (sym
))
2372 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
2379 /* This is a new csect. We need to look at the symbol class to
2380 figure out whether it should go in the text section or the
2383 switch (sym
->sy_tc
.class)
2393 S_SET_SEGMENT (sym
, text_section
);
2394 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
2395 ++ppc_text_subsegment
;
2396 list_ptr
= &ppc_text_csects
;
2405 if (ppc_toc_csect
!= NULL
2406 && ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
2408 S_SET_SEGMENT (sym
, data_section
);
2409 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
2410 ++ppc_data_subsegment
;
2411 list_ptr
= &ppc_data_csects
;
2417 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
2419 ppc_after_toc_frag
= frag_now
;
2421 sym
->sy_frag
= frag_now
;
2422 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2424 sym
->sy_tc
.align
= 2;
2425 sym
->sy_tc
.output
= 1;
2426 sym
->sy_tc
.within
= sym
;
2428 for (list
= *list_ptr
;
2429 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2430 list
= list
->sy_tc
.next
)
2432 list
->sy_tc
.next
= sym
;
2434 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2435 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2438 ppc_current_csect
= sym
;
2441 /* This function handles the .text and .data pseudo-ops. These
2442 pseudo-ops aren't really used by XCOFF; we implement them for the
2443 convenience of people who aren't used to XCOFF. */
2454 else if (type
== 'd')
2459 sym
= symbol_find_or_make (name
);
2461 ppc_change_csect (sym
);
2463 demand_empty_rest_of_line ();
2466 /* The .extern pseudo-op. We create an undefined symbol. */
2475 name
= input_line_pointer
;
2476 endc
= get_symbol_end ();
2478 (void) symbol_find_or_make (name
);
2480 *input_line_pointer
= endc
;
2482 demand_empty_rest_of_line ();
2485 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2495 name
= input_line_pointer
;
2496 endc
= get_symbol_end ();
2498 sym
= symbol_find_or_make (name
);
2500 *input_line_pointer
= endc
;
2502 sym
->sy_tc
.output
= 1;
2504 demand_empty_rest_of_line ();
2507 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2508 although I don't know why it bothers. */
2519 name
= input_line_pointer
;
2520 endc
= get_symbol_end ();
2522 sym
= symbol_find_or_make (name
);
2524 *input_line_pointer
= endc
;
2526 if (*input_line_pointer
!= ',')
2528 as_bad ("missing rename string");
2529 ignore_rest_of_line ();
2532 ++input_line_pointer
;
2534 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2536 demand_empty_rest_of_line ();
2539 /* The .stabx pseudo-op. This is similar to a normal .stabs
2540 pseudo-op, but slightly different. A sample is
2541 .stabx "main:F-1",.main,142,0
2542 The first argument is the symbol name to create. The second is the
2543 value, and the third is the storage class. The fourth seems to be
2544 always zero, and I am assuming it is the type. */
2555 name
= demand_copy_C_string (&len
);
2557 if (*input_line_pointer
!= ',')
2559 as_bad ("missing value");
2562 ++input_line_pointer
;
2564 ppc_stab_symbol
= true;
2565 sym
= symbol_make (name
);
2566 ppc_stab_symbol
= false;
2568 sym
->sy_tc
.real_name
= name
;
2570 (void) expression (&exp
);
2577 as_bad ("illegal .stabx expression; zero assumed");
2578 exp
.X_add_number
= 0;
2581 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2582 sym
->sy_frag
= &zero_address_frag
;
2586 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2587 sym
->sy_value
= exp
;
2591 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2592 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2597 /* The value is some complex expression. This will probably
2598 fail at some later point, but this is probably the right
2599 thing to do here. */
2600 sym
->sy_value
= exp
;
2604 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2605 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2607 if (*input_line_pointer
!= ',')
2609 as_bad ("missing class");
2612 ++input_line_pointer
;
2614 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2616 if (*input_line_pointer
!= ',')
2618 as_bad ("missing type");
2621 ++input_line_pointer
;
2623 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2625 sym
->sy_tc
.output
= 1;
2627 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2628 sym
->sy_tc
.within
= ppc_current_block
;
2630 if (exp
.X_op
!= O_symbol
2631 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2632 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2633 ppc_frob_label (sym
);
2636 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2637 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2638 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2639 ppc_current_csect
->sy_tc
.within
= sym
;
2642 demand_empty_rest_of_line ();
2645 /* The .function pseudo-op. This takes several arguments. The first
2646 argument seems to be the external name of the symbol. The second
2647 argment seems to be the label for the start of the function. gcc
2648 uses the same name for both. I have no idea what the third and
2649 fourth arguments are meant to be. The optional fifth argument is
2650 an expression for the size of the function. In COFF this symbol
2651 gets an aux entry like that used for a csect. */
2654 ppc_function (ignore
)
2663 name
= input_line_pointer
;
2664 endc
= get_symbol_end ();
2666 /* Ignore any [PR] suffix. */
2667 name
= ppc_canonicalize_symbol_name (name
);
2668 s
= strchr (name
, '[');
2669 if (s
!= (char *) NULL
2670 && strcmp (s
+ 1, "PR]") == 0)
2673 ext_sym
= symbol_find_or_make (name
);
2675 *input_line_pointer
= endc
;
2677 if (*input_line_pointer
!= ',')
2679 as_bad ("missing symbol name");
2680 ignore_rest_of_line ();
2683 ++input_line_pointer
;
2685 name
= input_line_pointer
;
2686 endc
= get_symbol_end ();
2688 lab_sym
= symbol_find_or_make (name
);
2690 *input_line_pointer
= endc
;
2692 if (ext_sym
!= lab_sym
)
2694 ext_sym
->sy_value
.X_op
= O_symbol
;
2695 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2696 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2697 ext_sym
->sy_value
.X_add_number
= 0;
2700 if (ext_sym
->sy_tc
.class == -1)
2701 ext_sym
->sy_tc
.class = XMC_PR
;
2702 ext_sym
->sy_tc
.output
= 1;
2704 if (*input_line_pointer
== ',')
2708 /* Ignore the third argument. */
2709 ++input_line_pointer
;
2710 expression (&ignore
);
2711 if (*input_line_pointer
== ',')
2713 /* Ignore the fourth argument. */
2714 ++input_line_pointer
;
2715 expression (&ignore
);
2716 if (*input_line_pointer
== ',')
2718 /* The fifth argument is the function size. */
2719 ++input_line_pointer
;
2720 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2723 &zero_address_frag
);
2724 pseudo_set (ext_sym
->sy_tc
.size
);
2729 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2730 SF_SET_FUNCTION (ext_sym
);
2731 SF_SET_PROCESS (ext_sym
);
2732 coff_add_linesym (ext_sym
);
2734 demand_empty_rest_of_line ();
2737 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2746 sym
= symbol_make (".bf");
2747 S_SET_SEGMENT (sym
, text_section
);
2748 sym
->sy_frag
= frag_now
;
2749 S_SET_VALUE (sym
, frag_now_fix ());
2750 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2752 coff_line_base
= get_absolute_expression ();
2754 S_SET_NUMBER_AUXILIARY (sym
, 1);
2755 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2757 sym
->sy_tc
.output
= 1;
2759 ppc_frob_label (sym
);
2761 demand_empty_rest_of_line ();
2764 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2765 ".ef", except that the line number is absolute, not relative to the
2766 most recent ".bf" symbol. */
2774 sym
= symbol_make (".ef");
2775 S_SET_SEGMENT (sym
, text_section
);
2776 sym
->sy_frag
= frag_now
;
2777 S_SET_VALUE (sym
, frag_now_fix ());
2778 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2779 S_SET_NUMBER_AUXILIARY (sym
, 1);
2780 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2781 sym
->sy_tc
.output
= 1;
2783 ppc_frob_label (sym
);
2785 demand_empty_rest_of_line ();
2788 /* The .bi and .ei pseudo-ops. These take a string argument and
2789 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2801 name
= demand_copy_C_string (&len
);
2803 /* The value of these symbols is actually file offset. Here we set
2804 the value to the index into the line number entries. In
2805 ppc_frob_symbols we set the fix_line field, which will cause BFD
2806 to do the right thing. */
2808 sym
= symbol_make (name
);
2809 /* obj-coff.c currently only handles line numbers correctly in the
2811 S_SET_SEGMENT (sym
, text_section
);
2812 S_SET_VALUE (sym
, coff_n_line_nos
);
2813 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2815 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2816 sym
->sy_tc
.output
= 1;
2818 for (look
= symbol_rootP
;
2819 (look
!= (symbolS
*) NULL
2820 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2821 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2822 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2823 look
= symbol_next (look
))
2825 if (look
!= (symbolS
*) NULL
)
2827 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2828 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2831 demand_empty_rest_of_line ();
2834 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2835 There is one argument, which is a csect symbol. The value of the
2836 .bs symbol is the index of this csect symbol. */
2847 if (ppc_current_block
!= NULL
)
2848 as_bad ("nested .bs blocks");
2850 name
= input_line_pointer
;
2851 endc
= get_symbol_end ();
2853 csect
= symbol_find_or_make (name
);
2855 *input_line_pointer
= endc
;
2857 sym
= symbol_make (".bs");
2858 S_SET_SEGMENT (sym
, now_seg
);
2859 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2860 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2861 sym
->sy_tc
.output
= 1;
2863 sym
->sy_tc
.within
= csect
;
2865 ppc_frob_label (sym
);
2867 ppc_current_block
= sym
;
2869 demand_empty_rest_of_line ();
2872 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2880 if (ppc_current_block
== NULL
)
2881 as_bad (".es without preceding .bs");
2883 sym
= symbol_make (".es");
2884 S_SET_SEGMENT (sym
, now_seg
);
2885 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2886 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2887 sym
->sy_tc
.output
= 1;
2889 ppc_frob_label (sym
);
2891 ppc_current_block
= NULL
;
2893 demand_empty_rest_of_line ();
2896 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2905 sym
= symbol_make (".bb");
2906 S_SET_SEGMENT (sym
, text_section
);
2907 sym
->sy_frag
= frag_now
;
2908 S_SET_VALUE (sym
, frag_now_fix ());
2909 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2911 S_SET_NUMBER_AUXILIARY (sym
, 1);
2912 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2914 sym
->sy_tc
.output
= 1;
2916 SF_SET_PROCESS (sym
);
2918 ppc_frob_label (sym
);
2920 demand_empty_rest_of_line ();
2923 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2932 sym
= symbol_make (".eb");
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
);
2937 S_SET_NUMBER_AUXILIARY (sym
, 1);
2938 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2939 sym
->sy_tc
.output
= 1;
2941 SF_SET_PROCESS (sym
);
2943 ppc_frob_label (sym
);
2945 demand_empty_rest_of_line ();
2948 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
2959 name
= demand_copy_C_string (&len
);
2960 sym
= symbol_make (name
);
2961 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2962 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2963 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
2964 S_SET_VALUE (sym
, 0);
2965 sym
->sy_tc
.output
= 1;
2967 ppc_frob_label (sym
);
2969 demand_empty_rest_of_line ();
2972 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
2980 sym
= symbol_make (".ec");
2981 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2982 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2983 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
2984 S_SET_VALUE (sym
, 0);
2985 sym
->sy_tc
.output
= 1;
2987 ppc_frob_label (sym
);
2989 demand_empty_rest_of_line ();
2992 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2998 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2999 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
3006 subseg
= ppc_data_subsegment
;
3007 ++ppc_data_subsegment
;
3009 subseg_new (segment_name (data_section
), subseg
);
3010 ppc_toc_frag
= frag_now
;
3012 sym
= symbol_find_or_make ("TOC[TC0]");
3013 sym
->sy_frag
= frag_now
;
3014 S_SET_SEGMENT (sym
, data_section
);
3015 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3016 sym
->sy_tc
.subseg
= subseg
;
3017 sym
->sy_tc
.output
= 1;
3018 sym
->sy_tc
.within
= sym
;
3020 ppc_toc_csect
= sym
;
3022 for (list
= ppc_data_csects
;
3023 list
->sy_tc
.next
!= (symbolS
*) NULL
;
3024 list
= list
->sy_tc
.next
)
3026 list
->sy_tc
.next
= sym
;
3028 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3029 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
3032 ppc_current_csect
= ppc_toc_csect
;
3034 demand_empty_rest_of_line ();
3037 #endif /* OBJ_XCOFF */
3039 /* The .tc pseudo-op. This is used when generating either XCOFF or
3040 ELF. This takes two or more arguments.
3042 When generating XCOFF output, the first argument is the name to
3043 give to this location in the toc; this will be a symbol with class
3044 TC. The rest of the arguments are 4 byte values to actually put at
3045 this location in the TOC; often there is just one more argument, a
3046 relocateable symbol reference.
3048 When not generating XCOFF output, the arguments are the same, but
3049 the first argument is simply ignored. */
3057 /* Define the TOC symbol name. */
3063 if (ppc_toc_csect
== (symbolS
*) NULL
3064 || ppc_toc_csect
!= ppc_current_csect
)
3066 as_bad (".tc not in .toc section");
3067 ignore_rest_of_line ();
3071 name
= input_line_pointer
;
3072 endc
= get_symbol_end ();
3074 sym
= symbol_find_or_make (name
);
3076 *input_line_pointer
= endc
;
3078 if (S_IS_DEFINED (sym
))
3082 label
= ppc_current_csect
->sy_tc
.within
;
3083 if (label
->sy_tc
.class != XMC_TC0
)
3085 as_bad (".tc with no label");
3086 ignore_rest_of_line ();
3090 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3091 label
->sy_frag
= sym
->sy_frag
;
3092 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3094 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3095 ++input_line_pointer
;
3100 S_SET_SEGMENT (sym
, now_seg
);
3101 sym
->sy_frag
= frag_now
;
3102 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3103 sym
->sy_tc
.class = XMC_TC
;
3104 sym
->sy_tc
.output
= 1;
3106 ppc_frob_label (sym
);
3109 #else /* ! defined (OBJ_XCOFF) */
3111 /* Skip the TOC symbol name. */
3112 while (is_part_of_name (*input_line_pointer
)
3113 || *input_line_pointer
== '['
3114 || *input_line_pointer
== ']'
3115 || *input_line_pointer
== '{'
3116 || *input_line_pointer
== '}')
3117 ++input_line_pointer
;
3119 /* Align to a four byte boundary. */
3121 record_alignment (now_seg
, 2);
3123 #endif /* ! defined (OBJ_XCOFF) */
3125 if (*input_line_pointer
!= ',')
3126 demand_empty_rest_of_line ();
3129 ++input_line_pointer
;
3136 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3138 /* Set the current section. */
3140 ppc_set_current_section (new)
3143 ppc_previous_section
= ppc_current_section
;
3144 ppc_current_section
= new;
3147 /* pseudo-op: .previous
3148 behaviour: toggles the current section with the previous section.
3150 warnings: "No previous section"
3153 ppc_previous(ignore
)
3158 if (ppc_previous_section
== NULL
)
3160 as_warn("No previous section to return to. Directive ignored.");
3164 subseg_set(ppc_previous_section
, 0);
3166 ppc_set_current_section(ppc_previous_section
);
3169 /* pseudo-op: .pdata
3170 behaviour: predefined read only data section
3174 initial: .section .pdata "adr3"
3175 a - don't know -- maybe a misprint
3176 d - initialized data
3178 3 - double word aligned (that would be 4 byte boundary)
3181 Tag index tables (also known as the function table) for exception
3182 handling, debugging, etc.
3189 if (pdata_section
== 0)
3191 pdata_section
= subseg_new (".pdata", 0);
3193 bfd_set_section_flags (stdoutput
, pdata_section
,
3194 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3195 | SEC_READONLY
| SEC_DATA
));
3197 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3201 pdata_section
= subseg_new(".pdata", 0);
3203 ppc_set_current_section(pdata_section
);
3206 /* pseudo-op: .ydata
3207 behaviour: predefined read only data section
3211 initial: .section .ydata "drw3"
3212 a - don't know -- maybe a misprint
3213 d - initialized data
3215 3 - double word aligned (that would be 4 byte boundary)
3217 Tag tables (also known as the scope table) for exception handling,
3224 if (ydata_section
== 0)
3226 ydata_section
= subseg_new (".ydata", 0);
3227 bfd_set_section_flags (stdoutput
, ydata_section
,
3228 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3229 | SEC_READONLY
| SEC_DATA
));
3231 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3235 ydata_section
= subseg_new (".ydata", 0);
3237 ppc_set_current_section(ydata_section
);
3240 /* pseudo-op: .reldata
3241 behaviour: predefined read write data section
3242 double word aligned (4-byte)
3243 FIXME: relocation is applied to it
3244 FIXME: what's the difference between this and .data?
3247 initial: .section .reldata "drw3"
3248 d - initialized data
3251 3 - double word aligned (that would be 8 byte boundary)
3254 Like .data, but intended to hold data subject to relocation, such as
3255 function descriptors, etc.
3261 if (reldata_section
== 0)
3263 reldata_section
= subseg_new (".reldata", 0);
3265 bfd_set_section_flags (stdoutput
, reldata_section
,
3266 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3269 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3273 reldata_section
= subseg_new (".reldata", 0);
3275 ppc_set_current_section(reldata_section
);
3278 /* pseudo-op: .rdata
3279 behaviour: predefined read only data section
3283 initial: .section .rdata "dr3"
3284 d - initialized data
3286 3 - double word aligned (that would be 4 byte boundary)
3292 if (rdata_section
== 0)
3294 rdata_section
= subseg_new (".rdata", 0);
3295 bfd_set_section_flags (stdoutput
, rdata_section
,
3296 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3297 | SEC_READONLY
| SEC_DATA
));
3299 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3303 rdata_section
= subseg_new (".rdata", 0);
3305 ppc_set_current_section(rdata_section
);
3308 /* pseudo-op: .ualong
3309 behaviour: much like .int, with the exception that no alignment is
3311 FIXME: test the alignment statement
3323 /* pseudo-op: .znop <symbol name>
3324 behaviour: Issue a nop instruction
3325 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3326 the supplied symbol name.
3328 warnings: Missing symbol name
3335 const struct powerpc_opcode
*opcode
;
3341 /* Strip out the symbol name */
3349 symbol_name
= input_line_pointer
;
3350 c
= get_symbol_end ();
3352 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3353 strcpy (name
, symbol_name
);
3355 sym
= symbol_find_or_make (name
);
3357 *input_line_pointer
= c
;
3361 /* Look up the opcode in the hash table. */
3362 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3364 /* stick in the nop */
3365 insn
= opcode
->opcode
;
3367 /* Write out the instruction. */
3369 md_number_to_chars (f
, insn
, 4);
3371 f
- frag_now
->fr_literal
,
3376 BFD_RELOC_16_GOT_PCREL
);
3389 register char *name
;
3393 register symbolS
*symbolP
;
3396 name
= input_line_pointer
;
3397 c
= get_symbol_end ();
3399 /* just after name is now '\0' */
3400 p
= input_line_pointer
;
3403 if (*input_line_pointer
!= ',')
3405 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3406 ignore_rest_of_line ();
3410 input_line_pointer
++; /* skip ',' */
3411 if ((temp
= get_absolute_expression ()) < 0)
3413 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
3414 ignore_rest_of_line ();
3420 /* The third argument to .comm is the alignment. */
3421 if (*input_line_pointer
!= ',')
3425 ++input_line_pointer
;
3426 align
= get_absolute_expression ();
3429 as_warn ("ignoring bad alignment");
3436 symbolP
= symbol_find_or_make (name
);
3439 if (S_IS_DEFINED (symbolP
))
3441 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3442 S_GET_NAME (symbolP
));
3443 ignore_rest_of_line ();
3447 if (S_GET_VALUE (symbolP
))
3449 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3450 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3451 S_GET_NAME (symbolP
),
3452 (long) S_GET_VALUE (symbolP
),
3457 S_SET_VALUE (symbolP
, (valueT
) temp
);
3458 S_SET_EXTERNAL (symbolP
);
3461 demand_empty_rest_of_line ();
3465 * implement the .section pseudo op:
3466 * .section name {, "flags"}
3468 * | +--- optional flags: 'b' for bss
3470 * +-- section name 'l' for lib
3474 * 'd' (apparently m88k for data)
3476 * But if the argument is not a quoted string, treat it as a
3477 * subsegment number.
3479 * FIXME: this is a copy of the section processing from obj-coff.c, with
3480 * additions/changes for the moto-pas assembler support. There are three
3483 * FIXME: I just noticed this. This doesn't work at all really. It it
3484 * setting bits that bfd probably neither understands or uses. The
3485 * correct approach (?) will have to incorporate extra fields attached
3486 * to the section to hold the system specific stuff. (krk)
3489 * 'a' - unknown - referred to in documentation, but no definition supplied
3490 * 'c' - section has code
3491 * 'd' - section has initialized data
3492 * 'u' - section has uninitialized data
3493 * 'i' - section contains directives (info)
3494 * 'n' - section can be discarded
3495 * 'R' - remove section at link time
3497 * Section Protection:
3498 * 'r' - section is readable
3499 * 'w' - section is writeable
3500 * 'x' - section is executable
3501 * 's' - section is sharable
3503 * Section Alignment:
3504 * '0' - align to byte boundary
3505 * '1' - align to halfword undary
3506 * '2' - align to word boundary
3507 * '3' - align to doubleword boundary
3508 * '4' - align to quadword boundary
3509 * '5' - align to 32 byte boundary
3510 * '6' - align to 64 byte boundary
3515 ppc_pe_section (ignore
)
3518 /* Strip out the section name */
3527 section_name
= input_line_pointer
;
3528 c
= get_symbol_end ();
3530 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3531 strcpy (name
, section_name
);
3533 *input_line_pointer
= c
;
3538 flags
= SEC_NO_FLAGS
;
3540 if (strcmp (name
, ".idata$2") == 0)
3544 else if (strcmp (name
, ".idata$3") == 0)
3548 else if (strcmp (name
, ".idata$4") == 0)
3552 else if (strcmp (name
, ".idata$5") == 0)
3556 else if (strcmp (name
, ".idata$6") == 0)
3561 align
= 4; /* default alignment to 16 byte boundary */
3563 if (*input_line_pointer
== ',')
3565 ++input_line_pointer
;
3567 if (*input_line_pointer
!= '"')
3568 exp
= get_absolute_expression ();
3571 ++input_line_pointer
;
3572 while (*input_line_pointer
!= '"'
3573 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3575 switch (*input_line_pointer
)
3577 /* Section Contents */
3578 case 'a': /* unknown */
3579 as_bad ("Unsupported section attribute -- 'a'");
3581 case 'c': /* code section */
3584 case 'd': /* section has initialized data */
3587 case 'u': /* section has uninitialized data */
3588 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3592 case 'i': /* section contains directives (info) */
3593 /* FIXME: This is IMAGE_SCN_LNK_INFO
3595 flags
|= SEC_HAS_CONTENTS
;
3597 case 'n': /* section can be discarded */
3600 case 'R': /* Remove section at link time */
3601 flags
|= SEC_NEVER_LOAD
;
3604 /* Section Protection */
3605 case 'r': /* section is readable */
3606 flags
|= IMAGE_SCN_MEM_READ
;
3608 case 'w': /* section is writeable */
3609 flags
|= IMAGE_SCN_MEM_WRITE
;
3611 case 'x': /* section is executable */
3612 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3614 case 's': /* section is sharable */
3615 flags
|= IMAGE_SCN_MEM_SHARED
;
3618 /* Section Alignment */
3619 case '0': /* align to byte boundary */
3620 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3623 case '1': /* align to halfword boundary */
3624 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3627 case '2': /* align to word boundary */
3628 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3631 case '3': /* align to doubleword boundary */
3632 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3635 case '4': /* align to quadword boundary */
3636 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3639 case '5': /* align to 32 byte boundary */
3640 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3643 case '6': /* align to 64 byte boundary */
3644 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3649 as_bad("unknown section attribute '%c'",
3650 *input_line_pointer
);
3653 ++input_line_pointer
;
3655 if (*input_line_pointer
== '"')
3656 ++input_line_pointer
;
3660 sec
= subseg_new (name
, (subsegT
) exp
);
3662 ppc_set_current_section(sec
);
3664 if (flags
!= SEC_NO_FLAGS
)
3666 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3667 as_bad ("error setting flags for \"%s\": %s",
3668 bfd_section_name (stdoutput
, sec
),
3669 bfd_errmsg (bfd_get_error ()));
3672 bfd_set_section_alignment(stdoutput
, sec
, align
);
3677 ppc_pe_function (ignore
)
3684 name
= input_line_pointer
;
3685 endc
= get_symbol_end ();
3687 ext_sym
= symbol_find_or_make (name
);
3689 *input_line_pointer
= endc
;
3691 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3692 SF_SET_FUNCTION (ext_sym
);
3693 SF_SET_PROCESS (ext_sym
);
3694 coff_add_linesym (ext_sym
);
3696 demand_empty_rest_of_line ();
3700 ppc_pe_tocd (ignore
)
3703 if (tocdata_section
== 0)
3705 tocdata_section
= subseg_new (".tocd", 0);
3706 /* FIXME: section flags won't work */
3707 bfd_set_section_flags (stdoutput
, tocdata_section
,
3708 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3709 | SEC_READONLY
| SEC_DATA
));
3711 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3715 rdata_section
= subseg_new (".tocd", 0);
3718 ppc_set_current_section(tocdata_section
);
3720 demand_empty_rest_of_line ();
3723 /* Don't adjust TOC relocs to use the section symbol. */
3726 ppc_pe_fix_adjustable (fix
)
3729 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3736 /* XCOFF specific symbol and file handling. */
3738 /* Canonicalize the symbol name. We use the to force the suffix, if
3739 any, to use square brackets, and to be in upper case. */
3742 ppc_canonicalize_symbol_name (name
)
3747 if (ppc_stab_symbol
)
3750 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3764 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3768 if (*s
== '\0' || s
[1] != '\0')
3769 as_bad ("bad symbol suffix");
3777 /* Set the class of a symbol based on the suffix, if any. This is
3778 called whenever a new symbol is created. */
3781 ppc_symbol_new_hook (sym
)
3786 sym
->sy_tc
.next
= NULL
;
3787 sym
->sy_tc
.output
= 0;
3788 sym
->sy_tc
.class = -1;
3789 sym
->sy_tc
.real_name
= NULL
;
3790 sym
->sy_tc
.subseg
= 0;
3791 sym
->sy_tc
.align
= 0;
3792 sym
->sy_tc
.size
= NULL
;
3793 sym
->sy_tc
.within
= NULL
;
3795 if (ppc_stab_symbol
)
3798 s
= strchr (S_GET_NAME (sym
), '[');
3799 if (s
== (const char *) NULL
)
3801 /* There is no suffix. */
3810 if (strcmp (s
, "BS]") == 0)
3811 sym
->sy_tc
.class = XMC_BS
;
3814 if (strcmp (s
, "DB]") == 0)
3815 sym
->sy_tc
.class = XMC_DB
;
3816 else if (strcmp (s
, "DS]") == 0)
3817 sym
->sy_tc
.class = XMC_DS
;
3820 if (strcmp (s
, "GL]") == 0)
3821 sym
->sy_tc
.class = XMC_GL
;
3824 if (strcmp (s
, "PR]") == 0)
3825 sym
->sy_tc
.class = XMC_PR
;
3828 if (strcmp (s
, "RO]") == 0)
3829 sym
->sy_tc
.class = XMC_RO
;
3830 else if (strcmp (s
, "RW]") == 0)
3831 sym
->sy_tc
.class = XMC_RW
;
3834 if (strcmp (s
, "SV]") == 0)
3835 sym
->sy_tc
.class = XMC_SV
;
3838 if (strcmp (s
, "TC]") == 0)
3839 sym
->sy_tc
.class = XMC_TC
;
3840 else if (strcmp (s
, "TI]") == 0)
3841 sym
->sy_tc
.class = XMC_TI
;
3842 else if (strcmp (s
, "TB]") == 0)
3843 sym
->sy_tc
.class = XMC_TB
;
3844 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3845 sym
->sy_tc
.class = XMC_TC0
;
3848 if (strcmp (s
, "UA]") == 0)
3849 sym
->sy_tc
.class = XMC_UA
;
3850 else if (strcmp (s
, "UC]") == 0)
3851 sym
->sy_tc
.class = XMC_UC
;
3854 if (strcmp (s
, "XO]") == 0)
3855 sym
->sy_tc
.class = XMC_XO
;
3859 if (sym
->sy_tc
.class == -1)
3860 as_bad ("Unrecognized symbol suffix");
3863 /* Set the class of a label based on where it is defined. This
3864 handles symbols without suffixes. Also, move the symbol so that it
3865 follows the csect symbol. */
3868 ppc_frob_label (sym
)
3871 if (ppc_current_csect
!= (symbolS
*) NULL
)
3873 if (sym
->sy_tc
.class == -1)
3874 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3876 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3877 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3879 ppc_current_csect
->sy_tc
.within
= sym
;
3883 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3884 seen. It tells ppc_adjust_symtab whether it needs to look through
3887 static boolean ppc_saw_abs
;
3889 /* Change the name of a symbol just before writing it out. Set the
3890 real name if the .rename pseudo-op was used. Otherwise, remove any
3891 class suffix. Return 1 if the symbol should not be included in the
3895 ppc_frob_symbol (sym
)
3898 static symbolS
*ppc_last_function
;
3899 static symbolS
*set_end
;
3901 /* Discard symbols that should not be included in the output symbol
3903 if (! sym
->sy_used_in_reloc
3904 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3905 || (! S_IS_EXTERNAL (sym
)
3906 && ! sym
->sy_tc
.output
3907 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3910 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3911 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3917 name
= S_GET_NAME (sym
);
3918 s
= strchr (name
, '[');
3919 if (s
!= (char *) NULL
)
3925 snew
= xmalloc (len
+ 1);
3926 memcpy (snew
, name
, len
);
3929 S_SET_NAME (sym
, snew
);
3933 if (set_end
!= (symbolS
*) NULL
)
3935 SA_SET_SYM_ENDNDX (set_end
, sym
);
3939 if (SF_GET_FUNCTION (sym
))
3941 if (ppc_last_function
!= (symbolS
*) NULL
)
3942 as_bad ("two .function pseudo-ops with no intervening .ef");
3943 ppc_last_function
= sym
;
3944 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3946 resolve_symbol_value (sym
->sy_tc
.size
);
3947 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3950 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3951 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3953 if (ppc_last_function
== (symbolS
*) NULL
)
3954 as_bad (".ef with no preceding .function");
3957 set_end
= ppc_last_function
;
3958 ppc_last_function
= NULL
;
3960 /* We don't have a C_EFCN symbol, but we need to force the
3961 COFF backend to believe that it has seen one. */
3962 coff_last_function
= NULL
;
3966 if (! S_IS_EXTERNAL (sym
)
3967 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3968 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3969 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3970 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
3971 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3972 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3973 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
3974 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
3975 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3976 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3978 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
3979 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3982 union internal_auxent
*a
;
3984 /* Create a csect aux. */
3985 i
= S_GET_NUMBER_AUXILIARY (sym
);
3986 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3987 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3988 if (sym
->sy_tc
.class == XMC_TC0
)
3990 /* This is the TOC table. */
3991 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3992 a
->x_csect
.x_scnlen
.l
= 0;
3993 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3995 else if (sym
->sy_tc
.subseg
!= 0)
3997 /* This is a csect symbol. x_scnlen is the size of the
3999 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
4000 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4001 S_GET_SEGMENT (sym
))
4002 - S_GET_VALUE (sym
));
4005 resolve_symbol_value (sym
->sy_tc
.next
);
4006 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
4007 - S_GET_VALUE (sym
));
4009 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
4011 else if (S_GET_SEGMENT (sym
) == bss_section
)
4013 /* This is a common symbol. */
4014 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
4015 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
4016 if (S_IS_EXTERNAL (sym
))
4017 sym
->sy_tc
.class = XMC_RW
;
4019 sym
->sy_tc
.class = XMC_BS
;
4021 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4023 /* This is an absolute symbol. The csect will be created by
4024 ppc_adjust_symtab. */
4026 a
->x_csect
.x_smtyp
= XTY_LD
;
4027 if (sym
->sy_tc
.class == -1)
4028 sym
->sy_tc
.class = XMC_XO
;
4030 else if (! S_IS_DEFINED (sym
))
4032 /* This is an external symbol. */
4033 a
->x_csect
.x_scnlen
.l
= 0;
4034 a
->x_csect
.x_smtyp
= XTY_ER
;
4036 else if (sym
->sy_tc
.class == XMC_TC
)
4040 /* This is a TOC definition. x_scnlen is the size of the
4042 next
= symbol_next (sym
);
4043 while (next
->sy_tc
.class == XMC_TC0
)
4044 next
= symbol_next (next
);
4045 if (next
== (symbolS
*) NULL
4046 || next
->sy_tc
.class != XMC_TC
)
4048 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4049 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4051 - S_GET_VALUE (sym
));
4053 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4054 - S_GET_VALUE (sym
));
4058 resolve_symbol_value (next
);
4059 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4060 - S_GET_VALUE (sym
));
4062 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4068 /* This is a normal symbol definition. x_scnlen is the
4069 symbol index of the containing csect. */
4070 if (S_GET_SEGMENT (sym
) == text_section
)
4071 csect
= ppc_text_csects
;
4072 else if (S_GET_SEGMENT (sym
) == data_section
)
4073 csect
= ppc_data_csects
;
4077 /* Skip the initial dummy symbol. */
4078 csect
= csect
->sy_tc
.next
;
4080 if (csect
== (symbolS
*) NULL
)
4082 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym
));
4083 a
->x_csect
.x_scnlen
.l
= 0;
4087 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
4089 resolve_symbol_value (csect
->sy_tc
.next
);
4090 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
4092 csect
= csect
->sy_tc
.next
;
4095 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4096 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
4098 a
->x_csect
.x_smtyp
= XTY_LD
;
4101 a
->x_csect
.x_parmhash
= 0;
4102 a
->x_csect
.x_snhash
= 0;
4103 if (sym
->sy_tc
.class == -1)
4104 a
->x_csect
.x_smclas
= XMC_PR
;
4106 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
4107 a
->x_csect
.x_stab
= 0;
4108 a
->x_csect
.x_snstab
= 0;
4110 /* Don't let the COFF backend resort these symbols. */
4111 sym
->bsym
->flags
|= BSF_NOT_AT_END
;
4113 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4115 /* We want the value to be the symbol index of the referenced
4116 csect symbol. BFD will do that for us if we set the right
4119 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
4120 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
4122 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4127 /* The value is the offset from the enclosing csect. */
4128 block
= sym
->sy_tc
.within
;
4129 csect
= block
->sy_tc
.within
;
4130 resolve_symbol_value (csect
);
4131 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4133 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4134 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4136 /* We want the value to be a file offset into the line numbers.
4137 BFD will do that for us if we set the right flags. We have
4138 already set the value correctly. */
4139 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
4145 /* Adjust the symbol table. This creates csect symbols for all
4146 absolute symbols. */
4149 ppc_adjust_symtab ()
4156 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4160 union internal_auxent
*a
;
4162 if (S_GET_SEGMENT (sym
) != absolute_section
)
4165 csect
= symbol_create (".abs[XO]", absolute_section
,
4166 S_GET_VALUE (sym
), &zero_address_frag
);
4167 csect
->bsym
->value
= S_GET_VALUE (sym
);
4168 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4169 i
= S_GET_NUMBER_AUXILIARY (csect
);
4170 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4171 a
= &coffsymbol (csect
->bsym
)->native
[i
+ 1].u
.auxent
;
4172 a
->x_csect
.x_scnlen
.l
= 0;
4173 a
->x_csect
.x_smtyp
= XTY_SD
;
4174 a
->x_csect
.x_parmhash
= 0;
4175 a
->x_csect
.x_snhash
= 0;
4176 a
->x_csect
.x_smclas
= XMC_XO
;
4177 a
->x_csect
.x_stab
= 0;
4178 a
->x_csect
.x_snstab
= 0;
4180 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4182 i
= S_GET_NUMBER_AUXILIARY (sym
);
4183 a
= &coffsymbol (sym
->bsym
)->native
[i
].u
.auxent
;
4184 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4185 coffsymbol (sym
->bsym
)->native
[i
].fix_scnlen
= 1;
4188 ppc_saw_abs
= false;
4191 /* Set the VMA for a section. This is called on all the sections in
4195 ppc_frob_section (sec
)
4198 static bfd_size_type vma
= 0;
4200 bfd_set_section_vma (stdoutput
, sec
, vma
);
4201 vma
+= bfd_section_size (stdoutput
, sec
);
4204 #endif /* OBJ_XCOFF */
4206 /* Turn a string in input_line_pointer into a floating point constant
4207 of type type, and store the appropriate bytes in *litp. The number
4208 of LITTLENUMS emitted is stored in *sizep . An error message is
4209 returned, or NULL on OK. */
4212 md_atof (type
, litp
, sizep
)
4218 LITTLENUM_TYPE words
[4];
4234 return "bad call to md_atof";
4237 t
= atof_ieee (input_line_pointer
, type
, words
);
4239 input_line_pointer
= t
;
4243 if (target_big_endian
)
4245 for (i
= 0; i
< prec
; i
++)
4247 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4253 for (i
= prec
- 1; i
>= 0; i
--)
4255 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4263 /* Write a value out to the object file, using the appropriate
4267 md_number_to_chars (buf
, val
, n
)
4272 if (target_big_endian
)
4273 number_to_chars_bigendian (buf
, val
, n
);
4275 number_to_chars_littleendian (buf
, val
, n
);
4278 /* Align a section (I don't know why this is machine dependent). */
4281 md_section_align (seg
, addr
)
4285 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4287 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4290 /* We don't have any form of relaxing. */
4293 md_estimate_size_before_relax (fragp
, seg
)
4301 /* Convert a machine dependent frag. We never generate these. */
4304 md_convert_frag (abfd
, sec
, fragp
)
4312 /* We have no need to default values of symbols. */
4316 md_undefined_symbol (name
)
4322 /* Functions concerning relocs. */
4324 /* The location from which a PC relative jump should be calculated,
4325 given a PC relative reloc. */
4328 md_pcrel_from_section (fixp
, sec
)
4333 if (fixp
->fx_addsy
!= (symbolS
*) NULL
4334 && (! S_IS_DEFINED (fixp
->fx_addsy
)
4335 || TC_FORCE_RELOCATION_SECTION (fixp
, sec
)))
4339 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4344 /* This is called to see whether a fixup should be adjusted to use a
4345 section symbol. We take the opportunity to change a fixup against
4346 a symbol in the TOC subsegment into a reloc against the
4347 corresponding .tc symbol. */
4350 ppc_fix_adjustable (fix
)
4355 resolve_symbol_value (fix
->fx_addsy
);
4356 val
= S_GET_VALUE (fix
->fx_addsy
);
4357 if (ppc_toc_csect
!= (symbolS
*) NULL
4358 && fix
->fx_addsy
!= (symbolS
*) NULL
4359 && fix
->fx_addsy
!= ppc_toc_csect
4360 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4361 && val
>= ppc_toc_frag
->fr_address
4362 && (ppc_after_toc_frag
== (fragS
*) NULL
4363 || val
< ppc_after_toc_frag
->fr_address
))
4367 for (sy
= symbol_next (ppc_toc_csect
);
4368 sy
!= (symbolS
*) NULL
;
4369 sy
= symbol_next (sy
))
4371 if (sy
->sy_tc
.class == XMC_TC0
)
4373 if (sy
->sy_tc
.class != XMC_TC
)
4375 resolve_symbol_value (sy
);
4376 if (val
== S_GET_VALUE (sy
))
4379 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4384 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4385 "symbol in .toc does not match any .tc");
4388 /* Possibly adjust the reloc to be against the csect. */
4389 if (fix
->fx_addsy
!= (symbolS
*) NULL
4390 && fix
->fx_addsy
->sy_tc
.subseg
== 0
4391 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
4392 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
4393 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
4397 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4398 csect
= ppc_text_csects
;
4399 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4400 csect
= ppc_data_csects
;
4404 /* Skip the initial dummy symbol. */
4405 csect
= csect
->sy_tc
.next
;
4407 if (csect
!= (symbolS
*) NULL
)
4409 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
4410 && (csect
->sy_tc
.next
->sy_frag
->fr_address
4411 <= fix
->fx_addsy
->sy_frag
->fr_address
))
4412 csect
= csect
->sy_tc
.next
;
4414 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4415 - csect
->sy_frag
->fr_address
);
4416 fix
->fx_addsy
= csect
;
4420 /* Adjust a reloc against a .lcomm symbol to be against the base
4422 if (fix
->fx_addsy
!= (symbolS
*) NULL
4423 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4424 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4426 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
4427 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4428 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
4429 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
4435 /* A reloc from one csect to another must be kept. The assembler
4436 will, of course, keep relocs between sections, and it will keep
4437 absolute relocs, but we need to force it to keep PC relative relocs
4438 between two csects in the same section. */
4441 ppc_force_relocation (fix
)
4444 /* At this point fix->fx_addsy should already have been converted to
4445 a csect symbol. If the csect does not include the fragment, then
4446 we need to force the relocation. */
4448 && fix
->fx_addsy
!= NULL
4449 && fix
->fx_addsy
->sy_tc
.subseg
!= 0
4450 && (fix
->fx_addsy
->sy_frag
->fr_address
> fix
->fx_frag
->fr_address
4451 || (fix
->fx_addsy
->sy_tc
.next
!= NULL
4452 && (fix
->fx_addsy
->sy_tc
.next
->sy_frag
->fr_address
4453 <= fix
->fx_frag
->fr_address
))))
4459 #endif /* OBJ_XCOFF */
4461 /* See whether a symbol is in the TOC section. */
4464 ppc_is_toc_sym (sym
)
4468 return sym
->sy_tc
.class == XMC_TC
;
4470 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4474 /* Apply a fixup to the object code. This is called for all the
4475 fixups we generated by the call to fix_new_exp, above. In the call
4476 above we used a reloc code which was the largest legal reloc code
4477 plus the operand index. Here we undo that to recover the operand
4478 index. At this point all symbol values should be fully resolved,
4479 and we attempt to completely resolve the reloc. If we can not do
4480 that, we determine the correct reloc code and put it back in the
4484 md_apply_fix3 (fixp
, valuep
, seg
)
4491 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4492 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4493 doing this relocation the code in write.c is going to call
4494 bfd_perform_relocation, which is also going to use the symbol
4495 value. That means that if the reloc is fully resolved we want to
4496 use *valuep since bfd_perform_relocation is not being used.
4497 However, if the reloc is not fully resolved we do not want to use
4498 *valuep, and must use fx_offset instead. However, if the reloc
4499 is PC relative, we do want to use *valuep since it includes the
4500 result of md_pcrel_from. This is confusing. */
4502 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4507 else if (fixp
->fx_pcrel
)
4511 value
= fixp
->fx_offset
;
4512 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4514 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4515 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4518 /* We can't actually support subtracting a symbol. */
4519 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4520 "expression too complex");
4525 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4528 const struct powerpc_operand
*operand
;
4532 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4534 operand
= &powerpc_operands
[opindex
];
4537 /* It appears that an instruction like
4539 when LC..1 is not a TOC symbol does not generate a reloc. It
4540 uses the offset of LC..1 within its csect. However, .long
4541 LC..1 will generate a reloc. I can't find any documentation
4542 on how these cases are to be distinguished, so this is a wild
4543 guess. These cases are generated by gcc -mminimal-toc. */
4544 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4545 && operand
->bits
== 16
4546 && operand
->shift
== 0
4547 && operand
->insert
== NULL
4548 && fixp
->fx_addsy
!= NULL
4549 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
4550 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
4551 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
4552 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4554 value
= fixp
->fx_offset
;
4559 /* Fetch the instruction, insert the fully resolved operand
4560 value, and stuff the instruction back again. */
4561 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4562 if (target_big_endian
)
4563 insn
= bfd_getb32 ((unsigned char *) where
);
4565 insn
= bfd_getl32 ((unsigned char *) where
);
4566 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4567 fixp
->fx_file
, fixp
->fx_line
);
4568 if (target_big_endian
)
4569 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4571 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4575 /* Nothing else to do here. */
4579 /* Determine a BFD reloc value based on the operand information.
4580 We are only prepared to turn a few of the operands into
4582 FIXME: We need to handle the DS field at the very least.
4583 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4584 there should be a new field in the operand table. */
4585 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4586 && operand
->bits
== 26
4587 && operand
->shift
== 0)
4588 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4589 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4590 && operand
->bits
== 16
4591 && operand
->shift
== 0)
4592 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4593 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4594 && operand
->bits
== 26
4595 && operand
->shift
== 0)
4596 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4597 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4598 && operand
->bits
== 16
4599 && operand
->shift
== 0)
4600 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4601 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4602 && operand
->bits
== 16
4603 && operand
->shift
== 0
4604 && operand
->insert
== NULL
4605 && fixp
->fx_addsy
!= NULL
4606 && ppc_is_toc_sym (fixp
->fx_addsy
))
4609 if (target_big_endian
)
4610 fixp
->fx_where
+= 2;
4611 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4618 /* Use expr_symbol_where to see if this is an expression
4620 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
4621 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4622 "unresolved expression that must be resolved");
4624 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4625 "unsupported relocation type");
4633 ppc_elf_validate_fix (fixp
, seg
);
4635 switch (fixp
->fx_r_type
)
4638 case BFD_RELOC_CTOR
:
4640 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4644 case BFD_RELOC_32_PCREL
:
4645 case BFD_RELOC_32_BASEREL
:
4646 case BFD_RELOC_PPC_EMB_NADDR32
:
4647 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4651 case BFD_RELOC_LO16
:
4652 case BFD_RELOC_HI16
:
4653 case BFD_RELOC_HI16_S
:
4655 case BFD_RELOC_GPREL16
:
4656 case BFD_RELOC_16_GOT_PCREL
:
4657 case BFD_RELOC_16_GOTOFF
:
4658 case BFD_RELOC_LO16_GOTOFF
:
4659 case BFD_RELOC_HI16_GOTOFF
:
4660 case BFD_RELOC_HI16_S_GOTOFF
:
4661 case BFD_RELOC_LO16_BASEREL
:
4662 case BFD_RELOC_HI16_BASEREL
:
4663 case BFD_RELOC_HI16_S_BASEREL
:
4664 case BFD_RELOC_PPC_EMB_NADDR16
:
4665 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
4666 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
4667 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
4668 case BFD_RELOC_PPC_EMB_SDAI16
:
4669 case BFD_RELOC_PPC_EMB_SDA2REL
:
4670 case BFD_RELOC_PPC_EMB_SDA2I16
:
4671 case BFD_RELOC_PPC_EMB_RELSEC16
:
4672 case BFD_RELOC_PPC_EMB_RELST_LO
:
4673 case BFD_RELOC_PPC_EMB_RELST_HI
:
4674 case BFD_RELOC_PPC_EMB_RELST_HA
:
4675 case BFD_RELOC_PPC_EMB_RELSDA
:
4676 case BFD_RELOC_PPC_TOC16
:
4678 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4679 "cannot emit PC relative %s relocation%s%s",
4680 bfd_get_reloc_code_name (fixp
->fx_r_type
),
4681 fixp
->fx_addsy
!= NULL
? " against " : "",
4682 (fixp
->fx_addsy
!= NULL
4683 ? S_GET_NAME (fixp
->fx_addsy
)
4686 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4690 /* Because SDA21 modifies the register field, the size is set to 4
4691 bytes, rather than 2, so offset it here appropriately */
4692 case BFD_RELOC_PPC_EMB_SDA21
:
4696 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
4697 + ((target_big_endian
) ? 2 : 0),
4705 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4709 case BFD_RELOC_PPC_LOCAL24PC
:
4710 if (!fixp
->fx_pcrel
)
4717 "Gas failure, reloc value %d\n", fixp
->fx_r_type
);
4724 fixp
->fx_addnumber
= value
;
4726 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4727 fixp
->fx_addnumber
= 0;
4731 fixp
->fx_addnumber
= 0;
4733 /* We want to use the offset within the data segment of the
4734 symbol, not the actual VMA of the symbol. */
4735 fixp
->fx_addnumber
=
4736 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4744 /* Generate a reloc for a fixup. */
4747 tc_gen_reloc (seg
, fixp
)
4753 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4755 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4756 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4757 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4758 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4760 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4761 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4764 reloc
->addend
= fixp
->fx_addnumber
;