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
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "opcode/ppc.h"
36 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
38 /* Tell the main code what the endianness is. */
39 extern int target_big_endian
;
41 /* Whether or not, we've set target_big_endian. */
42 static int set_target_endian
= 0;
44 /* Whether to use user friendly register names. */
45 #ifndef TARGET_REG_NAMES_P
47 #define TARGET_REG_NAMES_P true
49 #define TARGET_REG_NAMES_P false
53 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
55 static void ppc_set_cpu
PARAMS ((void));
56 static unsigned long ppc_insert_operand
57 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
58 offsetT val
, char *file
, unsigned int line
));
59 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
60 static void ppc_byte
PARAMS ((int));
61 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
62 static void ppc_tc
PARAMS ((int));
65 static void ppc_comm
PARAMS ((int));
66 static void ppc_bb
PARAMS ((int));
67 static void ppc_bc
PARAMS ((int));
68 static void ppc_bf
PARAMS ((int));
69 static void ppc_biei
PARAMS ((int));
70 static void ppc_bs
PARAMS ((int));
71 static void ppc_eb
PARAMS ((int));
72 static void ppc_ec
PARAMS ((int));
73 static void ppc_ef
PARAMS ((int));
74 static void ppc_es
PARAMS ((int));
75 static void ppc_csect
PARAMS ((int));
76 static void ppc_change_csect
PARAMS ((symbolS
*));
77 static void ppc_function
PARAMS ((int));
78 static void ppc_extern
PARAMS ((int));
79 static void ppc_lglobl
PARAMS ((int));
80 static void ppc_section
PARAMS ((int));
81 static void ppc_stabx
PARAMS ((int));
82 static void ppc_rename
PARAMS ((int));
83 static void ppc_toc
PARAMS ((int));
87 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
88 static void ppc_elf_cons
PARAMS ((int));
89 static void ppc_elf_rdata
PARAMS ((int));
90 static void ppc_elf_lcomm
PARAMS ((int));
91 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
95 static void ppc_set_current_section
PARAMS ((segT
));
96 static void ppc_previous
PARAMS ((int));
97 static void ppc_pdata
PARAMS ((int));
98 static void ppc_ydata
PARAMS ((int));
99 static void ppc_reldata
PARAMS ((int));
100 static void ppc_rdata
PARAMS ((int));
101 static void ppc_ualong
PARAMS ((int));
102 static void ppc_znop
PARAMS ((int));
103 static void ppc_pe_comm
PARAMS ((int));
104 static void ppc_pe_section
PARAMS ((int));
105 static void ppc_pe_function
PARAMS ((int));
106 static void ppc_pe_tocd
PARAMS ((int));
109 /* Generic assembler global variables which must be defined by all
112 /* Characters which always start a comment. */
113 #ifdef TARGET_SOLARIS_COMMENT
114 const char comment_chars
[] = "#!";
116 const char comment_chars
[] = "#";
119 /* Characters which start a comment at the beginning of a line. */
120 const char line_comment_chars
[] = "#";
122 /* Characters which may be used to separate multiple commands on a
124 const char line_separator_chars
[] = ";";
126 /* Characters which are used to indicate an exponent in a floating
128 const char EXP_CHARS
[] = "eE";
130 /* Characters which mean that a number is a floating point constant,
132 const char FLT_CHARS
[] = "dD";
134 /* The target specific pseudo-ops which we support. */
136 const pseudo_typeS md_pseudo_table
[] =
138 /* Pseudo-ops which must be overridden. */
139 { "byte", ppc_byte
, 0 },
142 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
143 legitimately belong in the obj-*.c file. However, XCOFF is based
144 on COFF, and is only implemented for the RS/6000. We just use
145 obj-coff.c, and add what we need here. */
146 { "comm", ppc_comm
, 0 },
147 { "lcomm", ppc_comm
, 1 },
151 { "bi", ppc_biei
, 0 },
153 { "csect", ppc_csect
, 0 },
154 { "data", ppc_section
, 'd' },
158 { "ei", ppc_biei
, 1 },
160 { "extern", ppc_extern
, 0 },
161 { "function", ppc_function
, 0 },
162 { "lglobl", ppc_lglobl
, 0 },
163 { "rename", ppc_rename
, 0 },
164 { "stabx", ppc_stabx
, 0 },
165 { "text", ppc_section
, 't' },
166 { "toc", ppc_toc
, 0 },
170 { "long", ppc_elf_cons
, 4 },
171 { "word", ppc_elf_cons
, 2 },
172 { "short", ppc_elf_cons
, 2 },
173 { "rdata", ppc_elf_rdata
, 0 },
174 { "rodata", ppc_elf_rdata
, 0 },
175 { "lcomm", ppc_elf_lcomm
, 0 },
179 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
180 { "previous", ppc_previous
, 0 },
181 { "pdata", ppc_pdata
, 0 },
182 { "ydata", ppc_ydata
, 0 },
183 { "reldata", ppc_reldata
, 0 },
184 { "rdata", ppc_rdata
, 0 },
185 { "ualong", ppc_ualong
, 0 },
186 { "znop", ppc_znop
, 0 },
187 { "comm", ppc_pe_comm
, 0 },
188 { "lcomm", ppc_pe_comm
, 1 },
189 { "section", ppc_pe_section
, 0 },
190 { "function", ppc_pe_function
,0 },
191 { "tocd", ppc_pe_tocd
, 0 },
194 /* This pseudo-op is used even when not generating XCOFF output. */
201 /* Predefined register names if -mregnames (or default for Windows NT). */
202 /* In general, there are lots of them, in an attempt to be compatible */
203 /* with a number of other Windows NT assemblers. */
205 /* Structure to hold information about predefined registers. */
212 /* List of registers that are pre-defined:
214 Each general register has predefined names of the form:
215 1. r<reg_num> which has the value <reg_num>.
216 2. r.<reg_num> which has the value <reg_num>.
219 Each floating point register has predefined names of the form:
220 1. f<reg_num> which has the value <reg_num>.
221 2. f.<reg_num> which has the value <reg_num>.
223 Each condition register has predefined names of the form:
224 1. cr<reg_num> which has the value <reg_num>.
225 2. cr.<reg_num> which has the value <reg_num>.
227 There are individual registers as well:
228 sp or r.sp has the value 1
229 rtoc or r.toc has the value 2
230 fpscr has the value 0
236 dsisr has the value 18
238 sdr1 has the value 25
239 srr0 has the value 26
240 srr1 has the value 27
242 The table is sorted. Suitable for searching by a binary search. */
244 static const struct pd_reg pre_defined_registers
[] =
246 { "cr.0", 0 }, /* Condition Registers */
266 { "dar", 19 }, /* Data Access Register */
267 { "dec", 22 }, /* Decrementer */
268 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
270 { "f.0", 0 }, /* Floating point registers */
338 { "lr", 8 }, /* Link Register */
342 { "r.0", 0 }, /* General Purpose Registers */
375 { "r.sp", 1 }, /* Stack Pointer */
377 { "r.toc", 2 }, /* Pointer to the table of contents */
379 { "r0", 0 }, /* More general purpose registers */
412 { "rtoc", 2 }, /* Table of contents */
414 { "sdr1", 25 }, /* Storage Description Register 1 */
418 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
419 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
425 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
427 /* Given NAME, find the register number associated with that name, return
428 the integer value associated with the given name or -1 on failure. */
430 static int reg_name_search
PARAMS ( (char * name
) );
433 reg_name_search (name
)
436 int middle
, low
, high
;
440 high
= REG_NAME_CNT
- 1;
444 middle
= (low
+ high
) / 2;
445 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
451 return pre_defined_registers
[middle
].value
;
459 * Summary of register_name().
461 * in: Input_line_pointer points to 1st char of operand.
463 * out: A expressionS.
464 * The operand may have been a register: in this case, X_op == O_register,
465 * X_add_number is set to the register number, and truth is returned.
466 * Input_line_pointer->(next non-blank) char after operand, or is in its
471 register_name (expressionP
)
472 expressionS
*expressionP
;
479 /* Find the spelling of the operand */
480 start
= name
= input_line_pointer
;
481 if (name
[0] == '%' && isalpha (name
[1]))
482 name
= ++input_line_pointer
;
484 else if (!reg_names_p
|| !isalpha (name
[0]))
487 c
= get_symbol_end ();
488 reg_number
= reg_name_search (name
);
490 /* look to see if it's in the register table */
493 expressionP
->X_op
= O_register
;
494 expressionP
->X_add_number
= reg_number
;
496 /* make the rest nice */
497 expressionP
->X_add_symbol
= NULL
;
498 expressionP
->X_op_symbol
= NULL
;
499 *input_line_pointer
= c
; /* put back the delimiting char */
504 /* reset the line as if we had not done anything */
505 *input_line_pointer
= c
; /* put back the delimiting char */
506 input_line_pointer
= start
; /* reset input_line pointer */
512 /* Local variables. */
514 /* The type of processor we are assembling for. This is one or more
515 of the PPC_OPCODE flags defined in opcode/ppc.h. */
516 static int ppc_cpu
= 0;
518 /* The size of the processor we are assembling for. This is either
519 PPC_OPCODE_32 or PPC_OPCODE_64. */
520 static int ppc_size
= PPC_OPCODE_32
;
522 /* Opcode hash table. */
523 static struct hash_control
*ppc_hash
;
525 /* Macro hash table. */
526 static struct hash_control
*ppc_macro_hash
;
529 /* Whether to warn about non PC relative relocations that aren't
530 in the .got2 section. */
531 static boolean mrelocatable
= false;
533 /* Flags to set in the elf header */
534 static flagword ppc_flags
= 0;
539 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
540 using a bunch of different sections. These assembler sections,
541 however, are all encompassed within the .text or .data sections of
542 the final output file. We handle this by using different
543 subsegments within these main segments. */
545 /* Next subsegment to allocate within the .text segment. */
546 static subsegT ppc_text_subsegment
= 2;
548 /* Linked list of csects in the text section. */
549 static symbolS
*ppc_text_csects
;
551 /* Next subsegment to allocate within the .data segment. */
552 static subsegT ppc_data_subsegment
= 2;
554 /* Linked list of csects in the data section. */
555 static symbolS
*ppc_data_csects
;
557 /* The current csect. */
558 static symbolS
*ppc_current_csect
;
560 /* The RS/6000 assembler uses a TOC which holds addresses of functions
561 and variables. Symbols are put in the TOC with the .tc pseudo-op.
562 A special relocation is used when accessing TOC entries. We handle
563 the TOC as a subsegment within the .data segment. We set it up if
564 we see a .toc pseudo-op, and save the csect symbol here. */
565 static symbolS
*ppc_toc_csect
;
567 /* The first frag in the TOC subsegment. */
568 static fragS
*ppc_toc_frag
;
570 /* The first frag in the first subsegment after the TOC in the .data
571 segment. NULL if there are no subsegments after the TOC. */
572 static fragS
*ppc_after_toc_frag
;
574 /* The current static block. */
575 static symbolS
*ppc_current_block
;
577 /* The COFF debugging section; set by md_begin. This is not the
578 .debug section, but is instead the secret BFD section which will
579 cause BFD to set the section number of a symbol to N_DEBUG. */
580 static asection
*ppc_coff_debug_section
;
582 #endif /* OBJ_XCOFF */
586 /* Various sections that we need for PE coff support. */
587 static segT ydata_section
;
588 static segT pdata_section
;
589 static segT reldata_section
;
590 static segT rdata_section
;
591 static segT tocdata_section
;
593 /* The current section and the previous section. See ppc_previous. */
594 static segT ppc_previous_section
;
595 static segT ppc_current_section
;
600 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
603 #ifndef WORKING_DOT_WORD
604 const int md_short_jump_size
= 4;
605 const int md_long_jump_size
= 4;
609 CONST
char *md_shortopts
= "b:l:usm:VQ:";
611 CONST
char *md_shortopts
= "um:";
613 struct option md_longopts
[] = {
614 {NULL
, no_argument
, NULL
, 0}
616 size_t md_longopts_size
= sizeof(md_longopts
);
619 md_parse_option (c
, arg
)
626 /* -u means that any undefined symbols should be treated as
627 external, which is the default for gas anyhow. */
632 /* Solaris as takes -le (presumably for little endian). For completeness
633 sake, recognize -be also. */
634 if (strcmp (arg
, "e") == 0)
636 target_big_endian
= 0;
637 set_target_endian
= 1;
645 if (strcmp (arg
, "e") == 0)
647 target_big_endian
= 1;
648 set_target_endian
= 1;
657 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
659 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
660 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
661 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
662 else if (strcmp (arg
, "pwr") == 0)
663 ppc_cpu
= PPC_OPCODE_POWER
;
664 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
665 instructions that are holdovers from the Power. */
666 else if (strcmp (arg
, "601") == 0)
667 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
668 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
669 Motorola PowerPC 603/604. */
670 else if (strcmp (arg
, "ppc") == 0
671 || strcmp (arg
, "ppc32") == 0
672 || strcmp (arg
, "403") == 0
673 || strcmp (arg
, "603") == 0
674 || strcmp (arg
, "604") == 0)
675 ppc_cpu
= PPC_OPCODE_PPC
;
676 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
678 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
680 ppc_cpu
= PPC_OPCODE_PPC
;
681 ppc_size
= PPC_OPCODE_64
;
683 /* -mcom means assemble for the common intersection between Power
684 and PowerPC. At present, we just allow the union, rather
685 than the intersection. */
686 else if (strcmp (arg
, "com") == 0)
687 ppc_cpu
= PPC_OPCODE_COMMON
;
688 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
689 else if (strcmp (arg
, "any") == 0)
690 ppc_cpu
= PPC_OPCODE_ANY
;
692 else if (strcmp (arg
, "regnames") == 0)
695 else if (strcmp (arg
, "no-regnames") == 0)
699 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
700 else if (strcmp (arg
, "relocatable") == 0)
703 ppc_flags
|= EF_PPC_RELOCATABLE
;
706 else if (strcmp (arg
, "relocatable-lib") == 0)
709 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
712 /* -memb, set embedded bit */
713 else if (strcmp (arg
, "emb") == 0)
714 ppc_flags
|= EF_PPC_EMB
;
716 /* -mlittle/-mbig set the endianess */
717 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
719 target_big_endian
= 0;
720 set_target_endian
= 1;
723 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
725 target_big_endian
= 1;
726 set_target_endian
= 1;
731 as_bad ("invalid switch -m%s", arg
);
737 /* -V: SVR4 argument to print version ID. */
742 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
743 should be emitted or not. FIXME: Not implemented. */
747 /* Solaris takes -s to specify that .stabs go in a .stabs section,
748 rather than .stabs.excl, which is ignored by the linker.
749 FIXME: Not implemented. */
765 md_show_usage (stream
)
771 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
772 -mpwr generate code for IBM POWER (RIOS1)\n\
773 -m601 generate code for Motorola PowerPC 601\n\
774 -mppc, -mppc32, -m403, -m603, -m604\n\
775 generate code for Motorola PowerPC 603/604\n\
776 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
777 -mcom generate code Power/PowerPC common instructions\n\
778 -many generate code for any architecture (PWR/PWRX/PPC)\n\
779 -mregnames Allow symbolic names for registers\n\
780 -mno-regnames Do not allow symbolic names for registers\n");
783 -mrelocatable support for GCC's -mrelocatble option\n\
784 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
785 -memb set PPC_EMB bit in ELF flags\n\
786 -mlittle, -mlittle-endian\n\
787 generate code for a little endian machine\n\
788 -mbig, -mbig-endian generate code for a big endian machine\n\
789 -V print assembler version number\n\
790 -Qy, -Qn ignored\n");
794 /* Set ppc_cpu if it is not already set. */
799 const char *default_os
= TARGET_OS
;
800 const char *default_cpu
= TARGET_CPU
;
804 if (strncmp (default_os
, "aix", 3) == 0
805 && default_os
[3] >= '4' && default_os
[3] <= '9')
806 ppc_cpu
= PPC_OPCODE_COMMON
;
807 else if (strncmp (default_os
, "aix3", 4) == 0)
808 ppc_cpu
= PPC_OPCODE_POWER
;
809 else if (strcmp (default_cpu
, "rs6000") == 0)
810 ppc_cpu
= PPC_OPCODE_POWER
;
811 else if (strcmp (default_cpu
, "powerpc") == 0
812 || strcmp (default_cpu
, "powerpcle") == 0)
813 ppc_cpu
= PPC_OPCODE_PPC
;
815 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu
, default_os
);
819 /* Figure out the BFD architecture to use. */
821 enum bfd_architecture
824 const char *default_cpu
= TARGET_CPU
;
827 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
828 return bfd_arch_powerpc
;
829 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
830 return bfd_arch_rs6000
;
831 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
833 if (strcmp (default_cpu
, "rs6000") == 0)
834 return bfd_arch_rs6000
;
835 else if (strcmp (default_cpu
, "powerpc") == 0
836 || strcmp (default_cpu
, "powerpcle") == 0)
837 return bfd_arch_powerpc
;
840 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
841 return bfd_arch_unknown
;
844 /* This function is called when the assembler starts up. It is called
845 after the options have been parsed and the output file has been
851 register const struct powerpc_opcode
*op
;
852 const struct powerpc_opcode
*op_end
;
853 const struct powerpc_macro
*macro
;
854 const struct powerpc_macro
*macro_end
;
855 boolean dup_insn
= false;
860 /* Set the ELF flags if desired. */
862 bfd_set_private_flags (stdoutput
, ppc_flags
);
865 /* Insert the opcodes into a hash table. */
866 ppc_hash
= hash_new ();
868 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
869 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
871 know ((op
->opcode
& op
->mask
) == op
->opcode
);
873 if ((op
->flags
& ppc_cpu
) != 0
874 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
875 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
879 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
880 if (retval
!= (const char *) NULL
)
882 /* Ignore Power duplicates for -m601 */
883 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
884 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
887 as_bad ("Internal assembler error for instruction %s", op
->name
);
893 /* Insert the macros into a hash table. */
894 ppc_macro_hash
= hash_new ();
896 macro_end
= powerpc_macros
+ powerpc_num_macros
;
897 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
899 if ((macro
->flags
& ppc_cpu
) != 0)
903 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
904 if (retval
!= (const char *) NULL
)
906 as_bad ("Internal assembler error for macro %s", macro
->name
);
915 /* Tell the main code what the endianness is if it is not overidden by the user. */
916 if (!set_target_endian
)
918 set_target_endian
= 1;
919 target_big_endian
= PPC_BIG_ENDIAN
;
923 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
925 /* Create dummy symbols to serve as initial csects. This forces the
926 text csects to precede the data csects. These symbols will not
928 ppc_text_csects
= symbol_make ("dummy\001");
929 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
930 ppc_data_csects
= symbol_make ("dummy\001");
931 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
936 ppc_current_section
= text_section
;
937 ppc_previous_section
= 0;
942 /* Insert an operand value into an instruction. */
945 ppc_insert_operand (insn
, operand
, val
, file
, line
)
947 const struct powerpc_operand
*operand
;
952 if (operand
->bits
!= 32)
957 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
959 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
960 && ppc_size
== PPC_OPCODE_32
)
961 max
= (1 << operand
->bits
) - 1;
963 max
= (1 << (operand
->bits
- 1)) - 1;
964 min
= - (1 << (operand
->bits
- 1));
968 max
= (1 << operand
->bits
) - 1;
972 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
977 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
980 "operand out of range (%s not between %ld and %ld)";
983 sprint_value (buf
, test
);
984 if (file
== (char *) NULL
)
985 as_warn (err
, buf
, min
, max
);
987 as_warn_where (file
, line
, err
, buf
, min
, max
);
996 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
997 if (errmsg
!= (const char *) NULL
)
1001 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1009 /* Parse @got, etc. and return the desired relocation. */
1010 static bfd_reloc_code_real_type
1011 ppc_elf_suffix (str_p
)
1017 bfd_reloc_code_real_type reloc
;
1025 struct map_bfd
*ptr
;
1027 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1029 static struct map_bfd mapping
[] = {
1030 MAP ("l", BFD_RELOC_LO16
),
1031 MAP ("h", BFD_RELOC_HI16
),
1032 MAP ("ha", BFD_RELOC_HI16_S
),
1033 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1034 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1035 MAP ("got", BFD_RELOC_16_GOTOFF
),
1036 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1037 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1038 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1039 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
1040 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1041 MAP ("copy", BFD_RELOC_PPC_COPY
),
1042 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1043 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1044 MAP ("plt", BFD_RELOC_32_PLTOFF
),
1045 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1046 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1047 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1048 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1049 MAP ("sdarel", BFD_RELOC_GPREL16
),
1050 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
1051 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1052 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1053 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1054 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1055 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1056 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1057 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1058 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1059 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1060 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1061 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1062 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1063 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1064 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1065 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1066 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1067 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1068 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1069 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1070 MAP ("xgot", BFD_RELOC_PPC_TOC16
),
1072 { (char *)0, 0, BFD_RELOC_UNUSED
}
1076 return BFD_RELOC_UNUSED
;
1078 for (ch
= *str
, str2
= ident
;
1079 (str2
< ident
+ sizeof (ident
) - 1
1080 && (isalnum (ch
) || ch
== '@'));
1083 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
1090 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1091 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1097 return BFD_RELOC_UNUSED
;
1100 /* Like normal .long/.short/.word, except support @got, etc. */
1101 /* clobbers input_line_pointer, checks */
1104 ppc_elf_cons (nbytes
)
1105 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
1108 bfd_reloc_code_real_type reloc
;
1110 if (is_it_end_of_statement ())
1112 demand_empty_rest_of_line ();
1119 if (exp
.X_op
== O_symbol
1120 && *input_line_pointer
== '@'
1121 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
1123 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1124 int size
= bfd_get_reloc_size (reloc_howto
);
1127 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
1131 register char *p
= frag_more ((int) nbytes
);
1132 int offset
= nbytes
- size
;
1134 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1138 emit_expr (&exp
, (unsigned int) nbytes
);
1140 while (*input_line_pointer
++ == ',');
1142 input_line_pointer
--; /* Put terminator back into stream. */
1143 demand_empty_rest_of_line ();
1146 /* Solaris pseduo op to change to the .rodata section. */
1151 char *save_line
= input_line_pointer
;
1152 static char section
[] = ".rodata\n";
1154 /* Just pretend this is .section .rodata */
1155 input_line_pointer
= section
;
1156 obj_elf_section (xxx
);
1158 input_line_pointer
= save_line
;
1161 /* Pseudo op to make file scope bss items */
1166 register char *name
;
1170 register symbolS
*symbolP
;
1177 name
= input_line_pointer
;
1178 c
= get_symbol_end ();
1180 /* just after name is now '\0' */
1181 p
= input_line_pointer
;
1184 if (*input_line_pointer
!= ',')
1186 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1187 ignore_rest_of_line ();
1191 input_line_pointer
++; /* skip ',' */
1192 if ((size
= get_absolute_expression ()) < 0)
1194 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size
);
1195 ignore_rest_of_line ();
1199 /* The third argument to .lcomm is the alignment. */
1200 if (*input_line_pointer
!= ',')
1204 ++input_line_pointer
;
1205 align
= get_absolute_expression ();
1208 as_warn ("ignoring bad alignment");
1214 symbolP
= symbol_find_or_make (name
);
1217 if (S_IS_DEFINED (symbolP
))
1219 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1220 S_GET_NAME (symbolP
));
1221 ignore_rest_of_line ();
1225 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1227 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1228 S_GET_NAME (symbolP
),
1229 (long) S_GET_VALUE (symbolP
),
1232 ignore_rest_of_line ();
1238 old_subsec
= now_subseg
;
1241 /* convert to a power of 2 alignment */
1242 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1245 as_bad ("Common alignment not a power of 2");
1246 ignore_rest_of_line ();
1253 record_alignment (bss_section
, align2
);
1254 subseg_set (bss_section
, 0);
1256 frag_align (align2
, 0);
1257 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1258 symbolP
->sy_frag
->fr_symbol
= 0;
1259 symbolP
->sy_frag
= frag_now
;
1260 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1263 S_SET_SIZE (symbolP
, size
);
1264 S_SET_SEGMENT (symbolP
, bss_section
);
1265 S_CLEAR_EXTERNAL (symbolP
);
1266 subseg_set (old_sec
, old_subsec
);
1267 demand_empty_rest_of_line ();
1270 /* Validate any relocations emitted for -mrelocatable, possibly adding
1271 fixups for word relocations in writable segments, so we can adjust
1274 ppc_elf_validate_fix (fixp
, seg
)
1281 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1282 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1283 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1284 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1285 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1286 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1287 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1288 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1289 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1290 && strcmp (segment_name (seg
), ".got2") != 0
1291 && strcmp (segment_name (seg
), ".dtors") != 0
1292 && strcmp (segment_name (seg
), ".ctors") != 0
1293 && strcmp (segment_name (seg
), ".fixup") != 0
1294 && strcmp (segment_name (seg
), ".stab") != 0
1295 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1296 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1298 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1299 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1301 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
1302 "Relocation cannot be done when using -mrelocatable");
1306 #endif /* OBJ_ELF */
1311 * Summary of parse_toc_entry().
1313 * in: Input_line_pointer points to the '[' in one of:
1315 * [toc] [tocv] [toc32] [toc64]
1317 * Anything else is an error of one kind or another.
1320 * return value: success or failure
1321 * toc_kind: kind of toc reference
1322 * input_line_pointer:
1323 * success: first char after the ']'
1324 * failure: unchanged
1328 * [toc] - rv == success, toc_kind = default_toc
1329 * [tocv] - rv == success, toc_kind = data_in_toc
1330 * [toc32] - rv == success, toc_kind = must_be_32
1331 * [toc64] - rv == success, toc_kind = must_be_64
1335 enum toc_size_qualifier
1337 default_toc
, /* The toc cell constructed should be the system default size */
1338 data_in_toc
, /* This is a direct reference to a toc cell */
1339 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1340 must_be_64
/* The toc cell constructed must be 64 bits wide */
1344 parse_toc_entry(toc_kind
)
1345 enum toc_size_qualifier
*toc_kind
;
1350 enum toc_size_qualifier t
;
1352 /* save the input_line_pointer */
1353 start
= input_line_pointer
;
1355 /* skip over the '[' , and whitespace */
1356 ++input_line_pointer
;
1359 /* find the spelling of the operand */
1360 toc_spec
= input_line_pointer
;
1361 c
= get_symbol_end ();
1363 if (strcmp(toc_spec
, "toc") == 0)
1367 else if (strcmp(toc_spec
, "tocv") == 0)
1371 else if (strcmp(toc_spec
, "toc32") == 0)
1375 else if (strcmp(toc_spec
, "toc64") == 0)
1381 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1382 *input_line_pointer
= c
; /* put back the delimiting char */
1383 input_line_pointer
= start
; /* reset input_line pointer */
1387 /* now find the ']' */
1388 *input_line_pointer
= c
; /* put back the delimiting char */
1390 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1391 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1395 as_bad ("syntax error: expected `]', found `%c'", c
);
1396 input_line_pointer
= start
; /* reset input_line pointer */
1400 *toc_kind
= t
; /* set return value */
1406 /* We need to keep a list of fixups. We can't simply generate them as
1407 we go, because that would require us to first create the frag, and
1408 that would screw up references to ``.''. */
1414 bfd_reloc_code_real_type reloc
;
1417 #define MAX_INSN_FIXUPS (5)
1419 /* This routine is called for each instruction to be assembled. */
1426 const struct powerpc_opcode
*opcode
;
1428 const unsigned char *opindex_ptr
;
1432 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1437 bfd_reloc_code_real_type reloc
;
1440 /* Get the opcode. */
1441 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1446 /* Look up the opcode in the hash table. */
1447 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1448 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1450 const struct powerpc_macro
*macro
;
1452 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1453 if (macro
== (const struct powerpc_macro
*) NULL
)
1454 as_bad ("Unrecognized opcode: `%s'", str
);
1456 ppc_macro (s
, macro
);
1461 insn
= opcode
->opcode
;
1464 while (isspace (*str
))
1467 /* PowerPC operands are just expressions. The only real issue is
1468 that a few operand types are optional. All cases which might use
1469 an optional operand separate the operands only with commas (in
1470 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1471 cases never have optional operands). There is never more than
1472 one optional operand for an instruction. So, before we start
1473 seriously parsing the operands, we check to see if we have an
1474 optional operand, and, if we do, we count the number of commas to
1475 see whether the operand should be omitted. */
1477 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1479 const struct powerpc_operand
*operand
;
1481 operand
= &powerpc_operands
[*opindex_ptr
];
1482 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1484 unsigned int opcount
;
1486 /* There is an optional operand. Count the number of
1487 commas in the input line. */
1494 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1501 /* If there are fewer operands in the line then are called
1502 for by the instruction, we want to skip the optional
1504 if (opcount
< strlen (opcode
->operands
))
1511 /* Gather the operands. */
1515 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1517 const struct powerpc_operand
*operand
;
1523 if (next_opindex
== 0)
1524 operand
= &powerpc_operands
[*opindex_ptr
];
1527 operand
= &powerpc_operands
[next_opindex
];
1533 /* If this is a fake operand, then we do not expect anything
1535 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1537 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1538 if (errmsg
!= (const char *) NULL
)
1543 /* If this is an optional operand, and we are skipping it, just
1545 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1548 if (operand
->insert
)
1550 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1551 if (errmsg
!= (const char *) NULL
)
1554 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1555 next_opindex
= *opindex_ptr
+ 1;
1559 /* Gather the operand. */
1560 hold
= input_line_pointer
;
1561 input_line_pointer
= str
;
1564 if (*input_line_pointer
== '[')
1566 /* We are expecting something like the second argument here:
1568 lwz r4,[toc].GS.0.static_int(rtoc)
1569 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1570 The argument following the `]' must be a symbol name, and the
1571 register must be the toc register: 'rtoc' or '2'
1573 The effect is to 0 as the displacement field
1574 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1575 the appropriate variation) reloc against it based on the symbol.
1576 The linker will build the toc, and insert the resolved toc offset.
1579 o The size of the toc entry is currently assumed to be
1580 32 bits. This should not be assumed to be a hard coded
1582 o In an effort to cope with a change from 32 to 64 bits,
1583 there are also toc entries that are specified to be
1584 either 32 or 64 bits:
1585 lwz r4,[toc32].GS.0.static_int(rtoc)
1586 lwz r4,[toc64].GS.0.static_int(rtoc)
1587 These demand toc entries of the specified size, and the
1588 instruction probably requires it.
1592 enum toc_size_qualifier toc_kind
;
1593 bfd_reloc_code_real_type toc_reloc
;
1595 /* go parse off the [tocXX] part */
1596 valid_toc
= parse_toc_entry(&toc_kind
);
1600 /* Note: message has already been issued. */
1601 /* FIXME: what sort of recovery should we do? */
1602 /* demand_rest_of_line(); return; ? */
1605 /* Now get the symbol following the ']' */
1611 /* In this case, we may not have seen the symbol yet, since */
1612 /* it is allowed to appear on a .extern or .globl or just be */
1613 /* a label in the .data section. */
1614 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1617 /* 1. The symbol must be defined and either in the toc */
1618 /* section, or a global. */
1619 /* 2. The reloc generated must have the TOCDEFN flag set in */
1620 /* upper bit mess of the reloc type. */
1621 /* FIXME: It's a little confusing what the tocv qualifier can */
1622 /* be used for. At the very least, I've seen three */
1623 /* uses, only one of which I'm sure I can explain. */
1624 if (ex
.X_op
== O_symbol
)
1626 assert (ex
.X_add_symbol
!= NULL
);
1627 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1629 as_warn("[tocv] symbol is not a toc symbol");
1633 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1636 /* FIXME: these next two specifically specify 32/64 bit toc */
1637 /* entries. We don't support them today. Is this the */
1638 /* right way to say that? */
1639 toc_reloc
= BFD_RELOC_UNUSED
;
1640 as_bad ("Unimplemented toc32 expression modifier");
1643 /* FIXME: see above */
1644 toc_reloc
= BFD_RELOC_UNUSED
;
1645 as_bad ("Unimplemented toc64 expression modifier");
1649 "Unexpected return value [%d] from parse_toc_entry!\n",
1655 /* We need to generate a fixup for this expression. */
1656 if (fc
>= MAX_INSN_FIXUPS
)
1657 as_fatal ("too many fixups");
1659 fixups
[fc
].reloc
= toc_reloc
;
1660 fixups
[fc
].exp
= ex
;
1661 fixups
[fc
].opindex
= *opindex_ptr
;
1664 /* Ok. We've set up the fixup for the instruction. Now make it
1665 look like the constant 0 was found here */
1667 ex
.X_op
= O_constant
;
1668 ex
.X_add_number
= 0;
1669 ex
.X_add_symbol
= NULL
;
1670 ex
.X_op_symbol
= NULL
;
1675 if (!register_name(&ex
))
1678 str
= input_line_pointer
;
1679 input_line_pointer
= hold
;
1681 if (ex
.X_op
== O_illegal
)
1682 as_bad ("illegal operand");
1683 else if (ex
.X_op
== O_absent
)
1684 as_bad ("missing operand");
1685 else if (ex
.X_op
== O_register
)
1687 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1690 else if (ex
.X_op
== O_constant
)
1693 /* Allow @HA, @L, @H on constants. */
1694 char *orig_str
= str
;
1696 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1703 case BFD_RELOC_LO16
:
1705 ex
.X_add_number
&= 0xffff;
1707 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
1712 case BFD_RELOC_HI16
:
1713 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1716 case BFD_RELOC_HI16_S
:
1717 ex
.X_add_number
= (((ex
.X_add_number
>> 16) & 0xffff)
1718 + ((ex
.X_add_number
>> 15) & 1));
1722 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1726 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1728 /* For the absoulte forms of branchs, convert the PC relative form back into
1730 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1734 case BFD_RELOC_PPC_B26
:
1735 reloc
= BFD_RELOC_PPC_BA26
;
1737 case BFD_RELOC_PPC_B16
:
1738 reloc
= BFD_RELOC_PPC_BA16
;
1740 case BFD_RELOC_PPC_B16_BRTAKEN
:
1741 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
1743 case BFD_RELOC_PPC_B16_BRNTAKEN
:
1744 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
1751 /* We need to generate a fixup for this expression. */
1752 if (fc
>= MAX_INSN_FIXUPS
)
1753 as_fatal ("too many fixups");
1754 fixups
[fc
].exp
= ex
;
1755 fixups
[fc
].opindex
= 0;
1756 fixups
[fc
].reloc
= reloc
;
1759 #endif /* OBJ_ELF */
1763 /* We need to generate a fixup for this expression. */
1764 if (fc
>= MAX_INSN_FIXUPS
)
1765 as_fatal ("too many fixups");
1766 fixups
[fc
].exp
= ex
;
1767 fixups
[fc
].opindex
= *opindex_ptr
;
1768 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1777 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1785 /* The call to expression should have advanced str past any
1788 && (endc
!= ',' || *str
!= '\0'))
1790 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1798 while (isspace (*str
))
1802 as_bad ("junk at end of line: `%s'", str
);
1804 /* Write out the instruction. */
1806 md_number_to_chars (f
, insn
, 4);
1808 /* Create any fixups. At this point we do not use a
1809 bfd_reloc_code_real_type, but instead just use the
1810 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1811 handle fixups for any operand type, although that is admittedly
1812 not a very exciting feature. We pick a BFD reloc type in
1814 for (i
= 0; i
< fc
; i
++)
1816 const struct powerpc_operand
*operand
;
1818 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1819 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1821 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1829 size
= bfd_get_reloc_size (reloc_howto
);
1830 offset
= target_big_endian
? (4 - size
) : 0;
1832 if (size
< 1 || size
> 4)
1835 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1836 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1839 /* Turn off complaints that the addend is too large for things like
1841 switch (fixups
[i
].reloc
)
1843 case BFD_RELOC_16_GOTOFF
:
1844 case BFD_RELOC_PPC_TOC16
:
1845 case BFD_RELOC_LO16
:
1846 case BFD_RELOC_HI16
:
1847 case BFD_RELOC_HI16_S
:
1848 fixP
->fx_no_overflow
= 1;
1855 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1857 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1858 ((bfd_reloc_code_real_type
)
1859 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1863 #ifndef WORKING_DOT_WORD
1864 /* Handle long and short jumps */
1866 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1868 addressT from_addr
, to_addr
;
1876 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1878 addressT from_addr
, to_addr
;
1886 /* Handle a macro. Gather all the operands, transform them as
1887 described by the macro, and call md_assemble recursively. All the
1888 operands are separated by commas; we don't accept parentheses
1889 around operands here. */
1892 ppc_macro (str
, macro
)
1894 const struct powerpc_macro
*macro
;
1905 /* Gather the users operands into the operands array. */
1910 if (count
>= sizeof operands
/ sizeof operands
[0])
1912 operands
[count
++] = s
;
1913 s
= strchr (s
, ',');
1914 if (s
== (char *) NULL
)
1919 if (count
!= macro
->operands
)
1921 as_bad ("wrong number of operands");
1925 /* Work out how large the string must be (the size is unbounded
1926 because it includes user input). */
1928 format
= macro
->format
;
1929 while (*format
!= '\0')
1938 arg
= strtol (format
+ 1, &send
, 10);
1939 know (send
!= format
&& arg
>= 0 && arg
< count
);
1940 len
+= strlen (operands
[arg
]);
1945 /* Put the string together. */
1946 complete
= s
= (char *) alloca (len
+ 1);
1947 format
= macro
->format
;
1948 while (*format
!= '\0')
1954 arg
= strtol (format
+ 1, &send
, 10);
1955 strcpy (s
, operands
[arg
]);
1962 /* Assemble the constructed instruction. */
1963 md_assemble (complete
);
1967 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
1970 ppc_section_letter (letter
, ptr_msg
)
1977 *ptr_msg
= "Bad .section directive: want a,w,x,e in string";
1982 ppc_section_word (ptr_str
)
1985 if (strncmp (*ptr_str
, "exclude", sizeof ("exclude")-1) == 0)
1987 *ptr_str
+= sizeof ("exclude")-1;
1995 ppc_section_type (ptr_str
)
1998 if (strncmp (*ptr_str
, "ordered", sizeof ("ordered")-1) == 0)
2000 *ptr_str
+= sizeof ("ordered")-1;
2008 ppc_section_flags (flags
, attr
, type
)
2013 if (type
== SHT_ORDERED
)
2014 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2016 if (attr
& SHF_EXCLUDE
)
2017 flags
|= SEC_EXCLUDE
;
2021 #endif /* OBJ_ELF */
2024 /* Pseudo-op handling. */
2026 /* The .byte pseudo-op. This is similar to the normal .byte
2027 pseudo-op, but it can also take a single ASCII string. */
2033 if (*input_line_pointer
!= '\"')
2039 /* Gather characters. A real double quote is doubled. Unusual
2040 characters are not permitted. */
2041 ++input_line_pointer
;
2046 c
= *input_line_pointer
++;
2050 if (*input_line_pointer
!= '\"')
2052 ++input_line_pointer
;
2055 FRAG_APPEND_1_CHAR (c
);
2058 demand_empty_rest_of_line ();
2063 /* XCOFF specific pseudo-op handling. */
2065 /* This is set if we are creating a .stabx symbol, since we don't want
2066 to handle symbol suffixes for such symbols. */
2067 static boolean ppc_stab_symbol
;
2069 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2070 symbols in the .bss segment as though they were local common
2071 symbols, and uses a different smclas. */
2077 asection
*current_seg
= now_seg
;
2078 subsegT current_subseg
= now_subseg
;
2084 symbolS
*lcomm_sym
= NULL
;
2088 name
= input_line_pointer
;
2089 endc
= get_symbol_end ();
2090 end_name
= input_line_pointer
;
2093 if (*input_line_pointer
!= ',')
2095 as_bad ("missing size");
2096 ignore_rest_of_line ();
2099 ++input_line_pointer
;
2101 size
= get_absolute_expression ();
2104 as_bad ("negative size");
2105 ignore_rest_of_line ();
2111 /* The third argument to .comm is the alignment. */
2112 if (*input_line_pointer
!= ',')
2116 ++input_line_pointer
;
2117 align
= get_absolute_expression ();
2120 as_warn ("ignoring bad alignment");
2139 /* The third argument to .lcomm appears to be the real local
2140 common symbol to create. References to the symbol named in
2141 the first argument are turned into references to the third
2143 if (*input_line_pointer
!= ',')
2145 as_bad ("missing real symbol name");
2146 ignore_rest_of_line ();
2149 ++input_line_pointer
;
2151 lcomm_name
= input_line_pointer
;
2152 lcomm_endc
= get_symbol_end ();
2154 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2156 *input_line_pointer
= lcomm_endc
;
2160 sym
= symbol_find_or_make (name
);
2163 if (S_IS_DEFINED (sym
)
2164 || S_GET_VALUE (sym
) != 0)
2166 as_bad ("attempt to redefine symbol");
2167 ignore_rest_of_line ();
2171 record_alignment (bss_section
, align
);
2174 || ! S_IS_DEFINED (lcomm_sym
))
2183 S_SET_EXTERNAL (sym
);
2187 lcomm_sym
->sy_tc
.output
= 1;
2188 def_sym
= lcomm_sym
;
2192 subseg_set (bss_section
, 1);
2193 frag_align (align
, 0);
2195 def_sym
->sy_frag
= frag_now
;
2196 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2197 def_size
, (char *) NULL
);
2199 S_SET_SEGMENT (def_sym
, bss_section
);
2200 def_sym
->sy_tc
.align
= align
;
2204 /* Align the size of lcomm_sym. */
2205 lcomm_sym
->sy_frag
->fr_offset
=
2206 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
2207 &~ ((1 << align
) - 1));
2208 if (align
> lcomm_sym
->sy_tc
.align
)
2209 lcomm_sym
->sy_tc
.align
= align
;
2214 /* Make sym an offset from lcomm_sym. */
2215 S_SET_SEGMENT (sym
, bss_section
);
2216 sym
->sy_frag
= lcomm_sym
->sy_frag
;
2217 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
2218 lcomm_sym
->sy_frag
->fr_offset
+= size
;
2221 subseg_set (current_seg
, current_subseg
);
2223 demand_empty_rest_of_line ();
2226 /* The .csect pseudo-op. This switches us into a different
2227 subsegment. The first argument is a symbol whose value is the
2228 start of the .csect. In COFF, csect symbols get special aux
2229 entries defined by the x_csect field of union internal_auxent. The
2230 optional second argument is the alignment (the default is 2). */
2240 name
= input_line_pointer
;
2241 endc
= get_symbol_end ();
2243 sym
= symbol_find_or_make (name
);
2245 *input_line_pointer
= endc
;
2247 if (S_GET_NAME (sym
)[0] == '\0')
2249 /* An unnamed csect is assumed to be [PR]. */
2250 sym
->sy_tc
.class = XMC_PR
;
2253 ppc_change_csect (sym
);
2255 if (*input_line_pointer
== ',')
2257 ++input_line_pointer
;
2258 sym
->sy_tc
.align
= get_absolute_expression ();
2261 demand_empty_rest_of_line ();
2264 /* Change to a different csect. */
2267 ppc_change_csect (sym
)
2270 if (S_IS_DEFINED (sym
))
2271 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
2278 /* This is a new csect. We need to look at the symbol class to
2279 figure out whether it should go in the text section or the
2282 switch (sym
->sy_tc
.class)
2292 S_SET_SEGMENT (sym
, text_section
);
2293 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
2294 ++ppc_text_subsegment
;
2295 list_ptr
= &ppc_text_csects
;
2304 if (ppc_toc_csect
!= NULL
2305 && ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
2307 S_SET_SEGMENT (sym
, data_section
);
2308 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
2309 ++ppc_data_subsegment
;
2310 list_ptr
= &ppc_data_csects
;
2316 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
2318 ppc_after_toc_frag
= frag_now
;
2320 sym
->sy_frag
= frag_now
;
2321 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2323 sym
->sy_tc
.align
= 2;
2324 sym
->sy_tc
.output
= 1;
2325 sym
->sy_tc
.within
= sym
;
2327 for (list
= *list_ptr
;
2328 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2329 list
= list
->sy_tc
.next
)
2331 list
->sy_tc
.next
= sym
;
2333 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2334 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2337 ppc_current_csect
= sym
;
2340 /* This function handles the .text and .data pseudo-ops. These
2341 pseudo-ops aren't really used by XCOFF; we implement them for the
2342 convenience of people who aren't used to XCOFF. */
2353 else if (type
== 'd')
2358 sym
= symbol_find_or_make (name
);
2360 ppc_change_csect (sym
);
2362 demand_empty_rest_of_line ();
2365 /* The .extern pseudo-op. We create an undefined symbol. */
2374 name
= input_line_pointer
;
2375 endc
= get_symbol_end ();
2377 (void) symbol_find_or_make (name
);
2379 *input_line_pointer
= endc
;
2381 demand_empty_rest_of_line ();
2384 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2394 name
= input_line_pointer
;
2395 endc
= get_symbol_end ();
2397 sym
= symbol_find_or_make (name
);
2399 *input_line_pointer
= endc
;
2401 sym
->sy_tc
.output
= 1;
2403 demand_empty_rest_of_line ();
2406 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2407 although I don't know why it bothers. */
2418 name
= input_line_pointer
;
2419 endc
= get_symbol_end ();
2421 sym
= symbol_find_or_make (name
);
2423 *input_line_pointer
= endc
;
2425 if (*input_line_pointer
!= ',')
2427 as_bad ("missing rename string");
2428 ignore_rest_of_line ();
2431 ++input_line_pointer
;
2433 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2435 demand_empty_rest_of_line ();
2438 /* The .stabx pseudo-op. This is similar to a normal .stabs
2439 pseudo-op, but slightly different. A sample is
2440 .stabx "main:F-1",.main,142,0
2441 The first argument is the symbol name to create. The second is the
2442 value, and the third is the storage class. The fourth seems to be
2443 always zero, and I am assuming it is the type. */
2454 name
= demand_copy_C_string (&len
);
2456 if (*input_line_pointer
!= ',')
2458 as_bad ("missing value");
2461 ++input_line_pointer
;
2463 ppc_stab_symbol
= true;
2464 sym
= symbol_make (name
);
2465 ppc_stab_symbol
= false;
2467 sym
->sy_tc
.real_name
= name
;
2469 (void) expression (&exp
);
2476 as_bad ("illegal .stabx expression; zero assumed");
2477 exp
.X_add_number
= 0;
2480 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2481 sym
->sy_frag
= &zero_address_frag
;
2485 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2486 sym
->sy_value
= exp
;
2490 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2491 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2496 /* The value is some complex expression. This will probably
2497 fail at some later point, but this is probably the right
2498 thing to do here. */
2499 sym
->sy_value
= exp
;
2503 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2504 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2506 if (*input_line_pointer
!= ',')
2508 as_bad ("missing class");
2511 ++input_line_pointer
;
2513 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2515 if (*input_line_pointer
!= ',')
2517 as_bad ("missing type");
2520 ++input_line_pointer
;
2522 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2524 sym
->sy_tc
.output
= 1;
2526 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2527 sym
->sy_tc
.within
= ppc_current_block
;
2529 if (exp
.X_op
!= O_symbol
2530 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2531 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2532 ppc_frob_label (sym
);
2535 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2536 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2537 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2538 ppc_current_csect
->sy_tc
.within
= sym
;
2541 demand_empty_rest_of_line ();
2544 /* The .function pseudo-op. This takes several arguments. The first
2545 argument seems to be the external name of the symbol. The second
2546 argment seems to be the label for the start of the function. gcc
2547 uses the same name for both. I have no idea what the third and
2548 fourth arguments are meant to be. The optional fifth argument is
2549 an expression for the size of the function. In COFF this symbol
2550 gets an aux entry like that used for a csect. */
2553 ppc_function (ignore
)
2562 name
= input_line_pointer
;
2563 endc
= get_symbol_end ();
2565 /* Ignore any [PR] suffix. */
2566 name
= ppc_canonicalize_symbol_name (name
);
2567 s
= strchr (name
, '[');
2568 if (s
!= (char *) NULL
2569 && strcmp (s
+ 1, "PR]") == 0)
2572 ext_sym
= symbol_find_or_make (name
);
2574 *input_line_pointer
= endc
;
2576 if (*input_line_pointer
!= ',')
2578 as_bad ("missing symbol name");
2579 ignore_rest_of_line ();
2582 ++input_line_pointer
;
2584 name
= input_line_pointer
;
2585 endc
= get_symbol_end ();
2587 lab_sym
= symbol_find_or_make (name
);
2589 *input_line_pointer
= endc
;
2591 if (ext_sym
!= lab_sym
)
2593 ext_sym
->sy_value
.X_op
= O_symbol
;
2594 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2595 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2596 ext_sym
->sy_value
.X_add_number
= 0;
2599 if (ext_sym
->sy_tc
.class == -1)
2600 ext_sym
->sy_tc
.class = XMC_PR
;
2601 ext_sym
->sy_tc
.output
= 1;
2603 if (*input_line_pointer
== ',')
2607 /* Ignore the third argument. */
2608 ++input_line_pointer
;
2609 expression (&ignore
);
2610 if (*input_line_pointer
== ',')
2612 /* Ignore the fourth argument. */
2613 ++input_line_pointer
;
2614 expression (&ignore
);
2615 if (*input_line_pointer
== ',')
2617 /* The fifth argument is the function size. */
2618 ++input_line_pointer
;
2619 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2622 &zero_address_frag
);
2623 pseudo_set (ext_sym
->sy_tc
.size
);
2628 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2629 SF_SET_FUNCTION (ext_sym
);
2630 SF_SET_PROCESS (ext_sym
);
2631 coff_add_linesym (ext_sym
);
2633 demand_empty_rest_of_line ();
2636 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2645 sym
= symbol_make (".bf");
2646 S_SET_SEGMENT (sym
, text_section
);
2647 sym
->sy_frag
= frag_now
;
2648 S_SET_VALUE (sym
, frag_now_fix ());
2649 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2651 coff_line_base
= get_absolute_expression ();
2653 S_SET_NUMBER_AUXILIARY (sym
, 1);
2654 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2656 sym
->sy_tc
.output
= 1;
2658 ppc_frob_label (sym
);
2660 demand_empty_rest_of_line ();
2663 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2664 ".ef", except that the line number is absolute, not relative to the
2665 most recent ".bf" symbol. */
2673 sym
= symbol_make (".ef");
2674 S_SET_SEGMENT (sym
, text_section
);
2675 sym
->sy_frag
= frag_now
;
2676 S_SET_VALUE (sym
, frag_now_fix ());
2677 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2678 S_SET_NUMBER_AUXILIARY (sym
, 1);
2679 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2680 sym
->sy_tc
.output
= 1;
2682 ppc_frob_label (sym
);
2684 demand_empty_rest_of_line ();
2687 /* The .bi and .ei pseudo-ops. These take a string argument and
2688 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2700 name
= demand_copy_C_string (&len
);
2702 /* The value of these symbols is actually file offset. Here we set
2703 the value to the index into the line number entries. In
2704 ppc_frob_symbols we set the fix_line field, which will cause BFD
2705 to do the right thing. */
2707 sym
= symbol_make (name
);
2708 /* obj-coff.c currently only handles line numbers correctly in the
2710 S_SET_SEGMENT (sym
, text_section
);
2711 S_SET_VALUE (sym
, coff_n_line_nos
);
2712 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2714 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2715 sym
->sy_tc
.output
= 1;
2717 for (look
= symbol_rootP
;
2718 (look
!= (symbolS
*) NULL
2719 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2720 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2721 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2722 look
= symbol_next (look
))
2724 if (look
!= (symbolS
*) NULL
)
2726 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2727 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2730 demand_empty_rest_of_line ();
2733 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2734 There is one argument, which is a csect symbol. The value of the
2735 .bs symbol is the index of this csect symbol. */
2746 if (ppc_current_block
!= NULL
)
2747 as_bad ("nested .bs blocks");
2749 name
= input_line_pointer
;
2750 endc
= get_symbol_end ();
2752 csect
= symbol_find_or_make (name
);
2754 *input_line_pointer
= endc
;
2756 sym
= symbol_make (".bs");
2757 S_SET_SEGMENT (sym
, now_seg
);
2758 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2759 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2760 sym
->sy_tc
.output
= 1;
2762 sym
->sy_tc
.within
= csect
;
2764 ppc_frob_label (sym
);
2766 ppc_current_block
= sym
;
2768 demand_empty_rest_of_line ();
2771 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2779 if (ppc_current_block
== NULL
)
2780 as_bad (".es without preceding .bs");
2782 sym
= symbol_make (".es");
2783 S_SET_SEGMENT (sym
, now_seg
);
2784 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2785 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2786 sym
->sy_tc
.output
= 1;
2788 ppc_frob_label (sym
);
2790 ppc_current_block
= NULL
;
2792 demand_empty_rest_of_line ();
2795 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2804 sym
= symbol_make (".bb");
2805 S_SET_SEGMENT (sym
, text_section
);
2806 sym
->sy_frag
= frag_now
;
2807 S_SET_VALUE (sym
, frag_now_fix ());
2808 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2810 S_SET_NUMBER_AUXILIARY (sym
, 1);
2811 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2813 sym
->sy_tc
.output
= 1;
2815 SF_SET_PROCESS (sym
);
2817 ppc_frob_label (sym
);
2819 demand_empty_rest_of_line ();
2822 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2831 sym
= symbol_make (".eb");
2832 S_SET_SEGMENT (sym
, text_section
);
2833 sym
->sy_frag
= frag_now
;
2834 S_SET_VALUE (sym
, frag_now_fix ());
2835 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2836 S_SET_NUMBER_AUXILIARY (sym
, 1);
2837 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2838 sym
->sy_tc
.output
= 1;
2840 SF_SET_PROCESS (sym
);
2842 ppc_frob_label (sym
);
2844 demand_empty_rest_of_line ();
2847 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
2858 name
= demand_copy_C_string (&len
);
2859 sym
= symbol_make (name
);
2860 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2861 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2862 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
2863 S_SET_VALUE (sym
, 0);
2864 sym
->sy_tc
.output
= 1;
2866 ppc_frob_label (sym
);
2868 demand_empty_rest_of_line ();
2871 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
2879 sym
= symbol_make (".ec");
2880 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2881 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2882 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
2883 S_SET_VALUE (sym
, 0);
2884 sym
->sy_tc
.output
= 1;
2886 ppc_frob_label (sym
);
2888 demand_empty_rest_of_line ();
2891 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2897 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2898 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2905 subseg
= ppc_data_subsegment
;
2906 ++ppc_data_subsegment
;
2908 subseg_new (segment_name (data_section
), subseg
);
2909 ppc_toc_frag
= frag_now
;
2911 sym
= symbol_find_or_make ("TOC[TC0]");
2912 sym
->sy_frag
= frag_now
;
2913 S_SET_SEGMENT (sym
, data_section
);
2914 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2915 sym
->sy_tc
.subseg
= subseg
;
2916 sym
->sy_tc
.output
= 1;
2917 sym
->sy_tc
.within
= sym
;
2919 ppc_toc_csect
= sym
;
2921 for (list
= ppc_data_csects
;
2922 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2923 list
= list
->sy_tc
.next
)
2925 list
->sy_tc
.next
= sym
;
2927 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2928 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2931 ppc_current_csect
= ppc_toc_csect
;
2933 demand_empty_rest_of_line ();
2936 #endif /* OBJ_XCOFF */
2938 /* The .tc pseudo-op. This is used when generating either XCOFF or
2939 ELF. This takes two or more arguments.
2941 When generating XCOFF output, the first argument is the name to
2942 give to this location in the toc; this will be a symbol with class
2943 TC. The rest of the arguments are 4 byte values to actually put at
2944 this location in the TOC; often there is just one more argument, a
2945 relocateable symbol reference.
2947 When not generating XCOFF output, the arguments are the same, but
2948 the first argument is simply ignored. */
2956 /* Define the TOC symbol name. */
2962 if (ppc_toc_csect
== (symbolS
*) NULL
2963 || ppc_toc_csect
!= ppc_current_csect
)
2965 as_bad (".tc not in .toc section");
2966 ignore_rest_of_line ();
2970 name
= input_line_pointer
;
2971 endc
= get_symbol_end ();
2973 sym
= symbol_find_or_make (name
);
2975 *input_line_pointer
= endc
;
2977 if (S_IS_DEFINED (sym
))
2981 label
= ppc_current_csect
->sy_tc
.within
;
2982 if (label
->sy_tc
.class != XMC_TC0
)
2984 as_warn (".tc with no label");
2985 ignore_rest_of_line ();
2989 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
2990 label
->sy_frag
= sym
->sy_frag
;
2991 S_SET_VALUE (label
, S_GET_VALUE (sym
));
2993 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2994 ++input_line_pointer
;
2999 S_SET_SEGMENT (sym
, now_seg
);
3000 sym
->sy_frag
= frag_now
;
3001 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3002 sym
->sy_tc
.class = XMC_TC
;
3003 sym
->sy_tc
.output
= 1;
3005 ppc_frob_label (sym
);
3008 #else /* ! defined (OBJ_XCOFF) */
3010 /* Skip the TOC symbol name. */
3011 while (is_part_of_name (*input_line_pointer
)
3012 || *input_line_pointer
== '['
3013 || *input_line_pointer
== ']'
3014 || *input_line_pointer
== '{'
3015 || *input_line_pointer
== '}')
3016 ++input_line_pointer
;
3018 /* Align to a four byte boundary. */
3020 record_alignment (now_seg
, 2);
3022 #endif /* ! defined (OBJ_XCOFF) */
3024 if (*input_line_pointer
!= ',')
3025 demand_empty_rest_of_line ();
3028 ++input_line_pointer
;
3035 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3037 /* Set the current section. */
3039 ppc_set_current_section (new)
3042 ppc_previous_section
= ppc_current_section
;
3043 ppc_current_section
= new;
3046 /* pseudo-op: .previous
3047 behaviour: toggles the current section with the previous section.
3049 warnings: "No previous section"
3052 ppc_previous(ignore
)
3057 if (ppc_previous_section
== NULL
)
3059 as_warn("No previous section to return to. Directive ignored.");
3063 subseg_set(ppc_previous_section
, 0);
3065 ppc_set_current_section(ppc_previous_section
);
3068 /* pseudo-op: .pdata
3069 behaviour: predefined read only data section
3073 initial: .section .pdata "adr3"
3074 a - don't know -- maybe a misprint
3075 d - initialized data
3077 3 - double word aligned (that would be 4 byte boundary)
3080 Tag index tables (also known as the function table) for exception
3081 handling, debugging, etc.
3088 if (pdata_section
== 0)
3090 pdata_section
= subseg_new (".pdata", 0);
3092 bfd_set_section_flags (stdoutput
, pdata_section
,
3093 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3094 | SEC_READONLY
| SEC_DATA
));
3096 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
3100 pdata_section
= subseg_new(".pdata", 0);
3102 ppc_set_current_section(pdata_section
);
3105 /* pseudo-op: .ydata
3106 behaviour: predefined read only data section
3110 initial: .section .ydata "drw3"
3111 a - don't know -- maybe a misprint
3112 d - initialized data
3114 3 - double word aligned (that would be 4 byte boundary)
3116 Tag tables (also known as the scope table) for exception handling,
3123 if (ydata_section
== 0)
3125 ydata_section
= subseg_new (".ydata", 0);
3126 bfd_set_section_flags (stdoutput
, ydata_section
,
3127 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3128 | SEC_READONLY
| SEC_DATA
));
3130 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
3134 ydata_section
= subseg_new (".ydata", 0);
3136 ppc_set_current_section(ydata_section
);
3139 /* pseudo-op: .reldata
3140 behaviour: predefined read write data section
3141 double word aligned (4-byte)
3142 FIXME: relocation is applied to it
3143 FIXME: what's the difference between this and .data?
3146 initial: .section .reldata "drw3"
3147 d - initialized data
3150 3 - double word aligned (that would be 8 byte boundary)
3153 Like .data, but intended to hold data subject to relocation, such as
3154 function descriptors, etc.
3160 if (reldata_section
== 0)
3162 reldata_section
= subseg_new (".reldata", 0);
3164 bfd_set_section_flags (stdoutput
, reldata_section
,
3165 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3168 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
3172 reldata_section
= subseg_new (".reldata", 0);
3174 ppc_set_current_section(reldata_section
);
3177 /* pseudo-op: .rdata
3178 behaviour: predefined read only data section
3182 initial: .section .rdata "dr3"
3183 d - initialized data
3185 3 - double word aligned (that would be 4 byte boundary)
3191 if (rdata_section
== 0)
3193 rdata_section
= subseg_new (".rdata", 0);
3194 bfd_set_section_flags (stdoutput
, rdata_section
,
3195 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3196 | SEC_READONLY
| SEC_DATA
));
3198 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
3202 rdata_section
= subseg_new (".rdata", 0);
3204 ppc_set_current_section(rdata_section
);
3207 /* pseudo-op: .ualong
3208 behaviour: much like .int, with the exception that no alignment is
3210 FIXME: test the alignment statement
3222 /* pseudo-op: .znop <symbol name>
3223 behaviour: Issue a nop instruction
3224 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3225 the supplied symbol name.
3227 warnings: Missing symbol name
3234 const struct powerpc_opcode
*opcode
;
3240 /* Strip out the symbol name */
3248 symbol_name
= input_line_pointer
;
3249 c
= get_symbol_end ();
3251 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
3252 strcpy (name
, symbol_name
);
3254 sym
= symbol_find_or_make (name
);
3256 *input_line_pointer
= c
;
3260 /* Look up the opcode in the hash table. */
3261 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
3263 /* stick in the nop */
3264 insn
= opcode
->opcode
;
3266 /* Write out the instruction. */
3268 md_number_to_chars (f
, insn
, 4);
3270 f
- frag_now
->fr_literal
,
3275 BFD_RELOC_16_GOT_PCREL
);
3288 register char *name
;
3292 register symbolS
*symbolP
;
3295 name
= input_line_pointer
;
3296 c
= get_symbol_end ();
3298 /* just after name is now '\0' */
3299 p
= input_line_pointer
;
3302 if (*input_line_pointer
!= ',')
3304 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3305 ignore_rest_of_line ();
3309 input_line_pointer
++; /* skip ',' */
3310 if ((temp
= get_absolute_expression ()) < 0)
3312 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
3313 ignore_rest_of_line ();
3319 /* The third argument to .comm is the alignment. */
3320 if (*input_line_pointer
!= ',')
3324 ++input_line_pointer
;
3325 align
= get_absolute_expression ();
3328 as_warn ("ignoring bad alignment");
3335 symbolP
= symbol_find_or_make (name
);
3338 if (S_IS_DEFINED (symbolP
))
3340 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3341 S_GET_NAME (symbolP
));
3342 ignore_rest_of_line ();
3346 if (S_GET_VALUE (symbolP
))
3348 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3349 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3350 S_GET_NAME (symbolP
),
3351 (long) S_GET_VALUE (symbolP
),
3356 S_SET_VALUE (symbolP
, (valueT
) temp
);
3357 S_SET_EXTERNAL (symbolP
);
3360 demand_empty_rest_of_line ();
3364 * implement the .section pseudo op:
3365 * .section name {, "flags"}
3367 * | +--- optional flags: 'b' for bss
3369 * +-- section name 'l' for lib
3373 * 'd' (apparently m88k for data)
3375 * But if the argument is not a quoted string, treat it as a
3376 * subsegment number.
3378 * FIXME: this is a copy of the section processing from obj-coff.c, with
3379 * additions/changes for the moto-pas assembler support. There are three
3382 * FIXME: I just noticed this. This doesn't work at all really. It it
3383 * setting bits that bfd probably neither understands or uses. The
3384 * correct approach (?) will have to incorporate extra fields attached
3385 * to the section to hold the system specific stuff. (krk)
3388 * 'a' - unknown - referred to in documentation, but no definition supplied
3389 * 'c' - section has code
3390 * 'd' - section has initialized data
3391 * 'u' - section has uninitialized data
3392 * 'i' - section contains directives (info)
3393 * 'n' - section can be discarded
3394 * 'R' - remove section at link time
3396 * Section Protection:
3397 * 'r' - section is readable
3398 * 'w' - section is writeable
3399 * 'x' - section is executable
3400 * 's' - section is sharable
3402 * Section Alignment:
3403 * '0' - align to byte boundary
3404 * '1' - align to halfword undary
3405 * '2' - align to word boundary
3406 * '3' - align to doubleword boundary
3407 * '4' - align to quadword boundary
3408 * '5' - align to 32 byte boundary
3409 * '6' - align to 64 byte boundary
3414 ppc_pe_section (ignore
)
3417 /* Strip out the section name */
3426 section_name
= input_line_pointer
;
3427 c
= get_symbol_end ();
3429 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3430 strcpy (name
, section_name
);
3432 *input_line_pointer
= c
;
3437 flags
= SEC_NO_FLAGS
;
3439 if (strcmp (name
, ".idata$2") == 0)
3443 else if (strcmp (name
, ".idata$3") == 0)
3447 else if (strcmp (name
, ".idata$4") == 0)
3451 else if (strcmp (name
, ".idata$5") == 0)
3455 else if (strcmp (name
, ".idata$6") == 0)
3460 align
= 4; /* default alignment to 16 byte boundary */
3462 if (*input_line_pointer
== ',')
3464 ++input_line_pointer
;
3466 if (*input_line_pointer
!= '"')
3467 exp
= get_absolute_expression ();
3470 ++input_line_pointer
;
3471 while (*input_line_pointer
!= '"'
3472 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3474 switch (*input_line_pointer
)
3476 /* Section Contents */
3477 case 'a': /* unknown */
3478 as_warn ("Unsupported section attribute -- 'a'");
3480 case 'c': /* code section */
3483 case 'd': /* section has initialized data */
3486 case 'u': /* section has uninitialized data */
3487 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3491 case 'i': /* section contains directives (info) */
3492 /* FIXME: This is IMAGE_SCN_LNK_INFO
3494 flags
|= SEC_HAS_CONTENTS
;
3496 case 'n': /* section can be discarded */
3499 case 'R': /* Remove section at link time */
3500 flags
|= SEC_NEVER_LOAD
;
3503 /* Section Protection */
3504 case 'r': /* section is readable */
3505 flags
|= IMAGE_SCN_MEM_READ
;
3507 case 'w': /* section is writeable */
3508 flags
|= IMAGE_SCN_MEM_WRITE
;
3510 case 'x': /* section is executable */
3511 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3513 case 's': /* section is sharable */
3514 flags
|= IMAGE_SCN_MEM_SHARED
;
3517 /* Section Alignment */
3518 case '0': /* align to byte boundary */
3519 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3522 case '1': /* align to halfword boundary */
3523 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3526 case '2': /* align to word boundary */
3527 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3530 case '3': /* align to doubleword boundary */
3531 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3534 case '4': /* align to quadword boundary */
3535 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3538 case '5': /* align to 32 byte boundary */
3539 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3542 case '6': /* align to 64 byte boundary */
3543 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3548 as_warn("unknown section attribute '%c'",
3549 *input_line_pointer
);
3552 ++input_line_pointer
;
3554 if (*input_line_pointer
== '"')
3555 ++input_line_pointer
;
3559 sec
= subseg_new (name
, (subsegT
) exp
);
3561 ppc_set_current_section(sec
);
3563 if (flags
!= SEC_NO_FLAGS
)
3565 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3566 as_warn ("error setting flags for \"%s\": %s",
3567 bfd_section_name (stdoutput
, sec
),
3568 bfd_errmsg (bfd_get_error ()));
3571 bfd_set_section_alignment(stdoutput
, sec
, align
);
3576 ppc_pe_function (ignore
)
3583 name
= input_line_pointer
;
3584 endc
= get_symbol_end ();
3586 ext_sym
= symbol_find_or_make (name
);
3588 *input_line_pointer
= endc
;
3590 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3591 SF_SET_FUNCTION (ext_sym
);
3592 SF_SET_PROCESS (ext_sym
);
3593 coff_add_linesym (ext_sym
);
3595 demand_empty_rest_of_line ();
3599 ppc_pe_tocd (ignore
)
3602 if (tocdata_section
== 0)
3604 tocdata_section
= subseg_new (".tocd", 0);
3605 /* FIXME: section flags won't work */
3606 bfd_set_section_flags (stdoutput
, tocdata_section
,
3607 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3608 | SEC_READONLY
| SEC_DATA
));
3610 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3614 rdata_section
= subseg_new (".tocd", 0);
3617 ppc_set_current_section(tocdata_section
);
3619 demand_empty_rest_of_line ();
3622 /* Don't adjust TOC relocs to use the section symbol. */
3625 ppc_pe_fix_adjustable (fix
)
3628 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3635 /* XCOFF specific symbol and file handling. */
3637 /* Canonicalize the symbol name. We use the to force the suffix, if
3638 any, to use square brackets, and to be in upper case. */
3641 ppc_canonicalize_symbol_name (name
)
3646 if (ppc_stab_symbol
)
3649 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3663 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3667 if (*s
== '\0' || s
[1] != '\0')
3668 as_bad ("bad symbol suffix");
3676 /* Set the class of a symbol based on the suffix, if any. This is
3677 called whenever a new symbol is created. */
3680 ppc_symbol_new_hook (sym
)
3685 sym
->sy_tc
.next
= NULL
;
3686 sym
->sy_tc
.output
= 0;
3687 sym
->sy_tc
.class = -1;
3688 sym
->sy_tc
.real_name
= NULL
;
3689 sym
->sy_tc
.subseg
= 0;
3690 sym
->sy_tc
.align
= 0;
3691 sym
->sy_tc
.size
= NULL
;
3692 sym
->sy_tc
.within
= NULL
;
3694 if (ppc_stab_symbol
)
3697 s
= strchr (S_GET_NAME (sym
), '[');
3698 if (s
== (const char *) NULL
)
3700 /* There is no suffix. */
3709 if (strcmp (s
, "BS]") == 0)
3710 sym
->sy_tc
.class = XMC_BS
;
3713 if (strcmp (s
, "DB]") == 0)
3714 sym
->sy_tc
.class = XMC_DB
;
3715 else if (strcmp (s
, "DS]") == 0)
3716 sym
->sy_tc
.class = XMC_DS
;
3719 if (strcmp (s
, "GL]") == 0)
3720 sym
->sy_tc
.class = XMC_GL
;
3723 if (strcmp (s
, "PR]") == 0)
3724 sym
->sy_tc
.class = XMC_PR
;
3727 if (strcmp (s
, "RO]") == 0)
3728 sym
->sy_tc
.class = XMC_RO
;
3729 else if (strcmp (s
, "RW]") == 0)
3730 sym
->sy_tc
.class = XMC_RW
;
3733 if (strcmp (s
, "SV]") == 0)
3734 sym
->sy_tc
.class = XMC_SV
;
3737 if (strcmp (s
, "TC]") == 0)
3738 sym
->sy_tc
.class = XMC_TC
;
3739 else if (strcmp (s
, "TI]") == 0)
3740 sym
->sy_tc
.class = XMC_TI
;
3741 else if (strcmp (s
, "TB]") == 0)
3742 sym
->sy_tc
.class = XMC_TB
;
3743 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3744 sym
->sy_tc
.class = XMC_TC0
;
3747 if (strcmp (s
, "UA]") == 0)
3748 sym
->sy_tc
.class = XMC_UA
;
3749 else if (strcmp (s
, "UC]") == 0)
3750 sym
->sy_tc
.class = XMC_UC
;
3753 if (strcmp (s
, "XO]") == 0)
3754 sym
->sy_tc
.class = XMC_XO
;
3758 if (sym
->sy_tc
.class == -1)
3759 as_bad ("Unrecognized symbol suffix");
3762 /* Set the class of a label based on where it is defined. This
3763 handles symbols without suffixes. Also, move the symbol so that it
3764 follows the csect symbol. */
3767 ppc_frob_label (sym
)
3770 if (ppc_current_csect
!= (symbolS
*) NULL
)
3772 if (sym
->sy_tc
.class == -1)
3773 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3775 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3776 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3778 ppc_current_csect
->sy_tc
.within
= sym
;
3782 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3783 seen. It tells ppc_adjust_symtab whether it needs to look through
3786 static boolean ppc_saw_abs
;
3788 /* Change the name of a symbol just before writing it out. Set the
3789 real name if the .rename pseudo-op was used. Otherwise, remove any
3790 class suffix. Return 1 if the symbol should not be included in the
3794 ppc_frob_symbol (sym
)
3797 static symbolS
*ppc_last_function
;
3798 static symbolS
*set_end
;
3800 /* Discard symbols that should not be included in the output symbol
3802 if (! sym
->sy_used_in_reloc
3803 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3804 || (! S_IS_EXTERNAL (sym
)
3805 && ! sym
->sy_tc
.output
3806 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3809 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3810 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3816 name
= S_GET_NAME (sym
);
3817 s
= strchr (name
, '[');
3818 if (s
!= (char *) NULL
)
3824 snew
= xmalloc (len
+ 1);
3825 memcpy (snew
, name
, len
);
3828 S_SET_NAME (sym
, snew
);
3832 if (set_end
!= (symbolS
*) NULL
)
3834 SA_SET_SYM_ENDNDX (set_end
, sym
);
3838 if (SF_GET_FUNCTION (sym
))
3840 if (ppc_last_function
!= (symbolS
*) NULL
)
3841 as_warn ("two .function pseudo-ops with no intervening .ef");
3842 ppc_last_function
= sym
;
3843 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3845 resolve_symbol_value (sym
->sy_tc
.size
);
3846 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3849 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3850 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3852 if (ppc_last_function
== (symbolS
*) NULL
)
3853 as_warn (".ef with no preceding .function");
3856 set_end
= ppc_last_function
;
3857 ppc_last_function
= NULL
;
3859 /* We don't have a C_EFCN symbol, but we need to force the
3860 COFF backend to believe that it has seen one. */
3861 coff_last_function
= NULL
;
3865 if (! S_IS_EXTERNAL (sym
)
3866 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3867 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3868 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3869 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
3870 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3871 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3872 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
3873 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
3874 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3875 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3877 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
3878 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3881 union internal_auxent
*a
;
3883 /* Create a csect aux. */
3884 i
= S_GET_NUMBER_AUXILIARY (sym
);
3885 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3886 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3887 if (sym
->sy_tc
.class == XMC_TC0
)
3889 /* This is the TOC table. */
3890 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3891 a
->x_csect
.x_scnlen
.l
= 0;
3892 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3894 else if (sym
->sy_tc
.subseg
!= 0)
3896 /* This is a csect symbol. x_scnlen is the size of the
3898 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3899 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3900 S_GET_SEGMENT (sym
))
3901 - S_GET_VALUE (sym
));
3904 resolve_symbol_value (sym
->sy_tc
.next
);
3905 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3906 - S_GET_VALUE (sym
));
3908 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3910 else if (S_GET_SEGMENT (sym
) == bss_section
)
3912 /* This is a common symbol. */
3913 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3914 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3915 if (S_IS_EXTERNAL (sym
))
3916 sym
->sy_tc
.class = XMC_RW
;
3918 sym
->sy_tc
.class = XMC_BS
;
3920 else if (S_GET_SEGMENT (sym
) == absolute_section
)
3922 /* This is an absolute symbol. The csect will be created by
3923 ppc_adjust_symtab. */
3925 a
->x_csect
.x_smtyp
= XTY_LD
;
3926 if (sym
->sy_tc
.class == -1)
3927 sym
->sy_tc
.class = XMC_XO
;
3929 else if (! S_IS_DEFINED (sym
))
3931 /* This is an external symbol. */
3932 a
->x_csect
.x_scnlen
.l
= 0;
3933 a
->x_csect
.x_smtyp
= XTY_ER
;
3935 else if (sym
->sy_tc
.class == XMC_TC
)
3939 /* This is a TOC definition. x_scnlen is the size of the
3941 next
= symbol_next (sym
);
3942 while (next
->sy_tc
.class == XMC_TC0
)
3943 next
= symbol_next (next
);
3944 if (next
== (symbolS
*) NULL
3945 || next
->sy_tc
.class != XMC_TC
)
3947 if (ppc_after_toc_frag
== (fragS
*) NULL
)
3948 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3950 - S_GET_VALUE (sym
));
3952 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
3953 - S_GET_VALUE (sym
));
3957 resolve_symbol_value (next
);
3958 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
3959 - S_GET_VALUE (sym
));
3961 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3967 /* This is a normal symbol definition. x_scnlen is the
3968 symbol index of the containing csect. */
3969 if (S_GET_SEGMENT (sym
) == text_section
)
3970 csect
= ppc_text_csects
;
3971 else if (S_GET_SEGMENT (sym
) == data_section
)
3972 csect
= ppc_data_csects
;
3976 /* Skip the initial dummy symbol. */
3977 csect
= csect
->sy_tc
.next
;
3979 if (csect
== (symbolS
*) NULL
)
3981 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym
));
3982 a
->x_csect
.x_scnlen
.l
= 0;
3986 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
3988 resolve_symbol_value (csect
->sy_tc
.next
);
3989 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
3991 csect
= csect
->sy_tc
.next
;
3994 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3995 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
3997 a
->x_csect
.x_smtyp
= XTY_LD
;
4000 a
->x_csect
.x_parmhash
= 0;
4001 a
->x_csect
.x_snhash
= 0;
4002 if (sym
->sy_tc
.class == -1)
4003 a
->x_csect
.x_smclas
= XMC_PR
;
4005 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
4006 a
->x_csect
.x_stab
= 0;
4007 a
->x_csect
.x_snstab
= 0;
4009 /* Don't let the COFF backend resort these symbols. */
4010 sym
->bsym
->flags
|= BSF_NOT_AT_END
;
4012 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4014 /* We want the value to be the symbol index of the referenced
4015 csect symbol. BFD will do that for us if we set the right
4018 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
4019 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
4021 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4026 /* The value is the offset from the enclosing csect. */
4027 block
= sym
->sy_tc
.within
;
4028 csect
= block
->sy_tc
.within
;
4029 resolve_symbol_value (csect
);
4030 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
4032 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
4033 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
4035 /* We want the value to be a file offset into the line numbers.
4036 BFD will do that for us if we set the right flags. We have
4037 already set the value correctly. */
4038 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
4044 /* Adjust the symbol table. This creates csect symbols for all
4045 absolute symbols. */
4048 ppc_adjust_symtab ()
4055 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
4059 union internal_auxent
*a
;
4061 if (S_GET_SEGMENT (sym
) != absolute_section
)
4064 csect
= symbol_create (".abs[XO]", absolute_section
,
4065 S_GET_VALUE (sym
), &zero_address_frag
);
4066 csect
->bsym
->value
= S_GET_VALUE (sym
);
4067 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
4068 i
= S_GET_NUMBER_AUXILIARY (csect
);
4069 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
4070 a
= &coffsymbol (csect
->bsym
)->native
[i
+ 1].u
.auxent
;
4071 a
->x_csect
.x_scnlen
.l
= 0;
4072 a
->x_csect
.x_smtyp
= XTY_SD
;
4073 a
->x_csect
.x_parmhash
= 0;
4074 a
->x_csect
.x_snhash
= 0;
4075 a
->x_csect
.x_smclas
= XMC_XO
;
4076 a
->x_csect
.x_stab
= 0;
4077 a
->x_csect
.x_snstab
= 0;
4079 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
4081 i
= S_GET_NUMBER_AUXILIARY (sym
);
4082 a
= &coffsymbol (sym
->bsym
)->native
[i
].u
.auxent
;
4083 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
4084 coffsymbol (sym
->bsym
)->native
[i
].fix_scnlen
= 1;
4087 ppc_saw_abs
= false;
4090 /* Set the VMA for a section. This is called on all the sections in
4094 ppc_frob_section (sec
)
4097 static bfd_size_type vma
= 0;
4099 bfd_set_section_vma (stdoutput
, sec
, vma
);
4100 vma
+= bfd_section_size (stdoutput
, sec
);
4103 #endif /* OBJ_XCOFF */
4105 /* Turn a string in input_line_pointer into a floating point constant
4106 of type type, and store the appropriate bytes in *litp. The number
4107 of LITTLENUMS emitted is stored in *sizep . An error message is
4108 returned, or NULL on OK. */
4111 md_atof (type
, litp
, sizep
)
4117 LITTLENUM_TYPE words
[4];
4133 return "bad call to md_atof";
4136 t
= atof_ieee (input_line_pointer
, type
, words
);
4138 input_line_pointer
= t
;
4142 if (target_big_endian
)
4144 for (i
= 0; i
< prec
; i
++)
4146 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4152 for (i
= prec
- 1; i
>= 0; i
--)
4154 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
4162 /* Write a value out to the object file, using the appropriate
4166 md_number_to_chars (buf
, val
, n
)
4171 if (target_big_endian
)
4172 number_to_chars_bigendian (buf
, val
, n
);
4174 number_to_chars_littleendian (buf
, val
, n
);
4177 /* Align a section (I don't know why this is machine dependent). */
4180 md_section_align (seg
, addr
)
4184 int align
= bfd_get_section_alignment (stdoutput
, seg
);
4186 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
4189 /* We don't have any form of relaxing. */
4192 md_estimate_size_before_relax (fragp
, seg
)
4200 /* Convert a machine dependent frag. We never generate these. */
4203 md_convert_frag (abfd
, sec
, fragp
)
4211 /* We have no need to default values of symbols. */
4215 md_undefined_symbol (name
)
4221 /* Functions concerning relocs. */
4223 /* The location from which a PC relative jump should be calculated,
4224 given a PC relative reloc. */
4227 md_pcrel_from_section (fixp
, sec
)
4232 if (fixp
->fx_addsy
!= (symbolS
*) NULL
4233 && (! S_IS_DEFINED (fixp
->fx_addsy
)
4234 || TC_FORCE_RELOCATION_SECTION (fixp
, sec
)))
4238 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4243 /* This is called to see whether a fixup should be adjusted to use a
4244 section symbol. We take the opportunity to change a fixup against
4245 a symbol in the TOC subsegment into a reloc against the
4246 corresponding .tc symbol. */
4249 ppc_fix_adjustable (fix
)
4254 resolve_symbol_value (fix
->fx_addsy
);
4255 val
= S_GET_VALUE (fix
->fx_addsy
);
4256 if (ppc_toc_csect
!= (symbolS
*) NULL
4257 && fix
->fx_addsy
!= (symbolS
*) NULL
4258 && fix
->fx_addsy
!= ppc_toc_csect
4259 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
4260 && val
>= ppc_toc_frag
->fr_address
4261 && (ppc_after_toc_frag
== (fragS
*) NULL
4262 || val
< ppc_after_toc_frag
->fr_address
))
4266 for (sy
= symbol_next (ppc_toc_csect
);
4267 sy
!= (symbolS
*) NULL
;
4268 sy
= symbol_next (sy
))
4270 if (sy
->sy_tc
.class == XMC_TC0
)
4272 if (sy
->sy_tc
.class != XMC_TC
)
4274 resolve_symbol_value (sy
);
4275 if (val
== S_GET_VALUE (sy
))
4278 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
4283 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4284 "symbol in .toc does not match any .tc");
4287 /* Possibly adjust the reloc to be against the csect. */
4288 if (fix
->fx_addsy
!= (symbolS
*) NULL
4289 && fix
->fx_addsy
->sy_tc
.subseg
== 0
4290 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
4291 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
4292 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
4296 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4297 csect
= ppc_text_csects
;
4298 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4299 csect
= ppc_data_csects
;
4303 /* Skip the initial dummy symbol. */
4304 csect
= csect
->sy_tc
.next
;
4306 if (csect
!= (symbolS
*) NULL
)
4308 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
4309 && (csect
->sy_tc
.next
->sy_frag
->fr_address
4310 <= fix
->fx_addsy
->sy_frag
->fr_address
))
4311 csect
= csect
->sy_tc
.next
;
4313 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4314 - csect
->sy_frag
->fr_address
);
4315 fix
->fx_addsy
= csect
;
4319 /* Adjust a reloc against a .lcomm symbol to be against the base
4321 if (fix
->fx_addsy
!= (symbolS
*) NULL
4322 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4323 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4325 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
4326 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4327 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
4328 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
4336 /* See whether a symbol is in the TOC section. */
4339 ppc_is_toc_sym (sym
)
4343 return sym
->sy_tc
.class == XMC_TC
;
4345 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4349 /* Apply a fixup to the object code. This is called for all the
4350 fixups we generated by the call to fix_new_exp, above. In the call
4351 above we used a reloc code which was the largest legal reloc code
4352 plus the operand index. Here we undo that to recover the operand
4353 index. At this point all symbol values should be fully resolved,
4354 and we attempt to completely resolve the reloc. If we can not do
4355 that, we determine the correct reloc code and put it back in the
4359 md_apply_fix3 (fixp
, valuep
, seg
)
4366 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4367 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4368 doing this relocation the code in write.c is going to call
4369 bfd_perform_relocation, which is also going to use the symbol
4370 value. That means that if the reloc is fully resolved we want to
4371 use *valuep since bfd_perform_relocation is not being used.
4372 However, if the reloc is not fully resolved we do not want to use
4373 *valuep, and must use fx_offset instead. However, if the reloc
4374 is PC relative, we do want to use *valuep since it includes the
4375 result of md_pcrel_from. This is confusing. */
4377 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4382 else if (fixp
->fx_pcrel
)
4386 value
= fixp
->fx_offset
;
4387 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4389 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4390 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4393 /* We can't actually support subtracting a symbol. */
4394 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4395 "expression too complex");
4400 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4403 const struct powerpc_operand
*operand
;
4407 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4409 operand
= &powerpc_operands
[opindex
];
4412 /* It appears that an instruction like
4414 when LC..1 is not a TOC symbol does not generate a reloc. It
4415 uses the offset of LC..1 within its csect. However, .long
4416 LC..1 will generate a reloc. I can't find any documentation
4417 on how these cases are to be distinguished, so this is a wild
4418 guess. These cases are generated by gcc -mminimal-toc. */
4419 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4420 && operand
->bits
== 16
4421 && operand
->shift
== 0
4422 && operand
->insert
== NULL
4423 && fixp
->fx_addsy
!= NULL
4424 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
4425 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
4426 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
4427 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4429 value
= fixp
->fx_offset
;
4434 /* Fetch the instruction, insert the fully resolved operand
4435 value, and stuff the instruction back again. */
4436 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4437 if (target_big_endian
)
4438 insn
= bfd_getb32 ((unsigned char *) where
);
4440 insn
= bfd_getl32 ((unsigned char *) where
);
4441 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4442 fixp
->fx_file
, fixp
->fx_line
);
4443 if (target_big_endian
)
4444 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4446 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4450 /* Nothing else to do here. */
4454 /* Determine a BFD reloc value based on the operand information.
4455 We are only prepared to turn a few of the operands into
4457 FIXME: We need to handle the DS field at the very least.
4458 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4459 there should be a new field in the operand table. */
4460 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4461 && operand
->bits
== 26
4462 && operand
->shift
== 0)
4463 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4464 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4465 && operand
->bits
== 16
4466 && operand
->shift
== 0)
4467 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4468 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4469 && operand
->bits
== 26
4470 && operand
->shift
== 0)
4471 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4472 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4473 && operand
->bits
== 16
4474 && operand
->shift
== 0)
4475 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4476 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4477 && operand
->bits
== 16
4478 && operand
->shift
== 0
4479 && operand
->insert
== NULL
4480 && fixp
->fx_addsy
!= NULL
4481 && ppc_is_toc_sym (fixp
->fx_addsy
))
4484 if (target_big_endian
)
4485 fixp
->fx_where
+= 2;
4486 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4490 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4491 "unresolved expression that must be resolved");
4499 ppc_elf_validate_fix (fixp
, seg
);
4501 switch (fixp
->fx_r_type
)
4504 case BFD_RELOC_CTOR
:
4506 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4510 case BFD_RELOC_32_PCREL
:
4511 case BFD_RELOC_32_BASEREL
:
4512 case BFD_RELOC_PPC_EMB_NADDR32
:
4513 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4517 case BFD_RELOC_LO16
:
4518 case BFD_RELOC_HI16
:
4519 case BFD_RELOC_HI16_S
:
4521 case BFD_RELOC_GPREL16
:
4522 case BFD_RELOC_16_GOT_PCREL
:
4523 case BFD_RELOC_16_GOTOFF
:
4524 case BFD_RELOC_LO16_GOTOFF
:
4525 case BFD_RELOC_HI16_GOTOFF
:
4526 case BFD_RELOC_HI16_S_GOTOFF
:
4527 case BFD_RELOC_LO16_BASEREL
:
4528 case BFD_RELOC_HI16_BASEREL
:
4529 case BFD_RELOC_HI16_S_BASEREL
:
4530 case BFD_RELOC_PPC_EMB_NADDR16
:
4531 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
4532 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
4533 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
4534 case BFD_RELOC_PPC_EMB_SDAI16
:
4535 case BFD_RELOC_PPC_EMB_SDA2REL
:
4536 case BFD_RELOC_PPC_EMB_SDA2I16
:
4537 case BFD_RELOC_PPC_EMB_RELSEC16
:
4538 case BFD_RELOC_PPC_EMB_RELST_LO
:
4539 case BFD_RELOC_PPC_EMB_RELST_HI
:
4540 case BFD_RELOC_PPC_EMB_RELST_HA
:
4541 case BFD_RELOC_PPC_EMB_RELSDA
:
4542 case BFD_RELOC_PPC_TOC16
:
4544 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4545 "cannot emit PC relative %s relocation%s%s",
4546 bfd_get_reloc_code_name (fixp
->fx_r_type
),
4547 fixp
->fx_addsy
!= NULL
? " against " : "",
4548 (fixp
->fx_addsy
!= NULL
4549 ? S_GET_NAME (fixp
->fx_addsy
)
4552 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4556 /* Because SDA21 modifies the register field, the size is set to 4
4557 bytes, rather than 2, so offset it here appropriately */
4558 case BFD_RELOC_PPC_EMB_SDA21
:
4562 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
4563 + ((target_big_endian
) ? 2 : 0),
4571 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4577 "Gas failure, reloc value %d\n", fixp
->fx_r_type
);
4584 fixp
->fx_addnumber
= value
;
4586 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4587 fixp
->fx_addnumber
= 0;
4591 fixp
->fx_addnumber
= 0;
4593 /* We want to use the offset within the data segment of the
4594 symbol, not the actual VMA of the symbol. */
4595 fixp
->fx_addnumber
=
4596 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4604 /* Generate a reloc for a fixup. */
4607 tc_gen_reloc (seg
, fixp
)
4613 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4615 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4616 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4617 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4618 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4620 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4621 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4624 reloc
->addend
= fixp
->fx_addnumber
;