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_bf
PARAMS ((int));
57 static void ppc_biei
PARAMS ((int));
58 static void ppc_bs
PARAMS ((int));
59 static void ppc_eb
PARAMS ((int));
60 static void ppc_ef
PARAMS ((int));
61 static void ppc_es
PARAMS ((int));
62 static void ppc_csect
PARAMS ((int));
63 static void ppc_function
PARAMS ((int));
64 static void ppc_extern
PARAMS ((int));
65 static void ppc_lglobl
PARAMS ((int));
66 static void ppc_stabx
PARAMS ((int));
67 static void ppc_rename
PARAMS ((int));
68 static void ppc_toc
PARAMS ((int));
72 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
73 static void ppc_elf_cons
PARAMS ((int));
74 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
78 static void ppc_set_current_section
PARAMS ((segT
));
79 static void ppc_previous
PARAMS ((int));
80 static void ppc_pdata
PARAMS ((int));
81 static void ppc_ydata
PARAMS ((int));
82 static void ppc_reldata
PARAMS ((int));
83 static void ppc_rdata
PARAMS ((int));
84 static void ppc_ualong
PARAMS ((int));
85 static void ppc_znop
PARAMS ((int));
86 static void ppc_pe_comm
PARAMS ((int));
87 static void ppc_pe_section
PARAMS ((int));
88 static void ppc_pe_function
PARAMS ((int));
89 static void ppc_pe_tocd
PARAMS ((int));
92 /* Generic assembler global variables which must be defined by all
95 /* Characters which always start a comment. */
96 const char comment_chars
[] = "#";
98 /* Characters which start a comment at the beginning of a line. */
99 const char line_comment_chars
[] = "#";
101 /* Characters which may be used to separate multiple commands on a
103 const char line_separator_chars
[] = ";";
105 /* Characters which are used to indicate an exponent in a floating
107 const char EXP_CHARS
[] = "eE";
109 /* Characters which mean that a number is a floating point constant,
111 const char FLT_CHARS
[] = "dD";
113 /* The target specific pseudo-ops which we support. */
115 const pseudo_typeS md_pseudo_table
[] =
117 /* Pseudo-ops which must be overridden. */
118 { "byte", ppc_byte
, 0 },
121 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
122 legitimately belong in the obj-*.c file. However, XCOFF is based
123 on COFF, and is only implemented for the RS/6000. We just use
124 obj-coff.c, and add what we need here. */
125 { "comm", ppc_comm
, 0 },
126 { "lcomm", ppc_comm
, 1 },
129 { "bi", ppc_biei
, 0 },
131 { "csect", ppc_csect
, 0 },
134 { "ei", ppc_biei
, 1 },
136 { "extern", ppc_extern
, 0 },
137 { "function", ppc_function
, 0 },
138 { "lglobl", ppc_lglobl
, 0 },
139 { "rename", ppc_rename
, 0 },
140 { "stabx", ppc_stabx
, 0 },
141 { "toc", ppc_toc
, 0 },
145 { "long", ppc_elf_cons
, 4 },
146 { "word", ppc_elf_cons
, 2 },
147 { "short", ppc_elf_cons
, 2 },
151 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
152 { "previous", ppc_previous
, 0 },
153 { "pdata", ppc_pdata
, 0 },
154 { "ydata", ppc_ydata
, 0 },
155 { "reldata", ppc_reldata
, 0 },
156 { "rdata", ppc_rdata
, 0 },
157 { "ualong", ppc_ualong
, 0 },
158 { "znop", ppc_znop
, 0 },
159 { "comm", ppc_pe_comm
, 0 },
160 { "lcomm", ppc_pe_comm
, 1 },
161 { "section", ppc_pe_section
, 0 },
162 { "function", ppc_pe_function
,0 },
163 { "tocd", ppc_pe_tocd
, 0 },
166 /* This pseudo-op is used even when not generating XCOFF output. */
174 /* The Windows NT PowerPC assembler uses predefined names. */
176 /* In general, there are lots of them, in an attempt to be compatible */
177 /* with a number of other Windows NT assemblers. */
179 /* Structure to hold information about predefined registers. */
186 /* List of registers that are pre-defined:
188 Each general register has predefined names of the form:
189 1. r<reg_num> which has the value <reg_num>.
190 2. r.<reg_num> which has the value <reg_num>.
193 Each floating point register has predefined names of the form:
194 1. f<reg_num> which has the value <reg_num>.
195 2. f.<reg_num> which has the value <reg_num>.
197 Each condition register has predefined names of the form:
198 1. cr<reg_num> which has the value <reg_num>.
199 2. cr.<reg_num> which has the value <reg_num>.
201 There are individual registers as well:
202 sp or r.sp has the value 1
203 rtoc or r.toc has the value 2
204 fpscr has the value 0
210 dsisr has the value 18
212 sdr1 has the value 25
213 srr0 has the value 26
214 srr1 has the value 27
216 The table is sorted. Suitable for searching by a binary search. */
218 static const struct pd_reg pre_defined_registers
[] =
220 { "cr.0", 0 }, /* Condition Registers */
240 { "dar", 19 }, /* Data Access Register */
241 { "dec", 22 }, /* Decrementer */
242 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
244 { "f.0", 0 }, /* Floating point registers */
312 { "lr", 8 }, /* Link Register */
316 { "r.0", 0 }, /* General Purpose Registers */
349 { "r.sp", 1 }, /* Stack Pointer */
351 { "r.toc", 2 }, /* Pointer to the table of contents */
353 { "r0", 0 }, /* More general purpose registers */
386 { "rtoc", 2 }, /* Table of contents */
388 { "sdr1", 25 }, /* Storage Description Register 1 */
392 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
393 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
399 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
401 /* Given NAME, find the register number associated with that name, return
402 the integer value associated with the given name or -1 on failure. */
404 static int reg_name_search
PARAMS ( (char * name
) );
407 reg_name_search (name
)
410 int middle
, low
, high
;
414 high
= REG_NAME_CNT
- 1;
418 middle
= (low
+ high
) / 2;
419 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
425 return pre_defined_registers
[middle
].value
;
435 /* Local variables. */
437 /* The type of processor we are assembling for. This is one or more
438 of the PPC_OPCODE flags defined in opcode/ppc.h. */
439 static int ppc_cpu
= 0;
441 /* The size of the processor we are assembling for. This is either
442 PPC_OPCODE_32 or PPC_OPCODE_64. */
443 static int ppc_size
= PPC_OPCODE_32
;
445 /* Opcode hash table. */
446 static struct hash_control
*ppc_hash
;
448 /* Macro hash table. */
449 static struct hash_control
*ppc_macro_hash
;
452 /* Whether to warn about non PC relative relocations that aren't
453 in the .got2 section. */
454 static boolean mrelocatable
= false;
456 /* Flags to set in the elf header */
457 static flagword ppc_flags
= 0;
462 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
463 using a bunch of different sections. These assembler sections,
464 however, are all encompassed within the .text or .data sections of
465 the final output file. We handle this by using different
466 subsegments within these main segments. */
468 /* Next subsegment to allocate within the .text segment. */
469 static subsegT ppc_text_subsegment
= 2;
471 /* Linked list of csects in the text section. */
472 static symbolS
*ppc_text_csects
;
474 /* Next subsegment to allocate within the .data segment. */
475 static subsegT ppc_data_subsegment
= 2;
477 /* Linked list of csects in the data section. */
478 static symbolS
*ppc_data_csects
;
480 /* The current csect. */
481 static symbolS
*ppc_current_csect
;
483 /* The RS/6000 assembler uses a TOC which holds addresses of functions
484 and variables. Symbols are put in the TOC with the .tc pseudo-op.
485 A special relocation is used when accessing TOC entries. We handle
486 the TOC as a subsegment within the .data segment. We set it up if
487 we see a .toc pseudo-op, and save the csect symbol here. */
488 static symbolS
*ppc_toc_csect
;
490 /* The first frag in the TOC subsegment. */
491 static fragS
*ppc_toc_frag
;
493 /* The first frag in the first subsegment after the TOC in the .data
494 segment. NULL if there are no subsegments after the TOC. */
495 static fragS
*ppc_after_toc_frag
;
497 /* The current static block. */
498 static symbolS
*ppc_current_block
;
500 /* The COFF debugging section; set by md_begin. This is not the
501 .debug section, but is instead the secret BFD section which will
502 cause BFD to set the section number of a symbol to N_DEBUG. */
503 static asection
*ppc_coff_debug_section
;
505 /* The size of the .debug section. */
506 static bfd_size_type ppc_debug_name_section_size
;
508 #endif /* OBJ_XCOFF */
512 /* Various sections that we need for PE coff support. */
513 static segT ydata_section
;
514 static segT pdata_section
;
515 static segT reldata_section
;
516 static segT rdata_section
;
517 static segT tocdata_section
;
519 /* The current section and the previous section. See ppc_previous. */
520 static segT ppc_previous_section
;
521 static segT ppc_current_section
;
526 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
529 #ifndef WORKING_DOT_WORD
530 const int md_short_jump_size
= 4;
531 const int md_long_jump_size
= 4;
535 CONST
char *md_shortopts
= "um:VQ:";
537 CONST
char *md_shortopts
= "um:";
539 struct option md_longopts
[] = {
540 {NULL
, no_argument
, NULL
, 0}
542 size_t md_longopts_size
= sizeof(md_longopts
);
545 md_parse_option (c
, arg
)
552 /* -u means that any undefined symbols should be treated as
553 external, which is the default for gas anyhow. */
557 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
559 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
560 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
561 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
562 else if (strcmp (arg
, "pwr") == 0)
563 ppc_cpu
= PPC_OPCODE_POWER
;
564 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
565 instructions that are holdovers from the Power. */
566 else if (strcmp (arg
, "601") == 0)
567 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
568 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
569 Motorola PowerPC 603/604. */
570 else if (strcmp (arg
, "ppc") == 0
571 || strcmp (arg
, "ppc32") == 0
572 || strcmp (arg
, "403") == 0
573 || strcmp (arg
, "603") == 0
574 || strcmp (arg
, "604") == 0)
575 ppc_cpu
= PPC_OPCODE_PPC
;
576 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
578 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
580 ppc_cpu
= PPC_OPCODE_PPC
;
581 ppc_size
= PPC_OPCODE_64
;
583 /* -mcom means assemble for the common intersection between Power
584 and PowerPC. At present, we just allow the union, rather
585 than the intersection. */
586 else if (strcmp (arg
, "com") == 0)
587 ppc_cpu
= PPC_OPCODE_COMMON
;
588 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
589 else if (strcmp (arg
, "any") == 0)
590 ppc_cpu
= PPC_OPCODE_ANY
;
593 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
594 else if (strcmp (arg
, "relocatable") == 0)
597 ppc_flags
|= EF_PPC_RELOCATABLE
;
600 else if (strcmp (arg
, "relocatable-lib") == 0)
603 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
606 /* -memb, set embedded bit */
607 else if (strcmp (arg
, "emb") == 0)
608 ppc_flags
|= EF_PPC_EMB
;
610 /* -mlittle/-mbig set the endianess */
611 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
613 target_big_endian
= 0;
614 set_target_endian
= 1;
617 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
619 target_big_endian
= 1;
620 set_target_endian
= 1;
625 as_bad ("invalid switch -m%s", arg
);
631 /* -V: SVR4 argument to print version ID. */
636 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
637 should be emitted or not. FIXME: Not implemented. */
650 md_show_usage (stream
)
656 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
657 -mpwr generate code for IBM POWER (RIOS1)\n\
658 -m601 generate code for Motorola PowerPC 601\n\
659 -mppc, -mppc32, -m403, -m603, -m604\n\
660 generate code for Motorola PowerPC 603/604\n\
661 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
662 -mcom generate code Power/PowerPC common instructions\n
663 -many generate code for any architecture (PWR/PWRX/PPC)\n");
666 -mrelocatable support for GCC's -mrelocatble option\n\
667 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
668 -memb set PPC_EMB bit in ELF flags\n\
669 -mlittle, -mlittle-endian\n\
670 generate code for a little endian machine\n\
671 -mbig, -mbig-endian generate code for a big endian machine\n\
672 -V print assembler version number\n\
673 -Qy, -Qn ignored\n");
677 /* Set ppc_cpu if it is not already set. */
682 const char *default_cpu
= TARGET_CPU
;
686 if (strcmp (default_cpu
, "rs6000") == 0)
687 ppc_cpu
= PPC_OPCODE_POWER
;
688 else if (strcmp (default_cpu
, "powerpc") == 0
689 || strcmp (default_cpu
, "powerpcle") == 0)
690 ppc_cpu
= PPC_OPCODE_PPC
;
692 as_fatal ("Unknown default cpu = %s", default_cpu
);
696 /* Figure out the BFD architecture to use. */
698 enum bfd_architecture
701 const char *default_cpu
= TARGET_CPU
;
704 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
705 return bfd_arch_powerpc
;
706 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
707 return bfd_arch_rs6000
;
708 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
710 if (strcmp (default_cpu
, "rs6000") == 0)
711 return bfd_arch_rs6000
;
712 else if (strcmp (default_cpu
, "powerpc") == 0
713 || strcmp (default_cpu
, "powerpcle") == 0)
714 return bfd_arch_powerpc
;
717 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
718 return bfd_arch_unknown
;
721 /* This function is called when the assembler starts up. It is called
722 after the options have been parsed and the output file has been
728 register const struct powerpc_opcode
*op
;
729 const struct powerpc_opcode
*op_end
;
730 const struct powerpc_macro
*macro
;
731 const struct powerpc_macro
*macro_end
;
732 boolean dup_insn
= false;
737 /* Set the ELF flags if desired. */
739 bfd_set_private_flags (stdoutput
, ppc_flags
);
742 /* Insert the opcodes into a hash table. */
743 ppc_hash
= hash_new ();
745 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
746 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
748 know ((op
->opcode
& op
->mask
) == op
->opcode
);
750 if ((op
->flags
& ppc_cpu
) != 0
751 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
752 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
756 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
757 if (retval
!= (const char *) NULL
)
759 /* Ignore Power duplicates for -m601 */
760 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
761 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
764 as_bad ("Internal assembler error for instruction %s", op
->name
);
770 /* Insert the macros into a hash table. */
771 ppc_macro_hash
= hash_new ();
773 macro_end
= powerpc_macros
+ powerpc_num_macros
;
774 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
776 if ((macro
->flags
& ppc_cpu
) != 0)
780 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
781 if (retval
!= (const char *) NULL
)
783 as_bad ("Internal assembler error for macro %s", macro
->name
);
792 /* Tell the main code what the endianness is if it is not overidden by the user. */
793 if (!set_target_endian
)
795 set_target_endian
= 1;
796 target_big_endian
= PPC_BIG_ENDIAN
;
800 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
802 /* Create dummy symbols to serve as initial csects. This forces the
803 text csects to precede the data csects. These symbols will not
805 ppc_text_csects
= symbol_make ("dummy\001");
806 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
807 ppc_data_csects
= symbol_make ("dummy\001");
808 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
813 ppc_current_section
= text_section
;
814 ppc_previous_section
= 0;
819 /* Insert an operand value into an instruction. */
822 ppc_insert_operand (insn
, operand
, val
, file
, line
)
824 const struct powerpc_operand
*operand
;
829 if (operand
->bits
!= 32)
834 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
836 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
837 && ppc_size
== PPC_OPCODE_32
)
838 max
= (1 << operand
->bits
) - 1;
840 max
= (1 << (operand
->bits
- 1)) - 1;
841 min
= - (1 << (operand
->bits
- 1));
845 max
= (1 << operand
->bits
) - 1;
849 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
854 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
857 "operand out of range (%s not between %ld and %ld)";
860 sprint_value (buf
, test
);
861 if (file
== (char *) NULL
)
862 as_warn (err
, buf
, min
, max
);
864 as_warn_where (file
, line
, err
, buf
, min
, max
);
873 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
874 if (errmsg
!= (const char *) NULL
)
878 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
885 /* Parse @got, etc. and return the desired relocation. */
886 static bfd_reloc_code_real_type
887 ppc_elf_suffix (str_p
)
893 bfd_reloc_code_real_type reloc
;
903 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
905 static struct map_bfd mapping
[] = {
906 MAP ("got", BFD_RELOC_PPC_TOC16
),
907 MAP ("l", BFD_RELOC_LO16
),
908 MAP ("h", BFD_RELOC_HI16
),
909 MAP ("ha", BFD_RELOC_HI16_S
),
910 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
911 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
912 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
913 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
914 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
915 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
916 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
917 MAP ("copy", BFD_RELOC_PPC_COPY
),
918 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
919 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
920 MAP ("plt", BFD_RELOC_32_PLTOFF
),
921 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
922 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
923 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
924 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
925 MAP ("sdarel", BFD_RELOC_GPREL16
),
926 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
927 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
928 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
929 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
931 { (char *)0, 0, BFD_RELOC_UNUSED
}
935 return BFD_RELOC_UNUSED
;
937 for (ch
= *str
, str2
= ident
;
938 str2
< ident
+ sizeof(ident
) - 1 && isalnum (ch
) || ch
== '@';
941 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
948 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
949 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
955 return BFD_RELOC_UNUSED
;
958 /* Like normal .long/.short/.word, except support @got, etc. */
959 /* clobbers input_line_pointer, checks */
962 ppc_elf_cons (nbytes
)
963 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
966 bfd_reloc_code_real_type reloc
;
968 if (is_it_end_of_statement ())
970 demand_empty_rest_of_line ();
977 if (exp
.X_op
== O_symbol
978 && *input_line_pointer
== '@'
979 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
981 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
982 int size
= bfd_get_reloc_size (reloc_howto
);
985 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
989 register char *p
= frag_more ((int) nbytes
);
990 int offset
= nbytes
- size
;
992 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
996 emit_expr (&exp
, (unsigned int) nbytes
);
998 while (*input_line_pointer
++ == ',');
1000 input_line_pointer
--; /* Put terminator back into stream. */
1001 demand_empty_rest_of_line ();
1004 /* Validate any relocations emitted for -mrelocatable, possibly adding
1005 fixups for word relocations in writable segments, so we can adjust
1008 ppc_elf_validate_fix (fixp
, seg
)
1015 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1016 && strcmp (segment_name (seg
), ".got2") != 0
1017 && strcmp (segment_name (seg
), ".dtors") != 0
1018 && strcmp (segment_name (seg
), ".ctors") != 0
1019 && strcmp (segment_name (seg
), ".fixup") != 0
1020 && strcmp (segment_name (seg
), ".stab") != 0)
1022 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1023 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1025 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
1026 "Relocation cannot be done when using -mrelocatable");
1031 #endif /* OBJ_ELF */
1035 * Summary of register_name().
1037 * in: Input_line_pointer points to 1st char of operand.
1039 * out: A expressionS.
1040 * The operand may have been a register: in this case, X_op == O_register,
1041 * X_add_number is set to the register number, and truth is returned.
1042 * Input_line_pointer->(next non-blank) char after operand, or is in its
1047 register_name (expressionP
)
1048 expressionS
*expressionP
;
1054 /* Find the spelling of the operand */
1055 name
= input_line_pointer
;
1056 c
= get_symbol_end ();
1057 reg_number
= reg_name_search (name
);
1059 /* look to see if it's in the register table */
1060 if (reg_number
>= 0)
1062 expressionP
->X_op
= O_register
;
1063 expressionP
->X_add_number
= reg_number
;
1065 /* make the rest nice */
1066 expressionP
->X_add_symbol
= NULL
;
1067 expressionP
->X_op_symbol
= NULL
;
1068 *input_line_pointer
= c
; /* put back the delimiting char */
1073 /* reset the line as if we had not done anything */
1074 *input_line_pointer
= c
; /* put back the delimiting char */
1075 input_line_pointer
= name
; /* reset input_line pointer */
1081 * Summary of parse_toc_entry().
1083 * in: Input_line_pointer points to the '[' in one of:
1085 * [toc] [tocv] [toc32] [toc64]
1087 * Anything else is an error of one kind or another.
1090 * return value: success or failure
1091 * toc_kind: kind of toc reference
1092 * input_line_pointer:
1093 * success: first char after the ']'
1094 * failure: unchanged
1098 * [toc] - rv == success, toc_kind = default_toc
1099 * [tocv] - rv == success, toc_kind = data_in_toc
1100 * [toc32] - rv == success, toc_kind = must_be_32
1101 * [toc64] - rv == success, toc_kind = must_be_64
1105 enum toc_size_qualifier
1107 default_toc
, /* The toc cell constructed should be the system default size */
1108 data_in_toc
, /* This is a direct reference to a toc cell */
1109 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1110 must_be_64
/* The toc cell constructed must be 64 bits wide */
1114 parse_toc_entry(toc_kind
)
1115 enum toc_size_qualifier
*toc_kind
;
1120 enum toc_size_qualifier t
;
1122 /* save the input_line_pointer */
1123 start
= input_line_pointer
;
1125 /* skip over the '[' , and whitespace */
1126 ++input_line_pointer
;
1129 /* find the spelling of the operand */
1130 toc_spec
= input_line_pointer
;
1131 c
= get_symbol_end ();
1133 if (strcmp(toc_spec
, "toc") == 0)
1137 else if (strcmp(toc_spec
, "tocv") == 0)
1141 else if (strcmp(toc_spec
, "toc32") == 0)
1145 else if (strcmp(toc_spec
, "toc64") == 0)
1151 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1152 *input_line_pointer
= c
; /* put back the delimiting char */
1153 input_line_pointer
= start
; /* reset input_line pointer */
1157 /* now find the ']' */
1158 *input_line_pointer
= c
; /* put back the delimiting char */
1160 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1161 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1165 as_bad ("syntax error: expected `]', found `%c'", c
);
1166 input_line_pointer
= start
; /* reset input_line pointer */
1170 *toc_kind
= t
; /* set return value */
1177 /* We need to keep a list of fixups. We can't simply generate them as
1178 we go, because that would require us to first create the frag, and
1179 that would screw up references to ``.''. */
1185 bfd_reloc_code_real_type reloc
;
1188 #define MAX_INSN_FIXUPS (5)
1190 /* This routine is called for each instruction to be assembled. */
1197 const struct powerpc_opcode
*opcode
;
1199 const unsigned char *opindex_ptr
;
1203 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1208 bfd_reloc_code_real_type reloc
;
1211 /* Get the opcode. */
1212 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1217 /* Look up the opcode in the hash table. */
1218 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1219 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1221 const struct powerpc_macro
*macro
;
1223 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1224 if (macro
== (const struct powerpc_macro
*) NULL
)
1225 as_bad ("Unrecognized opcode: `%s'", str
);
1227 ppc_macro (s
, macro
);
1232 insn
= opcode
->opcode
;
1235 while (isspace (*str
))
1238 /* PowerPC operands are just expressions. The only real issue is
1239 that a few operand types are optional. All cases which might use
1240 an optional operand separate the operands only with commas (in
1241 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1242 cases never have optional operands). There is never more than
1243 one optional operand for an instruction. So, before we start
1244 seriously parsing the operands, we check to see if we have an
1245 optional operand, and, if we do, we count the number of commas to
1246 see whether the operand should be omitted. */
1248 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1250 const struct powerpc_operand
*operand
;
1252 operand
= &powerpc_operands
[*opindex_ptr
];
1253 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1255 unsigned int opcount
;
1257 /* There is an optional operand. Count the number of
1258 commas in the input line. */
1265 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1272 /* If there are fewer operands in the line then are called
1273 for by the instruction, we want to skip the optional
1275 if (opcount
< strlen (opcode
->operands
))
1282 /* Gather the operands. */
1286 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1288 const struct powerpc_operand
*operand
;
1294 if (next_opindex
== 0)
1295 operand
= &powerpc_operands
[*opindex_ptr
];
1298 operand
= &powerpc_operands
[next_opindex
];
1304 /* If this is a fake operand, then we do not expect anything
1306 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1308 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1309 if (errmsg
!= (const char *) NULL
)
1314 /* If this is an optional operand, and we are skipping it, just
1316 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1319 if (operand
->insert
)
1321 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1322 if (errmsg
!= (const char *) NULL
)
1325 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1326 next_opindex
= *opindex_ptr
+ 1;
1330 /* Gather the operand. */
1331 hold
= input_line_pointer
;
1332 input_line_pointer
= str
;
1335 if (*input_line_pointer
== '[')
1337 /* We are expecting something like the second argument here:
1339 lwz r4,[toc].GS.0.static_int(rtoc)
1340 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1341 The argument following the `]' must be a symbol name, and the
1342 register must be the toc register: 'rtoc' or '2'
1344 The effect is to 0 as the displacement field
1345 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1346 the appropriate variation) reloc against it based on the symbol.
1347 The linker will build the toc, and insert the resolved toc offset.
1350 o The size of the toc entry is currently assumed to be
1351 32 bits. This should not be assumed to be a hard coded
1353 o In an effort to cope with a change from 32 to 64 bits,
1354 there are also toc entries that are specified to be
1355 either 32 or 64 bits:
1356 lwz r4,[toc32].GS.0.static_int(rtoc)
1357 lwz r4,[toc64].GS.0.static_int(rtoc)
1358 These demand toc entries of the specified size, and the
1359 instruction probably requires it.
1363 enum toc_size_qualifier toc_kind
;
1364 bfd_reloc_code_real_type toc_reloc
;
1366 /* go parse off the [tocXX] part */
1367 valid_toc
= parse_toc_entry(&toc_kind
);
1371 /* Note: message has already been issued. */
1372 /* FIXME: what sort of recovery should we do? */
1373 /* demand_rest_of_line(); return; ? */
1376 /* Now get the symbol following the ']' */
1382 /* In this case, we may not have seen the symbol yet, since */
1383 /* it is allowed to appear on a .extern or .globl or just be */
1384 /* a label in the .data section. */
1385 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1388 /* 1. The symbol must be defined and either in the toc */
1389 /* section, or a global. */
1390 /* 2. The reloc generated must have the TOCDEFN flag set in */
1391 /* upper bit mess of the reloc type. */
1392 /* FIXME: It's a little confusing what the tocv qualifier can */
1393 /* be used for. At the very least, I've seen three */
1394 /* uses, only one of which I'm sure I can explain. */
1395 if (ex
.X_op
== O_symbol
)
1397 assert (ex
.X_add_symbol
!= NULL
);
1398 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1400 as_warn("[tocv] symbol is not a toc symbol");
1404 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1407 /* FIXME: these next two specifically specify 32/64 bit toc */
1408 /* entries. We don't support them today. Is this the */
1409 /* right way to say that? */
1410 toc_reloc
= BFD_RELOC_UNUSED
;
1411 as_bad ("Unimplemented toc32 expression modifier");
1414 /* FIXME: see above */
1415 toc_reloc
= BFD_RELOC_UNUSED
;
1416 as_bad ("Unimplemented toc64 expression modifier");
1420 "Unexpected return value [%d] from parse_toc_entry!\n",
1426 /* We need to generate a fixup for this expression. */
1427 if (fc
>= MAX_INSN_FIXUPS
)
1428 as_fatal ("too many fixups");
1430 fixups
[fc
].reloc
= toc_reloc
;
1431 fixups
[fc
].exp
= ex
;
1432 fixups
[fc
].opindex
= *opindex_ptr
;
1435 /* Ok. We've set up the fixup for the instruction. Now make it
1436 look like the constant 0 was found here */
1438 ex
.X_op
= O_constant
;
1439 ex
.X_add_number
= 0;
1440 ex
.X_add_symbol
= NULL
;
1441 ex
.X_op_symbol
= NULL
;
1445 if (!register_name(&ex
))
1451 str
= input_line_pointer
;
1452 input_line_pointer
= hold
;
1455 str
= input_line_pointer
;
1456 input_line_pointer
= hold
;
1459 if (ex
.X_op
== O_illegal
)
1460 as_bad ("illegal operand");
1461 else if (ex
.X_op
== O_absent
)
1462 as_bad ("missing operand");
1463 else if (ex
.X_op
== O_constant
)
1466 /* Allow @HA, @L, @H on constants. */
1467 char *orig_str
= str
;
1469 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1476 case BFD_RELOC_LO16
:
1477 ex
.X_add_number
= ((ex
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1480 case BFD_RELOC_HI16
:
1481 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1484 case BFD_RELOC_HI16_S
:
1485 ex
.X_add_number
= ((ex
.X_add_number
>> 16) & 0xffff)
1486 + ((ex
.X_add_number
>> 15) & 1);
1490 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1494 else if (ex
.X_op
== O_register
)
1496 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1501 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1503 /* For the absoulte forms of branchs, convert the PC relative form back into
1505 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1508 case BFD_RELOC_PPC_B26
: reloc
= BFD_RELOC_PPC_BA26
; break;
1509 case BFD_RELOC_PPC_B16
: reloc
= BFD_RELOC_PPC_BA16
; break;
1510 case BFD_RELOC_PPC_B16_BRTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
; break;
1511 case BFD_RELOC_PPC_B16_BRNTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
; break;
1514 /* We need to generate a fixup for this expression. */
1515 if (fc
>= MAX_INSN_FIXUPS
)
1516 as_fatal ("too many fixups");
1517 fixups
[fc
].exp
= ex
;
1518 fixups
[fc
].opindex
= 0;
1519 fixups
[fc
].reloc
= reloc
;
1522 #endif /* OBJ_ELF */
1526 /* We need to generate a fixup for this expression. */
1527 if (fc
>= MAX_INSN_FIXUPS
)
1528 as_fatal ("too many fixups");
1529 fixups
[fc
].exp
= ex
;
1530 fixups
[fc
].opindex
= *opindex_ptr
;
1531 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1540 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1548 /* The call to expression should have advanced str past any
1551 && (endc
!= ',' || *str
!= '\0'))
1553 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1561 while (isspace (*str
))
1565 as_bad ("junk at end of line: `%s'", str
);
1567 /* Write out the instruction. */
1569 md_number_to_chars (f
, insn
, 4);
1571 /* Create any fixups. At this point we do not use a
1572 bfd_reloc_code_real_type, but instead just use the
1573 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1574 handle fixups for any operand type, although that is admittedly
1575 not a very exciting feature. We pick a BFD reloc type in
1577 for (i
= 0; i
< fc
; i
++)
1579 const struct powerpc_operand
*operand
;
1581 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1582 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1584 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1592 size
= bfd_get_reloc_size (reloc_howto
);
1593 offset
= target_big_endian
? (4 - size
) : 0;
1595 if (size
< 1 || size
> 4)
1598 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1599 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1602 /* Turn off complaints that the addend is too large for things like
1604 switch (fixups
[i
].reloc
)
1606 case BFD_RELOC_LO16
:
1607 case BFD_RELOC_HI16
:
1608 case BFD_RELOC_HI16_S
:
1609 fixP
->fx_no_overflow
= 1;
1616 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1618 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1619 ((bfd_reloc_code_real_type
)
1620 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1624 #ifndef WORKING_DOT_WORD
1625 /* Handle long and short jumps */
1627 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1629 addressT from_addr
, to_addr
;
1637 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1639 addressT from_addr
, to_addr
;
1647 /* Handle a macro. Gather all the operands, transform them as
1648 described by the macro, and call md_assemble recursively. All the
1649 operands are separated by commas; we don't accept parentheses
1650 around operands here. */
1653 ppc_macro (str
, macro
)
1655 const struct powerpc_macro
*macro
;
1666 /* Gather the users operands into the operands array. */
1671 if (count
>= sizeof operands
/ sizeof operands
[0])
1673 operands
[count
++] = s
;
1674 s
= strchr (s
, ',');
1675 if (s
== (char *) NULL
)
1680 if (count
!= macro
->operands
)
1682 as_bad ("wrong number of operands");
1686 /* Work out how large the string must be (the size is unbounded
1687 because it includes user input). */
1689 format
= macro
->format
;
1690 while (*format
!= '\0')
1699 arg
= strtol (format
+ 1, &send
, 10);
1700 know (send
!= format
&& arg
>= 0 && arg
< count
);
1701 len
+= strlen (operands
[arg
]);
1706 /* Put the string together. */
1707 complete
= s
= (char *) alloca (len
+ 1);
1708 format
= macro
->format
;
1709 while (*format
!= '\0')
1715 arg
= strtol (format
+ 1, &send
, 10);
1716 strcpy (s
, operands
[arg
]);
1723 /* Assemble the constructed instruction. */
1724 md_assemble (complete
);
1727 /* Pseudo-op handling. */
1729 /* The .byte pseudo-op. This is similar to the normal .byte
1730 pseudo-op, but it can also take a single ASCII string. */
1736 if (*input_line_pointer
!= '\"')
1742 /* Gather characters. A real double quote is doubled. Unusual
1743 characters are not permitted. */
1744 ++input_line_pointer
;
1749 c
= *input_line_pointer
++;
1753 if (*input_line_pointer
!= '\"')
1755 ++input_line_pointer
;
1758 FRAG_APPEND_1_CHAR (c
);
1761 demand_empty_rest_of_line ();
1766 /* XCOFF specific pseudo-op handling. */
1768 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1769 symbols in the .bss segment as though they were local common
1770 symbols, and uses a different smclas. */
1776 asection
*current_seg
= now_seg
;
1777 subsegT current_subseg
= now_subseg
;
1783 symbolS
*lcomm_sym
= NULL
;
1787 name
= input_line_pointer
;
1788 endc
= get_symbol_end ();
1789 end_name
= input_line_pointer
;
1792 if (*input_line_pointer
!= ',')
1794 as_bad ("missing size");
1795 ignore_rest_of_line ();
1798 ++input_line_pointer
;
1800 size
= get_absolute_expression ();
1803 as_bad ("negative size");
1804 ignore_rest_of_line ();
1810 /* The third argument to .comm is the alignment. */
1811 if (*input_line_pointer
!= ',')
1815 ++input_line_pointer
;
1816 align
= get_absolute_expression ();
1819 as_warn ("ignoring bad alignment");
1838 /* The third argument to .lcomm appears to be the real local
1839 common symbol to create. References to the symbol named in
1840 the first argument are turned into references to the third
1842 if (*input_line_pointer
!= ',')
1844 as_bad ("missing real symbol name");
1845 ignore_rest_of_line ();
1848 ++input_line_pointer
;
1850 lcomm_name
= input_line_pointer
;
1851 lcomm_endc
= get_symbol_end ();
1853 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1855 *input_line_pointer
= lcomm_endc
;
1859 sym
= symbol_find_or_make (name
);
1862 if (S_IS_DEFINED (sym
)
1863 || S_GET_VALUE (sym
) != 0)
1865 as_bad ("attempt to redefine symbol");
1866 ignore_rest_of_line ();
1870 record_alignment (bss_section
, align
);
1873 || ! S_IS_DEFINED (lcomm_sym
))
1882 S_SET_EXTERNAL (sym
);
1886 lcomm_sym
->sy_tc
.output
= 1;
1887 def_sym
= lcomm_sym
;
1891 subseg_set (bss_section
, 1);
1892 frag_align (align
, 0);
1894 def_sym
->sy_frag
= frag_now
;
1895 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1896 def_size
, (char *) NULL
);
1898 S_SET_SEGMENT (def_sym
, bss_section
);
1899 def_sym
->sy_tc
.align
= align
;
1903 /* Align the size of lcomm_sym. */
1904 lcomm_sym
->sy_frag
->fr_offset
=
1905 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1906 &~ ((1 << align
) - 1));
1907 if (align
> lcomm_sym
->sy_tc
.align
)
1908 lcomm_sym
->sy_tc
.align
= align
;
1913 /* Make sym an offset from lcomm_sym. */
1914 S_SET_SEGMENT (sym
, bss_section
);
1915 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1916 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1917 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1920 subseg_set (current_seg
, current_subseg
);
1922 demand_empty_rest_of_line ();
1925 /* The .csect pseudo-op. This switches us into a different
1926 subsegment. The first argument is a symbol whose value is the
1927 start of the .csect. In COFF, csect symbols get special aux
1928 entries defined by the x_csect field of union internal_auxent. The
1929 optional second argument is the alignment (the default is 2). */
1939 name
= input_line_pointer
;
1940 endc
= get_symbol_end ();
1942 sym
= symbol_find_or_make (name
);
1944 *input_line_pointer
= endc
;
1946 if (S_IS_DEFINED (sym
))
1947 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1954 /* This is a new csect. We need to look at the symbol class to
1955 figure out whether it should go in the text section or the
1958 switch (sym
->sy_tc
.class)
1968 S_SET_SEGMENT (sym
, text_section
);
1969 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1970 ++ppc_text_subsegment
;
1971 list_ptr
= &ppc_text_csects
;
1980 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1982 S_SET_SEGMENT (sym
, data_section
);
1983 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1984 ++ppc_data_subsegment
;
1985 list_ptr
= &ppc_data_csects
;
1991 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1993 ppc_after_toc_frag
= frag_now
;
1995 sym
->sy_frag
= frag_now
;
1996 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1998 sym
->sy_tc
.align
= 2;
1999 sym
->sy_tc
.output
= 1;
2000 sym
->sy_tc
.within
= sym
;
2002 for (list
= *list_ptr
;
2003 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2004 list
= list
->sy_tc
.next
)
2006 list
->sy_tc
.next
= sym
;
2008 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2009 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2012 if (*input_line_pointer
== ',')
2014 ++input_line_pointer
;
2015 sym
->sy_tc
.align
= get_absolute_expression ();
2018 ppc_current_csect
= sym
;
2020 demand_empty_rest_of_line ();
2023 /* The .extern pseudo-op. We create an undefined symbol. */
2032 name
= input_line_pointer
;
2033 endc
= get_symbol_end ();
2035 (void) symbol_find_or_make (name
);
2037 *input_line_pointer
= endc
;
2039 demand_empty_rest_of_line ();
2042 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
2043 this because it can't handle undefined symbols. I think we can
2053 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2054 although I don't know why it bothers. */
2065 name
= input_line_pointer
;
2066 endc
= get_symbol_end ();
2068 sym
= symbol_find_or_make (name
);
2070 *input_line_pointer
= endc
;
2072 if (*input_line_pointer
!= ',')
2074 as_bad ("missing rename string");
2075 ignore_rest_of_line ();
2078 ++input_line_pointer
;
2080 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2082 demand_empty_rest_of_line ();
2085 /* The .stabx pseudo-op. This is similar to a normal .stabs
2086 pseudo-op, but slightly different. A sample is
2087 .stabx "main:F-1",.main,142,0
2088 The first argument is the symbol name to create. The second is the
2089 value, and the third is the storage class. The fourth seems to be
2090 always zero, and I am assuming it is the type. */
2101 name
= demand_copy_C_string (&len
);
2103 if (*input_line_pointer
!= ',')
2105 as_bad ("missing value");
2108 ++input_line_pointer
;
2110 sym
= symbol_make (name
);
2112 (void) expression (&exp
);
2119 as_bad ("illegal .stabx expression; zero assumed");
2120 exp
.X_add_number
= 0;
2123 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2124 sym
->sy_frag
= &zero_address_frag
;
2128 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2129 sym
->sy_value
= exp
;
2133 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2134 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2139 /* The value is some complex expression. This will probably
2140 fail at some later point, but this is probably the right
2141 thing to do here. */
2142 sym
->sy_value
= exp
;
2146 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2147 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2149 if (*input_line_pointer
!= ',')
2151 as_bad ("missing class");
2154 ++input_line_pointer
;
2156 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2158 if (*input_line_pointer
!= ',')
2160 as_bad ("missing type");
2163 ++input_line_pointer
;
2165 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2167 sym
->sy_tc
.output
= 1;
2169 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2170 sym
->sy_tc
.within
= ppc_current_block
;
2172 if (exp
.X_op
!= O_symbol
2173 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2174 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2175 ppc_frob_label (sym
);
2178 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2179 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2180 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2181 ppc_current_csect
->sy_tc
.within
= sym
;
2184 if (strlen (name
) > SYMNMLEN
)
2186 /* For some reason, each name is preceded by a two byte length
2187 and followed by a null byte. */
2188 ppc_debug_name_section_size
+= strlen (name
) + 3;
2191 demand_empty_rest_of_line ();
2194 /* The .function pseudo-op. This takes several arguments. The first
2195 argument seems to be the external name of the symbol. The second
2196 argment seems to be the label for the start of the function. gcc
2197 uses the same name for both. I have no idea what the third and
2198 fourth arguments are meant to be. The optional fifth argument is
2199 an expression for the size of the function. In COFF this symbol
2200 gets an aux entry like that used for a csect. */
2203 ppc_function (ignore
)
2212 name
= input_line_pointer
;
2213 endc
= get_symbol_end ();
2215 /* Ignore any [PR] suffix. */
2216 name
= ppc_canonicalize_symbol_name (name
);
2217 s
= strchr (name
, '[');
2218 if (s
!= (char *) NULL
2219 && strcmp (s
+ 1, "PR]") == 0)
2222 ext_sym
= symbol_find_or_make (name
);
2224 *input_line_pointer
= endc
;
2226 if (*input_line_pointer
!= ',')
2228 as_bad ("missing symbol name");
2229 ignore_rest_of_line ();
2232 ++input_line_pointer
;
2234 name
= input_line_pointer
;
2235 endc
= get_symbol_end ();
2237 lab_sym
= symbol_find_or_make (name
);
2239 *input_line_pointer
= endc
;
2241 if (ext_sym
!= lab_sym
)
2243 ext_sym
->sy_value
.X_op
= O_symbol
;
2244 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2245 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2246 ext_sym
->sy_value
.X_add_number
= 0;
2249 if (ext_sym
->sy_tc
.class == -1)
2250 ext_sym
->sy_tc
.class = XMC_PR
;
2251 ext_sym
->sy_tc
.output
= 1;
2253 if (*input_line_pointer
== ',')
2257 /* Ignore the third argument. */
2258 ++input_line_pointer
;
2259 expression (&ignore
);
2260 if (*input_line_pointer
== ',')
2262 /* Ignore the fourth argument. */
2263 ++input_line_pointer
;
2264 expression (&ignore
);
2265 if (*input_line_pointer
== ',')
2267 /* The fifth argument is the function size. */
2268 ++input_line_pointer
;
2269 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2272 &zero_address_frag
);
2273 pseudo_set (ext_sym
->sy_tc
.size
);
2278 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2279 SF_SET_FUNCTION (ext_sym
);
2280 SF_SET_PROCESS (ext_sym
);
2281 coff_add_linesym (ext_sym
);
2283 demand_empty_rest_of_line ();
2286 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2295 sym
= symbol_make (".bf");
2296 S_SET_SEGMENT (sym
, text_section
);
2297 sym
->sy_frag
= frag_now
;
2298 S_SET_VALUE (sym
, frag_now_fix ());
2299 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2301 coff_line_base
= get_absolute_expression ();
2303 S_SET_NUMBER_AUXILIARY (sym
, 1);
2304 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2306 sym
->sy_tc
.output
= 1;
2308 ppc_frob_label (sym
);
2310 demand_empty_rest_of_line ();
2313 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2314 ".ef", except that the line number is absolute, not relative to the
2315 most recent ".bf" symbol. */
2323 sym
= symbol_make (".ef");
2324 S_SET_SEGMENT (sym
, text_section
);
2325 sym
->sy_frag
= frag_now
;
2326 S_SET_VALUE (sym
, frag_now_fix ());
2327 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2328 S_SET_NUMBER_AUXILIARY (sym
, 1);
2329 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2330 sym
->sy_tc
.output
= 1;
2332 ppc_frob_label (sym
);
2334 demand_empty_rest_of_line ();
2337 /* The .bi and .ei pseudo-ops. These take a string argument and
2338 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2350 name
= demand_copy_C_string (&len
);
2352 /* The value of these symbols is actually file offset. Here we set
2353 the value to the index into the line number entries. In
2354 ppc_frob_symbols we set the fix_line field, which will cause BFD
2355 to do the right thing. */
2357 sym
= symbol_make (name
);
2358 S_SET_SEGMENT (sym
, now_seg
);
2359 S_SET_VALUE (sym
, coff_n_line_nos
);
2360 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2362 /* obj-coff.c currently only handles line numbers correctly in the
2364 assert (now_seg
== text_section
);
2366 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2367 sym
->sy_tc
.output
= 1;
2369 for (look
= symbol_rootP
;
2370 (look
!= (symbolS
*) NULL
2371 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2372 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2373 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2374 look
= symbol_next (look
))
2376 if (look
!= (symbolS
*) NULL
)
2378 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2379 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2382 demand_empty_rest_of_line ();
2385 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2386 There is one argument, which is a csect symbol. The value of the
2387 .bs symbol is the index of this csect symbol. */
2398 if (ppc_current_block
!= NULL
)
2399 as_bad ("nested .bs blocks");
2401 name
= input_line_pointer
;
2402 endc
= get_symbol_end ();
2404 csect
= symbol_find_or_make (name
);
2406 *input_line_pointer
= endc
;
2408 sym
= symbol_make (".bs");
2409 S_SET_SEGMENT (sym
, now_seg
);
2410 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2411 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2412 sym
->sy_tc
.output
= 1;
2414 sym
->sy_tc
.within
= csect
;
2416 ppc_frob_label (sym
);
2418 ppc_current_block
= sym
;
2420 demand_empty_rest_of_line ();
2423 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2431 if (ppc_current_block
== NULL
)
2432 as_bad (".es without preceding .bs");
2434 sym
= symbol_make (".es");
2435 S_SET_SEGMENT (sym
, now_seg
);
2436 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2437 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2438 sym
->sy_tc
.output
= 1;
2440 ppc_frob_label (sym
);
2442 ppc_current_block
= NULL
;
2444 demand_empty_rest_of_line ();
2447 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2456 sym
= symbol_make (".bb");
2457 S_SET_SEGMENT (sym
, text_section
);
2458 sym
->sy_frag
= frag_now
;
2459 S_SET_VALUE (sym
, frag_now_fix ());
2460 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2462 S_SET_NUMBER_AUXILIARY (sym
, 1);
2463 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2465 sym
->sy_tc
.output
= 1;
2467 ppc_frob_label (sym
);
2469 demand_empty_rest_of_line ();
2472 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2481 sym
= symbol_make (".eb");
2482 S_SET_SEGMENT (sym
, text_section
);
2483 sym
->sy_frag
= frag_now
;
2484 S_SET_VALUE (sym
, frag_now_fix ());
2485 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2486 S_SET_NUMBER_AUXILIARY (sym
, 1);
2487 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2488 sym
->sy_tc
.output
= 1;
2490 ppc_frob_label (sym
);
2492 demand_empty_rest_of_line ();
2495 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2501 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2502 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2509 subseg
= ppc_data_subsegment
;
2510 ++ppc_data_subsegment
;
2512 subseg_new (segment_name (data_section
), subseg
);
2513 ppc_toc_frag
= frag_now
;
2515 sym
= symbol_find_or_make ("TOC[TC0]");
2516 sym
->sy_frag
= frag_now
;
2517 S_SET_SEGMENT (sym
, data_section
);
2518 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2519 sym
->sy_tc
.subseg
= subseg
;
2520 sym
->sy_tc
.output
= 1;
2521 sym
->sy_tc
.within
= sym
;
2523 ppc_toc_csect
= sym
;
2525 for (list
= ppc_data_csects
;
2526 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2527 list
= list
->sy_tc
.next
)
2529 list
->sy_tc
.next
= sym
;
2531 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2532 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2535 ppc_current_csect
= ppc_toc_csect
;
2537 demand_empty_rest_of_line ();
2540 #endif /* OBJ_XCOFF */
2542 /* The .tc pseudo-op. This is used when generating either XCOFF or
2543 ELF. This takes two or more arguments.
2545 When generating XCOFF output, the first argument is the name to
2546 give to this location in the toc; this will be a symbol with class
2547 TC. The rest of the arguments are 4 byte values to actually put at
2548 this location in the TOC; often there is just one more argument, a
2549 relocateable symbol reference.
2551 When not generating XCOFF output, the arguments are the same, but
2552 the first argument is simply ignored. */
2560 /* Define the TOC symbol name. */
2566 if (ppc_toc_csect
== (symbolS
*) NULL
2567 || ppc_toc_csect
!= ppc_current_csect
)
2569 as_bad (".tc not in .toc section");
2570 ignore_rest_of_line ();
2574 name
= input_line_pointer
;
2575 endc
= get_symbol_end ();
2577 sym
= symbol_find_or_make (name
);
2579 *input_line_pointer
= endc
;
2581 if (S_IS_DEFINED (sym
))
2585 label
= ppc_current_csect
->sy_tc
.within
;
2586 if (label
->sy_tc
.class != XMC_TC0
)
2588 as_warn (".tc with no label");
2589 ignore_rest_of_line ();
2593 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
2594 label
->sy_frag
= sym
->sy_frag
;
2595 S_SET_VALUE (label
, S_GET_VALUE (sym
));
2597 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2598 ++input_line_pointer
;
2603 S_SET_SEGMENT (sym
, now_seg
);
2604 sym
->sy_frag
= frag_now
;
2605 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2606 sym
->sy_tc
.class = XMC_TC
;
2607 sym
->sy_tc
.output
= 1;
2609 ppc_frob_label (sym
);
2612 #else /* ! defined (OBJ_XCOFF) */
2614 /* Skip the TOC symbol name. */
2615 while (is_part_of_name (*input_line_pointer
)
2616 || *input_line_pointer
== '['
2617 || *input_line_pointer
== ']'
2618 || *input_line_pointer
== '{'
2619 || *input_line_pointer
== '}')
2620 ++input_line_pointer
;
2622 /* Align to a four byte boundary. */
2624 record_alignment (now_seg
, 2);
2626 #endif /* ! defined (OBJ_XCOFF) */
2628 if (*input_line_pointer
!= ',')
2629 demand_empty_rest_of_line ();
2632 ++input_line_pointer
;
2639 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2641 /* Set the current section. */
2643 ppc_set_current_section (new)
2646 ppc_previous_section
= ppc_current_section
;
2647 ppc_current_section
= new;
2650 /* pseudo-op: .previous
2651 behaviour: toggles the current section with the previous section.
2653 warnings: "No previous section"
2656 ppc_previous(ignore
)
2661 if (ppc_previous_section
== NULL
)
2663 as_warn("No previous section to return to. Directive ignored.");
2667 subseg_set(ppc_previous_section
, 0);
2669 ppc_set_current_section(ppc_previous_section
);
2672 /* pseudo-op: .pdata
2673 behaviour: predefined read only data section
2677 initial: .section .pdata "adr3"
2678 a - don't know -- maybe a misprint
2679 d - initialized data
2681 3 - double word aligned (that would be 4 byte boundary)
2684 Tag index tables (also known as the function table) for exception
2685 handling, debugging, etc.
2692 if (pdata_section
== 0)
2694 pdata_section
= subseg_new (".pdata", 0);
2696 bfd_set_section_flags (stdoutput
, pdata_section
,
2697 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2698 | SEC_READONLY
| SEC_DATA
));
2700 bfd_set_section_alignment (stdoutput
, pdata_section
, 3);
2704 pdata_section
= subseg_new(".pdata", 0);
2706 ppc_set_current_section(pdata_section
);
2709 /* pseudo-op: .ydata
2710 behaviour: predefined read only data section
2714 initial: .section .ydata "drw3"
2715 a - don't know -- maybe a misprint
2716 d - initialized data
2718 3 - double word aligned (that would be 4 byte boundary)
2720 Tag tables (also known as the scope table) for exception handling,
2727 if (ydata_section
== 0)
2729 ydata_section
= subseg_new (".ydata", 0);
2730 bfd_set_section_flags (stdoutput
, ydata_section
,
2731 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2732 | SEC_READONLY
| SEC_DATA
));
2734 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
2738 ydata_section
= subseg_new (".ydata", 0);
2740 ppc_set_current_section(ydata_section
);
2743 /* pseudo-op: .reldata
2744 behaviour: predefined read write data section
2745 double word aligned (4-byte)
2746 FIXME: relocation is applied to it
2747 FIXME: what's the difference between this and .data?
2750 initial: .section .reldata "drw3"
2751 d - initialized data
2754 3 - double word aligned (that would be 8 byte boundary)
2757 Like .data, but intended to hold data subject to relocation, such as
2758 function descriptors, etc.
2764 if (reldata_section
== 0)
2766 reldata_section
= subseg_new (".reldata", 0);
2768 bfd_set_section_flags (stdoutput
, reldata_section
,
2769 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2772 bfd_set_section_alignment (stdoutput
, reldata_section
, 3);
2776 reldata_section
= subseg_new (".reldata", 0);
2778 ppc_set_current_section(reldata_section
);
2781 /* pseudo-op: .rdata
2782 behaviour: predefined read only data section
2786 initial: .section .rdata "dr3"
2787 d - initialized data
2789 3 - double word aligned (that would be 4 byte boundary)
2795 if (rdata_section
== 0)
2797 rdata_section
= subseg_new (".rdata", 0);
2798 bfd_set_section_flags (stdoutput
, rdata_section
,
2799 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2800 | SEC_READONLY
| SEC_DATA
));
2802 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
2806 rdata_section
= subseg_new (".rdata", 0);
2808 ppc_set_current_section(rdata_section
);
2811 /* pseudo-op: .ualong
2812 behaviour: much like .int, with the exception that no alignment is
2814 FIXME: test the alignment statement
2826 /* pseudo-op: .znop <symbol name>
2827 behaviour: Issue a nop instruction
2828 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2829 the supplied symbol name.
2831 warnings: Missing symbol name
2838 const struct powerpc_opcode
*opcode
;
2844 /* Strip out the symbol name */
2852 symbol_name
= input_line_pointer
;
2853 c
= get_symbol_end ();
2855 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
2856 strcpy (name
, symbol_name
);
2858 sym
= symbol_find_or_make (name
);
2860 *input_line_pointer
= c
;
2864 /* Look up the opcode in the hash table. */
2865 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
2867 /* stick in the nop */
2868 insn
= opcode
->opcode
;
2870 /* Write out the instruction. */
2872 md_number_to_chars (f
, insn
, 4);
2874 f
- frag_now
->fr_literal
,
2879 BFD_RELOC_16_GOT_PCREL
);
2892 register char *name
;
2896 register symbolS
*symbolP
;
2899 name
= input_line_pointer
;
2900 c
= get_symbol_end ();
2902 /* just after name is now '\0' */
2903 p
= input_line_pointer
;
2906 if (*input_line_pointer
!= ',')
2908 as_bad ("Expected comma after symbol-name: rest of line ignored.");
2909 ignore_rest_of_line ();
2913 input_line_pointer
++; /* skip ',' */
2914 if ((temp
= get_absolute_expression ()) < 0)
2916 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
2917 ignore_rest_of_line ();
2923 /* The third argument to .comm is the alignment. */
2924 if (*input_line_pointer
!= ',')
2928 ++input_line_pointer
;
2929 align
= get_absolute_expression ();
2932 as_warn ("ignoring bad alignment");
2939 symbolP
= symbol_find_or_make (name
);
2942 if (S_IS_DEFINED (symbolP
))
2944 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2945 S_GET_NAME (symbolP
));
2946 ignore_rest_of_line ();
2950 if (S_GET_VALUE (symbolP
))
2952 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
2953 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
2954 S_GET_NAME (symbolP
),
2955 (long) S_GET_VALUE (symbolP
),
2960 S_SET_VALUE (symbolP
, (valueT
) temp
);
2961 S_SET_EXTERNAL (symbolP
);
2964 demand_empty_rest_of_line ();
2968 * implement the .section pseudo op:
2969 * .section name {, "flags"}
2971 * | +--- optional flags: 'b' for bss
2973 * +-- section name 'l' for lib
2977 * 'd' (apparently m88k for data)
2979 * But if the argument is not a quoted string, treat it as a
2980 * subsegment number.
2982 * FIXME: this is a copy of the section processing from obj-coff.c, with
2983 * additions/changes for the moto-pas assembler support. There are three
2986 * FIXME: I just noticed this. This doesn't work at all really. It it
2987 * setting bits that bfd probably neither understands or uses. The
2988 * correct approach (?) will have to incorporate extra fields attached
2989 * to the section to hold the system specific stuff. (krk)
2992 * 'a' - unknown - referred to in documentation, but no definition supplied
2993 * 'c' - section has code
2994 * 'd' - section has initialized data
2995 * 'u' - section has uninitialized data
2996 * 'i' - section contains directives (info)
2997 * 'n' - section can be discarded
2998 * 'R' - remove section at link time
3000 * Section Protection:
3001 * 'r' - section is readable
3002 * 'w' - section is writeable
3003 * 'x' - section is executable
3004 * 's' - section is sharable
3006 * Section Alignment:
3007 * '0' - align to byte boundary
3008 * '1' - align to halfword undary
3009 * '2' - align to word boundary
3010 * '3' - align to doubleword boundary
3011 * '4' - align to quadword boundary
3012 * '5' - align to 32 byte boundary
3013 * '6' - align to 64 byte boundary
3018 ppc_pe_section (ignore
)
3021 /* Strip out the section name */
3030 align
= 4; /* default alignment to 16 byte boundary */
3032 section_name
= input_line_pointer
;
3033 c
= get_symbol_end ();
3035 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3036 strcpy (name
, section_name
);
3038 *input_line_pointer
= c
;
3043 flags
= SEC_NO_FLAGS
;
3045 if (*input_line_pointer
== ',')
3047 ++input_line_pointer
;
3049 if (*input_line_pointer
!= '"')
3050 exp
= get_absolute_expression ();
3053 ++input_line_pointer
;
3054 while (*input_line_pointer
!= '"'
3055 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3057 switch (*input_line_pointer
)
3059 /* Section Contents */
3060 case 'a': /* unknown */
3061 as_warn ("Unsupported section attribute -- 'a'");
3063 case 'c': /* code section */
3066 case 'd': /* section has initialized data */
3069 case 'u': /* section has uninitialized data */
3070 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3074 case 'i': /* section contains directives (info) */
3075 /* FIXME: This is IMAGE_SCN_LNK_INFO
3077 flags
|= SEC_HAS_CONTENTS
;
3079 case 'n': /* section can be discarded */
3082 case 'R': /* Remove section at link time */
3083 flags
|= SEC_NEVER_LOAD
;
3086 /* Section Protection */
3087 case 'r': /* section is readable */
3088 flags
|= IMAGE_SCN_MEM_READ
;
3090 case 'w': /* section is writeable */
3091 flags
|= IMAGE_SCN_MEM_WRITE
;
3093 case 'x': /* section is executable */
3094 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3096 case 's': /* section is sharable */
3097 flags
|= IMAGE_SCN_MEM_SHARED
;
3100 /* Section Alignment */
3101 case '0': /* align to byte boundary */
3102 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3105 case '1': /* align to halfword boundary */
3106 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3109 case '2': /* align to word boundary */
3110 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3113 case '3': /* align to doubleword boundary */
3114 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3117 case '4': /* align to quadword boundary */
3118 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3121 case '5': /* align to 32 byte boundary */
3122 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3125 case '6': /* align to 64 byte boundary */
3126 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3131 as_warn("unknown section attribute '%c'",
3132 *input_line_pointer
);
3135 ++input_line_pointer
;
3137 if (*input_line_pointer
== '"')
3138 ++input_line_pointer
;
3142 sec
= subseg_new (name
, (subsegT
) exp
);
3144 ppc_set_current_section(sec
);
3146 if (flags
!= SEC_NO_FLAGS
)
3148 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3149 as_warn ("error setting flags for \"%s\": %s",
3150 bfd_section_name (stdoutput
, sec
),
3151 bfd_errmsg (bfd_get_error ()));
3154 bfd_set_section_alignment(stdoutput
, sec
, align
);
3159 ppc_pe_function (ignore
)
3166 name
= input_line_pointer
;
3167 endc
= get_symbol_end ();
3169 ext_sym
= symbol_find_or_make (name
);
3171 *input_line_pointer
= endc
;
3173 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3174 SF_SET_FUNCTION (ext_sym
);
3175 SF_SET_PROCESS (ext_sym
);
3176 coff_add_linesym (ext_sym
);
3178 demand_empty_rest_of_line ();
3182 ppc_pe_tocd (ignore
)
3185 if (tocdata_section
== 0)
3187 tocdata_section
= subseg_new (".tocd", 0);
3188 /* FIXME: section flags won't work */
3189 bfd_set_section_flags (stdoutput
, tocdata_section
,
3190 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3191 | SEC_READONLY
| SEC_DATA
));
3193 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3197 rdata_section
= subseg_new (".tocd", 0);
3200 ppc_set_current_section(tocdata_section
);
3202 demand_empty_rest_of_line ();
3205 /* Don't adjust TOC relocs to use the section symbol. */
3208 ppc_pe_fix_adjustable (fix
)
3211 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3218 /* XCOFF specific symbol and file handling. */
3220 /* Canonicalize the symbol name. We use the to force the suffix, if
3221 any, to use square brackets, and to be in upper case. */
3224 ppc_canonicalize_symbol_name (name
)
3229 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3243 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3247 if (*s
== '\0' || s
[1] != '\0')
3248 as_bad ("bad symbol suffix");
3256 /* Set the class of a symbol based on the suffix, if any. This is
3257 called whenever a new symbol is created. */
3260 ppc_symbol_new_hook (sym
)
3265 sym
->sy_tc
.next
= NULL
;
3266 sym
->sy_tc
.output
= 0;
3267 sym
->sy_tc
.class = -1;
3268 sym
->sy_tc
.real_name
= NULL
;
3269 sym
->sy_tc
.subseg
= 0;
3270 sym
->sy_tc
.align
= 0;
3271 sym
->sy_tc
.size
= NULL
;
3272 sym
->sy_tc
.within
= NULL
;
3274 s
= strchr (S_GET_NAME (sym
), '[');
3275 if (s
== (const char *) NULL
)
3277 /* There is no suffix. */
3286 if (strcmp (s
, "BS]") == 0)
3287 sym
->sy_tc
.class = XMC_BS
;
3290 if (strcmp (s
, "DB]") == 0)
3291 sym
->sy_tc
.class = XMC_DB
;
3292 else if (strcmp (s
, "DS]") == 0)
3293 sym
->sy_tc
.class = XMC_DS
;
3296 if (strcmp (s
, "GL]") == 0)
3297 sym
->sy_tc
.class = XMC_GL
;
3300 if (strcmp (s
, "PR]") == 0)
3301 sym
->sy_tc
.class = XMC_PR
;
3304 if (strcmp (s
, "RO]") == 0)
3305 sym
->sy_tc
.class = XMC_RO
;
3306 else if (strcmp (s
, "RW]") == 0)
3307 sym
->sy_tc
.class = XMC_RW
;
3310 if (strcmp (s
, "SV]") == 0)
3311 sym
->sy_tc
.class = XMC_SV
;
3314 if (strcmp (s
, "TC]") == 0)
3315 sym
->sy_tc
.class = XMC_TC
;
3316 else if (strcmp (s
, "TI]") == 0)
3317 sym
->sy_tc
.class = XMC_TI
;
3318 else if (strcmp (s
, "TB]") == 0)
3319 sym
->sy_tc
.class = XMC_TB
;
3320 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3321 sym
->sy_tc
.class = XMC_TC0
;
3324 if (strcmp (s
, "UA]") == 0)
3325 sym
->sy_tc
.class = XMC_UA
;
3326 else if (strcmp (s
, "UC]") == 0)
3327 sym
->sy_tc
.class = XMC_UC
;
3330 if (strcmp (s
, "XO]") == 0)
3331 sym
->sy_tc
.class = XMC_XO
;
3335 if (sym
->sy_tc
.class == -1)
3336 as_bad ("Unrecognized symbol suffix");
3339 /* Set the class of a label based on where it is defined. This
3340 handles symbols without suffixes. Also, move the symbol so that it
3341 follows the csect symbol. */
3344 ppc_frob_label (sym
)
3347 if (ppc_current_csect
!= (symbolS
*) NULL
)
3349 if (sym
->sy_tc
.class == -1)
3350 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3352 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3353 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3355 ppc_current_csect
->sy_tc
.within
= sym
;
3359 /* Change the name of a symbol just before writing it out. Set the
3360 real name if the .rename pseudo-op was used. Otherwise, remove any
3361 class suffix. Return 1 if the symbol should not be included in the
3365 ppc_frob_symbol (sym
)
3368 static symbolS
*ppc_last_function
;
3369 static symbolS
*set_end
;
3371 /* Discard symbols that should not be included in the output symbol
3373 if (! sym
->sy_used_in_reloc
3374 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3375 || (! S_IS_EXTERNAL (sym
)
3376 && ! sym
->sy_tc
.output
3377 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3380 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3381 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3387 name
= S_GET_NAME (sym
);
3388 s
= strchr (name
, '[');
3389 if (s
!= (char *) NULL
)
3395 snew
= xmalloc (len
+ 1);
3396 memcpy (snew
, name
, len
);
3399 S_SET_NAME (sym
, snew
);
3403 if (set_end
!= (symbolS
*) NULL
)
3405 SA_SET_SYM_ENDNDX (set_end
, sym
);
3409 if (SF_GET_FUNCTION (sym
))
3411 if (ppc_last_function
!= (symbolS
*) NULL
)
3412 as_warn ("two .function pseudo-ops with no intervening .ef");
3413 ppc_last_function
= sym
;
3414 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3416 resolve_symbol_value (sym
->sy_tc
.size
);
3417 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3420 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3421 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3423 if (ppc_last_function
== (symbolS
*) NULL
)
3424 as_warn (".ef with no preceding .function");
3427 set_end
= ppc_last_function
;
3428 ppc_last_function
= NULL
;
3430 /* We don't have a C_EFCN symbol, but we need to force the
3431 COFF backend to believe that it has seen one. */
3432 coff_last_function
= NULL
;
3436 if (! S_IS_EXTERNAL (sym
)
3437 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3438 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3439 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3440 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3441 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3442 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
3443 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
3444 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3445 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3447 if ((S_GET_STORAGE_CLASS (sym
) == C_EXT
3448 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3449 && S_GET_SEGMENT (sym
) != absolute_section
)
3452 union internal_auxent
*a
;
3454 /* Create a csect aux. */
3455 i
= S_GET_NUMBER_AUXILIARY (sym
);
3456 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3457 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3458 if (sym
->sy_tc
.class == XMC_TC0
)
3460 /* This is the TOC table. */
3461 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3462 a
->x_csect
.x_scnlen
.l
= 0;
3463 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3465 else if (sym
->sy_tc
.subseg
!= 0)
3467 /* This is a csect symbol. x_scnlen is the size of the
3469 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3470 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3471 S_GET_SEGMENT (sym
))
3472 - S_GET_VALUE (sym
));
3475 resolve_symbol_value (sym
->sy_tc
.next
);
3476 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3477 - S_GET_VALUE (sym
));
3479 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3481 else if (S_GET_SEGMENT (sym
) == bss_section
)
3483 /* This is a common symbol. */
3484 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3485 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3486 if (S_IS_EXTERNAL (sym
))
3487 sym
->sy_tc
.class = XMC_RW
;
3489 sym
->sy_tc
.class = XMC_BS
;
3491 else if (! S_IS_DEFINED (sym
))
3493 /* This is an external symbol. */
3494 a
->x_csect
.x_scnlen
.l
= 0;
3495 a
->x_csect
.x_smtyp
= XTY_ER
;
3497 else if (sym
->sy_tc
.class == XMC_TC
)
3501 /* This is a TOC definition. x_scnlen is the size of the
3503 next
= symbol_next (sym
);
3504 while (next
->sy_tc
.class == XMC_TC0
)
3505 next
= symbol_next (next
);
3506 if (next
== (symbolS
*) NULL
3507 || next
->sy_tc
.class != XMC_TC
)
3509 if (ppc_after_toc_frag
== (fragS
*) NULL
)
3510 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3512 - S_GET_VALUE (sym
));
3514 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
3515 - S_GET_VALUE (sym
));
3519 resolve_symbol_value (next
);
3520 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
3521 - S_GET_VALUE (sym
));
3523 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3529 /* This is a normal symbol definition. x_scnlen is the
3530 symbol index of the containing csect. */
3531 if (S_GET_SEGMENT (sym
) == text_section
)
3532 csect
= ppc_text_csects
;
3533 else if (S_GET_SEGMENT (sym
) == data_section
)
3534 csect
= ppc_data_csects
;
3538 /* Skip the initial dummy symbol. */
3539 csect
= csect
->sy_tc
.next
;
3541 if (csect
== (symbolS
*) NULL
)
3542 a
->x_csect
.x_scnlen
.l
= 0;
3545 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
3547 resolve_symbol_value (csect
->sy_tc
.next
);
3548 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
3550 csect
= csect
->sy_tc
.next
;
3553 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3554 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
3556 a
->x_csect
.x_smtyp
= XTY_LD
;
3559 a
->x_csect
.x_parmhash
= 0;
3560 a
->x_csect
.x_snhash
= 0;
3561 if (sym
->sy_tc
.class == -1)
3562 a
->x_csect
.x_smclas
= XMC_PR
;
3564 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
3565 a
->x_csect
.x_stab
= 0;
3566 a
->x_csect
.x_snstab
= 0;
3568 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
3570 /* We want the value to be the symbol index of the referenced
3571 csect symbol. BFD will do that for us if we set the right
3574 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
3575 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
3577 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
3582 /* The value is the offset from the enclosing csect. */
3583 block
= sym
->sy_tc
.within
;
3584 csect
= block
->sy_tc
.within
;
3585 resolve_symbol_value (csect
);
3586 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
3588 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
3589 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
3591 /* We want the value to be a file offset into the line numbers.
3592 BFD will do that for us if we set the right flags. We have
3593 already set the value correctly. */
3594 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
3600 /* Set the VMA for a section. This is called on all the sections in
3604 ppc_frob_section (sec
)
3607 static bfd_size_type vma
= 0;
3609 bfd_set_section_vma (stdoutput
, sec
, vma
);
3610 vma
+= bfd_section_size (stdoutput
, sec
);
3613 /* Adjust the file by adding a .debug section if needed. */
3618 if (ppc_debug_name_section_size
> 0)
3622 sec
= bfd_make_section (stdoutput
, ".debug");
3623 if (sec
== (asection
*) NULL
3624 || ! bfd_set_section_size (stdoutput
, sec
,
3625 ppc_debug_name_section_size
)
3626 || ! bfd_set_section_flags (stdoutput
, sec
,
3627 SEC_HAS_CONTENTS
| SEC_LOAD
))
3628 as_fatal ("can't make .debug section");
3632 #endif /* OBJ_XCOFF */
3634 /* Turn a string in input_line_pointer into a floating point constant
3635 of type type, and store the appropriate bytes in *litp. The number
3636 of LITTLENUMS emitted is stored in *sizep . An error message is
3637 returned, or NULL on OK. */
3640 md_atof (type
, litp
, sizep
)
3646 LITTLENUM_TYPE words
[4];
3662 return "bad call to md_atof";
3665 t
= atof_ieee (input_line_pointer
, type
, words
);
3667 input_line_pointer
= t
;
3671 if (target_big_endian
)
3673 for (i
= 0; i
< prec
; i
++)
3675 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3681 for (i
= prec
- 1; i
>= 0; i
--)
3683 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3691 /* Write a value out to the object file, using the appropriate
3695 md_number_to_chars (buf
, val
, n
)
3700 if (target_big_endian
)
3701 number_to_chars_bigendian (buf
, val
, n
);
3703 number_to_chars_littleendian (buf
, val
, n
);
3706 /* Align a section (I don't know why this is machine dependent). */
3709 md_section_align (seg
, addr
)
3713 int align
= bfd_get_section_alignment (stdoutput
, seg
);
3715 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
3718 /* We don't have any form of relaxing. */
3721 md_estimate_size_before_relax (fragp
, seg
)
3729 /* Convert a machine dependent frag. We never generate these. */
3732 md_convert_frag (abfd
, sec
, fragp
)
3740 /* We have no need to default values of symbols. */
3744 md_undefined_symbol (name
)
3750 /* Functions concerning relocs. */
3752 /* The location from which a PC relative jump should be calculated,
3753 given a PC relative reloc. */
3756 md_pcrel_from_section (fixp
, sec
)
3761 if (fixp
->fx_addsy
!= (symbolS
*) NULL
3762 && (! S_IS_DEFINED (fixp
->fx_addsy
)
3763 || TC_FORCE_RELOCATION_SECTION (fixp
, sec
)))
3767 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3772 /* This is called to see whether a fixup should be adjusted to use a
3773 section symbol. We take the opportunity to change a fixup against
3774 a symbol in the TOC subsegment into a reloc against the
3775 corresponding .tc symbol. */
3778 ppc_fix_adjustable (fix
)
3783 resolve_symbol_value (fix
->fx_addsy
);
3784 val
= S_GET_VALUE (fix
->fx_addsy
);
3785 if (ppc_toc_csect
!= (symbolS
*) NULL
3786 && fix
->fx_addsy
!= (symbolS
*) NULL
3787 && fix
->fx_addsy
!= ppc_toc_csect
3788 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
3789 && val
>= ppc_toc_frag
->fr_address
3790 && (ppc_after_toc_frag
== (fragS
*) NULL
3791 || val
< ppc_after_toc_frag
->fr_address
))
3795 for (sy
= symbol_next (ppc_toc_csect
);
3796 sy
!= (symbolS
*) NULL
;
3797 sy
= symbol_next (sy
))
3799 if (sy
->sy_tc
.class == XMC_TC0
)
3801 if (sy
->sy_tc
.class != XMC_TC
)
3803 resolve_symbol_value (sy
);
3804 if (val
== S_GET_VALUE (sy
))
3807 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
3812 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3813 "symbol in .toc does not match any .tc");
3816 /* Possibly adjust the reloc to be against the csect. */
3817 if (fix
->fx_addsy
!= (symbolS
*) NULL
3818 && fix
->fx_addsy
->sy_tc
.subseg
== 0
3819 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
3820 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
3821 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
3825 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
3826 csect
= ppc_text_csects
;
3827 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
3828 csect
= ppc_data_csects
;
3832 /* Skip the initial dummy symbol. */
3833 csect
= csect
->sy_tc
.next
;
3835 if (csect
!= (symbolS
*) NULL
)
3837 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
3838 && (csect
->sy_tc
.next
->sy_frag
->fr_address
3839 <= fix
->fx_addsy
->sy_frag
->fr_address
))
3840 csect
= csect
->sy_tc
.next
;
3842 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3843 - csect
->sy_frag
->fr_address
);
3844 fix
->fx_addsy
= csect
;
3848 /* Adjust a reloc against a .lcomm symbol to be against the base
3850 if (fix
->fx_addsy
!= (symbolS
*) NULL
3851 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
3852 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
3854 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
3855 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3856 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
3857 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
3865 /* See whether a symbol is in the TOC section. */
3868 ppc_is_toc_sym (sym
)
3872 return sym
->sy_tc
.class == XMC_TC
;
3874 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
3878 /* Apply a fixup to the object code. This is called for all the
3879 fixups we generated by the call to fix_new_exp, above. In the call
3880 above we used a reloc code which was the largest legal reloc code
3881 plus the operand index. Here we undo that to recover the operand
3882 index. At this point all symbol values should be fully resolved,
3883 and we attempt to completely resolve the reloc. If we can not do
3884 that, we determine the correct reloc code and put it back in the
3888 md_apply_fix3 (fixp
, valuep
, seg
)
3895 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
3896 the symbol values. Since we are using BFD_ASSEMBLER, if we are
3897 doing this relocation the code in write.c is going to call
3898 bfd_perform_relocation, which is also going to use the symbol
3899 value. That means that if the reloc is fully resolved we want to
3900 use *valuep since bfd_perform_relocation is not being used.
3901 However, if the reloc is not fully resolved we do not want to use
3902 *valuep, and must use fx_offset instead. However, if the reloc
3903 is PC relative, we do want to use *valuep since it includes the
3904 result of md_pcrel_from. This is confusing. */
3906 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
3911 else if (fixp
->fx_pcrel
)
3915 value
= fixp
->fx_offset
;
3916 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
3918 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
3919 value
-= S_GET_VALUE (fixp
->fx_subsy
);
3922 /* We can't actually support subtracting a symbol. */
3923 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3924 "expression too complex");
3929 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
3932 const struct powerpc_operand
*operand
;
3936 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
3938 operand
= &powerpc_operands
[opindex
];
3941 /* It appears that an instruction like
3943 when LC..1 is not a TOC symbol does not generate a reloc. It
3944 uses the offset of LC..1 within its csect. However, .long
3945 LC..1 will generate a reloc. I can't find any documentation
3946 on how these cases are to be distinguished, so this is a wild
3947 guess. These cases are generated by gcc -mminimal-toc. */
3948 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
3949 && operand
->bits
== 16
3950 && operand
->shift
== 0
3951 && operand
->insert
== NULL
3952 && fixp
->fx_addsy
!= NULL
3953 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
3954 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
3955 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
3956 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
3958 value
= fixp
->fx_offset
;
3963 /* Fetch the instruction, insert the fully resolved operand
3964 value, and stuff the instruction back again. */
3965 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
3966 if (target_big_endian
)
3967 insn
= bfd_getb32 ((unsigned char *) where
);
3969 insn
= bfd_getl32 ((unsigned char *) where
);
3970 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
3971 fixp
->fx_file
, fixp
->fx_line
);
3972 if (target_big_endian
)
3973 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
3975 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
3979 /* Nothing else to do here. */
3983 /* Determine a BFD reloc value based on the operand information.
3984 We are only prepared to turn a few of the operands into
3986 FIXME: We need to handle the DS field at the very least.
3987 FIXME: Selecting the reloc type is a bit haphazard; perhaps
3988 there should be a new field in the operand table. */
3989 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3990 && operand
->bits
== 26
3991 && operand
->shift
== 0)
3992 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
3993 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3994 && operand
->bits
== 16
3995 && operand
->shift
== 0)
3996 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
3997 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3998 && operand
->bits
== 26
3999 && operand
->shift
== 0)
4000 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
4001 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4002 && operand
->bits
== 16
4003 && operand
->shift
== 0)
4004 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4005 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4006 && operand
->bits
== 16
4007 && operand
->shift
== 0
4008 && operand
->insert
== NULL
4009 && fixp
->fx_addsy
!= NULL
4010 && ppc_is_toc_sym (fixp
->fx_addsy
))
4013 if (target_big_endian
)
4014 fixp
->fx_where
+= 2;
4015 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4019 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4020 "unresolved expression that must be resolved");
4028 ppc_elf_validate_fix (fixp
, seg
);
4030 switch (fixp
->fx_r_type
)
4033 case BFD_RELOC_CTOR
:
4036 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4037 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4038 } /* fall through */
4040 case BFD_RELOC_32_PCREL
:
4041 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4045 case BFD_RELOC_LO16
:
4046 case BFD_RELOC_HI16
:
4047 case BFD_RELOC_HI16_S
:
4048 case BFD_RELOC_PPC_TOC16
:
4050 case BFD_RELOC_GPREL16
:
4051 case BFD_RELOC_16_GOT_PCREL
:
4055 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4063 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4073 fixp
->fx_addnumber
= value
;
4075 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4076 fixp
->fx_addnumber
= 0;
4080 fixp
->fx_addnumber
= 0;
4082 /* We want to use the offset within the data segment of the
4083 symbol, not the actual VMA of the symbol. */
4084 fixp
->fx_addnumber
=
4085 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4093 /* Generate a reloc for a fixup. */
4096 tc_gen_reloc (seg
, fixp
)
4102 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4104 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4105 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4106 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4107 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4109 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4110 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4113 reloc
->addend
= fixp
->fx_addnumber
;