1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994 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 static void ppc_set_cpu
PARAMS ((void));
45 static unsigned long ppc_insert_operand
46 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
47 offsetT val
, char *file
, unsigned int line
));
48 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
49 static void ppc_byte
PARAMS ((int));
50 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
51 static void ppc_tc
PARAMS ((int));
54 static void ppc_comm
PARAMS ((int));
55 static void ppc_bb
PARAMS ((int));
56 static void ppc_bc
PARAMS ((int));
57 static void ppc_bf
PARAMS ((int));
58 static void ppc_biei
PARAMS ((int));
59 static void ppc_bs
PARAMS ((int));
60 static void ppc_eb
PARAMS ((int));
61 static void ppc_ec
PARAMS ((int));
62 static void ppc_ef
PARAMS ((int));
63 static void ppc_es
PARAMS ((int));
64 static void ppc_csect
PARAMS ((int));
65 static void ppc_change_csect
PARAMS ((symbolS
*));
66 static void ppc_function
PARAMS ((int));
67 static void ppc_extern
PARAMS ((int));
68 static void ppc_lglobl
PARAMS ((int));
69 static void ppc_section
PARAMS ((int));
70 static void ppc_stabx
PARAMS ((int));
71 static void ppc_rename
PARAMS ((int));
72 static void ppc_toc
PARAMS ((int));
76 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
77 static void ppc_elf_cons
PARAMS ((int));
78 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
82 static void ppc_set_current_section
PARAMS ((segT
));
83 static void ppc_previous
PARAMS ((int));
84 static void ppc_pdata
PARAMS ((int));
85 static void ppc_ydata
PARAMS ((int));
86 static void ppc_reldata
PARAMS ((int));
87 static void ppc_rdata
PARAMS ((int));
88 static void ppc_ualong
PARAMS ((int));
89 static void ppc_znop
PARAMS ((int));
90 static void ppc_pe_comm
PARAMS ((int));
91 static void ppc_pe_section
PARAMS ((int));
92 static void ppc_pe_function
PARAMS ((int));
93 static void ppc_pe_tocd
PARAMS ((int));
96 /* Generic assembler global variables which must be defined by all
99 /* Characters which always start a comment. */
100 const char comment_chars
[] = "#";
102 /* Characters which start a comment at the beginning of a line. */
103 const char line_comment_chars
[] = "#";
105 /* Characters which may be used to separate multiple commands on a
107 const char line_separator_chars
[] = ";";
109 /* Characters which are used to indicate an exponent in a floating
111 const char EXP_CHARS
[] = "eE";
113 /* Characters which mean that a number is a floating point constant,
115 const char FLT_CHARS
[] = "dD";
117 /* The target specific pseudo-ops which we support. */
119 const pseudo_typeS md_pseudo_table
[] =
121 /* Pseudo-ops which must be overridden. */
122 { "byte", ppc_byte
, 0 },
125 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
126 legitimately belong in the obj-*.c file. However, XCOFF is based
127 on COFF, and is only implemented for the RS/6000. We just use
128 obj-coff.c, and add what we need here. */
129 { "comm", ppc_comm
, 0 },
130 { "lcomm", ppc_comm
, 1 },
134 { "bi", ppc_biei
, 0 },
136 { "csect", ppc_csect
, 0 },
137 { "data", ppc_section
, 'd' },
141 { "ei", ppc_biei
, 1 },
143 { "extern", ppc_extern
, 0 },
144 { "function", ppc_function
, 0 },
145 { "lglobl", ppc_lglobl
, 0 },
146 { "rename", ppc_rename
, 0 },
147 { "stabx", ppc_stabx
, 0 },
148 { "text", ppc_section
, 't' },
149 { "toc", ppc_toc
, 0 },
153 { "long", ppc_elf_cons
, 4 },
154 { "word", ppc_elf_cons
, 2 },
155 { "short", ppc_elf_cons
, 2 },
159 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
160 { "previous", ppc_previous
, 0 },
161 { "pdata", ppc_pdata
, 0 },
162 { "ydata", ppc_ydata
, 0 },
163 { "reldata", ppc_reldata
, 0 },
164 { "rdata", ppc_rdata
, 0 },
165 { "ualong", ppc_ualong
, 0 },
166 { "znop", ppc_znop
, 0 },
167 { "comm", ppc_pe_comm
, 0 },
168 { "lcomm", ppc_pe_comm
, 1 },
169 { "section", ppc_pe_section
, 0 },
170 { "function", ppc_pe_function
,0 },
171 { "tocd", ppc_pe_tocd
, 0 },
174 /* This pseudo-op is used even when not generating XCOFF output. */
182 /* The Windows NT PowerPC assembler uses predefined names. */
184 /* In general, there are lots of them, in an attempt to be compatible */
185 /* with a number of other Windows NT assemblers. */
187 /* Structure to hold information about predefined registers. */
194 /* List of registers that are pre-defined:
196 Each general register has predefined names of the form:
197 1. r<reg_num> which has the value <reg_num>.
198 2. r.<reg_num> which has the value <reg_num>.
201 Each floating point register has predefined names of the form:
202 1. f<reg_num> which has the value <reg_num>.
203 2. f.<reg_num> which has the value <reg_num>.
205 Each condition register has predefined names of the form:
206 1. cr<reg_num> which has the value <reg_num>.
207 2. cr.<reg_num> which has the value <reg_num>.
209 There are individual registers as well:
210 sp or r.sp has the value 1
211 rtoc or r.toc has the value 2
212 fpscr has the value 0
218 dsisr has the value 18
220 sdr1 has the value 25
221 srr0 has the value 26
222 srr1 has the value 27
224 The table is sorted. Suitable for searching by a binary search. */
226 static const struct pd_reg pre_defined_registers
[] =
228 { "cr.0", 0 }, /* Condition Registers */
248 { "dar", 19 }, /* Data Access Register */
249 { "dec", 22 }, /* Decrementer */
250 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
252 { "f.0", 0 }, /* Floating point registers */
320 { "lr", 8 }, /* Link Register */
324 { "r.0", 0 }, /* General Purpose Registers */
357 { "r.sp", 1 }, /* Stack Pointer */
359 { "r.toc", 2 }, /* Pointer to the table of contents */
361 { "r0", 0 }, /* More general purpose registers */
394 { "rtoc", 2 }, /* Table of contents */
396 { "sdr1", 25 }, /* Storage Description Register 1 */
400 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
401 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
407 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
409 /* Given NAME, find the register number associated with that name, return
410 the integer value associated with the given name or -1 on failure. */
412 static int reg_name_search
PARAMS ( (char * name
) );
415 reg_name_search (name
)
418 int middle
, low
, high
;
422 high
= REG_NAME_CNT
- 1;
426 middle
= (low
+ high
) / 2;
427 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
433 return pre_defined_registers
[middle
].value
;
443 /* Local variables. */
445 /* The type of processor we are assembling for. This is one or more
446 of the PPC_OPCODE flags defined in opcode/ppc.h. */
447 static int ppc_cpu
= 0;
449 /* The size of the processor we are assembling for. This is either
450 PPC_OPCODE_32 or PPC_OPCODE_64. */
451 static int ppc_size
= PPC_OPCODE_32
;
453 /* Opcode hash table. */
454 static struct hash_control
*ppc_hash
;
456 /* Macro hash table. */
457 static struct hash_control
*ppc_macro_hash
;
460 /* Whether to warn about non PC relative relocations that aren't
461 in the .got2 section. */
462 static boolean mrelocatable
= false;
464 /* Flags to set in the elf header */
465 static flagword ppc_flags
= 0;
470 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
471 using a bunch of different sections. These assembler sections,
472 however, are all encompassed within the .text or .data sections of
473 the final output file. We handle this by using different
474 subsegments within these main segments. */
476 /* Next subsegment to allocate within the .text segment. */
477 static subsegT ppc_text_subsegment
= 2;
479 /* Linked list of csects in the text section. */
480 static symbolS
*ppc_text_csects
;
482 /* Next subsegment to allocate within the .data segment. */
483 static subsegT ppc_data_subsegment
= 2;
485 /* Linked list of csects in the data section. */
486 static symbolS
*ppc_data_csects
;
488 /* The current csect. */
489 static symbolS
*ppc_current_csect
;
491 /* The RS/6000 assembler uses a TOC which holds addresses of functions
492 and variables. Symbols are put in the TOC with the .tc pseudo-op.
493 A special relocation is used when accessing TOC entries. We handle
494 the TOC as a subsegment within the .data segment. We set it up if
495 we see a .toc pseudo-op, and save the csect symbol here. */
496 static symbolS
*ppc_toc_csect
;
498 /* The first frag in the TOC subsegment. */
499 static fragS
*ppc_toc_frag
;
501 /* The first frag in the first subsegment after the TOC in the .data
502 segment. NULL if there are no subsegments after the TOC. */
503 static fragS
*ppc_after_toc_frag
;
505 /* The current static block. */
506 static symbolS
*ppc_current_block
;
508 /* The COFF debugging section; set by md_begin. This is not the
509 .debug section, but is instead the secret BFD section which will
510 cause BFD to set the section number of a symbol to N_DEBUG. */
511 static asection
*ppc_coff_debug_section
;
513 /* The size of the .debug section. */
514 static bfd_size_type ppc_debug_name_section_size
;
516 #endif /* OBJ_XCOFF */
520 /* Various sections that we need for PE coff support. */
521 static segT ydata_section
;
522 static segT pdata_section
;
523 static segT reldata_section
;
524 static segT rdata_section
;
525 static segT tocdata_section
;
527 /* The current section and the previous section. See ppc_previous. */
528 static segT ppc_previous_section
;
529 static segT ppc_current_section
;
534 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
537 #ifndef WORKING_DOT_WORD
538 const int md_short_jump_size
= 4;
539 const int md_long_jump_size
= 4;
543 CONST
char *md_shortopts
= "um:VQ:";
545 CONST
char *md_shortopts
= "um:";
547 struct option md_longopts
[] = {
548 {NULL
, no_argument
, NULL
, 0}
550 size_t md_longopts_size
= sizeof(md_longopts
);
553 md_parse_option (c
, arg
)
560 /* -u means that any undefined symbols should be treated as
561 external, which is the default for gas anyhow. */
565 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
567 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
568 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
569 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
570 else if (strcmp (arg
, "pwr") == 0)
571 ppc_cpu
= PPC_OPCODE_POWER
;
572 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
573 instructions that are holdovers from the Power. */
574 else if (strcmp (arg
, "601") == 0)
575 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
576 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
577 Motorola PowerPC 603/604. */
578 else if (strcmp (arg
, "ppc") == 0
579 || strcmp (arg
, "ppc32") == 0
580 || strcmp (arg
, "403") == 0
581 || strcmp (arg
, "603") == 0
582 || strcmp (arg
, "604") == 0)
583 ppc_cpu
= PPC_OPCODE_PPC
;
584 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
586 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
588 ppc_cpu
= PPC_OPCODE_PPC
;
589 ppc_size
= PPC_OPCODE_64
;
591 /* -mcom means assemble for the common intersection between Power
592 and PowerPC. At present, we just allow the union, rather
593 than the intersection. */
594 else if (strcmp (arg
, "com") == 0)
595 ppc_cpu
= PPC_OPCODE_COMMON
;
596 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
597 else if (strcmp (arg
, "any") == 0)
598 ppc_cpu
= PPC_OPCODE_ANY
;
601 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
602 else if (strcmp (arg
, "relocatable") == 0)
605 ppc_flags
|= EF_PPC_RELOCATABLE
;
608 else if (strcmp (arg
, "relocatable-lib") == 0)
611 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
614 /* -memb, set embedded bit */
615 else if (strcmp (arg
, "emb") == 0)
616 ppc_flags
|= EF_PPC_EMB
;
618 /* -mlittle/-mbig set the endianess */
619 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
621 target_big_endian
= 0;
622 set_target_endian
= 1;
625 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
627 target_big_endian
= 1;
628 set_target_endian
= 1;
633 as_bad ("invalid switch -m%s", arg
);
639 /* -V: SVR4 argument to print version ID. */
644 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
645 should be emitted or not. FIXME: Not implemented. */
658 md_show_usage (stream
)
664 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
665 -mpwr generate code for IBM POWER (RIOS1)\n\
666 -m601 generate code for Motorola PowerPC 601\n\
667 -mppc, -mppc32, -m403, -m603, -m604\n\
668 generate code for Motorola PowerPC 603/604\n\
669 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
670 -mcom generate code Power/PowerPC common instructions\n
671 -many generate code for any architecture (PWR/PWRX/PPC)\n");
674 -mrelocatable support for GCC's -mrelocatble option\n\
675 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
676 -memb set PPC_EMB bit in ELF flags\n\
677 -mlittle, -mlittle-endian\n\
678 generate code for a little endian machine\n\
679 -mbig, -mbig-endian generate code for a big endian machine\n\
680 -V print assembler version number\n\
681 -Qy, -Qn ignored\n");
685 /* Set ppc_cpu if it is not already set. */
690 const char *default_cpu
= TARGET_CPU
;
694 if (strcmp (default_cpu
, "rs6000") == 0)
695 ppc_cpu
= PPC_OPCODE_POWER
;
696 else if (strcmp (default_cpu
, "powerpc") == 0
697 || strcmp (default_cpu
, "powerpcle") == 0)
698 ppc_cpu
= PPC_OPCODE_PPC
;
700 as_fatal ("Unknown default cpu = %s", default_cpu
);
704 /* Figure out the BFD architecture to use. */
706 enum bfd_architecture
709 const char *default_cpu
= TARGET_CPU
;
712 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
713 return bfd_arch_powerpc
;
714 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
715 return bfd_arch_rs6000
;
716 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
718 if (strcmp (default_cpu
, "rs6000") == 0)
719 return bfd_arch_rs6000
;
720 else if (strcmp (default_cpu
, "powerpc") == 0
721 || strcmp (default_cpu
, "powerpcle") == 0)
722 return bfd_arch_powerpc
;
725 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
726 return bfd_arch_unknown
;
729 /* This function is called when the assembler starts up. It is called
730 after the options have been parsed and the output file has been
736 register const struct powerpc_opcode
*op
;
737 const struct powerpc_opcode
*op_end
;
738 const struct powerpc_macro
*macro
;
739 const struct powerpc_macro
*macro_end
;
740 boolean dup_insn
= false;
745 /* Set the ELF flags if desired. */
747 bfd_set_private_flags (stdoutput
, ppc_flags
);
750 /* Insert the opcodes into a hash table. */
751 ppc_hash
= hash_new ();
753 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
754 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
756 know ((op
->opcode
& op
->mask
) == op
->opcode
);
758 if ((op
->flags
& ppc_cpu
) != 0
759 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
760 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
764 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
765 if (retval
!= (const char *) NULL
)
767 /* Ignore Power duplicates for -m601 */
768 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
769 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
772 as_bad ("Internal assembler error for instruction %s", op
->name
);
778 /* Insert the macros into a hash table. */
779 ppc_macro_hash
= hash_new ();
781 macro_end
= powerpc_macros
+ powerpc_num_macros
;
782 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
784 if ((macro
->flags
& ppc_cpu
) != 0)
788 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
789 if (retval
!= (const char *) NULL
)
791 as_bad ("Internal assembler error for macro %s", macro
->name
);
800 /* Tell the main code what the endianness is if it is not overidden by the user. */
801 if (!set_target_endian
)
803 set_target_endian
= 1;
804 target_big_endian
= PPC_BIG_ENDIAN
;
808 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
810 /* Create dummy symbols to serve as initial csects. This forces the
811 text csects to precede the data csects. These symbols will not
813 ppc_text_csects
= symbol_make ("dummy\001");
814 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
815 ppc_data_csects
= symbol_make ("dummy\001");
816 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
821 ppc_current_section
= text_section
;
822 ppc_previous_section
= 0;
827 /* Insert an operand value into an instruction. */
830 ppc_insert_operand (insn
, operand
, val
, file
, line
)
832 const struct powerpc_operand
*operand
;
837 if (operand
->bits
!= 32)
842 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
844 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
845 && ppc_size
== PPC_OPCODE_32
)
846 max
= (1 << operand
->bits
) - 1;
848 max
= (1 << (operand
->bits
- 1)) - 1;
849 min
= - (1 << (operand
->bits
- 1));
853 max
= (1 << operand
->bits
) - 1;
857 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
862 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
865 "operand out of range (%s not between %ld and %ld)";
868 sprint_value (buf
, test
);
869 if (file
== (char *) NULL
)
870 as_warn (err
, buf
, min
, max
);
872 as_warn_where (file
, line
, err
, buf
, min
, max
);
881 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
882 if (errmsg
!= (const char *) NULL
)
886 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
893 /* Parse @got, etc. and return the desired relocation. */
894 static bfd_reloc_code_real_type
895 ppc_elf_suffix (str_p
)
901 bfd_reloc_code_real_type reloc
;
911 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
913 static struct map_bfd mapping
[] = {
914 MAP ("got", BFD_RELOC_PPC_TOC16
),
915 MAP ("l", BFD_RELOC_LO16
),
916 MAP ("h", BFD_RELOC_HI16
),
917 MAP ("ha", BFD_RELOC_HI16_S
),
918 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
919 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
920 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
921 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
922 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
923 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
924 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
925 MAP ("copy", BFD_RELOC_PPC_COPY
),
926 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
927 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
928 MAP ("plt", BFD_RELOC_32_PLTOFF
),
929 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
930 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
931 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
932 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
933 MAP ("sdarel", BFD_RELOC_GPREL16
),
934 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
935 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
936 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
937 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
939 { (char *)0, 0, BFD_RELOC_UNUSED
}
943 return BFD_RELOC_UNUSED
;
945 for (ch
= *str
, str2
= ident
;
946 str2
< ident
+ sizeof(ident
) - 1 && isalnum (ch
) || ch
== '@';
949 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
956 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
957 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
963 return BFD_RELOC_UNUSED
;
966 /* Like normal .long/.short/.word, except support @got, etc. */
967 /* clobbers input_line_pointer, checks */
970 ppc_elf_cons (nbytes
)
971 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
974 bfd_reloc_code_real_type reloc
;
976 if (is_it_end_of_statement ())
978 demand_empty_rest_of_line ();
985 if (exp
.X_op
== O_symbol
986 && *input_line_pointer
== '@'
987 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
989 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
990 int size
= bfd_get_reloc_size (reloc_howto
);
993 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
997 register char *p
= frag_more ((int) nbytes
);
998 int offset
= nbytes
- size
;
1000 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
1004 emit_expr (&exp
, (unsigned int) nbytes
);
1006 while (*input_line_pointer
++ == ',');
1008 input_line_pointer
--; /* Put terminator back into stream. */
1009 demand_empty_rest_of_line ();
1012 /* Validate any relocations emitted for -mrelocatable, possibly adding
1013 fixups for word relocations in writable segments, so we can adjust
1016 ppc_elf_validate_fix (fixp
, seg
)
1023 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1024 && strcmp (segment_name (seg
), ".got2") != 0
1025 && strcmp (segment_name (seg
), ".dtors") != 0
1026 && strcmp (segment_name (seg
), ".ctors") != 0
1027 && strcmp (segment_name (seg
), ".fixup") != 0
1028 && strcmp (segment_name (seg
), ".stab") != 0)
1030 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1031 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1033 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
1034 "Relocation cannot be done when using -mrelocatable");
1039 #endif /* OBJ_ELF */
1043 * Summary of register_name().
1045 * in: Input_line_pointer points to 1st char of operand.
1047 * out: A expressionS.
1048 * The operand may have been a register: in this case, X_op == O_register,
1049 * X_add_number is set to the register number, and truth is returned.
1050 * Input_line_pointer->(next non-blank) char after operand, or is in its
1055 register_name (expressionP
)
1056 expressionS
*expressionP
;
1062 /* Find the spelling of the operand */
1063 name
= input_line_pointer
;
1064 c
= get_symbol_end ();
1065 reg_number
= reg_name_search (name
);
1067 /* look to see if it's in the register table */
1068 if (reg_number
>= 0)
1070 expressionP
->X_op
= O_register
;
1071 expressionP
->X_add_number
= reg_number
;
1073 /* make the rest nice */
1074 expressionP
->X_add_symbol
= NULL
;
1075 expressionP
->X_op_symbol
= NULL
;
1076 *input_line_pointer
= c
; /* put back the delimiting char */
1081 /* reset the line as if we had not done anything */
1082 *input_line_pointer
= c
; /* put back the delimiting char */
1083 input_line_pointer
= name
; /* reset input_line pointer */
1089 * Summary of parse_toc_entry().
1091 * in: Input_line_pointer points to the '[' in one of:
1093 * [toc] [tocv] [toc32] [toc64]
1095 * Anything else is an error of one kind or another.
1098 * return value: success or failure
1099 * toc_kind: kind of toc reference
1100 * input_line_pointer:
1101 * success: first char after the ']'
1102 * failure: unchanged
1106 * [toc] - rv == success, toc_kind = default_toc
1107 * [tocv] - rv == success, toc_kind = data_in_toc
1108 * [toc32] - rv == success, toc_kind = must_be_32
1109 * [toc64] - rv == success, toc_kind = must_be_64
1113 enum toc_size_qualifier
1115 default_toc
, /* The toc cell constructed should be the system default size */
1116 data_in_toc
, /* This is a direct reference to a toc cell */
1117 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1118 must_be_64
/* The toc cell constructed must be 64 bits wide */
1122 parse_toc_entry(toc_kind
)
1123 enum toc_size_qualifier
*toc_kind
;
1128 enum toc_size_qualifier t
;
1130 /* save the input_line_pointer */
1131 start
= input_line_pointer
;
1133 /* skip over the '[' , and whitespace */
1134 ++input_line_pointer
;
1137 /* find the spelling of the operand */
1138 toc_spec
= input_line_pointer
;
1139 c
= get_symbol_end ();
1141 if (strcmp(toc_spec
, "toc") == 0)
1145 else if (strcmp(toc_spec
, "tocv") == 0)
1149 else if (strcmp(toc_spec
, "toc32") == 0)
1153 else if (strcmp(toc_spec
, "toc64") == 0)
1159 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1160 *input_line_pointer
= c
; /* put back the delimiting char */
1161 input_line_pointer
= start
; /* reset input_line pointer */
1165 /* now find the ']' */
1166 *input_line_pointer
= c
; /* put back the delimiting char */
1168 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1169 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1173 as_bad ("syntax error: expected `]', found `%c'", c
);
1174 input_line_pointer
= start
; /* reset input_line pointer */
1178 *toc_kind
= t
; /* set return value */
1185 /* We need to keep a list of fixups. We can't simply generate them as
1186 we go, because that would require us to first create the frag, and
1187 that would screw up references to ``.''. */
1193 bfd_reloc_code_real_type reloc
;
1196 #define MAX_INSN_FIXUPS (5)
1198 /* This routine is called for each instruction to be assembled. */
1205 const struct powerpc_opcode
*opcode
;
1207 const unsigned char *opindex_ptr
;
1211 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1216 bfd_reloc_code_real_type reloc
;
1219 /* Get the opcode. */
1220 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1225 /* Look up the opcode in the hash table. */
1226 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1227 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1229 const struct powerpc_macro
*macro
;
1231 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1232 if (macro
== (const struct powerpc_macro
*) NULL
)
1233 as_bad ("Unrecognized opcode: `%s'", str
);
1235 ppc_macro (s
, macro
);
1240 insn
= opcode
->opcode
;
1243 while (isspace (*str
))
1246 /* PowerPC operands are just expressions. The only real issue is
1247 that a few operand types are optional. All cases which might use
1248 an optional operand separate the operands only with commas (in
1249 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1250 cases never have optional operands). There is never more than
1251 one optional operand for an instruction. So, before we start
1252 seriously parsing the operands, we check to see if we have an
1253 optional operand, and, if we do, we count the number of commas to
1254 see whether the operand should be omitted. */
1256 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1258 const struct powerpc_operand
*operand
;
1260 operand
= &powerpc_operands
[*opindex_ptr
];
1261 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1263 unsigned int opcount
;
1265 /* There is an optional operand. Count the number of
1266 commas in the input line. */
1273 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1280 /* If there are fewer operands in the line then are called
1281 for by the instruction, we want to skip the optional
1283 if (opcount
< strlen (opcode
->operands
))
1290 /* Gather the operands. */
1294 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1296 const struct powerpc_operand
*operand
;
1302 if (next_opindex
== 0)
1303 operand
= &powerpc_operands
[*opindex_ptr
];
1306 operand
= &powerpc_operands
[next_opindex
];
1312 /* If this is a fake operand, then we do not expect anything
1314 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1316 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1317 if (errmsg
!= (const char *) NULL
)
1322 /* If this is an optional operand, and we are skipping it, just
1324 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1327 if (operand
->insert
)
1329 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1330 if (errmsg
!= (const char *) NULL
)
1333 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1334 next_opindex
= *opindex_ptr
+ 1;
1338 /* Gather the operand. */
1339 hold
= input_line_pointer
;
1340 input_line_pointer
= str
;
1343 if (*input_line_pointer
== '[')
1345 /* We are expecting something like the second argument here:
1347 lwz r4,[toc].GS.0.static_int(rtoc)
1348 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1349 The argument following the `]' must be a symbol name, and the
1350 register must be the toc register: 'rtoc' or '2'
1352 The effect is to 0 as the displacement field
1353 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1354 the appropriate variation) reloc against it based on the symbol.
1355 The linker will build the toc, and insert the resolved toc offset.
1358 o The size of the toc entry is currently assumed to be
1359 32 bits. This should not be assumed to be a hard coded
1361 o In an effort to cope with a change from 32 to 64 bits,
1362 there are also toc entries that are specified to be
1363 either 32 or 64 bits:
1364 lwz r4,[toc32].GS.0.static_int(rtoc)
1365 lwz r4,[toc64].GS.0.static_int(rtoc)
1366 These demand toc entries of the specified size, and the
1367 instruction probably requires it.
1371 enum toc_size_qualifier toc_kind
;
1372 bfd_reloc_code_real_type toc_reloc
;
1374 /* go parse off the [tocXX] part */
1375 valid_toc
= parse_toc_entry(&toc_kind
);
1379 /* Note: message has already been issued. */
1380 /* FIXME: what sort of recovery should we do? */
1381 /* demand_rest_of_line(); return; ? */
1384 /* Now get the symbol following the ']' */
1390 /* In this case, we may not have seen the symbol yet, since */
1391 /* it is allowed to appear on a .extern or .globl or just be */
1392 /* a label in the .data section. */
1393 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1396 /* 1. The symbol must be defined and either in the toc */
1397 /* section, or a global. */
1398 /* 2. The reloc generated must have the TOCDEFN flag set in */
1399 /* upper bit mess of the reloc type. */
1400 /* FIXME: It's a little confusing what the tocv qualifier can */
1401 /* be used for. At the very least, I've seen three */
1402 /* uses, only one of which I'm sure I can explain. */
1403 if (ex
.X_op
== O_symbol
)
1405 assert (ex
.X_add_symbol
!= NULL
);
1406 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1408 as_warn("[tocv] symbol is not a toc symbol");
1412 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1415 /* FIXME: these next two specifically specify 32/64 bit toc */
1416 /* entries. We don't support them today. Is this the */
1417 /* right way to say that? */
1418 toc_reloc
= BFD_RELOC_UNUSED
;
1419 as_bad ("Unimplemented toc32 expression modifier");
1422 /* FIXME: see above */
1423 toc_reloc
= BFD_RELOC_UNUSED
;
1424 as_bad ("Unimplemented toc64 expression modifier");
1428 "Unexpected return value [%d] from parse_toc_entry!\n",
1434 /* We need to generate a fixup for this expression. */
1435 if (fc
>= MAX_INSN_FIXUPS
)
1436 as_fatal ("too many fixups");
1438 fixups
[fc
].reloc
= toc_reloc
;
1439 fixups
[fc
].exp
= ex
;
1440 fixups
[fc
].opindex
= *opindex_ptr
;
1443 /* Ok. We've set up the fixup for the instruction. Now make it
1444 look like the constant 0 was found here */
1446 ex
.X_op
= O_constant
;
1447 ex
.X_add_number
= 0;
1448 ex
.X_add_symbol
= NULL
;
1449 ex
.X_op_symbol
= NULL
;
1453 if (!register_name(&ex
))
1459 str
= input_line_pointer
;
1460 input_line_pointer
= hold
;
1463 str
= input_line_pointer
;
1464 input_line_pointer
= hold
;
1467 if (ex
.X_op
== O_illegal
)
1468 as_bad ("illegal operand");
1469 else if (ex
.X_op
== O_absent
)
1470 as_bad ("missing operand");
1471 else if (ex
.X_op
== O_constant
)
1474 /* Allow @HA, @L, @H on constants. */
1475 char *orig_str
= str
;
1477 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1484 case BFD_RELOC_LO16
:
1485 ex
.X_add_number
= ((ex
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1488 case BFD_RELOC_HI16
:
1489 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1492 case BFD_RELOC_HI16_S
:
1493 ex
.X_add_number
= ((ex
.X_add_number
>> 16) & 0xffff)
1494 + ((ex
.X_add_number
>> 15) & 1);
1498 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1502 else if (ex
.X_op
== O_register
)
1504 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1509 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1511 /* For the absoulte forms of branchs, convert the PC relative form back into
1513 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1516 case BFD_RELOC_PPC_B26
: reloc
= BFD_RELOC_PPC_BA26
; break;
1517 case BFD_RELOC_PPC_B16
: reloc
= BFD_RELOC_PPC_BA16
; break;
1518 case BFD_RELOC_PPC_B16_BRTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
; break;
1519 case BFD_RELOC_PPC_B16_BRNTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
; break;
1522 /* We need to generate a fixup for this expression. */
1523 if (fc
>= MAX_INSN_FIXUPS
)
1524 as_fatal ("too many fixups");
1525 fixups
[fc
].exp
= ex
;
1526 fixups
[fc
].opindex
= 0;
1527 fixups
[fc
].reloc
= reloc
;
1530 #endif /* OBJ_ELF */
1534 /* We need to generate a fixup for this expression. */
1535 if (fc
>= MAX_INSN_FIXUPS
)
1536 as_fatal ("too many fixups");
1537 fixups
[fc
].exp
= ex
;
1538 fixups
[fc
].opindex
= *opindex_ptr
;
1539 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1548 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1556 /* The call to expression should have advanced str past any
1559 && (endc
!= ',' || *str
!= '\0'))
1561 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1569 while (isspace (*str
))
1573 as_bad ("junk at end of line: `%s'", str
);
1575 /* Write out the instruction. */
1577 md_number_to_chars (f
, insn
, 4);
1579 /* Create any fixups. At this point we do not use a
1580 bfd_reloc_code_real_type, but instead just use the
1581 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1582 handle fixups for any operand type, although that is admittedly
1583 not a very exciting feature. We pick a BFD reloc type in
1585 for (i
= 0; i
< fc
; i
++)
1587 const struct powerpc_operand
*operand
;
1589 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1590 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1592 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1600 size
= bfd_get_reloc_size (reloc_howto
);
1601 offset
= target_big_endian
? (4 - size
) : 0;
1603 if (size
< 1 || size
> 4)
1606 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1607 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1610 /* Turn off complaints that the addend is too large for things like
1612 switch (fixups
[i
].reloc
)
1614 case BFD_RELOC_LO16
:
1615 case BFD_RELOC_HI16
:
1616 case BFD_RELOC_HI16_S
:
1617 fixP
->fx_no_overflow
= 1;
1624 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1626 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1627 ((bfd_reloc_code_real_type
)
1628 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1632 #ifndef WORKING_DOT_WORD
1633 /* Handle long and short jumps */
1635 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1637 addressT from_addr
, to_addr
;
1645 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1647 addressT from_addr
, to_addr
;
1655 /* Handle a macro. Gather all the operands, transform them as
1656 described by the macro, and call md_assemble recursively. All the
1657 operands are separated by commas; we don't accept parentheses
1658 around operands here. */
1661 ppc_macro (str
, macro
)
1663 const struct powerpc_macro
*macro
;
1674 /* Gather the users operands into the operands array. */
1679 if (count
>= sizeof operands
/ sizeof operands
[0])
1681 operands
[count
++] = s
;
1682 s
= strchr (s
, ',');
1683 if (s
== (char *) NULL
)
1688 if (count
!= macro
->operands
)
1690 as_bad ("wrong number of operands");
1694 /* Work out how large the string must be (the size is unbounded
1695 because it includes user input). */
1697 format
= macro
->format
;
1698 while (*format
!= '\0')
1707 arg
= strtol (format
+ 1, &send
, 10);
1708 know (send
!= format
&& arg
>= 0 && arg
< count
);
1709 len
+= strlen (operands
[arg
]);
1714 /* Put the string together. */
1715 complete
= s
= (char *) alloca (len
+ 1);
1716 format
= macro
->format
;
1717 while (*format
!= '\0')
1723 arg
= strtol (format
+ 1, &send
, 10);
1724 strcpy (s
, operands
[arg
]);
1731 /* Assemble the constructed instruction. */
1732 md_assemble (complete
);
1735 /* Pseudo-op handling. */
1737 /* The .byte pseudo-op. This is similar to the normal .byte
1738 pseudo-op, but it can also take a single ASCII string. */
1744 if (*input_line_pointer
!= '\"')
1750 /* Gather characters. A real double quote is doubled. Unusual
1751 characters are not permitted. */
1752 ++input_line_pointer
;
1757 c
= *input_line_pointer
++;
1761 if (*input_line_pointer
!= '\"')
1763 ++input_line_pointer
;
1766 FRAG_APPEND_1_CHAR (c
);
1769 demand_empty_rest_of_line ();
1774 /* XCOFF specific pseudo-op handling. */
1776 /* This is set if we are creating a .stabx symbol, since we don't want
1777 to handle symbol suffixes for such symbols. */
1778 static boolean ppc_stab_symbol
;
1780 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1781 symbols in the .bss segment as though they were local common
1782 symbols, and uses a different smclas. */
1788 asection
*current_seg
= now_seg
;
1789 subsegT current_subseg
= now_subseg
;
1795 symbolS
*lcomm_sym
= NULL
;
1799 name
= input_line_pointer
;
1800 endc
= get_symbol_end ();
1801 end_name
= input_line_pointer
;
1804 if (*input_line_pointer
!= ',')
1806 as_bad ("missing size");
1807 ignore_rest_of_line ();
1810 ++input_line_pointer
;
1812 size
= get_absolute_expression ();
1815 as_bad ("negative size");
1816 ignore_rest_of_line ();
1822 /* The third argument to .comm is the alignment. */
1823 if (*input_line_pointer
!= ',')
1827 ++input_line_pointer
;
1828 align
= get_absolute_expression ();
1831 as_warn ("ignoring bad alignment");
1850 /* The third argument to .lcomm appears to be the real local
1851 common symbol to create. References to the symbol named in
1852 the first argument are turned into references to the third
1854 if (*input_line_pointer
!= ',')
1856 as_bad ("missing real symbol name");
1857 ignore_rest_of_line ();
1860 ++input_line_pointer
;
1862 lcomm_name
= input_line_pointer
;
1863 lcomm_endc
= get_symbol_end ();
1865 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1867 *input_line_pointer
= lcomm_endc
;
1871 sym
= symbol_find_or_make (name
);
1874 if (S_IS_DEFINED (sym
)
1875 || S_GET_VALUE (sym
) != 0)
1877 as_bad ("attempt to redefine symbol");
1878 ignore_rest_of_line ();
1882 record_alignment (bss_section
, align
);
1885 || ! S_IS_DEFINED (lcomm_sym
))
1894 S_SET_EXTERNAL (sym
);
1898 lcomm_sym
->sy_tc
.output
= 1;
1899 def_sym
= lcomm_sym
;
1903 subseg_set (bss_section
, 1);
1904 frag_align (align
, 0);
1906 def_sym
->sy_frag
= frag_now
;
1907 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1908 def_size
, (char *) NULL
);
1910 S_SET_SEGMENT (def_sym
, bss_section
);
1911 def_sym
->sy_tc
.align
= align
;
1915 /* Align the size of lcomm_sym. */
1916 lcomm_sym
->sy_frag
->fr_offset
=
1917 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1918 &~ ((1 << align
) - 1));
1919 if (align
> lcomm_sym
->sy_tc
.align
)
1920 lcomm_sym
->sy_tc
.align
= align
;
1925 /* Make sym an offset from lcomm_sym. */
1926 S_SET_SEGMENT (sym
, bss_section
);
1927 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1928 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1929 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1932 subseg_set (current_seg
, current_subseg
);
1934 demand_empty_rest_of_line ();
1937 /* The .csect pseudo-op. This switches us into a different
1938 subsegment. The first argument is a symbol whose value is the
1939 start of the .csect. In COFF, csect symbols get special aux
1940 entries defined by the x_csect field of union internal_auxent. The
1941 optional second argument is the alignment (the default is 2). */
1951 name
= input_line_pointer
;
1952 endc
= get_symbol_end ();
1954 sym
= symbol_find_or_make (name
);
1956 *input_line_pointer
= endc
;
1958 ppc_change_csect (sym
);
1960 if (*input_line_pointer
== ',')
1962 ++input_line_pointer
;
1963 sym
->sy_tc
.align
= get_absolute_expression ();
1966 demand_empty_rest_of_line ();
1969 /* Change to a different csect. */
1972 ppc_change_csect (sym
)
1975 if (S_IS_DEFINED (sym
))
1976 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1983 /* This is a new csect. We need to look at the symbol class to
1984 figure out whether it should go in the text section or the
1987 switch (sym
->sy_tc
.class)
1997 S_SET_SEGMENT (sym
, text_section
);
1998 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1999 ++ppc_text_subsegment
;
2000 list_ptr
= &ppc_text_csects
;
2009 if (ppc_toc_csect
!= NULL
2010 && ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
2012 S_SET_SEGMENT (sym
, data_section
);
2013 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
2014 ++ppc_data_subsegment
;
2015 list_ptr
= &ppc_data_csects
;
2021 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
2023 ppc_after_toc_frag
= frag_now
;
2025 sym
->sy_frag
= frag_now
;
2026 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2028 sym
->sy_tc
.align
= 2;
2029 sym
->sy_tc
.output
= 1;
2030 sym
->sy_tc
.within
= sym
;
2032 for (list
= *list_ptr
;
2033 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2034 list
= list
->sy_tc
.next
)
2036 list
->sy_tc
.next
= sym
;
2038 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2039 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2042 ppc_current_csect
= sym
;
2045 /* This function handles the .text and .data pseudo-ops. These
2046 pseudo-ops aren't really used by XCOFF; we implement them for the
2047 convenience of people who aren't used to XCOFF. */
2058 else if (type
== 'd')
2063 sym
= symbol_find_or_make (name
);
2065 ppc_change_csect (sym
);
2067 demand_empty_rest_of_line ();
2070 /* The .extern pseudo-op. We create an undefined symbol. */
2079 name
= input_line_pointer
;
2080 endc
= get_symbol_end ();
2082 (void) symbol_find_or_make (name
);
2084 *input_line_pointer
= endc
;
2086 demand_empty_rest_of_line ();
2089 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2099 name
= input_line_pointer
;
2100 endc
= get_symbol_end ();
2102 sym
= symbol_find_or_make (name
);
2104 *input_line_pointer
= endc
;
2106 sym
->sy_tc
.output
= 1;
2108 demand_empty_rest_of_line ();
2111 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2112 although I don't know why it bothers. */
2123 name
= input_line_pointer
;
2124 endc
= get_symbol_end ();
2126 sym
= symbol_find_or_make (name
);
2128 *input_line_pointer
= endc
;
2130 if (*input_line_pointer
!= ',')
2132 as_bad ("missing rename string");
2133 ignore_rest_of_line ();
2136 ++input_line_pointer
;
2138 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2140 demand_empty_rest_of_line ();
2143 /* The .stabx pseudo-op. This is similar to a normal .stabs
2144 pseudo-op, but slightly different. A sample is
2145 .stabx "main:F-1",.main,142,0
2146 The first argument is the symbol name to create. The second is the
2147 value, and the third is the storage class. The fourth seems to be
2148 always zero, and I am assuming it is the type. */
2159 name
= demand_copy_C_string (&len
);
2161 if (*input_line_pointer
!= ',')
2163 as_bad ("missing value");
2166 ++input_line_pointer
;
2168 ppc_stab_symbol
= true;
2169 sym
= symbol_make (name
);
2170 ppc_stab_symbol
= false;
2172 sym
->sy_tc
.real_name
= name
;
2174 (void) expression (&exp
);
2181 as_bad ("illegal .stabx expression; zero assumed");
2182 exp
.X_add_number
= 0;
2185 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2186 sym
->sy_frag
= &zero_address_frag
;
2190 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2191 sym
->sy_value
= exp
;
2195 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2196 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2201 /* The value is some complex expression. This will probably
2202 fail at some later point, but this is probably the right
2203 thing to do here. */
2204 sym
->sy_value
= exp
;
2208 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2209 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2211 if (*input_line_pointer
!= ',')
2213 as_bad ("missing class");
2216 ++input_line_pointer
;
2218 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2220 if (*input_line_pointer
!= ',')
2222 as_bad ("missing type");
2225 ++input_line_pointer
;
2227 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2229 sym
->sy_tc
.output
= 1;
2231 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2232 sym
->sy_tc
.within
= ppc_current_block
;
2234 if (exp
.X_op
!= O_symbol
2235 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2236 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2237 ppc_frob_label (sym
);
2240 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2241 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2242 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2243 ppc_current_csect
->sy_tc
.within
= sym
;
2246 if (strlen (name
) > SYMNMLEN
)
2248 /* For some reason, each name is preceded by a two byte length
2249 and followed by a null byte. */
2250 ppc_debug_name_section_size
+= strlen (name
) + 3;
2253 demand_empty_rest_of_line ();
2256 /* The .function pseudo-op. This takes several arguments. The first
2257 argument seems to be the external name of the symbol. The second
2258 argment seems to be the label for the start of the function. gcc
2259 uses the same name for both. I have no idea what the third and
2260 fourth arguments are meant to be. The optional fifth argument is
2261 an expression for the size of the function. In COFF this symbol
2262 gets an aux entry like that used for a csect. */
2265 ppc_function (ignore
)
2274 name
= input_line_pointer
;
2275 endc
= get_symbol_end ();
2277 /* Ignore any [PR] suffix. */
2278 name
= ppc_canonicalize_symbol_name (name
);
2279 s
= strchr (name
, '[');
2280 if (s
!= (char *) NULL
2281 && strcmp (s
+ 1, "PR]") == 0)
2284 ext_sym
= symbol_find_or_make (name
);
2286 *input_line_pointer
= endc
;
2288 if (*input_line_pointer
!= ',')
2290 as_bad ("missing symbol name");
2291 ignore_rest_of_line ();
2294 ++input_line_pointer
;
2296 name
= input_line_pointer
;
2297 endc
= get_symbol_end ();
2299 lab_sym
= symbol_find_or_make (name
);
2301 *input_line_pointer
= endc
;
2303 if (ext_sym
!= lab_sym
)
2305 ext_sym
->sy_value
.X_op
= O_symbol
;
2306 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2307 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2308 ext_sym
->sy_value
.X_add_number
= 0;
2311 if (ext_sym
->sy_tc
.class == -1)
2312 ext_sym
->sy_tc
.class = XMC_PR
;
2313 ext_sym
->sy_tc
.output
= 1;
2315 if (*input_line_pointer
== ',')
2319 /* Ignore the third argument. */
2320 ++input_line_pointer
;
2321 expression (&ignore
);
2322 if (*input_line_pointer
== ',')
2324 /* Ignore the fourth argument. */
2325 ++input_line_pointer
;
2326 expression (&ignore
);
2327 if (*input_line_pointer
== ',')
2329 /* The fifth argument is the function size. */
2330 ++input_line_pointer
;
2331 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2334 &zero_address_frag
);
2335 pseudo_set (ext_sym
->sy_tc
.size
);
2340 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2341 SF_SET_FUNCTION (ext_sym
);
2342 SF_SET_PROCESS (ext_sym
);
2343 coff_add_linesym (ext_sym
);
2345 demand_empty_rest_of_line ();
2348 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2357 sym
= symbol_make (".bf");
2358 S_SET_SEGMENT (sym
, text_section
);
2359 sym
->sy_frag
= frag_now
;
2360 S_SET_VALUE (sym
, frag_now_fix ());
2361 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2363 coff_line_base
= get_absolute_expression ();
2365 S_SET_NUMBER_AUXILIARY (sym
, 1);
2366 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2368 sym
->sy_tc
.output
= 1;
2370 ppc_frob_label (sym
);
2372 demand_empty_rest_of_line ();
2375 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2376 ".ef", except that the line number is absolute, not relative to the
2377 most recent ".bf" symbol. */
2385 sym
= symbol_make (".ef");
2386 S_SET_SEGMENT (sym
, text_section
);
2387 sym
->sy_frag
= frag_now
;
2388 S_SET_VALUE (sym
, frag_now_fix ());
2389 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2390 S_SET_NUMBER_AUXILIARY (sym
, 1);
2391 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2392 sym
->sy_tc
.output
= 1;
2394 ppc_frob_label (sym
);
2396 demand_empty_rest_of_line ();
2399 /* The .bi and .ei pseudo-ops. These take a string argument and
2400 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2412 name
= demand_copy_C_string (&len
);
2414 /* The value of these symbols is actually file offset. Here we set
2415 the value to the index into the line number entries. In
2416 ppc_frob_symbols we set the fix_line field, which will cause BFD
2417 to do the right thing. */
2419 sym
= symbol_make (name
);
2420 S_SET_SEGMENT (sym
, now_seg
);
2421 S_SET_VALUE (sym
, coff_n_line_nos
);
2422 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2424 /* obj-coff.c currently only handles line numbers correctly in the
2426 assert (now_seg
== text_section
);
2428 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2429 sym
->sy_tc
.output
= 1;
2431 for (look
= symbol_rootP
;
2432 (look
!= (symbolS
*) NULL
2433 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2434 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2435 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2436 look
= symbol_next (look
))
2438 if (look
!= (symbolS
*) NULL
)
2440 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2441 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2444 demand_empty_rest_of_line ();
2447 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2448 There is one argument, which is a csect symbol. The value of the
2449 .bs symbol is the index of this csect symbol. */
2460 if (ppc_current_block
!= NULL
)
2461 as_bad ("nested .bs blocks");
2463 name
= input_line_pointer
;
2464 endc
= get_symbol_end ();
2466 csect
= symbol_find_or_make (name
);
2468 *input_line_pointer
= endc
;
2470 sym
= symbol_make (".bs");
2471 S_SET_SEGMENT (sym
, now_seg
);
2472 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2473 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2474 sym
->sy_tc
.output
= 1;
2476 sym
->sy_tc
.within
= csect
;
2478 ppc_frob_label (sym
);
2480 ppc_current_block
= sym
;
2482 demand_empty_rest_of_line ();
2485 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2493 if (ppc_current_block
== NULL
)
2494 as_bad (".es without preceding .bs");
2496 sym
= symbol_make (".es");
2497 S_SET_SEGMENT (sym
, now_seg
);
2498 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2499 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2500 sym
->sy_tc
.output
= 1;
2502 ppc_frob_label (sym
);
2504 ppc_current_block
= NULL
;
2506 demand_empty_rest_of_line ();
2509 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2518 sym
= symbol_make (".bb");
2519 S_SET_SEGMENT (sym
, text_section
);
2520 sym
->sy_frag
= frag_now
;
2521 S_SET_VALUE (sym
, frag_now_fix ());
2522 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2524 S_SET_NUMBER_AUXILIARY (sym
, 1);
2525 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2527 sym
->sy_tc
.output
= 1;
2529 SF_SET_PROCESS (sym
);
2531 ppc_frob_label (sym
);
2533 demand_empty_rest_of_line ();
2536 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2545 sym
= symbol_make (".eb");
2546 S_SET_SEGMENT (sym
, text_section
);
2547 sym
->sy_frag
= frag_now
;
2548 S_SET_VALUE (sym
, frag_now_fix ());
2549 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2550 S_SET_NUMBER_AUXILIARY (sym
, 1);
2551 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2552 sym
->sy_tc
.output
= 1;
2554 SF_SET_PROCESS (sym
);
2556 ppc_frob_label (sym
);
2558 demand_empty_rest_of_line ();
2561 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
2572 name
= demand_copy_C_string (&len
);
2573 sym
= symbol_make (name
);
2574 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2575 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2576 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
2577 S_SET_VALUE (sym
, 0);
2578 sym
->sy_tc
.output
= 1;
2580 ppc_frob_label (sym
);
2582 if (strlen (name
) > SYMNMLEN
)
2583 ppc_debug_name_section_size
+= strlen (name
) + 3;
2585 demand_empty_rest_of_line ();
2588 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
2596 sym
= symbol_make (".ec");
2597 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2598 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2599 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
2600 S_SET_VALUE (sym
, 0);
2601 sym
->sy_tc
.output
= 1;
2603 ppc_frob_label (sym
);
2605 demand_empty_rest_of_line ();
2608 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2614 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2615 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2622 subseg
= ppc_data_subsegment
;
2623 ++ppc_data_subsegment
;
2625 subseg_new (segment_name (data_section
), subseg
);
2626 ppc_toc_frag
= frag_now
;
2628 sym
= symbol_find_or_make ("TOC[TC0]");
2629 sym
->sy_frag
= frag_now
;
2630 S_SET_SEGMENT (sym
, data_section
);
2631 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2632 sym
->sy_tc
.subseg
= subseg
;
2633 sym
->sy_tc
.output
= 1;
2634 sym
->sy_tc
.within
= sym
;
2636 ppc_toc_csect
= sym
;
2638 for (list
= ppc_data_csects
;
2639 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2640 list
= list
->sy_tc
.next
)
2642 list
->sy_tc
.next
= sym
;
2644 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2645 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2648 ppc_current_csect
= ppc_toc_csect
;
2650 demand_empty_rest_of_line ();
2653 #endif /* OBJ_XCOFF */
2655 /* The .tc pseudo-op. This is used when generating either XCOFF or
2656 ELF. This takes two or more arguments.
2658 When generating XCOFF output, the first argument is the name to
2659 give to this location in the toc; this will be a symbol with class
2660 TC. The rest of the arguments are 4 byte values to actually put at
2661 this location in the TOC; often there is just one more argument, a
2662 relocateable symbol reference.
2664 When not generating XCOFF output, the arguments are the same, but
2665 the first argument is simply ignored. */
2673 /* Define the TOC symbol name. */
2679 if (ppc_toc_csect
== (symbolS
*) NULL
2680 || ppc_toc_csect
!= ppc_current_csect
)
2682 as_bad (".tc not in .toc section");
2683 ignore_rest_of_line ();
2687 name
= input_line_pointer
;
2688 endc
= get_symbol_end ();
2690 sym
= symbol_find_or_make (name
);
2692 *input_line_pointer
= endc
;
2694 if (S_IS_DEFINED (sym
))
2698 label
= ppc_current_csect
->sy_tc
.within
;
2699 if (label
->sy_tc
.class != XMC_TC0
)
2701 as_warn (".tc with no label");
2702 ignore_rest_of_line ();
2706 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
2707 label
->sy_frag
= sym
->sy_frag
;
2708 S_SET_VALUE (label
, S_GET_VALUE (sym
));
2710 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2711 ++input_line_pointer
;
2716 S_SET_SEGMENT (sym
, now_seg
);
2717 sym
->sy_frag
= frag_now
;
2718 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2719 sym
->sy_tc
.class = XMC_TC
;
2720 sym
->sy_tc
.output
= 1;
2722 ppc_frob_label (sym
);
2725 #else /* ! defined (OBJ_XCOFF) */
2727 /* Skip the TOC symbol name. */
2728 while (is_part_of_name (*input_line_pointer
)
2729 || *input_line_pointer
== '['
2730 || *input_line_pointer
== ']'
2731 || *input_line_pointer
== '{'
2732 || *input_line_pointer
== '}')
2733 ++input_line_pointer
;
2735 /* Align to a four byte boundary. */
2737 record_alignment (now_seg
, 2);
2739 #endif /* ! defined (OBJ_XCOFF) */
2741 if (*input_line_pointer
!= ',')
2742 demand_empty_rest_of_line ();
2745 ++input_line_pointer
;
2752 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2754 /* Set the current section. */
2756 ppc_set_current_section (new)
2759 ppc_previous_section
= ppc_current_section
;
2760 ppc_current_section
= new;
2763 /* pseudo-op: .previous
2764 behaviour: toggles the current section with the previous section.
2766 warnings: "No previous section"
2769 ppc_previous(ignore
)
2774 if (ppc_previous_section
== NULL
)
2776 as_warn("No previous section to return to. Directive ignored.");
2780 subseg_set(ppc_previous_section
, 0);
2782 ppc_set_current_section(ppc_previous_section
);
2785 /* pseudo-op: .pdata
2786 behaviour: predefined read only data section
2790 initial: .section .pdata "adr3"
2791 a - don't know -- maybe a misprint
2792 d - initialized data
2794 3 - double word aligned (that would be 4 byte boundary)
2797 Tag index tables (also known as the function table) for exception
2798 handling, debugging, etc.
2805 if (pdata_section
== 0)
2807 pdata_section
= subseg_new (".pdata", 0);
2809 bfd_set_section_flags (stdoutput
, pdata_section
,
2810 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2811 | SEC_READONLY
| SEC_DATA
));
2813 bfd_set_section_alignment (stdoutput
, pdata_section
, 3);
2817 pdata_section
= subseg_new(".pdata", 0);
2819 ppc_set_current_section(pdata_section
);
2822 /* pseudo-op: .ydata
2823 behaviour: predefined read only data section
2827 initial: .section .ydata "drw3"
2828 a - don't know -- maybe a misprint
2829 d - initialized data
2831 3 - double word aligned (that would be 4 byte boundary)
2833 Tag tables (also known as the scope table) for exception handling,
2840 if (ydata_section
== 0)
2842 ydata_section
= subseg_new (".ydata", 0);
2843 bfd_set_section_flags (stdoutput
, ydata_section
,
2844 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2845 | SEC_READONLY
| SEC_DATA
));
2847 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
2851 ydata_section
= subseg_new (".ydata", 0);
2853 ppc_set_current_section(ydata_section
);
2856 /* pseudo-op: .reldata
2857 behaviour: predefined read write data section
2858 double word aligned (4-byte)
2859 FIXME: relocation is applied to it
2860 FIXME: what's the difference between this and .data?
2863 initial: .section .reldata "drw3"
2864 d - initialized data
2867 3 - double word aligned (that would be 8 byte boundary)
2870 Like .data, but intended to hold data subject to relocation, such as
2871 function descriptors, etc.
2877 if (reldata_section
== 0)
2879 reldata_section
= subseg_new (".reldata", 0);
2881 bfd_set_section_flags (stdoutput
, reldata_section
,
2882 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2885 bfd_set_section_alignment (stdoutput
, reldata_section
, 3);
2889 reldata_section
= subseg_new (".reldata", 0);
2891 ppc_set_current_section(reldata_section
);
2894 /* pseudo-op: .rdata
2895 behaviour: predefined read only data section
2899 initial: .section .rdata "dr3"
2900 d - initialized data
2902 3 - double word aligned (that would be 4 byte boundary)
2908 if (rdata_section
== 0)
2910 rdata_section
= subseg_new (".rdata", 0);
2911 bfd_set_section_flags (stdoutput
, rdata_section
,
2912 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2913 | SEC_READONLY
| SEC_DATA
));
2915 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
2919 rdata_section
= subseg_new (".rdata", 0);
2921 ppc_set_current_section(rdata_section
);
2924 /* pseudo-op: .ualong
2925 behaviour: much like .int, with the exception that no alignment is
2927 FIXME: test the alignment statement
2939 /* pseudo-op: .znop <symbol name>
2940 behaviour: Issue a nop instruction
2941 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2942 the supplied symbol name.
2944 warnings: Missing symbol name
2951 const struct powerpc_opcode
*opcode
;
2957 /* Strip out the symbol name */
2965 symbol_name
= input_line_pointer
;
2966 c
= get_symbol_end ();
2968 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
2969 strcpy (name
, symbol_name
);
2971 sym
= symbol_find_or_make (name
);
2973 *input_line_pointer
= c
;
2977 /* Look up the opcode in the hash table. */
2978 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
2980 /* stick in the nop */
2981 insn
= opcode
->opcode
;
2983 /* Write out the instruction. */
2985 md_number_to_chars (f
, insn
, 4);
2987 f
- frag_now
->fr_literal
,
2992 BFD_RELOC_16_GOT_PCREL
);
3005 register char *name
;
3009 register symbolS
*symbolP
;
3012 name
= input_line_pointer
;
3013 c
= get_symbol_end ();
3015 /* just after name is now '\0' */
3016 p
= input_line_pointer
;
3019 if (*input_line_pointer
!= ',')
3021 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3022 ignore_rest_of_line ();
3026 input_line_pointer
++; /* skip ',' */
3027 if ((temp
= get_absolute_expression ()) < 0)
3029 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
3030 ignore_rest_of_line ();
3036 /* The third argument to .comm is the alignment. */
3037 if (*input_line_pointer
!= ',')
3041 ++input_line_pointer
;
3042 align
= get_absolute_expression ();
3045 as_warn ("ignoring bad alignment");
3052 symbolP
= symbol_find_or_make (name
);
3055 if (S_IS_DEFINED (symbolP
))
3057 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3058 S_GET_NAME (symbolP
));
3059 ignore_rest_of_line ();
3063 if (S_GET_VALUE (symbolP
))
3065 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
3066 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3067 S_GET_NAME (symbolP
),
3068 (long) S_GET_VALUE (symbolP
),
3073 S_SET_VALUE (symbolP
, (valueT
) temp
);
3074 S_SET_EXTERNAL (symbolP
);
3077 demand_empty_rest_of_line ();
3081 * implement the .section pseudo op:
3082 * .section name {, "flags"}
3084 * | +--- optional flags: 'b' for bss
3086 * +-- section name 'l' for lib
3090 * 'd' (apparently m88k for data)
3092 * But if the argument is not a quoted string, treat it as a
3093 * subsegment number.
3095 * FIXME: this is a copy of the section processing from obj-coff.c, with
3096 * additions/changes for the moto-pas assembler support. There are three
3099 * FIXME: I just noticed this. This doesn't work at all really. It it
3100 * setting bits that bfd probably neither understands or uses. The
3101 * correct approach (?) will have to incorporate extra fields attached
3102 * to the section to hold the system specific stuff. (krk)
3105 * 'a' - unknown - referred to in documentation, but no definition supplied
3106 * 'c' - section has code
3107 * 'd' - section has initialized data
3108 * 'u' - section has uninitialized data
3109 * 'i' - section contains directives (info)
3110 * 'n' - section can be discarded
3111 * 'R' - remove section at link time
3113 * Section Protection:
3114 * 'r' - section is readable
3115 * 'w' - section is writeable
3116 * 'x' - section is executable
3117 * 's' - section is sharable
3119 * Section Alignment:
3120 * '0' - align to byte boundary
3121 * '1' - align to halfword undary
3122 * '2' - align to word boundary
3123 * '3' - align to doubleword boundary
3124 * '4' - align to quadword boundary
3125 * '5' - align to 32 byte boundary
3126 * '6' - align to 64 byte boundary
3131 ppc_pe_section (ignore
)
3134 /* Strip out the section name */
3143 align
= 4; /* default alignment to 16 byte boundary */
3145 section_name
= input_line_pointer
;
3146 c
= get_symbol_end ();
3148 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3149 strcpy (name
, section_name
);
3151 *input_line_pointer
= c
;
3156 flags
= SEC_NO_FLAGS
;
3158 if (*input_line_pointer
== ',')
3160 ++input_line_pointer
;
3162 if (*input_line_pointer
!= '"')
3163 exp
= get_absolute_expression ();
3166 ++input_line_pointer
;
3167 while (*input_line_pointer
!= '"'
3168 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3170 switch (*input_line_pointer
)
3172 /* Section Contents */
3173 case 'a': /* unknown */
3174 as_warn ("Unsupported section attribute -- 'a'");
3176 case 'c': /* code section */
3179 case 'd': /* section has initialized data */
3182 case 'u': /* section has uninitialized data */
3183 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3187 case 'i': /* section contains directives (info) */
3188 /* FIXME: This is IMAGE_SCN_LNK_INFO
3190 flags
|= SEC_HAS_CONTENTS
;
3192 case 'n': /* section can be discarded */
3195 case 'R': /* Remove section at link time */
3196 flags
|= SEC_NEVER_LOAD
;
3199 /* Section Protection */
3200 case 'r': /* section is readable */
3201 flags
|= IMAGE_SCN_MEM_READ
;
3203 case 'w': /* section is writeable */
3204 flags
|= IMAGE_SCN_MEM_WRITE
;
3206 case 'x': /* section is executable */
3207 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3209 case 's': /* section is sharable */
3210 flags
|= IMAGE_SCN_MEM_SHARED
;
3213 /* Section Alignment */
3214 case '0': /* align to byte boundary */
3215 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3218 case '1': /* align to halfword boundary */
3219 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3222 case '2': /* align to word boundary */
3223 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3226 case '3': /* align to doubleword boundary */
3227 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3230 case '4': /* align to quadword boundary */
3231 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3234 case '5': /* align to 32 byte boundary */
3235 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3238 case '6': /* align to 64 byte boundary */
3239 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3244 as_warn("unknown section attribute '%c'",
3245 *input_line_pointer
);
3248 ++input_line_pointer
;
3250 if (*input_line_pointer
== '"')
3251 ++input_line_pointer
;
3255 sec
= subseg_new (name
, (subsegT
) exp
);
3257 ppc_set_current_section(sec
);
3259 if (flags
!= SEC_NO_FLAGS
)
3261 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3262 as_warn ("error setting flags for \"%s\": %s",
3263 bfd_section_name (stdoutput
, sec
),
3264 bfd_errmsg (bfd_get_error ()));
3267 bfd_set_section_alignment(stdoutput
, sec
, align
);
3272 ppc_pe_function (ignore
)
3279 name
= input_line_pointer
;
3280 endc
= get_symbol_end ();
3282 ext_sym
= symbol_find_or_make (name
);
3284 *input_line_pointer
= endc
;
3286 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3287 SF_SET_FUNCTION (ext_sym
);
3288 SF_SET_PROCESS (ext_sym
);
3289 coff_add_linesym (ext_sym
);
3291 demand_empty_rest_of_line ();
3295 ppc_pe_tocd (ignore
)
3298 if (tocdata_section
== 0)
3300 tocdata_section
= subseg_new (".tocd", 0);
3301 /* FIXME: section flags won't work */
3302 bfd_set_section_flags (stdoutput
, tocdata_section
,
3303 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3304 | SEC_READONLY
| SEC_DATA
));
3306 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3310 rdata_section
= subseg_new (".tocd", 0);
3313 ppc_set_current_section(tocdata_section
);
3315 demand_empty_rest_of_line ();
3318 /* Don't adjust TOC relocs to use the section symbol. */
3321 ppc_pe_fix_adjustable (fix
)
3324 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3331 /* XCOFF specific symbol and file handling. */
3333 /* Canonicalize the symbol name. We use the to force the suffix, if
3334 any, to use square brackets, and to be in upper case. */
3337 ppc_canonicalize_symbol_name (name
)
3342 if (ppc_stab_symbol
)
3345 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3359 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3363 if (*s
== '\0' || s
[1] != '\0')
3364 as_bad ("bad symbol suffix");
3372 /* Set the class of a symbol based on the suffix, if any. This is
3373 called whenever a new symbol is created. */
3376 ppc_symbol_new_hook (sym
)
3381 sym
->sy_tc
.next
= NULL
;
3382 sym
->sy_tc
.output
= 0;
3383 sym
->sy_tc
.class = -1;
3384 sym
->sy_tc
.real_name
= NULL
;
3385 sym
->sy_tc
.subseg
= 0;
3386 sym
->sy_tc
.align
= 0;
3387 sym
->sy_tc
.size
= NULL
;
3388 sym
->sy_tc
.within
= NULL
;
3390 if (ppc_stab_symbol
)
3393 s
= strchr (S_GET_NAME (sym
), '[');
3394 if (s
== (const char *) NULL
)
3396 /* There is no suffix. */
3405 if (strcmp (s
, "BS]") == 0)
3406 sym
->sy_tc
.class = XMC_BS
;
3409 if (strcmp (s
, "DB]") == 0)
3410 sym
->sy_tc
.class = XMC_DB
;
3411 else if (strcmp (s
, "DS]") == 0)
3412 sym
->sy_tc
.class = XMC_DS
;
3415 if (strcmp (s
, "GL]") == 0)
3416 sym
->sy_tc
.class = XMC_GL
;
3419 if (strcmp (s
, "PR]") == 0)
3420 sym
->sy_tc
.class = XMC_PR
;
3423 if (strcmp (s
, "RO]") == 0)
3424 sym
->sy_tc
.class = XMC_RO
;
3425 else if (strcmp (s
, "RW]") == 0)
3426 sym
->sy_tc
.class = XMC_RW
;
3429 if (strcmp (s
, "SV]") == 0)
3430 sym
->sy_tc
.class = XMC_SV
;
3433 if (strcmp (s
, "TC]") == 0)
3434 sym
->sy_tc
.class = XMC_TC
;
3435 else if (strcmp (s
, "TI]") == 0)
3436 sym
->sy_tc
.class = XMC_TI
;
3437 else if (strcmp (s
, "TB]") == 0)
3438 sym
->sy_tc
.class = XMC_TB
;
3439 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3440 sym
->sy_tc
.class = XMC_TC0
;
3443 if (strcmp (s
, "UA]") == 0)
3444 sym
->sy_tc
.class = XMC_UA
;
3445 else if (strcmp (s
, "UC]") == 0)
3446 sym
->sy_tc
.class = XMC_UC
;
3449 if (strcmp (s
, "XO]") == 0)
3450 sym
->sy_tc
.class = XMC_XO
;
3454 if (sym
->sy_tc
.class == -1)
3455 as_bad ("Unrecognized symbol suffix");
3458 /* Set the class of a label based on where it is defined. This
3459 handles symbols without suffixes. Also, move the symbol so that it
3460 follows the csect symbol. */
3463 ppc_frob_label (sym
)
3466 if (ppc_current_csect
!= (symbolS
*) NULL
)
3468 if (sym
->sy_tc
.class == -1)
3469 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3471 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3472 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3474 ppc_current_csect
->sy_tc
.within
= sym
;
3478 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3479 seen. It tells ppc_adjust_symtab whether it needs to look through
3482 static boolean ppc_saw_abs
;
3484 /* Change the name of a symbol just before writing it out. Set the
3485 real name if the .rename pseudo-op was used. Otherwise, remove any
3486 class suffix. Return 1 if the symbol should not be included in the
3490 ppc_frob_symbol (sym
)
3493 static symbolS
*ppc_last_function
;
3494 static symbolS
*set_end
;
3496 /* Discard symbols that should not be included in the output symbol
3498 if (! sym
->sy_used_in_reloc
3499 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3500 || (! S_IS_EXTERNAL (sym
)
3501 && ! sym
->sy_tc
.output
3502 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3505 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3506 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3512 name
= S_GET_NAME (sym
);
3513 s
= strchr (name
, '[');
3514 if (s
!= (char *) NULL
)
3520 snew
= xmalloc (len
+ 1);
3521 memcpy (snew
, name
, len
);
3524 S_SET_NAME (sym
, snew
);
3528 if (set_end
!= (symbolS
*) NULL
)
3530 SA_SET_SYM_ENDNDX (set_end
, sym
);
3534 if (SF_GET_FUNCTION (sym
))
3536 if (ppc_last_function
!= (symbolS
*) NULL
)
3537 as_warn ("two .function pseudo-ops with no intervening .ef");
3538 ppc_last_function
= sym
;
3539 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3541 resolve_symbol_value (sym
->sy_tc
.size
);
3542 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3545 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3546 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3548 if (ppc_last_function
== (symbolS
*) NULL
)
3549 as_warn (".ef with no preceding .function");
3552 set_end
= ppc_last_function
;
3553 ppc_last_function
= NULL
;
3555 /* We don't have a C_EFCN symbol, but we need to force the
3556 COFF backend to believe that it has seen one. */
3557 coff_last_function
= NULL
;
3561 if (! S_IS_EXTERNAL (sym
)
3562 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3563 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3564 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3565 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
3566 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3567 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3568 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
3569 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
3570 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3571 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3573 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
3574 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3577 union internal_auxent
*a
;
3579 /* Create a csect aux. */
3580 i
= S_GET_NUMBER_AUXILIARY (sym
);
3581 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3582 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3583 if (sym
->sy_tc
.class == XMC_TC0
)
3585 /* This is the TOC table. */
3586 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3587 a
->x_csect
.x_scnlen
.l
= 0;
3588 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3590 else if (sym
->sy_tc
.subseg
!= 0)
3592 /* This is a csect symbol. x_scnlen is the size of the
3594 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3595 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3596 S_GET_SEGMENT (sym
))
3597 - S_GET_VALUE (sym
));
3600 resolve_symbol_value (sym
->sy_tc
.next
);
3601 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3602 - S_GET_VALUE (sym
));
3604 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3606 else if (S_GET_SEGMENT (sym
) == bss_section
)
3608 /* This is a common symbol. */
3609 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3610 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3611 if (S_IS_EXTERNAL (sym
))
3612 sym
->sy_tc
.class = XMC_RW
;
3614 sym
->sy_tc
.class = XMC_BS
;
3616 else if (S_GET_SEGMENT (sym
) == absolute_section
)
3618 /* This is an absolute symbol. The csect will be created by
3619 ppc_adjust_symtab. */
3621 a
->x_csect
.x_smtyp
= XTY_LD
;
3622 if (sym
->sy_tc
.class == -1)
3623 sym
->sy_tc
.class = XMC_XO
;
3625 else if (! S_IS_DEFINED (sym
))
3627 /* This is an external symbol. */
3628 a
->x_csect
.x_scnlen
.l
= 0;
3629 a
->x_csect
.x_smtyp
= XTY_ER
;
3631 else if (sym
->sy_tc
.class == XMC_TC
)
3635 /* This is a TOC definition. x_scnlen is the size of the
3637 next
= symbol_next (sym
);
3638 while (next
->sy_tc
.class == XMC_TC0
)
3639 next
= symbol_next (next
);
3640 if (next
== (symbolS
*) NULL
3641 || next
->sy_tc
.class != XMC_TC
)
3643 if (ppc_after_toc_frag
== (fragS
*) NULL
)
3644 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3646 - S_GET_VALUE (sym
));
3648 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
3649 - S_GET_VALUE (sym
));
3653 resolve_symbol_value (next
);
3654 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
3655 - S_GET_VALUE (sym
));
3657 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3663 /* This is a normal symbol definition. x_scnlen is the
3664 symbol index of the containing csect. */
3665 if (S_GET_SEGMENT (sym
) == text_section
)
3666 csect
= ppc_text_csects
;
3667 else if (S_GET_SEGMENT (sym
) == data_section
)
3668 csect
= ppc_data_csects
;
3672 /* Skip the initial dummy symbol. */
3673 csect
= csect
->sy_tc
.next
;
3675 if (csect
== (symbolS
*) NULL
)
3677 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym
));
3678 a
->x_csect
.x_scnlen
.l
= 0;
3682 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
3684 resolve_symbol_value (csect
->sy_tc
.next
);
3685 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
3687 csect
= csect
->sy_tc
.next
;
3690 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3691 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
3693 a
->x_csect
.x_smtyp
= XTY_LD
;
3696 a
->x_csect
.x_parmhash
= 0;
3697 a
->x_csect
.x_snhash
= 0;
3698 if (sym
->sy_tc
.class == -1)
3699 a
->x_csect
.x_smclas
= XMC_PR
;
3701 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
3702 a
->x_csect
.x_stab
= 0;
3703 a
->x_csect
.x_snstab
= 0;
3705 /* Don't let the COFF backend resort these symbols. */
3706 sym
->bsym
->flags
|= BSF_NOT_AT_END
;
3708 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
3710 /* We want the value to be the symbol index of the referenced
3711 csect symbol. BFD will do that for us if we set the right
3714 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
3715 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
3717 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
3722 /* The value is the offset from the enclosing csect. */
3723 block
= sym
->sy_tc
.within
;
3724 csect
= block
->sy_tc
.within
;
3725 resolve_symbol_value (csect
);
3726 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
3728 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
3729 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
3731 /* We want the value to be a file offset into the line numbers.
3732 BFD will do that for us if we set the right flags. We have
3733 already set the value correctly. */
3734 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
3740 /* Adjust the symbol table. This creates csect symbols for all
3741 absolute symbols. */
3744 ppc_adjust_symtab ()
3751 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
3755 union internal_auxent
*a
;
3757 if (S_GET_SEGMENT (sym
) != absolute_section
)
3760 csect
= symbol_create (".abs[XO]", absolute_section
,
3761 S_GET_VALUE (sym
), &zero_address_frag
);
3762 csect
->bsym
->value
= S_GET_VALUE (sym
);
3763 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
3764 i
= S_GET_NUMBER_AUXILIARY (csect
);
3765 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
3766 a
= &coffsymbol (csect
->bsym
)->native
[i
+ 1].u
.auxent
;
3767 a
->x_csect
.x_scnlen
.l
= 0;
3768 a
->x_csect
.x_smtyp
= XTY_SD
;
3769 a
->x_csect
.x_parmhash
= 0;
3770 a
->x_csect
.x_snhash
= 0;
3771 a
->x_csect
.x_smclas
= XMC_XO
;
3772 a
->x_csect
.x_stab
= 0;
3773 a
->x_csect
.x_snstab
= 0;
3775 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
3777 i
= S_GET_NUMBER_AUXILIARY (sym
);
3778 a
= &coffsymbol (sym
->bsym
)->native
[i
].u
.auxent
;
3779 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3780 coffsymbol (sym
->bsym
)->native
[i
].fix_scnlen
= 1;
3783 ppc_saw_abs
= false;
3786 /* Set the VMA for a section. This is called on all the sections in
3790 ppc_frob_section (sec
)
3793 static bfd_size_type vma
= 0;
3795 bfd_set_section_vma (stdoutput
, sec
, vma
);
3796 vma
+= bfd_section_size (stdoutput
, sec
);
3799 /* Adjust the file by adding a .debug section if needed. */
3804 if (ppc_debug_name_section_size
> 0)
3808 sec
= bfd_make_section (stdoutput
, ".debug");
3809 if (sec
== (asection
*) NULL
3810 || ! bfd_set_section_size (stdoutput
, sec
,
3811 ppc_debug_name_section_size
)
3812 || ! bfd_set_section_flags (stdoutput
, sec
,
3813 SEC_HAS_CONTENTS
| SEC_LOAD
))
3814 as_fatal ("can't make .debug section");
3818 #endif /* OBJ_XCOFF */
3820 /* Turn a string in input_line_pointer into a floating point constant
3821 of type type, and store the appropriate bytes in *litp. The number
3822 of LITTLENUMS emitted is stored in *sizep . An error message is
3823 returned, or NULL on OK. */
3826 md_atof (type
, litp
, sizep
)
3832 LITTLENUM_TYPE words
[4];
3848 return "bad call to md_atof";
3851 t
= atof_ieee (input_line_pointer
, type
, words
);
3853 input_line_pointer
= t
;
3857 if (target_big_endian
)
3859 for (i
= 0; i
< prec
; i
++)
3861 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3867 for (i
= prec
- 1; i
>= 0; i
--)
3869 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3877 /* Write a value out to the object file, using the appropriate
3881 md_number_to_chars (buf
, val
, n
)
3886 if (target_big_endian
)
3887 number_to_chars_bigendian (buf
, val
, n
);
3889 number_to_chars_littleendian (buf
, val
, n
);
3892 /* Align a section (I don't know why this is machine dependent). */
3895 md_section_align (seg
, addr
)
3899 int align
= bfd_get_section_alignment (stdoutput
, seg
);
3901 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
3904 /* We don't have any form of relaxing. */
3907 md_estimate_size_before_relax (fragp
, seg
)
3915 /* Convert a machine dependent frag. We never generate these. */
3918 md_convert_frag (abfd
, sec
, fragp
)
3926 /* We have no need to default values of symbols. */
3930 md_undefined_symbol (name
)
3936 /* Functions concerning relocs. */
3938 /* The location from which a PC relative jump should be calculated,
3939 given a PC relative reloc. */
3942 md_pcrel_from_section (fixp
, sec
)
3947 if (fixp
->fx_addsy
!= (symbolS
*) NULL
3948 && (! S_IS_DEFINED (fixp
->fx_addsy
)
3949 || TC_FORCE_RELOCATION_SECTION (fixp
, sec
)))
3953 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3958 /* This is called to see whether a fixup should be adjusted to use a
3959 section symbol. We take the opportunity to change a fixup against
3960 a symbol in the TOC subsegment into a reloc against the
3961 corresponding .tc symbol. */
3964 ppc_fix_adjustable (fix
)
3969 resolve_symbol_value (fix
->fx_addsy
);
3970 val
= S_GET_VALUE (fix
->fx_addsy
);
3971 if (ppc_toc_csect
!= (symbolS
*) NULL
3972 && fix
->fx_addsy
!= (symbolS
*) NULL
3973 && fix
->fx_addsy
!= ppc_toc_csect
3974 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
3975 && val
>= ppc_toc_frag
->fr_address
3976 && (ppc_after_toc_frag
== (fragS
*) NULL
3977 || val
< ppc_after_toc_frag
->fr_address
))
3981 for (sy
= symbol_next (ppc_toc_csect
);
3982 sy
!= (symbolS
*) NULL
;
3983 sy
= symbol_next (sy
))
3985 if (sy
->sy_tc
.class == XMC_TC0
)
3987 if (sy
->sy_tc
.class != XMC_TC
)
3989 resolve_symbol_value (sy
);
3990 if (val
== S_GET_VALUE (sy
))
3993 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
3998 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3999 "symbol in .toc does not match any .tc");
4002 /* Possibly adjust the reloc to be against the csect. */
4003 if (fix
->fx_addsy
!= (symbolS
*) NULL
4004 && fix
->fx_addsy
->sy_tc
.subseg
== 0
4005 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
4006 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
4007 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
4011 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
4012 csect
= ppc_text_csects
;
4013 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
4014 csect
= ppc_data_csects
;
4018 /* Skip the initial dummy symbol. */
4019 csect
= csect
->sy_tc
.next
;
4021 if (csect
!= (symbolS
*) NULL
)
4023 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
4024 && (csect
->sy_tc
.next
->sy_frag
->fr_address
4025 <= fix
->fx_addsy
->sy_frag
->fr_address
))
4026 csect
= csect
->sy_tc
.next
;
4028 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4029 - csect
->sy_frag
->fr_address
);
4030 fix
->fx_addsy
= csect
;
4034 /* Adjust a reloc against a .lcomm symbol to be against the base
4036 if (fix
->fx_addsy
!= (symbolS
*) NULL
4037 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
4038 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
4040 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
4041 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
4042 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
4043 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
4051 /* See whether a symbol is in the TOC section. */
4054 ppc_is_toc_sym (sym
)
4058 return sym
->sy_tc
.class == XMC_TC
;
4060 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
4064 /* Apply a fixup to the object code. This is called for all the
4065 fixups we generated by the call to fix_new_exp, above. In the call
4066 above we used a reloc code which was the largest legal reloc code
4067 plus the operand index. Here we undo that to recover the operand
4068 index. At this point all symbol values should be fully resolved,
4069 and we attempt to completely resolve the reloc. If we can not do
4070 that, we determine the correct reloc code and put it back in the
4074 md_apply_fix3 (fixp
, valuep
, seg
)
4081 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4082 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4083 doing this relocation the code in write.c is going to call
4084 bfd_perform_relocation, which is also going to use the symbol
4085 value. That means that if the reloc is fully resolved we want to
4086 use *valuep since bfd_perform_relocation is not being used.
4087 However, if the reloc is not fully resolved we do not want to use
4088 *valuep, and must use fx_offset instead. However, if the reloc
4089 is PC relative, we do want to use *valuep since it includes the
4090 result of md_pcrel_from. This is confusing. */
4092 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
4097 else if (fixp
->fx_pcrel
)
4101 value
= fixp
->fx_offset
;
4102 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
4104 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
4105 value
-= S_GET_VALUE (fixp
->fx_subsy
);
4108 /* We can't actually support subtracting a symbol. */
4109 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4110 "expression too complex");
4115 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
4118 const struct powerpc_operand
*operand
;
4122 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
4124 operand
= &powerpc_operands
[opindex
];
4127 /* It appears that an instruction like
4129 when LC..1 is not a TOC symbol does not generate a reloc. It
4130 uses the offset of LC..1 within its csect. However, .long
4131 LC..1 will generate a reloc. I can't find any documentation
4132 on how these cases are to be distinguished, so this is a wild
4133 guess. These cases are generated by gcc -mminimal-toc. */
4134 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4135 && operand
->bits
== 16
4136 && operand
->shift
== 0
4137 && operand
->insert
== NULL
4138 && fixp
->fx_addsy
!= NULL
4139 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
4140 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
4141 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
4142 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
4144 value
= fixp
->fx_offset
;
4149 /* Fetch the instruction, insert the fully resolved operand
4150 value, and stuff the instruction back again. */
4151 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
4152 if (target_big_endian
)
4153 insn
= bfd_getb32 ((unsigned char *) where
);
4155 insn
= bfd_getl32 ((unsigned char *) where
);
4156 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
4157 fixp
->fx_file
, fixp
->fx_line
);
4158 if (target_big_endian
)
4159 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
4161 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
4165 /* Nothing else to do here. */
4169 /* Determine a BFD reloc value based on the operand information.
4170 We are only prepared to turn a few of the operands into
4172 FIXME: We need to handle the DS field at the very least.
4173 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4174 there should be a new field in the operand table. */
4175 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4176 && operand
->bits
== 26
4177 && operand
->shift
== 0)
4178 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
4179 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
4180 && operand
->bits
== 16
4181 && operand
->shift
== 0)
4182 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
4183 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4184 && operand
->bits
== 26
4185 && operand
->shift
== 0)
4186 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4187 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4188 && operand
->bits
== 16
4189 && operand
->shift
== 0)
4190 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4191 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4192 && operand
->bits
== 16
4193 && operand
->shift
== 0
4194 && operand
->insert
== NULL
4195 && fixp
->fx_addsy
!= NULL
4196 && ppc_is_toc_sym (fixp
->fx_addsy
))
4199 if (target_big_endian
)
4200 fixp
->fx_where
+= 2;
4201 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4205 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4206 "unresolved expression that must be resolved");
4214 ppc_elf_validate_fix (fixp
, seg
);
4216 switch (fixp
->fx_r_type
)
4219 case BFD_RELOC_CTOR
:
4222 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4223 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4224 } /* fall through */
4226 case BFD_RELOC_32_PCREL
:
4227 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4231 case BFD_RELOC_LO16
:
4232 case BFD_RELOC_HI16
:
4233 case BFD_RELOC_HI16_S
:
4234 case BFD_RELOC_PPC_TOC16
:
4236 case BFD_RELOC_GPREL16
:
4237 case BFD_RELOC_16_GOT_PCREL
:
4241 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4249 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4259 fixp
->fx_addnumber
= value
;
4261 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4262 fixp
->fx_addnumber
= 0;
4266 fixp
->fx_addnumber
= 0;
4268 /* We want to use the offset within the data segment of the
4269 symbol, not the actual VMA of the symbol. */
4270 fixp
->fx_addnumber
=
4271 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4279 /* Generate a reloc for a fixup. */
4282 tc_gen_reloc (seg
, fixp
)
4288 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4290 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4291 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4292 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4293 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4295 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4296 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4299 reloc
->addend
= fixp
->fx_addnumber
;