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. FIXME: We
565 ignore the option for now, but we should really use it to permit
566 instructions defined on the 601 that are not part of the standard
567 PowerPC architecture (mostly holdovers from the POWER). */
568 else if (strcmp (arg
, "601") == 0)
569 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
570 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
571 Motorola PowerPC 603/604. */
572 else if (strcmp (arg
, "ppc") == 0
573 || strcmp (arg
, "ppc32") == 0
574 || strcmp (arg
, "403") == 0
575 || strcmp (arg
, "603") == 0
576 || strcmp (arg
, "604") == 0)
577 ppc_cpu
= PPC_OPCODE_PPC
;
578 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
580 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
582 ppc_cpu
= PPC_OPCODE_PPC
;
583 ppc_size
= PPC_OPCODE_64
;
585 /* -mcom means assemble for the common intersection between Power
586 and PowerPC. At preseent, we just allow the union, rather
587 than the intersection. */
588 else if (strcmp (arg
, "com") == 0)
589 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_PPC
;
590 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
591 else if (strcmp (arg
, "any") == 0)
592 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_PPC
;
595 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
596 else if (strcmp (arg
, "relocatable") == 0)
599 ppc_flags
|= EF_PPC_RELOCATABLE
;
602 else if (strcmp (arg
, "relocatable-lib") == 0)
605 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
608 /* -memb, set embedded bit */
609 else if (strcmp (arg
, "emb") == 0)
610 ppc_flags
|= EF_PPC_EMB
;
612 /* -mlittle/-mbig set the endianess */
613 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
615 target_big_endian
= 0;
616 set_target_endian
= 1;
619 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
621 target_big_endian
= 1;
622 set_target_endian
= 1;
627 as_bad ("invalid switch -m%s", arg
);
633 /* -V: SVR4 argument to print version ID. */
638 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
639 should be emitted or not. FIXME: Not implemented. */
652 md_show_usage (stream
)
658 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
659 -mpwr generate code for IBM POWER (RIOS1)\n\
660 -m601 generate code for Motorola PowerPC 601\n\
661 -mppc, -mppc32, -m403, -m603, -m604\n\
662 generate code for Motorola PowerPC 603/604\n\
663 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
664 -mcom generate code Power/PowerPC common instructions\n
665 -many generate code for any architecture (PWR/PWRX/PPC)\n");
668 -mrelocatable support for GCC's -mrelocatble option\n\
669 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
670 -memb set PPC_EMB bit in ELF flags\n\
671 -mlittle, -mlittle-endian\n\
672 generate code for a little endian machine\n\
673 -mbig, -mbig-endian generate code for a big endian machine\n\
674 -V print assembler version number\n\
675 -Qy, -Qn ignored\n");
679 /* Set ppc_cpu if it is not already set. */
684 const char *default_cpu
= TARGET_CPU
;
688 if (strcmp (default_cpu
, "rs6000") == 0)
689 ppc_cpu
= PPC_OPCODE_POWER
;
690 else if (strcmp (default_cpu
, "powerpc") == 0
691 || strcmp (default_cpu
, "powerpcle") == 0)
692 ppc_cpu
= PPC_OPCODE_PPC
;
694 as_fatal ("Unknown default cpu = %s", default_cpu
);
698 /* Figure out the BFD architecture to use. */
700 enum bfd_architecture
705 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
706 return bfd_arch_powerpc
;
707 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
708 return bfd_arch_rs6000
;
711 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
712 return bfd_arch_unknown
;
716 /* This function is called when the assembler starts up. It is called
717 after the options have been parsed and the output file has been
723 register const struct powerpc_opcode
*op
;
724 const struct powerpc_opcode
*op_end
;
725 const struct powerpc_macro
*macro
;
726 const struct powerpc_macro
*macro_end
;
731 /* Set the ELF flags if desired. */
733 bfd_set_private_flags (stdoutput
, ppc_flags
);
736 /* Insert the opcodes into a hash table. */
737 ppc_hash
= hash_new ();
739 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
740 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
742 know ((op
->opcode
& op
->mask
) == op
->opcode
);
744 if ((op
->flags
& ppc_cpu
) != 0
745 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
746 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
750 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
751 if (retval
!= (const char *) NULL
)
753 /* We permit a duplication of the mfdec instruction on
754 the 601, because it seems to have one value on the
755 601 and a different value on other PowerPC
756 processors. It's easier to permit a duplication than
757 to define a new instruction type flag. When using
758 -many, the comparison instructions are a harmless
760 if (strcmp (retval
, "exists") != 0
761 || (((ppc_cpu
& PPC_OPCODE_601
) == 0
762 || strcmp (op
->name
, "mfdec") != 0)
763 && (ppc_cpu
!= (PPC_OPCODE_POWER
766 || (strcmp (op
->name
, "cmpli") != 0
767 && strcmp (op
->name
, "cmpi") != 0
768 && strcmp (op
->name
, "cmp") != 0
769 && strcmp (op
->name
, "cmpl") != 0))))
775 /* Insert the macros into a hash table. */
776 ppc_macro_hash
= hash_new ();
778 macro_end
= powerpc_macros
+ powerpc_num_macros
;
779 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
781 if ((macro
->flags
& ppc_cpu
) != 0)
785 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
786 if (retval
!= (const char *) NULL
)
791 /* Tell the main code what the endianness is if it is not overidden by the user. */
792 if (!set_target_endian
)
794 set_target_endian
= 1;
795 target_big_endian
= PPC_BIG_ENDIAN
;
799 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
801 /* Create dummy symbols to serve as initial csects. This forces the
802 text csects to precede the data csects. These symbols will not
804 ppc_text_csects
= symbol_make ("dummy\001");
805 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
806 ppc_data_csects
= symbol_make ("dummy\001");
807 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
812 ppc_current_section
= text_section
;
813 ppc_previous_section
= 0;
818 /* Insert an operand value into an instruction. */
821 ppc_insert_operand (insn
, operand
, val
, file
, line
)
823 const struct powerpc_operand
*operand
;
828 if (operand
->bits
!= 32)
833 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
835 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
836 && ppc_size
== PPC_OPCODE_32
)
837 max
= (1 << operand
->bits
) - 1;
839 max
= (1 << (operand
->bits
- 1)) - 1;
840 min
= - (1 << (operand
->bits
- 1));
844 max
= (1 << operand
->bits
) - 1;
848 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
853 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
856 "operand out of range (%s not between %ld and %ld)";
859 sprint_value (buf
, test
);
860 if (file
== (char *) NULL
)
861 as_warn (err
, buf
, min
, max
);
863 as_warn_where (file
, line
, err
, buf
, min
, max
);
872 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
873 if (errmsg
!= (const char *) NULL
)
877 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
884 /* Parse @got, etc. and return the desired relocation. */
885 static bfd_reloc_code_real_type
886 ppc_elf_suffix (str_p
)
892 bfd_reloc_code_real_type reloc
;
902 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
904 static struct map_bfd mapping
[] = {
905 MAP ("got", BFD_RELOC_PPC_TOC16
),
906 MAP ("l", BFD_RELOC_LO16
),
907 MAP ("h", BFD_RELOC_HI16
),
908 MAP ("ha", BFD_RELOC_HI16_S
),
909 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
910 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
911 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
912 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
913 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
914 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
915 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
916 MAP ("copy", BFD_RELOC_PPC_COPY
),
917 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
918 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
919 MAP ("plt", BFD_RELOC_32_PLTOFF
),
920 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
921 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
922 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
923 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
924 MAP ("sdarel", BFD_RELOC_GPREL16
),
925 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
926 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
927 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
928 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
930 { (char *)0, 0, BFD_RELOC_UNUSED
}
934 return BFD_RELOC_UNUSED
;
936 for (ch
= *str
, str2
= ident
;
937 str2
< ident
+ sizeof(ident
) - 1 && isalnum (ch
) || ch
== '@';
940 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
947 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
948 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
954 return BFD_RELOC_UNUSED
;
957 /* Like normal .long/.short/.word, except support @got, etc. */
958 /* clobbers input_line_pointer, checks */
961 ppc_elf_cons (nbytes
)
962 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
965 bfd_reloc_code_real_type reloc
;
967 if (is_it_end_of_statement ())
969 demand_empty_rest_of_line ();
976 if (exp
.X_op
== O_symbol
977 && *input_line_pointer
== '@'
978 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
980 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
981 int size
= bfd_get_reloc_size (reloc_howto
);
984 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
988 register char *p
= frag_more ((int) nbytes
);
989 int offset
= nbytes
- size
;
991 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
995 emit_expr (&exp
, (unsigned int) nbytes
);
997 while (*input_line_pointer
++ == ',');
999 input_line_pointer
--; /* Put terminator back into stream. */
1000 demand_empty_rest_of_line ();
1003 /* Validate any relocations emitted for -mrelocatable, possibly adding
1004 fixups for word relocations in writable segments, so we can adjust
1007 ppc_elf_validate_fix (fixp
, seg
)
1014 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1015 && strcmp (segment_name (seg
), ".got2") != 0
1016 && strcmp (segment_name (seg
), ".dtors") != 0
1017 && strcmp (segment_name (seg
), ".ctors") != 0
1018 && strcmp (segment_name (seg
), ".fixup") != 0
1019 && strcmp (segment_name (seg
), ".stab") != 0)
1021 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1022 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1024 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
1025 "Relocation cannot be done when using -mrelocatable");
1030 #endif /* OBJ_ELF */
1034 * Summary of register_name().
1036 * in: Input_line_pointer points to 1st char of operand.
1038 * out: A expressionS.
1039 * The operand may have been a register: in this case, X_op == O_register,
1040 * X_add_number is set to the register number, and truth is returned.
1041 * Input_line_pointer->(next non-blank) char after operand, or is in its
1046 register_name (expressionP
)
1047 expressionS
*expressionP
;
1053 /* Find the spelling of the operand */
1054 name
= input_line_pointer
;
1055 c
= get_symbol_end ();
1056 reg_number
= reg_name_search (name
);
1058 /* look to see if it's in the register table */
1059 if (reg_number
>= 0)
1061 expressionP
->X_op
= O_register
;
1062 expressionP
->X_add_number
= reg_number
;
1064 /* make the rest nice */
1065 expressionP
->X_add_symbol
= NULL
;
1066 expressionP
->X_op_symbol
= NULL
;
1067 *input_line_pointer
= c
; /* put back the delimiting char */
1072 /* reset the line as if we had not done anything */
1073 *input_line_pointer
= c
; /* put back the delimiting char */
1074 input_line_pointer
= name
; /* reset input_line pointer */
1080 * Summary of parse_toc_entry().
1082 * in: Input_line_pointer points to the '[' in one of:
1084 * [toc] [tocv] [toc32] [toc64]
1086 * Anything else is an error of one kind or another.
1089 * return value: success or failure
1090 * toc_kind: kind of toc reference
1091 * input_line_pointer:
1092 * success: first char after the ']'
1093 * failure: unchanged
1097 * [toc] - rv == success, toc_kind = default_toc
1098 * [tocv] - rv == success, toc_kind = data_in_toc
1099 * [toc32] - rv == success, toc_kind = must_be_32
1100 * [toc64] - rv == success, toc_kind = must_be_64
1104 enum toc_size_qualifier
1106 default_toc
, /* The toc cell constructed should be the system default size */
1107 data_in_toc
, /* This is a direct reference to a toc cell */
1108 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1109 must_be_64
/* The toc cell constructed must be 64 bits wide */
1113 parse_toc_entry(toc_kind
)
1114 enum toc_size_qualifier
*toc_kind
;
1119 enum toc_size_qualifier t
;
1121 /* save the input_line_pointer */
1122 start
= input_line_pointer
;
1124 /* skip over the '[' , and whitespace */
1125 ++input_line_pointer
;
1128 /* find the spelling of the operand */
1129 toc_spec
= input_line_pointer
;
1130 c
= get_symbol_end ();
1132 if (strcmp(toc_spec
, "toc") == 0)
1136 else if (strcmp(toc_spec
, "tocv") == 0)
1140 else if (strcmp(toc_spec
, "toc32") == 0)
1144 else if (strcmp(toc_spec
, "toc64") == 0)
1150 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1151 *input_line_pointer
= c
; /* put back the delimiting char */
1152 input_line_pointer
= start
; /* reset input_line pointer */
1156 /* now find the ']' */
1157 *input_line_pointer
= c
; /* put back the delimiting char */
1159 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1160 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1164 as_bad ("syntax error: expected `]', found `%c'", c
);
1165 input_line_pointer
= start
; /* reset input_line pointer */
1169 *toc_kind
= t
; /* set return value */
1176 /* We need to keep a list of fixups. We can't simply generate them as
1177 we go, because that would require us to first create the frag, and
1178 that would screw up references to ``.''. */
1184 bfd_reloc_code_real_type reloc
;
1187 #define MAX_INSN_FIXUPS (5)
1189 /* This routine is called for each instruction to be assembled. */
1196 const struct powerpc_opcode
*opcode
;
1198 const unsigned char *opindex_ptr
;
1202 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1207 bfd_reloc_code_real_type reloc
;
1210 /* Get the opcode. */
1211 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1216 /* Look up the opcode in the hash table. */
1217 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1218 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1220 const struct powerpc_macro
*macro
;
1222 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1223 if (macro
== (const struct powerpc_macro
*) NULL
)
1224 as_bad ("Unrecognized opcode: `%s'", str
);
1226 ppc_macro (s
, macro
);
1231 insn
= opcode
->opcode
;
1234 while (isspace (*str
))
1237 /* PowerPC operands are just expressions. The only real issue is
1238 that a few operand types are optional. All cases which might use
1239 an optional operand separate the operands only with commas (in
1240 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1241 cases never have optional operands). There is never more than
1242 one optional operand for an instruction. So, before we start
1243 seriously parsing the operands, we check to see if we have an
1244 optional operand, and, if we do, we count the number of commas to
1245 see whether the operand should be omitted. */
1247 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1249 const struct powerpc_operand
*operand
;
1251 operand
= &powerpc_operands
[*opindex_ptr
];
1252 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1254 unsigned int opcount
;
1256 /* There is an optional operand. Count the number of
1257 commas in the input line. */
1264 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1271 /* If there are fewer operands in the line then are called
1272 for by the instruction, we want to skip the optional
1274 if (opcount
< strlen (opcode
->operands
))
1281 /* Gather the operands. */
1285 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1287 const struct powerpc_operand
*operand
;
1293 if (next_opindex
== 0)
1294 operand
= &powerpc_operands
[*opindex_ptr
];
1297 operand
= &powerpc_operands
[next_opindex
];
1303 /* If this is a fake operand, then we do not expect anything
1305 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1307 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1308 if (errmsg
!= (const char *) NULL
)
1313 /* If this is an optional operand, and we are skipping it, just
1315 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1318 if (operand
->insert
)
1320 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1321 if (errmsg
!= (const char *) NULL
)
1324 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1325 next_opindex
= *opindex_ptr
+ 1;
1329 /* Gather the operand. */
1330 hold
= input_line_pointer
;
1331 input_line_pointer
= str
;
1334 if (*input_line_pointer
== '[')
1336 /* We are expecting something like the second argument here:
1338 lwz r4,[toc].GS.0.static_int(rtoc)
1339 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1340 The argument following the `]' must be a symbol name, and the
1341 register must be the toc register: 'rtoc' or '2'
1343 The effect is to 0 as the displacement field
1344 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1345 the appropriate variation) reloc against it based on the symbol.
1346 The linker will build the toc, and insert the resolved toc offset.
1349 o The size of the toc entry is currently assumed to be
1350 32 bits. This should not be assumed to be a hard coded
1352 o In an effort to cope with a change from 32 to 64 bits,
1353 there are also toc entries that are specified to be
1354 either 32 or 64 bits:
1355 lwz r4,[toc32].GS.0.static_int(rtoc)
1356 lwz r4,[toc64].GS.0.static_int(rtoc)
1357 These demand toc entries of the specified size, and the
1358 instruction probably requires it.
1362 enum toc_size_qualifier toc_kind
;
1363 bfd_reloc_code_real_type toc_reloc
;
1365 /* go parse off the [tocXX] part */
1366 valid_toc
= parse_toc_entry(&toc_kind
);
1370 /* Note: message has already been issued. */
1371 /* FIXME: what sort of recovery should we do? */
1372 /* demand_rest_of_line(); return; ? */
1375 /* Now get the symbol following the ']' */
1381 /* In this case, we may not have seen the symbol yet, since */
1382 /* it is allowed to appear on a .extern or .globl or just be */
1383 /* a label in the .data section. */
1384 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1387 /* 1. The symbol must be defined and either in the toc */
1388 /* section, or a global. */
1389 /* 2. The reloc generated must have the TOCDEFN flag set in */
1390 /* upper bit mess of the reloc type. */
1391 /* FIXME: It's a little confusing what the tocv qualifier can */
1392 /* be used for. At the very least, I've seen three */
1393 /* uses, only one of which I'm sure I can explain. */
1394 if (ex
.X_op
== O_symbol
)
1396 assert (ex
.X_add_symbol
!= NULL
);
1397 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1399 as_warn("[tocv] symbol is not a toc symbol");
1403 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1406 /* FIXME: these next two specifically specify 32/64 bit toc */
1407 /* entries. We don't support them today. Is this the */
1408 /* right way to say that? */
1409 toc_reloc
= BFD_RELOC_UNUSED
;
1410 as_bad ("Unimplemented toc32 expression modifier");
1413 /* FIXME: see above */
1414 toc_reloc
= BFD_RELOC_UNUSED
;
1415 as_bad ("Unimplemented toc64 expression modifier");
1419 "Unexpected return value [%d] from parse_toc_entry!\n",
1425 /* We need to generate a fixup for this expression. */
1426 if (fc
>= MAX_INSN_FIXUPS
)
1427 as_fatal ("too many fixups");
1429 fixups
[fc
].reloc
= toc_reloc
;
1430 fixups
[fc
].exp
= ex
;
1431 fixups
[fc
].opindex
= *opindex_ptr
;
1434 /* Ok. We've set up the fixup for the instruction. Now make it
1435 look like the constant 0 was found here */
1437 ex
.X_op
= O_constant
;
1438 ex
.X_add_number
= 0;
1439 ex
.X_add_symbol
= NULL
;
1440 ex
.X_op_symbol
= NULL
;
1444 if (!register_name(&ex
))
1450 str
= input_line_pointer
;
1451 input_line_pointer
= hold
;
1454 str
= input_line_pointer
;
1455 input_line_pointer
= hold
;
1458 if (ex
.X_op
== O_illegal
)
1459 as_bad ("illegal operand");
1460 else if (ex
.X_op
== O_absent
)
1461 as_bad ("missing operand");
1462 else if (ex
.X_op
== O_constant
)
1465 /* Allow @HA, @L, @H on constants. */
1466 char *orig_str
= str
;
1468 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1475 case BFD_RELOC_LO16
:
1476 ex
.X_add_number
= ((ex
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1479 case BFD_RELOC_HI16
:
1480 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1483 case BFD_RELOC_HI16_S
:
1484 ex
.X_add_number
= ((ex
.X_add_number
>> 16) & 0xffff)
1485 + ((ex
.X_add_number
>> 15) & 1);
1489 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1493 else if (ex
.X_op
== O_register
)
1495 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1500 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1502 /* For the absoulte forms of branchs, convert the PC relative form back into
1504 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1507 case BFD_RELOC_PPC_B26
: reloc
= BFD_RELOC_PPC_BA26
; break;
1508 case BFD_RELOC_PPC_B16
: reloc
= BFD_RELOC_PPC_BA16
; break;
1509 case BFD_RELOC_PPC_B16_BRTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
; break;
1510 case BFD_RELOC_PPC_B16_BRNTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
; break;
1513 /* We need to generate a fixup for this expression. */
1514 if (fc
>= MAX_INSN_FIXUPS
)
1515 as_fatal ("too many fixups");
1516 fixups
[fc
].exp
= ex
;
1517 fixups
[fc
].opindex
= 0;
1518 fixups
[fc
].reloc
= reloc
;
1521 #endif /* OBJ_ELF */
1525 /* We need to generate a fixup for this expression. */
1526 if (fc
>= MAX_INSN_FIXUPS
)
1527 as_fatal ("too many fixups");
1528 fixups
[fc
].exp
= ex
;
1529 fixups
[fc
].opindex
= *opindex_ptr
;
1530 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1539 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1547 /* The call to expression should have advanced str past any
1550 && (endc
!= ',' || *str
!= '\0'))
1552 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1560 while (isspace (*str
))
1564 as_bad ("junk at end of line: `%s'", str
);
1566 /* Write out the instruction. */
1568 md_number_to_chars (f
, insn
, 4);
1570 /* Create any fixups. At this point we do not use a
1571 bfd_reloc_code_real_type, but instead just use the
1572 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1573 handle fixups for any operand type, although that is admittedly
1574 not a very exciting feature. We pick a BFD reloc type in
1576 for (i
= 0; i
< fc
; i
++)
1578 const struct powerpc_operand
*operand
;
1580 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1581 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1583 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1591 size
= bfd_get_reloc_size (reloc_howto
);
1592 offset
= target_big_endian
? (4 - size
) : 0;
1594 if (size
< 1 || size
> 4)
1597 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1598 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1601 /* Turn off complaints that the addend is too large for things like
1603 switch (fixups
[i
].reloc
)
1605 case BFD_RELOC_LO16
:
1606 case BFD_RELOC_HI16
:
1607 case BFD_RELOC_HI16_S
:
1608 fixP
->fx_no_overflow
= 1;
1615 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1617 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1618 ((bfd_reloc_code_real_type
)
1619 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1623 #ifndef WORKING_DOT_WORD
1624 /* Handle long and short jumps */
1626 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1628 addressT from_addr
, to_addr
;
1636 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1638 addressT from_addr
, to_addr
;
1646 /* Handle a macro. Gather all the operands, transform them as
1647 described by the macro, and call md_assemble recursively. All the
1648 operands are separated by commas; we don't accept parentheses
1649 around operands here. */
1652 ppc_macro (str
, macro
)
1654 const struct powerpc_macro
*macro
;
1665 /* Gather the users operands into the operands array. */
1670 if (count
>= sizeof operands
/ sizeof operands
[0])
1672 operands
[count
++] = s
;
1673 s
= strchr (s
, ',');
1674 if (s
== (char *) NULL
)
1679 if (count
!= macro
->operands
)
1681 as_bad ("wrong number of operands");
1685 /* Work out how large the string must be (the size is unbounded
1686 because it includes user input). */
1688 format
= macro
->format
;
1689 while (*format
!= '\0')
1698 arg
= strtol (format
+ 1, &send
, 10);
1699 know (send
!= format
&& arg
>= 0 && arg
< count
);
1700 len
+= strlen (operands
[arg
]);
1705 /* Put the string together. */
1706 complete
= s
= (char *) alloca (len
+ 1);
1707 format
= macro
->format
;
1708 while (*format
!= '\0')
1714 arg
= strtol (format
+ 1, &send
, 10);
1715 strcpy (s
, operands
[arg
]);
1722 /* Assemble the constructed instruction. */
1723 md_assemble (complete
);
1726 /* Pseudo-op handling. */
1728 /* The .byte pseudo-op. This is similar to the normal .byte
1729 pseudo-op, but it can also take a single ASCII string. */
1735 if (*input_line_pointer
!= '\"')
1741 /* Gather characters. A real double quote is doubled. Unusual
1742 characters are not permitted. */
1743 ++input_line_pointer
;
1748 c
= *input_line_pointer
++;
1752 if (*input_line_pointer
!= '\"')
1754 ++input_line_pointer
;
1757 FRAG_APPEND_1_CHAR (c
);
1760 demand_empty_rest_of_line ();
1765 /* XCOFF specific pseudo-op handling. */
1767 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1768 symbols in the .bss segment as though they were local common
1769 symbols, and uses a different smclas. */
1775 asection
*current_seg
= now_seg
;
1776 subsegT current_subseg
= now_subseg
;
1782 symbolS
*lcomm_sym
= NULL
;
1786 name
= input_line_pointer
;
1787 endc
= get_symbol_end ();
1788 end_name
= input_line_pointer
;
1791 if (*input_line_pointer
!= ',')
1793 as_bad ("missing size");
1794 ignore_rest_of_line ();
1797 ++input_line_pointer
;
1799 size
= get_absolute_expression ();
1802 as_bad ("negative size");
1803 ignore_rest_of_line ();
1809 /* The third argument to .comm is the alignment. */
1810 if (*input_line_pointer
!= ',')
1814 ++input_line_pointer
;
1815 align
= get_absolute_expression ();
1818 as_warn ("ignoring bad alignment");
1837 /* The third argument to .lcomm appears to be the real local
1838 common symbol to create. References to the symbol named in
1839 the first argument are turned into references to the third
1841 if (*input_line_pointer
!= ',')
1843 as_bad ("missing real symbol name");
1844 ignore_rest_of_line ();
1847 ++input_line_pointer
;
1849 lcomm_name
= input_line_pointer
;
1850 lcomm_endc
= get_symbol_end ();
1852 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1854 *input_line_pointer
= lcomm_endc
;
1858 sym
= symbol_find_or_make (name
);
1861 if (S_IS_DEFINED (sym
)
1862 || S_GET_VALUE (sym
) != 0)
1864 as_bad ("attempt to redefine symbol");
1865 ignore_rest_of_line ();
1869 record_alignment (bss_section
, align
);
1872 || ! S_IS_DEFINED (lcomm_sym
))
1881 S_SET_EXTERNAL (sym
);
1885 lcomm_sym
->sy_tc
.output
= 1;
1886 def_sym
= lcomm_sym
;
1890 subseg_set (bss_section
, 1);
1891 frag_align (align
, 0);
1893 def_sym
->sy_frag
= frag_now
;
1894 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1895 def_size
, (char *) NULL
);
1897 S_SET_SEGMENT (def_sym
, bss_section
);
1898 def_sym
->sy_tc
.align
= align
;
1902 /* Align the size of lcomm_sym. */
1903 lcomm_sym
->sy_frag
->fr_offset
=
1904 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1905 &~ ((1 << align
) - 1));
1906 if (align
> lcomm_sym
->sy_tc
.align
)
1907 lcomm_sym
->sy_tc
.align
= align
;
1912 /* Make sym an offset from lcomm_sym. */
1913 S_SET_SEGMENT (sym
, bss_section
);
1914 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1915 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1916 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1919 subseg_set (current_seg
, current_subseg
);
1921 demand_empty_rest_of_line ();
1924 /* The .csect pseudo-op. This switches us into a different
1925 subsegment. The first argument is a symbol whose value is the
1926 start of the .csect. In COFF, csect symbols get special aux
1927 entries defined by the x_csect field of union internal_auxent. The
1928 optional second argument is the alignment (the default is 2). */
1938 name
= input_line_pointer
;
1939 endc
= get_symbol_end ();
1941 sym
= symbol_find_or_make (name
);
1943 *input_line_pointer
= endc
;
1945 if (S_IS_DEFINED (sym
))
1946 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1953 /* This is a new csect. We need to look at the symbol class to
1954 figure out whether it should go in the text section or the
1957 switch (sym
->sy_tc
.class)
1967 S_SET_SEGMENT (sym
, text_section
);
1968 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1969 ++ppc_text_subsegment
;
1970 list_ptr
= &ppc_text_csects
;
1979 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1981 S_SET_SEGMENT (sym
, data_section
);
1982 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1983 ++ppc_data_subsegment
;
1984 list_ptr
= &ppc_data_csects
;
1990 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1992 ppc_after_toc_frag
= frag_now
;
1994 sym
->sy_frag
= frag_now
;
1995 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1997 sym
->sy_tc
.align
= 2;
1998 sym
->sy_tc
.output
= 1;
1999 sym
->sy_tc
.within
= sym
;
2001 for (list
= *list_ptr
;
2002 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2003 list
= list
->sy_tc
.next
)
2005 list
->sy_tc
.next
= sym
;
2007 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2008 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2011 if (*input_line_pointer
== ',')
2013 ++input_line_pointer
;
2014 sym
->sy_tc
.align
= get_absolute_expression ();
2017 ppc_current_csect
= sym
;
2019 demand_empty_rest_of_line ();
2022 /* The .extern pseudo-op. We create an undefined symbol. */
2031 name
= input_line_pointer
;
2032 endc
= get_symbol_end ();
2034 (void) symbol_find_or_make (name
);
2036 *input_line_pointer
= endc
;
2038 demand_empty_rest_of_line ();
2041 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
2042 this because it can't handle undefined symbols. I think we can
2052 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2053 although I don't know why it bothers. */
2064 name
= input_line_pointer
;
2065 endc
= get_symbol_end ();
2067 sym
= symbol_find_or_make (name
);
2069 *input_line_pointer
= endc
;
2071 if (*input_line_pointer
!= ',')
2073 as_bad ("missing rename string");
2074 ignore_rest_of_line ();
2077 ++input_line_pointer
;
2079 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2081 demand_empty_rest_of_line ();
2084 /* The .stabx pseudo-op. This is similar to a normal .stabs
2085 pseudo-op, but slightly different. A sample is
2086 .stabx "main:F-1",.main,142,0
2087 The first argument is the symbol name to create. The second is the
2088 value, and the third is the storage class. The fourth seems to be
2089 always zero, and I am assuming it is the type. */
2100 name
= demand_copy_C_string (&len
);
2102 if (*input_line_pointer
!= ',')
2104 as_bad ("missing value");
2107 ++input_line_pointer
;
2109 sym
= symbol_make (name
);
2111 (void) expression (&exp
);
2118 as_bad ("illegal .stabx expression; zero assumed");
2119 exp
.X_add_number
= 0;
2122 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2123 sym
->sy_frag
= &zero_address_frag
;
2127 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2128 sym
->sy_value
= exp
;
2132 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2133 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2138 /* The value is some complex expression. This will probably
2139 fail at some later point, but this is probably the right
2140 thing to do here. */
2141 sym
->sy_value
= exp
;
2145 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2146 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2148 if (*input_line_pointer
!= ',')
2150 as_bad ("missing class");
2153 ++input_line_pointer
;
2155 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2157 if (*input_line_pointer
!= ',')
2159 as_bad ("missing type");
2162 ++input_line_pointer
;
2164 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2166 sym
->sy_tc
.output
= 1;
2168 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2169 sym
->sy_tc
.within
= ppc_current_block
;
2171 if (exp
.X_op
!= O_symbol
2172 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2173 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2174 ppc_frob_label (sym
);
2177 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2178 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2179 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2180 ppc_current_csect
->sy_tc
.within
= sym
;
2183 if (strlen (name
) > SYMNMLEN
)
2185 /* For some reason, each name is preceded by a two byte length
2186 and followed by a null byte. */
2187 ppc_debug_name_section_size
+= strlen (name
) + 3;
2190 demand_empty_rest_of_line ();
2193 /* The .function pseudo-op. This takes several arguments. The first
2194 argument seems to be the external name of the symbol. The second
2195 argment seems to be the label for the start of the function. gcc
2196 uses the same name for both. I have no idea what the third and
2197 fourth arguments are meant to be. The optional fifth argument is
2198 an expression for the size of the function. In COFF this symbol
2199 gets an aux entry like that used for a csect. */
2202 ppc_function (ignore
)
2211 name
= input_line_pointer
;
2212 endc
= get_symbol_end ();
2214 /* Ignore any [PR] suffix. */
2215 name
= ppc_canonicalize_symbol_name (name
);
2216 s
= strchr (name
, '[');
2217 if (s
!= (char *) NULL
2218 && strcmp (s
+ 1, "PR]") == 0)
2221 ext_sym
= symbol_find_or_make (name
);
2223 *input_line_pointer
= endc
;
2225 if (*input_line_pointer
!= ',')
2227 as_bad ("missing symbol name");
2228 ignore_rest_of_line ();
2231 ++input_line_pointer
;
2233 name
= input_line_pointer
;
2234 endc
= get_symbol_end ();
2236 lab_sym
= symbol_find_or_make (name
);
2238 *input_line_pointer
= endc
;
2240 if (ext_sym
!= lab_sym
)
2242 ext_sym
->sy_value
.X_op
= O_symbol
;
2243 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2244 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2245 ext_sym
->sy_value
.X_add_number
= 0;
2248 if (ext_sym
->sy_tc
.class == -1)
2249 ext_sym
->sy_tc
.class = XMC_PR
;
2250 ext_sym
->sy_tc
.output
= 1;
2252 if (*input_line_pointer
== ',')
2256 /* Ignore the third argument. */
2257 ++input_line_pointer
;
2258 expression (&ignore
);
2259 if (*input_line_pointer
== ',')
2261 /* Ignore the fourth argument. */
2262 ++input_line_pointer
;
2263 expression (&ignore
);
2264 if (*input_line_pointer
== ',')
2266 /* The fifth argument is the function size. */
2267 ++input_line_pointer
;
2268 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2271 &zero_address_frag
);
2272 pseudo_set (ext_sym
->sy_tc
.size
);
2277 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2278 SF_SET_FUNCTION (ext_sym
);
2279 SF_SET_PROCESS (ext_sym
);
2280 coff_add_linesym (ext_sym
);
2282 demand_empty_rest_of_line ();
2285 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2294 sym
= symbol_make (".bf");
2295 S_SET_SEGMENT (sym
, text_section
);
2296 sym
->sy_frag
= frag_now
;
2297 S_SET_VALUE (sym
, frag_now_fix ());
2298 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2300 coff_line_base
= get_absolute_expression ();
2302 S_SET_NUMBER_AUXILIARY (sym
, 1);
2303 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2305 sym
->sy_tc
.output
= 1;
2307 ppc_frob_label (sym
);
2309 demand_empty_rest_of_line ();
2312 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2313 ".ef", except that the line number is absolute, not relative to the
2314 most recent ".bf" symbol. */
2322 sym
= symbol_make (".ef");
2323 S_SET_SEGMENT (sym
, text_section
);
2324 sym
->sy_frag
= frag_now
;
2325 S_SET_VALUE (sym
, frag_now_fix ());
2326 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2327 S_SET_NUMBER_AUXILIARY (sym
, 1);
2328 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2329 sym
->sy_tc
.output
= 1;
2331 ppc_frob_label (sym
);
2333 demand_empty_rest_of_line ();
2336 /* The .bi and .ei pseudo-ops. These take a string argument and
2337 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2349 name
= demand_copy_C_string (&len
);
2351 /* The value of these symbols is actually file offset. Here we set
2352 the value to the index into the line number entries. In
2353 ppc_frob_symbols we set the fix_line field, which will cause BFD
2354 to do the right thing. */
2356 sym
= symbol_make (name
);
2357 S_SET_SEGMENT (sym
, now_seg
);
2358 S_SET_VALUE (sym
, coff_n_line_nos
);
2359 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2361 /* obj-coff.c currently only handles line numbers correctly in the
2363 assert (now_seg
== text_section
);
2365 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2366 sym
->sy_tc
.output
= 1;
2368 for (look
= symbol_rootP
;
2369 (look
!= (symbolS
*) NULL
2370 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2371 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2372 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2373 look
= symbol_next (look
))
2375 if (look
!= (symbolS
*) NULL
)
2377 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2378 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2381 demand_empty_rest_of_line ();
2384 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2385 There is one argument, which is a csect symbol. The value of the
2386 .bs symbol is the index of this csect symbol. */
2397 if (ppc_current_block
!= NULL
)
2398 as_bad ("nested .bs blocks");
2400 name
= input_line_pointer
;
2401 endc
= get_symbol_end ();
2403 csect
= symbol_find_or_make (name
);
2405 *input_line_pointer
= endc
;
2407 sym
= symbol_make (".bs");
2408 S_SET_SEGMENT (sym
, now_seg
);
2409 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2410 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2411 sym
->sy_tc
.output
= 1;
2413 sym
->sy_tc
.within
= csect
;
2415 ppc_frob_label (sym
);
2417 ppc_current_block
= sym
;
2419 demand_empty_rest_of_line ();
2422 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2430 if (ppc_current_block
== NULL
)
2431 as_bad (".es without preceding .bs");
2433 sym
= symbol_make (".es");
2434 S_SET_SEGMENT (sym
, now_seg
);
2435 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2436 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2437 sym
->sy_tc
.output
= 1;
2439 ppc_frob_label (sym
);
2441 ppc_current_block
= NULL
;
2443 demand_empty_rest_of_line ();
2446 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2455 sym
= symbol_make (".bb");
2456 S_SET_SEGMENT (sym
, text_section
);
2457 sym
->sy_frag
= frag_now
;
2458 S_SET_VALUE (sym
, frag_now_fix ());
2459 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2461 S_SET_NUMBER_AUXILIARY (sym
, 1);
2462 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2464 sym
->sy_tc
.output
= 1;
2466 ppc_frob_label (sym
);
2468 demand_empty_rest_of_line ();
2471 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2480 sym
= symbol_make (".eb");
2481 S_SET_SEGMENT (sym
, text_section
);
2482 sym
->sy_frag
= frag_now
;
2483 S_SET_VALUE (sym
, frag_now_fix ());
2484 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2485 S_SET_NUMBER_AUXILIARY (sym
, 1);
2486 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2487 sym
->sy_tc
.output
= 1;
2489 ppc_frob_label (sym
);
2491 demand_empty_rest_of_line ();
2494 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2500 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2501 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2508 subseg
= ppc_data_subsegment
;
2509 ++ppc_data_subsegment
;
2511 subseg_new (segment_name (data_section
), subseg
);
2512 ppc_toc_frag
= frag_now
;
2514 sym
= symbol_find_or_make ("TOC[TC0]");
2515 sym
->sy_frag
= frag_now
;
2516 S_SET_SEGMENT (sym
, data_section
);
2517 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2518 sym
->sy_tc
.subseg
= subseg
;
2519 sym
->sy_tc
.output
= 1;
2520 sym
->sy_tc
.within
= sym
;
2522 ppc_toc_csect
= sym
;
2524 for (list
= ppc_data_csects
;
2525 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2526 list
= list
->sy_tc
.next
)
2528 list
->sy_tc
.next
= sym
;
2530 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2531 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2534 ppc_current_csect
= ppc_toc_csect
;
2536 demand_empty_rest_of_line ();
2539 #endif /* OBJ_XCOFF */
2541 /* The .tc pseudo-op. This is used when generating either XCOFF or
2542 ELF. This takes two or more arguments.
2544 When generating XCOFF output, the first argument is the name to
2545 give to this location in the toc; this will be a symbol with class
2546 TC. The rest of the arguments are 4 byte values to actually put at
2547 this location in the TOC; often there is just one more argument, a
2548 relocateable symbol reference.
2550 When not generating XCOFF output, the arguments are the same, but
2551 the first argument is simply ignored. */
2559 /* Define the TOC symbol name. */
2565 if (ppc_toc_csect
== (symbolS
*) NULL
2566 || ppc_toc_csect
!= ppc_current_csect
)
2568 as_bad (".tc not in .toc section");
2569 ignore_rest_of_line ();
2573 name
= input_line_pointer
;
2574 endc
= get_symbol_end ();
2576 sym
= symbol_find_or_make (name
);
2578 *input_line_pointer
= endc
;
2580 if (S_IS_DEFINED (sym
))
2584 label
= ppc_current_csect
->sy_tc
.within
;
2585 if (label
->sy_tc
.class != XMC_TC0
)
2587 as_warn (".tc with no label");
2588 ignore_rest_of_line ();
2592 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
2593 label
->sy_frag
= sym
->sy_frag
;
2594 S_SET_VALUE (label
, S_GET_VALUE (sym
));
2596 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2597 ++input_line_pointer
;
2602 S_SET_SEGMENT (sym
, now_seg
);
2603 sym
->sy_frag
= frag_now
;
2604 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2605 sym
->sy_tc
.class = XMC_TC
;
2606 sym
->sy_tc
.output
= 1;
2608 ppc_frob_label (sym
);
2611 #else /* ! defined (OBJ_XCOFF) */
2613 /* Skip the TOC symbol name. */
2614 while (is_part_of_name (*input_line_pointer
)
2615 || *input_line_pointer
== '['
2616 || *input_line_pointer
== ']'
2617 || *input_line_pointer
== '{'
2618 || *input_line_pointer
== '}')
2619 ++input_line_pointer
;
2621 /* Align to a four byte boundary. */
2623 record_alignment (now_seg
, 2);
2625 #endif /* ! defined (OBJ_XCOFF) */
2627 if (*input_line_pointer
!= ',')
2628 demand_empty_rest_of_line ();
2631 ++input_line_pointer
;
2638 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2640 /* Set the current section. */
2642 ppc_set_current_section (new)
2645 ppc_previous_section
= ppc_current_section
;
2646 ppc_current_section
= new;
2649 /* pseudo-op: .previous
2650 behaviour: toggles the current section with the previous section.
2652 warnings: "No previous section"
2655 ppc_previous(ignore
)
2660 if (ppc_previous_section
== NULL
)
2662 as_warn("No previous section to return to. Directive ignored.");
2666 subseg_set(ppc_previous_section
, 0);
2668 ppc_set_current_section(ppc_previous_section
);
2671 /* pseudo-op: .pdata
2672 behaviour: predefined read only data section
2676 initial: .section .pdata "adr3"
2677 a - don't know -- maybe a misprint
2678 d - initialized data
2680 3 - double word aligned (that would be 4 byte boundary)
2683 Tag index tables (also known as the function table) for exception
2684 handling, debugging, etc.
2691 if (pdata_section
== 0)
2693 pdata_section
= subseg_new (".pdata", 0);
2695 bfd_set_section_flags (stdoutput
, pdata_section
,
2696 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2697 | SEC_READONLY
| SEC_DATA
));
2699 bfd_set_section_alignment (stdoutput
, pdata_section
, 3);
2703 pdata_section
= subseg_new(".pdata", 0);
2705 ppc_set_current_section(pdata_section
);
2708 /* pseudo-op: .ydata
2709 behaviour: predefined read only data section
2713 initial: .section .ydata "drw3"
2714 a - don't know -- maybe a misprint
2715 d - initialized data
2717 3 - double word aligned (that would be 4 byte boundary)
2719 Tag tables (also known as the scope table) for exception handling,
2726 if (ydata_section
== 0)
2728 ydata_section
= subseg_new (".ydata", 0);
2729 bfd_set_section_flags (stdoutput
, ydata_section
,
2730 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2731 | SEC_READONLY
| SEC_DATA
));
2733 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
2737 ydata_section
= subseg_new (".ydata", 0);
2739 ppc_set_current_section(ydata_section
);
2742 /* pseudo-op: .reldata
2743 behaviour: predefined read write data section
2744 double word aligned (4-byte)
2745 FIXME: relocation is applied to it
2746 FIXME: what's the difference between this and .data?
2749 initial: .section .reldata "drw3"
2750 d - initialized data
2753 3 - double word aligned (that would be 8 byte boundary)
2756 Like .data, but intended to hold data subject to relocation, such as
2757 function descriptors, etc.
2763 if (reldata_section
== 0)
2765 reldata_section
= subseg_new (".reldata", 0);
2767 bfd_set_section_flags (stdoutput
, reldata_section
,
2768 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2771 bfd_set_section_alignment (stdoutput
, reldata_section
, 3);
2775 reldata_section
= subseg_new (".reldata", 0);
2777 ppc_set_current_section(reldata_section
);
2780 /* pseudo-op: .rdata
2781 behaviour: predefined read only data section
2785 initial: .section .rdata "dr3"
2786 d - initialized data
2788 3 - double word aligned (that would be 4 byte boundary)
2794 if (rdata_section
== 0)
2796 rdata_section
= subseg_new (".rdata", 0);
2797 bfd_set_section_flags (stdoutput
, rdata_section
,
2798 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2799 | SEC_READONLY
| SEC_DATA
));
2801 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
2805 rdata_section
= subseg_new (".rdata", 0);
2807 ppc_set_current_section(rdata_section
);
2810 /* pseudo-op: .ualong
2811 behaviour: much like .int, with the exception that no alignment is
2813 FIXME: test the alignment statement
2825 /* pseudo-op: .znop <symbol name>
2826 behaviour: Issue a nop instruction
2827 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2828 the supplied symbol name.
2830 warnings: Missing symbol name
2837 const struct powerpc_opcode
*opcode
;
2843 /* Strip out the symbol name */
2851 symbol_name
= input_line_pointer
;
2852 c
= get_symbol_end ();
2854 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
2855 strcpy (name
, symbol_name
);
2857 sym
= symbol_find_or_make (name
);
2859 *input_line_pointer
= c
;
2863 /* Look up the opcode in the hash table. */
2864 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
2866 /* stick in the nop */
2867 insn
= opcode
->opcode
;
2869 /* Write out the instruction. */
2871 md_number_to_chars (f
, insn
, 4);
2873 f
- frag_now
->fr_literal
,
2878 BFD_RELOC_16_GOT_PCREL
);
2891 register char *name
;
2895 register symbolS
*symbolP
;
2898 name
= input_line_pointer
;
2899 c
= get_symbol_end ();
2901 /* just after name is now '\0' */
2902 p
= input_line_pointer
;
2905 if (*input_line_pointer
!= ',')
2907 as_bad ("Expected comma after symbol-name: rest of line ignored.");
2908 ignore_rest_of_line ();
2912 input_line_pointer
++; /* skip ',' */
2913 if ((temp
= get_absolute_expression ()) < 0)
2915 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
2916 ignore_rest_of_line ();
2922 /* The third argument to .comm is the alignment. */
2923 if (*input_line_pointer
!= ',')
2927 ++input_line_pointer
;
2928 align
= get_absolute_expression ();
2931 as_warn ("ignoring bad alignment");
2938 symbolP
= symbol_find_or_make (name
);
2941 if (S_IS_DEFINED (symbolP
))
2943 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2944 S_GET_NAME (symbolP
));
2945 ignore_rest_of_line ();
2949 if (S_GET_VALUE (symbolP
))
2951 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
2952 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
2953 S_GET_NAME (symbolP
),
2954 (long) S_GET_VALUE (symbolP
),
2959 S_SET_VALUE (symbolP
, (valueT
) temp
);
2960 S_SET_EXTERNAL (symbolP
);
2963 demand_empty_rest_of_line ();
2967 * implement the .section pseudo op:
2968 * .section name {, "flags"}
2970 * | +--- optional flags: 'b' for bss
2972 * +-- section name 'l' for lib
2976 * 'd' (apparently m88k for data)
2978 * But if the argument is not a quoted string, treat it as a
2979 * subsegment number.
2981 * FIXME: this is a copy of the section processing from obj-coff.c, with
2982 * additions/changes for the moto-pas assembler support. There are three
2985 * FIXME: I just noticed this. This doesn't work at all really. It it
2986 * setting bits that bfd probably neither understands or uses. The
2987 * correct approach (?) will have to incorporate extra fields attached
2988 * to the section to hold the system specific stuff. (krk)
2991 * 'a' - unknown - referred to in documentation, but no definition supplied
2992 * 'c' - section has code
2993 * 'd' - section has initialized data
2994 * 'u' - section has uninitialized data
2995 * 'i' - section contains directives (info)
2996 * 'n' - section can be discarded
2997 * 'R' - remove section at link time
2999 * Section Protection:
3000 * 'r' - section is readable
3001 * 'w' - section is writeable
3002 * 'x' - section is executable
3003 * 's' - section is sharable
3005 * Section Alignment:
3006 * '0' - align to byte boundary
3007 * '1' - align to halfword undary
3008 * '2' - align to word boundary
3009 * '3' - align to doubleword boundary
3010 * '4' - align to quadword boundary
3011 * '5' - align to 32 byte boundary
3012 * '6' - align to 64 byte boundary
3017 ppc_pe_section (ignore
)
3020 /* Strip out the section name */
3029 align
= 4; /* default alignment to 16 byte boundary */
3031 section_name
= input_line_pointer
;
3032 c
= get_symbol_end ();
3034 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3035 strcpy (name
, section_name
);
3037 *input_line_pointer
= c
;
3042 flags
= SEC_NO_FLAGS
;
3044 if (*input_line_pointer
== ',')
3046 ++input_line_pointer
;
3048 if (*input_line_pointer
!= '"')
3049 exp
= get_absolute_expression ();
3052 ++input_line_pointer
;
3053 while (*input_line_pointer
!= '"'
3054 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3056 switch (*input_line_pointer
)
3058 /* Section Contents */
3059 case 'a': /* unknown */
3060 as_warn ("Unsupported section attribute -- 'a'");
3062 case 'c': /* code section */
3065 case 'd': /* section has initialized data */
3068 case 'u': /* section has uninitialized data */
3069 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3073 case 'i': /* section contains directives (info) */
3074 /* FIXME: This is IMAGE_SCN_LNK_INFO
3076 flags
|= SEC_HAS_CONTENTS
;
3078 case 'n': /* section can be discarded */
3081 case 'R': /* Remove section at link time */
3082 flags
|= SEC_NEVER_LOAD
;
3085 /* Section Protection */
3086 case 'r': /* section is readable */
3087 flags
|= IMAGE_SCN_MEM_READ
;
3089 case 'w': /* section is writeable */
3090 flags
|= IMAGE_SCN_MEM_WRITE
;
3092 case 'x': /* section is executable */
3093 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3095 case 's': /* section is sharable */
3096 flags
|= IMAGE_SCN_MEM_SHARED
;
3099 /* Section Alignment */
3100 case '0': /* align to byte boundary */
3101 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3104 case '1': /* align to halfword boundary */
3105 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3108 case '2': /* align to word boundary */
3109 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3112 case '3': /* align to doubleword boundary */
3113 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3116 case '4': /* align to quadword boundary */
3117 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3120 case '5': /* align to 32 byte boundary */
3121 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3124 case '6': /* align to 64 byte boundary */
3125 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3130 as_warn("unknown section attribute '%c'",
3131 *input_line_pointer
);
3134 ++input_line_pointer
;
3136 if (*input_line_pointer
== '"')
3137 ++input_line_pointer
;
3141 sec
= subseg_new (name
, (subsegT
) exp
);
3143 ppc_set_current_section(sec
);
3145 if (flags
!= SEC_NO_FLAGS
)
3147 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3148 as_warn ("error setting flags for \"%s\": %s",
3149 bfd_section_name (stdoutput
, sec
),
3150 bfd_errmsg (bfd_get_error ()));
3153 bfd_set_section_alignment(stdoutput
, sec
, align
);
3158 ppc_pe_function (ignore
)
3165 name
= input_line_pointer
;
3166 endc
= get_symbol_end ();
3168 ext_sym
= symbol_find_or_make (name
);
3170 *input_line_pointer
= endc
;
3172 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3173 SF_SET_FUNCTION (ext_sym
);
3174 SF_SET_PROCESS (ext_sym
);
3175 coff_add_linesym (ext_sym
);
3177 demand_empty_rest_of_line ();
3181 ppc_pe_tocd (ignore
)
3184 if (tocdata_section
== 0)
3186 tocdata_section
= subseg_new (".tocd", 0);
3187 /* FIXME: section flags won't work */
3188 bfd_set_section_flags (stdoutput
, tocdata_section
,
3189 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3190 | SEC_READONLY
| SEC_DATA
));
3192 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3196 rdata_section
= subseg_new (".tocd", 0);
3199 ppc_set_current_section(tocdata_section
);
3201 demand_empty_rest_of_line ();
3204 /* Don't adjust TOC relocs to use the section symbol. */
3207 ppc_pe_fix_adjustable (fix
)
3210 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3217 /* XCOFF specific symbol and file handling. */
3219 /* Canonicalize the symbol name. We use the to force the suffix, if
3220 any, to use square brackets, and to be in upper case. */
3223 ppc_canonicalize_symbol_name (name
)
3228 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3242 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3246 if (*s
== '\0' || s
[1] != '\0')
3247 as_bad ("bad symbol suffix");
3255 /* Set the class of a symbol based on the suffix, if any. This is
3256 called whenever a new symbol is created. */
3259 ppc_symbol_new_hook (sym
)
3264 sym
->sy_tc
.next
= NULL
;
3265 sym
->sy_tc
.output
= 0;
3266 sym
->sy_tc
.class = -1;
3267 sym
->sy_tc
.real_name
= NULL
;
3268 sym
->sy_tc
.subseg
= 0;
3269 sym
->sy_tc
.align
= 0;
3270 sym
->sy_tc
.size
= NULL
;
3271 sym
->sy_tc
.within
= NULL
;
3273 s
= strchr (S_GET_NAME (sym
), '[');
3274 if (s
== (const char *) NULL
)
3276 /* There is no suffix. */
3285 if (strcmp (s
, "BS]") == 0)
3286 sym
->sy_tc
.class = XMC_BS
;
3289 if (strcmp (s
, "DB]") == 0)
3290 sym
->sy_tc
.class = XMC_DB
;
3291 else if (strcmp (s
, "DS]") == 0)
3292 sym
->sy_tc
.class = XMC_DS
;
3295 if (strcmp (s
, "GL]") == 0)
3296 sym
->sy_tc
.class = XMC_GL
;
3299 if (strcmp (s
, "PR]") == 0)
3300 sym
->sy_tc
.class = XMC_PR
;
3303 if (strcmp (s
, "RO]") == 0)
3304 sym
->sy_tc
.class = XMC_RO
;
3305 else if (strcmp (s
, "RW]") == 0)
3306 sym
->sy_tc
.class = XMC_RW
;
3309 if (strcmp (s
, "SV]") == 0)
3310 sym
->sy_tc
.class = XMC_SV
;
3313 if (strcmp (s
, "TC]") == 0)
3314 sym
->sy_tc
.class = XMC_TC
;
3315 else if (strcmp (s
, "TI]") == 0)
3316 sym
->sy_tc
.class = XMC_TI
;
3317 else if (strcmp (s
, "TB]") == 0)
3318 sym
->sy_tc
.class = XMC_TB
;
3319 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3320 sym
->sy_tc
.class = XMC_TC0
;
3323 if (strcmp (s
, "UA]") == 0)
3324 sym
->sy_tc
.class = XMC_UA
;
3325 else if (strcmp (s
, "UC]") == 0)
3326 sym
->sy_tc
.class = XMC_UC
;
3329 if (strcmp (s
, "XO]") == 0)
3330 sym
->sy_tc
.class = XMC_XO
;
3334 if (sym
->sy_tc
.class == -1)
3335 as_bad ("Unrecognized symbol suffix");
3338 /* Set the class of a label based on where it is defined. This
3339 handles symbols without suffixes. Also, move the symbol so that it
3340 follows the csect symbol. */
3343 ppc_frob_label (sym
)
3346 if (ppc_current_csect
!= (symbolS
*) NULL
)
3348 if (sym
->sy_tc
.class == -1)
3349 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3351 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3352 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3354 ppc_current_csect
->sy_tc
.within
= sym
;
3358 /* Change the name of a symbol just before writing it out. Set the
3359 real name if the .rename pseudo-op was used. Otherwise, remove any
3360 class suffix. Return 1 if the symbol should not be included in the
3364 ppc_frob_symbol (sym
)
3367 static symbolS
*ppc_last_function
;
3368 static symbolS
*set_end
;
3370 /* Discard symbols that should not be included in the output symbol
3372 if (! sym
->sy_used_in_reloc
3373 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3374 || (! S_IS_EXTERNAL (sym
)
3375 && ! sym
->sy_tc
.output
3376 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3379 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3380 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3386 name
= S_GET_NAME (sym
);
3387 s
= strchr (name
, '[');
3388 if (s
!= (char *) NULL
)
3394 snew
= xmalloc (len
+ 1);
3395 memcpy (snew
, name
, len
);
3398 S_SET_NAME (sym
, snew
);
3402 if (set_end
!= (symbolS
*) NULL
)
3404 SA_SET_SYM_ENDNDX (set_end
, sym
);
3408 if (SF_GET_FUNCTION (sym
))
3410 if (ppc_last_function
!= (symbolS
*) NULL
)
3411 as_warn ("two .function pseudo-ops with no intervening .ef");
3412 ppc_last_function
= sym
;
3413 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3415 resolve_symbol_value (sym
->sy_tc
.size
);
3416 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3419 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3420 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3422 if (ppc_last_function
== (symbolS
*) NULL
)
3423 as_warn (".ef with no preceding .function");
3426 set_end
= ppc_last_function
;
3427 ppc_last_function
= NULL
;
3429 /* We don't have a C_EFCN symbol, but we need to force the
3430 COFF backend to believe that it has seen one. */
3431 coff_last_function
= NULL
;
3435 if (! S_IS_EXTERNAL (sym
)
3436 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3437 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3438 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3439 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3440 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3441 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
3442 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
3443 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3444 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3446 if ((S_GET_STORAGE_CLASS (sym
) == C_EXT
3447 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3448 && S_GET_SEGMENT (sym
) != absolute_section
)
3451 union internal_auxent
*a
;
3453 /* Create a csect aux. */
3454 i
= S_GET_NUMBER_AUXILIARY (sym
);
3455 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3456 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3457 if (sym
->sy_tc
.class == XMC_TC0
)
3459 /* This is the TOC table. */
3460 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3461 a
->x_csect
.x_scnlen
.l
= 0;
3462 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3464 else if (sym
->sy_tc
.subseg
!= 0)
3466 /* This is a csect symbol. x_scnlen is the size of the
3468 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3469 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3470 S_GET_SEGMENT (sym
))
3471 - S_GET_VALUE (sym
));
3474 resolve_symbol_value (sym
->sy_tc
.next
);
3475 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3476 - S_GET_VALUE (sym
));
3478 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3480 else if (S_GET_SEGMENT (sym
) == bss_section
)
3482 /* This is a common symbol. */
3483 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3484 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3485 if (S_IS_EXTERNAL (sym
))
3486 sym
->sy_tc
.class = XMC_RW
;
3488 sym
->sy_tc
.class = XMC_BS
;
3490 else if (! S_IS_DEFINED (sym
))
3492 /* This is an external symbol. */
3493 a
->x_csect
.x_scnlen
.l
= 0;
3494 a
->x_csect
.x_smtyp
= XTY_ER
;
3496 else if (sym
->sy_tc
.class == XMC_TC
)
3500 /* This is a TOC definition. x_scnlen is the size of the
3502 next
= symbol_next (sym
);
3503 while (next
->sy_tc
.class == XMC_TC0
)
3504 next
= symbol_next (next
);
3505 if (next
== (symbolS
*) NULL
3506 || next
->sy_tc
.class != XMC_TC
)
3508 if (ppc_after_toc_frag
== (fragS
*) NULL
)
3509 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3511 - S_GET_VALUE (sym
));
3513 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
3514 - S_GET_VALUE (sym
));
3518 resolve_symbol_value (next
);
3519 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
3520 - S_GET_VALUE (sym
));
3522 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3528 /* This is a normal symbol definition. x_scnlen is the
3529 symbol index of the containing csect. */
3530 if (S_GET_SEGMENT (sym
) == text_section
)
3531 csect
= ppc_text_csects
;
3532 else if (S_GET_SEGMENT (sym
) == data_section
)
3533 csect
= ppc_data_csects
;
3537 /* Skip the initial dummy symbol. */
3538 csect
= csect
->sy_tc
.next
;
3540 if (csect
== (symbolS
*) NULL
)
3541 a
->x_csect
.x_scnlen
.l
= 0;
3544 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
3546 resolve_symbol_value (csect
->sy_tc
.next
);
3547 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
3549 csect
= csect
->sy_tc
.next
;
3552 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3553 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
3555 a
->x_csect
.x_smtyp
= XTY_LD
;
3558 a
->x_csect
.x_parmhash
= 0;
3559 a
->x_csect
.x_snhash
= 0;
3560 if (sym
->sy_tc
.class == -1)
3561 a
->x_csect
.x_smclas
= XMC_PR
;
3563 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
3564 a
->x_csect
.x_stab
= 0;
3565 a
->x_csect
.x_snstab
= 0;
3567 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
3569 /* We want the value to be the symbol index of the referenced
3570 csect symbol. BFD will do that for us if we set the right
3573 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
3574 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
3576 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
3581 /* The value is the offset from the enclosing csect. */
3582 block
= sym
->sy_tc
.within
;
3583 csect
= block
->sy_tc
.within
;
3584 resolve_symbol_value (csect
);
3585 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
3587 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
3588 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
3590 /* We want the value to be a file offset into the line numbers.
3591 BFD will do that for us if we set the right flags. We have
3592 already set the value correctly. */
3593 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
3599 /* Set the VMA for a section. This is called on all the sections in
3603 ppc_frob_section (sec
)
3606 static bfd_size_type vma
= 0;
3608 bfd_set_section_vma (stdoutput
, sec
, vma
);
3609 vma
+= bfd_section_size (stdoutput
, sec
);
3612 /* Adjust the file by adding a .debug section if needed. */
3617 if (ppc_debug_name_section_size
> 0)
3621 sec
= bfd_make_section (stdoutput
, ".debug");
3622 if (sec
== (asection
*) NULL
3623 || ! bfd_set_section_size (stdoutput
, sec
,
3624 ppc_debug_name_section_size
)
3625 || ! bfd_set_section_flags (stdoutput
, sec
,
3626 SEC_HAS_CONTENTS
| SEC_LOAD
))
3627 as_fatal ("can't make .debug section");
3631 #endif /* OBJ_XCOFF */
3633 /* Turn a string in input_line_pointer into a floating point constant
3634 of type type, and store the appropriate bytes in *litp. The number
3635 of LITTLENUMS emitted is stored in *sizep . An error message is
3636 returned, or NULL on OK. */
3639 md_atof (type
, litp
, sizep
)
3645 LITTLENUM_TYPE words
[4];
3661 return "bad call to md_atof";
3664 t
= atof_ieee (input_line_pointer
, type
, words
);
3666 input_line_pointer
= t
;
3670 if (target_big_endian
)
3672 for (i
= 0; i
< prec
; i
++)
3674 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3680 for (i
= prec
- 1; i
>= 0; i
--)
3682 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3690 /* Write a value out to the object file, using the appropriate
3694 md_number_to_chars (buf
, val
, n
)
3699 if (target_big_endian
)
3700 number_to_chars_bigendian (buf
, val
, n
);
3702 number_to_chars_littleendian (buf
, val
, n
);
3705 /* Align a section (I don't know why this is machine dependent). */
3708 md_section_align (seg
, addr
)
3712 int align
= bfd_get_section_alignment (stdoutput
, seg
);
3714 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
3717 /* We don't have any form of relaxing. */
3720 md_estimate_size_before_relax (fragp
, seg
)
3728 /* Convert a machine dependent frag. We never generate these. */
3731 md_convert_frag (abfd
, sec
, fragp
)
3739 /* We have no need to default values of symbols. */
3743 md_undefined_symbol (name
)
3749 /* Functions concerning relocs. */
3751 /* The location from which a PC relative jump should be calculated,
3752 given a PC relative reloc. */
3755 md_pcrel_from (fixp
)
3759 if (fixp
->fx_addsy
!= (symbolS
*) NULL
3760 && (! S_IS_DEFINED (fixp
->fx_addsy
)
3761 || TC_FORCE_RELOCATION (fixp
)))
3765 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3770 /* This is called to see whether a fixup should be adjusted to use a
3771 section symbol. We take the opportunity to change a fixup against
3772 a symbol in the TOC subsegment into a reloc against the
3773 corresponding .tc symbol. */
3776 ppc_fix_adjustable (fix
)
3781 resolve_symbol_value (fix
->fx_addsy
);
3782 val
= S_GET_VALUE (fix
->fx_addsy
);
3783 if (ppc_toc_csect
!= (symbolS
*) NULL
3784 && fix
->fx_addsy
!= (symbolS
*) NULL
3785 && fix
->fx_addsy
!= ppc_toc_csect
3786 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
3787 && val
>= ppc_toc_frag
->fr_address
3788 && (ppc_after_toc_frag
== (fragS
*) NULL
3789 || val
< ppc_after_toc_frag
->fr_address
))
3793 for (sy
= symbol_next (ppc_toc_csect
);
3794 sy
!= (symbolS
*) NULL
;
3795 sy
= symbol_next (sy
))
3797 if (sy
->sy_tc
.class == XMC_TC0
)
3799 if (sy
->sy_tc
.class != XMC_TC
)
3801 resolve_symbol_value (sy
);
3802 if (val
== S_GET_VALUE (sy
))
3805 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
3810 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3811 "symbol in .toc does not match any .tc");
3814 /* Possibly adjust the reloc to be against the csect. */
3815 if (fix
->fx_addsy
!= (symbolS
*) NULL
3816 && fix
->fx_addsy
->sy_tc
.subseg
== 0
3817 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
3818 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
3819 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
3823 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
3824 csect
= ppc_text_csects
;
3825 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
3826 csect
= ppc_data_csects
;
3830 /* Skip the initial dummy symbol. */
3831 csect
= csect
->sy_tc
.next
;
3833 if (csect
!= (symbolS
*) NULL
)
3835 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
3836 && (csect
->sy_tc
.next
->sy_frag
->fr_address
3837 <= fix
->fx_addsy
->sy_frag
->fr_address
))
3838 csect
= csect
->sy_tc
.next
;
3840 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3841 - csect
->sy_frag
->fr_address
);
3842 fix
->fx_addsy
= csect
;
3846 /* Adjust a reloc against a .lcomm symbol to be against the base
3848 if (fix
->fx_addsy
!= (symbolS
*) NULL
3849 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
3850 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
3852 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
3853 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3854 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
3855 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
3863 /* See whether a symbol is in the TOC section. */
3866 ppc_is_toc_sym (sym
)
3870 return sym
->sy_tc
.class == XMC_TC
;
3872 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
3876 /* Apply a fixup to the object code. This is called for all the
3877 fixups we generated by the call to fix_new_exp, above. In the call
3878 above we used a reloc code which was the largest legal reloc code
3879 plus the operand index. Here we undo that to recover the operand
3880 index. At this point all symbol values should be fully resolved,
3881 and we attempt to completely resolve the reloc. If we can not do
3882 that, we determine the correct reloc code and put it back in the
3886 md_apply_fix3 (fixp
, valuep
, seg
)
3893 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
3894 the symbol values. Since we are using BFD_ASSEMBLER, if we are
3895 doing this relocation the code in write.c is going to call
3896 bfd_perform_relocation, which is also going to use the symbol
3897 value. That means that if the reloc is fully resolved we want to
3898 use *valuep since bfd_perform_relocation is not being used.
3899 However, if the reloc is not fully resolved we do not want to use
3900 *valuep, and must use fx_offset instead. However, if the reloc
3901 is PC relative, we do want to use *valuep since it includes the
3902 result of md_pcrel_from. This is confusing. */
3904 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
3909 else if (fixp
->fx_pcrel
)
3913 value
= fixp
->fx_offset
;
3914 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
3916 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
3917 value
-= S_GET_VALUE (fixp
->fx_subsy
);
3920 /* We can't actually support subtracting a symbol. */
3921 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3922 "expression too complex");
3927 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
3930 const struct powerpc_operand
*operand
;
3934 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
3936 operand
= &powerpc_operands
[opindex
];
3939 /* It appears that an instruction like
3941 when LC..1 is not a TOC symbol does not generate a reloc. It
3942 uses the offset of LC..1 within its csect. However, .long
3943 LC..1 will generate a reloc. I can't find any documentation
3944 on how these cases are to be distinguished, so this is a wild
3945 guess. These cases are generated by gcc -mminimal-toc. */
3946 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
3947 && operand
->bits
== 16
3948 && operand
->shift
== 0
3949 && operand
->insert
== NULL
3950 && fixp
->fx_addsy
!= NULL
3951 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
3952 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
3953 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
3954 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
3956 value
= fixp
->fx_offset
;
3961 /* Fetch the instruction, insert the fully resolved operand
3962 value, and stuff the instruction back again. */
3963 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
3964 if (target_big_endian
)
3965 insn
= bfd_getb32 ((unsigned char *) where
);
3967 insn
= bfd_getl32 ((unsigned char *) where
);
3968 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
3969 fixp
->fx_file
, fixp
->fx_line
);
3970 if (target_big_endian
)
3971 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
3973 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
3977 /* Nothing else to do here. */
3981 /* Determine a BFD reloc value based on the operand information.
3982 We are only prepared to turn a few of the operands into
3984 FIXME: We need to handle the DS field at the very least.
3985 FIXME: Selecting the reloc type is a bit haphazard; perhaps
3986 there should be a new field in the operand table. */
3987 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3988 && operand
->bits
== 26
3989 && operand
->shift
== 0)
3990 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
3991 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3992 && operand
->bits
== 16
3993 && operand
->shift
== 0)
3994 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
3995 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3996 && operand
->bits
== 26
3997 && operand
->shift
== 0)
3998 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
3999 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
4000 && operand
->bits
== 16
4001 && operand
->shift
== 0)
4002 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4003 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4004 && operand
->bits
== 16
4005 && operand
->shift
== 0
4006 && operand
->insert
== NULL
4007 && fixp
->fx_addsy
!= NULL
4008 && ppc_is_toc_sym (fixp
->fx_addsy
))
4011 if (target_big_endian
)
4012 fixp
->fx_where
+= 2;
4013 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4017 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4018 "unresolved expression that must be resolved");
4026 ppc_elf_validate_fix (fixp
, seg
);
4028 switch (fixp
->fx_r_type
)
4031 case BFD_RELOC_CTOR
:
4034 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4035 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4036 } /* fall through */
4038 case BFD_RELOC_32_PCREL
:
4039 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4043 case BFD_RELOC_LO16
:
4044 case BFD_RELOC_HI16
:
4045 case BFD_RELOC_HI16_S
:
4046 case BFD_RELOC_PPC_TOC16
:
4048 case BFD_RELOC_GPREL16
:
4049 case BFD_RELOC_16_GOT_PCREL
:
4053 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4061 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4071 fixp
->fx_addnumber
= value
;
4073 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4074 fixp
->fx_addnumber
= 0;
4078 fixp
->fx_addnumber
= 0;
4080 /* We want to use the offset within the data segment of the
4081 symbol, not the actual VMA of the symbol. */
4082 fixp
->fx_addnumber
=
4083 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4091 /* Generate a reloc for a fixup. */
4094 tc_gen_reloc (seg
, fixp
)
4100 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4102 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4103 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4104 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4105 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4107 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4108 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4111 reloc
->addend
= fixp
->fx_addnumber
;