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
587 else if (strcmp (arg
, "com") == 0)
588 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_PPC
;
589 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
590 else if (strcmp (arg
, "any") == 0)
591 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_PPC
;
594 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
595 else if (strcmp (arg
, "relocatable") == 0)
598 ppc_flags
|= EF_PPC_RELOCATABLE
;
601 else if (strcmp (arg
, "relocatable-lib") == 0)
604 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
607 /* -memb, set embedded bit */
608 else if (strcmp (arg
, "emb") == 0)
609 ppc_flags
|= EF_PPC_EMB
;
611 /* -mlittle/-mbig set the endianess */
612 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
614 target_big_endian
= 0;
615 set_target_endian
= 1;
618 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
620 target_big_endian
= 1;
621 set_target_endian
= 1;
626 as_bad ("invalid switch -m%s", arg
);
632 /* -V: SVR4 argument to print version ID. */
637 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
638 should be emitted or not. FIXME: Not implemented. */
651 md_show_usage (stream
)
657 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
658 -mpwr generate code for IBM POWER (RIOS1)\n\
659 -m601 generate code for Motorola PowerPC 601\n\
660 -mppc, -mppc32, -m403, -m603, -m604\n\
661 generate code for Motorola PowerPC 603/604\n\
662 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
663 -mcom generate code Power/PowerPC common instructions\n
664 -many generate code for any architecture (PWR/PWRX/PPC)\n");
667 -mrelocatable support for GCC's -mrelocatble option\n\
668 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
669 -memb set PPC_EMB bit in ELF flags\n\
670 -mlittle, -mlittle-endian\n\
671 generate code for a little endian machine\n\
672 -mbig, -mbig-endian generate code for a big endian machine\n\
673 -V print assembler version number\n\
674 -Qy, -Qn ignored\n");
678 /* Set ppc_cpu if it is not already set. */
683 const char *default_cpu
= TARGET_CPU
;
687 if (strcmp (default_cpu
, "rs6000") == 0)
688 ppc_cpu
= PPC_OPCODE_POWER
;
689 else if (strcmp (default_cpu
, "powerpc") == 0
690 || strcmp (default_cpu
, "powerpcle") == 0)
691 ppc_cpu
= PPC_OPCODE_PPC
;
693 as_fatal ("Unknown default cpu = %s", default_cpu
);
697 /* Figure out the BFD architecture to use. */
699 enum bfd_architecture
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
;
710 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
711 return bfd_arch_unknown
;
715 /* This function is called when the assembler starts up. It is called
716 after the options have been parsed and the output file has been
722 register const struct powerpc_opcode
*op
;
723 const struct powerpc_opcode
*op_end
;
724 const struct powerpc_macro
*macro
;
725 const struct powerpc_macro
*macro_end
;
730 /* Set the ELF flags if desired. */
732 bfd_set_private_flags (stdoutput
, ppc_flags
);
735 /* Insert the opcodes into a hash table. */
736 ppc_hash
= hash_new ();
738 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
739 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
741 know ((op
->opcode
& op
->mask
) == op
->opcode
);
743 if ((op
->flags
& ppc_cpu
) != 0
744 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
745 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
)
746 /* If -mcom, check for instructions not in both Power/PowerPC */
747 && (ppc_cpu
!= (PPC_OPCODE_POWER
| PPC_OPCODE_PPC
)
748 || (op
->flags
& (PPC_OPCODE_POWER
| PPC_OPCODE_PPC
)) == ppc_cpu
))
752 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
753 if (retval
!= (const char *) NULL
)
755 /* We permit a duplication of the mfdec instruction on
756 the 601, because it seems to have one value on the
757 601 and a different value on other PowerPC
758 processors. It's easier to permit a duplication than
759 to define a new instruction type flag. When using
760 -many, the comparison instructions are a harmless
762 if (strcmp (retval
, "exists") != 0
763 || (((ppc_cpu
& PPC_OPCODE_601
) == 0
764 || strcmp (op
->name
, "mfdec") != 0)
765 && (ppc_cpu
!= (PPC_OPCODE_POWER
768 || (strcmp (op
->name
, "cmpli") != 0
769 && strcmp (op
->name
, "cmpi") != 0
770 && strcmp (op
->name
, "cmp") != 0
771 && strcmp (op
->name
, "cmpl") != 0))))
777 /* Insert the macros into a hash table. */
778 ppc_macro_hash
= hash_new ();
780 macro_end
= powerpc_macros
+ powerpc_num_macros
;
781 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
783 if ((macro
->flags
& ppc_cpu
) != 0)
787 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
788 if (retval
!= (const char *) NULL
)
793 /* Tell the main code what the endianness is if it is not overidden by the user. */
794 if (!set_target_endian
)
796 set_target_endian
= 1;
797 target_big_endian
= PPC_BIG_ENDIAN
;
801 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
803 /* Create dummy symbols to serve as initial csects. This forces the
804 text csects to precede the data csects. These symbols will not
806 ppc_text_csects
= symbol_make ("dummy\001");
807 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
808 ppc_data_csects
= symbol_make ("dummy\001");
809 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
814 ppc_current_section
= text_section
;
815 ppc_previous_section
= 0;
820 /* Insert an operand value into an instruction. */
823 ppc_insert_operand (insn
, operand
, val
, file
, line
)
825 const struct powerpc_operand
*operand
;
830 if (operand
->bits
!= 32)
835 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
837 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
838 && ppc_size
== PPC_OPCODE_32
)
839 max
= (1 << operand
->bits
) - 1;
841 max
= (1 << (operand
->bits
- 1)) - 1;
842 min
= - (1 << (operand
->bits
- 1));
846 max
= (1 << operand
->bits
) - 1;
850 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
855 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
858 "operand out of range (%s not between %ld and %ld)";
861 sprint_value (buf
, test
);
862 if (file
== (char *) NULL
)
863 as_warn (err
, buf
, min
, max
);
865 as_warn_where (file
, line
, err
, buf
, min
, max
);
874 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
875 if (errmsg
!= (const char *) NULL
)
879 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
886 /* Parse @got, etc. and return the desired relocation. */
887 static bfd_reloc_code_real_type
888 ppc_elf_suffix (str_p
)
894 bfd_reloc_code_real_type reloc
;
904 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
906 static struct map_bfd mapping
[] = {
907 MAP ("got", BFD_RELOC_PPC_TOC16
),
908 MAP ("l", BFD_RELOC_LO16
),
909 MAP ("h", BFD_RELOC_HI16
),
910 MAP ("ha", BFD_RELOC_HI16_S
),
911 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
912 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
913 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
914 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
915 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
916 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
917 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
918 MAP ("copy", BFD_RELOC_PPC_COPY
),
919 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
920 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
921 MAP ("plt", BFD_RELOC_32_PLTOFF
),
922 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
923 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
924 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
925 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
926 MAP ("sdarel", BFD_RELOC_GPREL16
),
927 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
928 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
929 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
930 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
932 { (char *)0, 0, BFD_RELOC_UNUSED
}
936 return BFD_RELOC_UNUSED
;
938 for (ch
= *str
, str2
= ident
;
939 str2
< ident
+ sizeof(ident
) - 1 && isalnum (ch
) || ch
== '@';
942 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
949 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
950 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
956 return BFD_RELOC_UNUSED
;
959 /* Like normal .long/.short/.word, except support @got, etc. */
960 /* clobbers input_line_pointer, checks */
963 ppc_elf_cons (nbytes
)
964 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
967 bfd_reloc_code_real_type reloc
;
969 if (is_it_end_of_statement ())
971 demand_empty_rest_of_line ();
978 if (exp
.X_op
== O_symbol
979 && *input_line_pointer
== '@'
980 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
982 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
983 int size
= bfd_get_reloc_size (reloc_howto
);
986 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
990 register char *p
= frag_more ((int) nbytes
);
991 int offset
= nbytes
- size
;
993 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
997 emit_expr (&exp
, (unsigned int) nbytes
);
999 while (*input_line_pointer
++ == ',');
1001 input_line_pointer
--; /* Put terminator back into stream. */
1002 demand_empty_rest_of_line ();
1005 /* Validate any relocations emitted for -mrelocatable, possibly adding
1006 fixups for word relocations in writable segments, so we can adjust
1009 ppc_elf_validate_fix (fixp
, seg
)
1016 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1017 && strcmp (segment_name (seg
), ".got2") != 0
1018 && strcmp (segment_name (seg
), ".dtors") != 0
1019 && strcmp (segment_name (seg
), ".ctors") != 0
1020 && strcmp (segment_name (seg
), ".fixup") != 0
1021 && strcmp (segment_name (seg
), ".stab") != 0)
1023 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1024 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1026 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
1027 "Relocation cannot be done when using -mrelocatable");
1032 #endif /* OBJ_ELF */
1036 * Summary of register_name().
1038 * in: Input_line_pointer points to 1st char of operand.
1040 * out: A expressionS.
1041 * The operand may have been a register: in this case, X_op == O_register,
1042 * X_add_number is set to the register number, and truth is returned.
1043 * Input_line_pointer->(next non-blank) char after operand, or is in its
1048 register_name (expressionP
)
1049 expressionS
*expressionP
;
1055 /* Find the spelling of the operand */
1056 name
= input_line_pointer
;
1057 c
= get_symbol_end ();
1058 reg_number
= reg_name_search (name
);
1060 /* look to see if it's in the register table */
1061 if (reg_number
>= 0)
1063 expressionP
->X_op
= O_register
;
1064 expressionP
->X_add_number
= reg_number
;
1066 /* make the rest nice */
1067 expressionP
->X_add_symbol
= NULL
;
1068 expressionP
->X_op_symbol
= NULL
;
1069 *input_line_pointer
= c
; /* put back the delimiting char */
1074 /* reset the line as if we had not done anything */
1075 *input_line_pointer
= c
; /* put back the delimiting char */
1076 input_line_pointer
= name
; /* reset input_line pointer */
1082 * Summary of parse_toc_entry().
1084 * in: Input_line_pointer points to the '[' in one of:
1086 * [toc] [tocv] [toc32] [toc64]
1088 * Anything else is an error of one kind or another.
1091 * return value: success or failure
1092 * toc_kind: kind of toc reference
1093 * input_line_pointer:
1094 * success: first char after the ']'
1095 * failure: unchanged
1099 * [toc] - rv == success, toc_kind = default_toc
1100 * [tocv] - rv == success, toc_kind = data_in_toc
1101 * [toc32] - rv == success, toc_kind = must_be_32
1102 * [toc64] - rv == success, toc_kind = must_be_64
1106 enum toc_size_qualifier
1108 default_toc
, /* The toc cell constructed should be the system default size */
1109 data_in_toc
, /* This is a direct reference to a toc cell */
1110 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1111 must_be_64
/* The toc cell constructed must be 64 bits wide */
1115 parse_toc_entry(toc_kind
)
1116 enum toc_size_qualifier
*toc_kind
;
1121 enum toc_size_qualifier t
;
1123 /* save the input_line_pointer */
1124 start
= input_line_pointer
;
1126 /* skip over the '[' , and whitespace */
1127 ++input_line_pointer
;
1130 /* find the spelling of the operand */
1131 toc_spec
= input_line_pointer
;
1132 c
= get_symbol_end ();
1134 if (strcmp(toc_spec
, "toc") == 0)
1138 else if (strcmp(toc_spec
, "tocv") == 0)
1142 else if (strcmp(toc_spec
, "toc32") == 0)
1146 else if (strcmp(toc_spec
, "toc64") == 0)
1152 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1153 *input_line_pointer
= c
; /* put back the delimiting char */
1154 input_line_pointer
= start
; /* reset input_line pointer */
1158 /* now find the ']' */
1159 *input_line_pointer
= c
; /* put back the delimiting char */
1161 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1162 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1166 as_bad ("syntax error: expected `]', found `%c'", c
);
1167 input_line_pointer
= start
; /* reset input_line pointer */
1171 *toc_kind
= t
; /* set return value */
1178 /* We need to keep a list of fixups. We can't simply generate them as
1179 we go, because that would require us to first create the frag, and
1180 that would screw up references to ``.''. */
1186 bfd_reloc_code_real_type reloc
;
1189 #define MAX_INSN_FIXUPS (5)
1191 /* This routine is called for each instruction to be assembled. */
1198 const struct powerpc_opcode
*opcode
;
1200 const unsigned char *opindex_ptr
;
1204 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1209 bfd_reloc_code_real_type reloc
;
1212 /* Get the opcode. */
1213 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1218 /* Look up the opcode in the hash table. */
1219 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1220 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1222 const struct powerpc_macro
*macro
;
1224 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1225 if (macro
== (const struct powerpc_macro
*) NULL
)
1226 as_bad ("Unrecognized opcode: `%s'", str
);
1228 ppc_macro (s
, macro
);
1233 insn
= opcode
->opcode
;
1236 while (isspace (*str
))
1239 /* PowerPC operands are just expressions. The only real issue is
1240 that a few operand types are optional. All cases which might use
1241 an optional operand separate the operands only with commas (in
1242 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1243 cases never have optional operands). There is never more than
1244 one optional operand for an instruction. So, before we start
1245 seriously parsing the operands, we check to see if we have an
1246 optional operand, and, if we do, we count the number of commas to
1247 see whether the operand should be omitted. */
1249 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1251 const struct powerpc_operand
*operand
;
1253 operand
= &powerpc_operands
[*opindex_ptr
];
1254 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1256 unsigned int opcount
;
1258 /* There is an optional operand. Count the number of
1259 commas in the input line. */
1266 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1273 /* If there are fewer operands in the line then are called
1274 for by the instruction, we want to skip the optional
1276 if (opcount
< strlen (opcode
->operands
))
1283 /* Gather the operands. */
1287 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1289 const struct powerpc_operand
*operand
;
1295 if (next_opindex
== 0)
1296 operand
= &powerpc_operands
[*opindex_ptr
];
1299 operand
= &powerpc_operands
[next_opindex
];
1305 /* If this is a fake operand, then we do not expect anything
1307 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1309 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1310 if (errmsg
!= (const char *) NULL
)
1315 /* If this is an optional operand, and we are skipping it, just
1317 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1320 if (operand
->insert
)
1322 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1323 if (errmsg
!= (const char *) NULL
)
1326 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1327 next_opindex
= *opindex_ptr
+ 1;
1331 /* Gather the operand. */
1332 hold
= input_line_pointer
;
1333 input_line_pointer
= str
;
1336 if (*input_line_pointer
== '[')
1338 /* We are expecting something like the second argument here:
1340 lwz r4,[toc].GS.0.static_int(rtoc)
1341 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1342 The argument following the `]' must be a symbol name, and the
1343 register must be the toc register: 'rtoc' or '2'
1345 The effect is to 0 as the displacement field
1346 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1347 the appropriate variation) reloc against it based on the symbol.
1348 The linker will build the toc, and insert the resolved toc offset.
1351 o The size of the toc entry is currently assumed to be
1352 32 bits. This should not be assumed to be a hard coded
1354 o In an effort to cope with a change from 32 to 64 bits,
1355 there are also toc entries that are specified to be
1356 either 32 or 64 bits:
1357 lwz r4,[toc32].GS.0.static_int(rtoc)
1358 lwz r4,[toc64].GS.0.static_int(rtoc)
1359 These demand toc entries of the specified size, and the
1360 instruction probably requires it.
1364 enum toc_size_qualifier toc_kind
;
1365 bfd_reloc_code_real_type toc_reloc
;
1367 /* go parse off the [tocXX] part */
1368 valid_toc
= parse_toc_entry(&toc_kind
);
1372 /* Note: message has already been issued. */
1373 /* FIXME: what sort of recovery should we do? */
1374 /* demand_rest_of_line(); return; ? */
1377 /* Now get the symbol following the ']' */
1383 /* In this case, we may not have seen the symbol yet, since */
1384 /* it is allowed to appear on a .extern or .globl or just be */
1385 /* a label in the .data section. */
1386 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1389 /* 1. The symbol must be defined and either in the toc */
1390 /* section, or a global. */
1391 /* 2. The reloc generated must have the TOCDEFN flag set in */
1392 /* upper bit mess of the reloc type. */
1393 /* FIXME: It's a little confusing what the tocv qualifier can */
1394 /* be used for. At the very least, I've seen three */
1395 /* uses, only one of which I'm sure I can explain. */
1396 if (ex
.X_op
== O_symbol
)
1398 assert (ex
.X_add_symbol
!= NULL
);
1399 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1401 as_warn("[tocv] symbol is not a toc symbol");
1405 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1408 /* FIXME: these next two specifically specify 32/64 bit toc */
1409 /* entries. We don't support them today. Is this the */
1410 /* right way to say that? */
1411 toc_reloc
= BFD_RELOC_UNUSED
;
1412 as_bad ("Unimplemented toc32 expression modifier");
1415 /* FIXME: see above */
1416 toc_reloc
= BFD_RELOC_UNUSED
;
1417 as_bad ("Unimplemented toc64 expression modifier");
1421 "Unexpected return value [%d] from parse_toc_entry!\n",
1427 /* We need to generate a fixup for this expression. */
1428 if (fc
>= MAX_INSN_FIXUPS
)
1429 as_fatal ("too many fixups");
1431 fixups
[fc
].reloc
= toc_reloc
;
1432 fixups
[fc
].exp
= ex
;
1433 fixups
[fc
].opindex
= *opindex_ptr
;
1436 /* Ok. We've set up the fixup for the instruction. Now make it
1437 look like the constant 0 was found here */
1439 ex
.X_op
= O_constant
;
1440 ex
.X_add_number
= 0;
1441 ex
.X_add_symbol
= NULL
;
1442 ex
.X_op_symbol
= NULL
;
1446 if (!register_name(&ex
))
1452 str
= input_line_pointer
;
1453 input_line_pointer
= hold
;
1456 str
= input_line_pointer
;
1457 input_line_pointer
= hold
;
1460 if (ex
.X_op
== O_illegal
)
1461 as_bad ("illegal operand");
1462 else if (ex
.X_op
== O_absent
)
1463 as_bad ("missing operand");
1464 else if (ex
.X_op
== O_constant
)
1467 /* Allow @HA, @L, @H on constants. */
1468 char *orig_str
= str
;
1470 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1477 case BFD_RELOC_LO16
:
1478 ex
.X_add_number
= ((ex
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1481 case BFD_RELOC_HI16
:
1482 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1485 case BFD_RELOC_HI16_S
:
1486 ex
.X_add_number
= ((ex
.X_add_number
>> 16) & 0xffff)
1487 + ((ex
.X_add_number
>> 15) & 1);
1491 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1495 else if (ex
.X_op
== O_register
)
1497 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1502 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1504 /* For the absoulte forms of branchs, convert the PC relative form back into
1506 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1509 case BFD_RELOC_PPC_B26
: reloc
= BFD_RELOC_PPC_BA26
; break;
1510 case BFD_RELOC_PPC_B16
: reloc
= BFD_RELOC_PPC_BA16
; break;
1511 case BFD_RELOC_PPC_B16_BRTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
; break;
1512 case BFD_RELOC_PPC_B16_BRNTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
; break;
1515 /* We need to generate a fixup for this expression. */
1516 if (fc
>= MAX_INSN_FIXUPS
)
1517 as_fatal ("too many fixups");
1518 fixups
[fc
].exp
= ex
;
1519 fixups
[fc
].opindex
= 0;
1520 fixups
[fc
].reloc
= reloc
;
1523 #endif /* OBJ_ELF */
1527 /* We need to generate a fixup for this expression. */
1528 if (fc
>= MAX_INSN_FIXUPS
)
1529 as_fatal ("too many fixups");
1530 fixups
[fc
].exp
= ex
;
1531 fixups
[fc
].opindex
= *opindex_ptr
;
1532 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1541 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1549 /* The call to expression should have advanced str past any
1552 && (endc
!= ',' || *str
!= '\0'))
1554 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1562 while (isspace (*str
))
1566 as_bad ("junk at end of line: `%s'", str
);
1568 /* Write out the instruction. */
1570 md_number_to_chars (f
, insn
, 4);
1572 /* Create any fixups. At this point we do not use a
1573 bfd_reloc_code_real_type, but instead just use the
1574 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1575 handle fixups for any operand type, although that is admittedly
1576 not a very exciting feature. We pick a BFD reloc type in
1578 for (i
= 0; i
< fc
; i
++)
1580 const struct powerpc_operand
*operand
;
1582 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1583 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1585 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1593 size
= bfd_get_reloc_size (reloc_howto
);
1594 offset
= target_big_endian
? (4 - size
) : 0;
1596 if (size
< 1 || size
> 4)
1599 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1600 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1603 /* Turn off complaints that the addend is too large for things like
1605 switch (fixups
[i
].reloc
)
1607 case BFD_RELOC_LO16
:
1608 case BFD_RELOC_HI16
:
1609 case BFD_RELOC_HI16_S
:
1610 fixP
->fx_no_overflow
= 1;
1617 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1619 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1620 ((bfd_reloc_code_real_type
)
1621 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1625 #ifndef WORKING_DOT_WORD
1626 /* Handle long and short jumps */
1628 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1630 addressT from_addr
, to_addr
;
1638 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1640 addressT from_addr
, to_addr
;
1648 /* Handle a macro. Gather all the operands, transform them as
1649 described by the macro, and call md_assemble recursively. All the
1650 operands are separated by commas; we don't accept parentheses
1651 around operands here. */
1654 ppc_macro (str
, macro
)
1656 const struct powerpc_macro
*macro
;
1667 /* Gather the users operands into the operands array. */
1672 if (count
>= sizeof operands
/ sizeof operands
[0])
1674 operands
[count
++] = s
;
1675 s
= strchr (s
, ',');
1676 if (s
== (char *) NULL
)
1681 if (count
!= macro
->operands
)
1683 as_bad ("wrong number of operands");
1687 /* Work out how large the string must be (the size is unbounded
1688 because it includes user input). */
1690 format
= macro
->format
;
1691 while (*format
!= '\0')
1700 arg
= strtol (format
+ 1, &send
, 10);
1701 know (send
!= format
&& arg
>= 0 && arg
< count
);
1702 len
+= strlen (operands
[arg
]);
1707 /* Put the string together. */
1708 complete
= s
= (char *) alloca (len
+ 1);
1709 format
= macro
->format
;
1710 while (*format
!= '\0')
1716 arg
= strtol (format
+ 1, &send
, 10);
1717 strcpy (s
, operands
[arg
]);
1724 /* Assemble the constructed instruction. */
1725 md_assemble (complete
);
1728 /* Pseudo-op handling. */
1730 /* The .byte pseudo-op. This is similar to the normal .byte
1731 pseudo-op, but it can also take a single ASCII string. */
1737 if (*input_line_pointer
!= '\"')
1743 /* Gather characters. A real double quote is doubled. Unusual
1744 characters are not permitted. */
1745 ++input_line_pointer
;
1750 c
= *input_line_pointer
++;
1754 if (*input_line_pointer
!= '\"')
1756 ++input_line_pointer
;
1759 FRAG_APPEND_1_CHAR (c
);
1762 demand_empty_rest_of_line ();
1767 /* XCOFF specific pseudo-op handling. */
1769 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1770 symbols in the .bss segment as though they were local common
1771 symbols, and uses a different smclas. */
1777 asection
*current_seg
= now_seg
;
1778 subsegT current_subseg
= now_subseg
;
1784 symbolS
*lcomm_sym
= NULL
;
1788 name
= input_line_pointer
;
1789 endc
= get_symbol_end ();
1790 end_name
= input_line_pointer
;
1793 if (*input_line_pointer
!= ',')
1795 as_bad ("missing size");
1796 ignore_rest_of_line ();
1799 ++input_line_pointer
;
1801 size
= get_absolute_expression ();
1804 as_bad ("negative size");
1805 ignore_rest_of_line ();
1811 /* The third argument to .comm is the alignment. */
1812 if (*input_line_pointer
!= ',')
1816 ++input_line_pointer
;
1817 align
= get_absolute_expression ();
1820 as_warn ("ignoring bad alignment");
1839 /* The third argument to .lcomm appears to be the real local
1840 common symbol to create. References to the symbol named in
1841 the first argument are turned into references to the third
1843 if (*input_line_pointer
!= ',')
1845 as_bad ("missing real symbol name");
1846 ignore_rest_of_line ();
1849 ++input_line_pointer
;
1851 lcomm_name
= input_line_pointer
;
1852 lcomm_endc
= get_symbol_end ();
1854 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1856 *input_line_pointer
= lcomm_endc
;
1860 sym
= symbol_find_or_make (name
);
1863 if (S_IS_DEFINED (sym
)
1864 || S_GET_VALUE (sym
) != 0)
1866 as_bad ("attempt to redefine symbol");
1867 ignore_rest_of_line ();
1871 record_alignment (bss_section
, align
);
1874 || ! S_IS_DEFINED (lcomm_sym
))
1883 S_SET_EXTERNAL (sym
);
1887 lcomm_sym
->sy_tc
.output
= 1;
1888 def_sym
= lcomm_sym
;
1892 subseg_set (bss_section
, 1);
1893 frag_align (align
, 0);
1895 def_sym
->sy_frag
= frag_now
;
1896 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1897 def_size
, (char *) NULL
);
1899 S_SET_SEGMENT (def_sym
, bss_section
);
1900 def_sym
->sy_tc
.align
= align
;
1904 /* Align the size of lcomm_sym. */
1905 lcomm_sym
->sy_frag
->fr_offset
=
1906 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1907 &~ ((1 << align
) - 1));
1908 if (align
> lcomm_sym
->sy_tc
.align
)
1909 lcomm_sym
->sy_tc
.align
= align
;
1914 /* Make sym an offset from lcomm_sym. */
1915 S_SET_SEGMENT (sym
, bss_section
);
1916 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1917 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1918 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1921 subseg_set (current_seg
, current_subseg
);
1923 demand_empty_rest_of_line ();
1926 /* The .csect pseudo-op. This switches us into a different
1927 subsegment. The first argument is a symbol whose value is the
1928 start of the .csect. In COFF, csect symbols get special aux
1929 entries defined by the x_csect field of union internal_auxent. The
1930 optional second argument is the alignment (the default is 2). */
1940 name
= input_line_pointer
;
1941 endc
= get_symbol_end ();
1943 sym
= symbol_find_or_make (name
);
1945 *input_line_pointer
= endc
;
1947 if (S_IS_DEFINED (sym
))
1948 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1955 /* This is a new csect. We need to look at the symbol class to
1956 figure out whether it should go in the text section or the
1959 switch (sym
->sy_tc
.class)
1969 S_SET_SEGMENT (sym
, text_section
);
1970 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1971 ++ppc_text_subsegment
;
1972 list_ptr
= &ppc_text_csects
;
1981 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1983 S_SET_SEGMENT (sym
, data_section
);
1984 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1985 ++ppc_data_subsegment
;
1986 list_ptr
= &ppc_data_csects
;
1992 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1994 ppc_after_toc_frag
= frag_now
;
1996 sym
->sy_frag
= frag_now
;
1997 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1999 sym
->sy_tc
.align
= 2;
2000 sym
->sy_tc
.output
= 1;
2001 sym
->sy_tc
.within
= sym
;
2003 for (list
= *list_ptr
;
2004 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2005 list
= list
->sy_tc
.next
)
2007 list
->sy_tc
.next
= sym
;
2009 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2010 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2013 if (*input_line_pointer
== ',')
2015 ++input_line_pointer
;
2016 sym
->sy_tc
.align
= get_absolute_expression ();
2019 ppc_current_csect
= sym
;
2021 demand_empty_rest_of_line ();
2024 /* The .extern pseudo-op. We create an undefined symbol. */
2033 name
= input_line_pointer
;
2034 endc
= get_symbol_end ();
2036 (void) symbol_find_or_make (name
);
2038 *input_line_pointer
= endc
;
2040 demand_empty_rest_of_line ();
2043 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
2044 this because it can't handle undefined symbols. I think we can
2054 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2055 although I don't know why it bothers. */
2066 name
= input_line_pointer
;
2067 endc
= get_symbol_end ();
2069 sym
= symbol_find_or_make (name
);
2071 *input_line_pointer
= endc
;
2073 if (*input_line_pointer
!= ',')
2075 as_bad ("missing rename string");
2076 ignore_rest_of_line ();
2079 ++input_line_pointer
;
2081 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2083 demand_empty_rest_of_line ();
2086 /* The .stabx pseudo-op. This is similar to a normal .stabs
2087 pseudo-op, but slightly different. A sample is
2088 .stabx "main:F-1",.main,142,0
2089 The first argument is the symbol name to create. The second is the
2090 value, and the third is the storage class. The fourth seems to be
2091 always zero, and I am assuming it is the type. */
2102 name
= demand_copy_C_string (&len
);
2104 if (*input_line_pointer
!= ',')
2106 as_bad ("missing value");
2109 ++input_line_pointer
;
2111 sym
= symbol_make (name
);
2113 (void) expression (&exp
);
2120 as_bad ("illegal .stabx expression; zero assumed");
2121 exp
.X_add_number
= 0;
2124 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2125 sym
->sy_frag
= &zero_address_frag
;
2129 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2130 sym
->sy_value
= exp
;
2134 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2135 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2140 /* The value is some complex expression. This will probably
2141 fail at some later point, but this is probably the right
2142 thing to do here. */
2143 sym
->sy_value
= exp
;
2147 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2148 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2150 if (*input_line_pointer
!= ',')
2152 as_bad ("missing class");
2155 ++input_line_pointer
;
2157 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2159 if (*input_line_pointer
!= ',')
2161 as_bad ("missing type");
2164 ++input_line_pointer
;
2166 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2168 sym
->sy_tc
.output
= 1;
2170 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2171 sym
->sy_tc
.within
= ppc_current_block
;
2173 if (exp
.X_op
!= O_symbol
2174 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2175 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2176 ppc_frob_label (sym
);
2179 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2180 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2181 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2182 ppc_current_csect
->sy_tc
.within
= sym
;
2185 if (strlen (name
) > SYMNMLEN
)
2187 /* For some reason, each name is preceded by a two byte length
2188 and followed by a null byte. */
2189 ppc_debug_name_section_size
+= strlen (name
) + 3;
2192 demand_empty_rest_of_line ();
2195 /* The .function pseudo-op. This takes several arguments. The first
2196 argument seems to be the external name of the symbol. The second
2197 argment seems to be the label for the start of the function. gcc
2198 uses the same name for both. I have no idea what the third and
2199 fourth arguments are meant to be. The optional fifth argument is
2200 an expression for the size of the function. In COFF this symbol
2201 gets an aux entry like that used for a csect. */
2204 ppc_function (ignore
)
2213 name
= input_line_pointer
;
2214 endc
= get_symbol_end ();
2216 /* Ignore any [PR] suffix. */
2217 name
= ppc_canonicalize_symbol_name (name
);
2218 s
= strchr (name
, '[');
2219 if (s
!= (char *) NULL
2220 && strcmp (s
+ 1, "PR]") == 0)
2223 ext_sym
= symbol_find_or_make (name
);
2225 *input_line_pointer
= endc
;
2227 if (*input_line_pointer
!= ',')
2229 as_bad ("missing symbol name");
2230 ignore_rest_of_line ();
2233 ++input_line_pointer
;
2235 name
= input_line_pointer
;
2236 endc
= get_symbol_end ();
2238 lab_sym
= symbol_find_or_make (name
);
2240 *input_line_pointer
= endc
;
2242 if (ext_sym
!= lab_sym
)
2244 ext_sym
->sy_value
.X_op
= O_symbol
;
2245 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2246 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2247 ext_sym
->sy_value
.X_add_number
= 0;
2250 if (ext_sym
->sy_tc
.class == -1)
2251 ext_sym
->sy_tc
.class = XMC_PR
;
2252 ext_sym
->sy_tc
.output
= 1;
2254 if (*input_line_pointer
== ',')
2258 /* Ignore the third argument. */
2259 ++input_line_pointer
;
2260 expression (&ignore
);
2261 if (*input_line_pointer
== ',')
2263 /* Ignore the fourth argument. */
2264 ++input_line_pointer
;
2265 expression (&ignore
);
2266 if (*input_line_pointer
== ',')
2268 /* The fifth argument is the function size. */
2269 ++input_line_pointer
;
2270 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2273 &zero_address_frag
);
2274 pseudo_set (ext_sym
->sy_tc
.size
);
2279 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2280 SF_SET_FUNCTION (ext_sym
);
2281 SF_SET_PROCESS (ext_sym
);
2282 coff_add_linesym (ext_sym
);
2284 demand_empty_rest_of_line ();
2287 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2296 sym
= symbol_make (".bf");
2297 S_SET_SEGMENT (sym
, text_section
);
2298 sym
->sy_frag
= frag_now
;
2299 S_SET_VALUE (sym
, frag_now_fix ());
2300 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2302 coff_line_base
= get_absolute_expression ();
2304 S_SET_NUMBER_AUXILIARY (sym
, 1);
2305 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2307 sym
->sy_tc
.output
= 1;
2309 ppc_frob_label (sym
);
2311 demand_empty_rest_of_line ();
2314 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2315 ".ef", except that the line number is absolute, not relative to the
2316 most recent ".bf" symbol. */
2324 sym
= symbol_make (".ef");
2325 S_SET_SEGMENT (sym
, text_section
);
2326 sym
->sy_frag
= frag_now
;
2327 S_SET_VALUE (sym
, frag_now_fix ());
2328 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2329 S_SET_NUMBER_AUXILIARY (sym
, 1);
2330 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2331 sym
->sy_tc
.output
= 1;
2333 ppc_frob_label (sym
);
2335 demand_empty_rest_of_line ();
2338 /* The .bi and .ei pseudo-ops. These take a string argument and
2339 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2351 name
= demand_copy_C_string (&len
);
2353 /* The value of these symbols is actually file offset. Here we set
2354 the value to the index into the line number entries. In
2355 ppc_frob_symbols we set the fix_line field, which will cause BFD
2356 to do the right thing. */
2358 sym
= symbol_make (name
);
2359 S_SET_SEGMENT (sym
, now_seg
);
2360 S_SET_VALUE (sym
, coff_n_line_nos
);
2361 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2363 /* obj-coff.c currently only handles line numbers correctly in the
2365 assert (now_seg
== text_section
);
2367 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2368 sym
->sy_tc
.output
= 1;
2370 for (look
= symbol_rootP
;
2371 (look
!= (symbolS
*) NULL
2372 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2373 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2374 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2375 look
= symbol_next (look
))
2377 if (look
!= (symbolS
*) NULL
)
2379 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2380 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2383 demand_empty_rest_of_line ();
2386 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2387 There is one argument, which is a csect symbol. The value of the
2388 .bs symbol is the index of this csect symbol. */
2399 if (ppc_current_block
!= NULL
)
2400 as_bad ("nested .bs blocks");
2402 name
= input_line_pointer
;
2403 endc
= get_symbol_end ();
2405 csect
= symbol_find_or_make (name
);
2407 *input_line_pointer
= endc
;
2409 sym
= symbol_make (".bs");
2410 S_SET_SEGMENT (sym
, now_seg
);
2411 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2412 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2413 sym
->sy_tc
.output
= 1;
2415 sym
->sy_tc
.within
= csect
;
2417 ppc_frob_label (sym
);
2419 ppc_current_block
= sym
;
2421 demand_empty_rest_of_line ();
2424 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2432 if (ppc_current_block
== NULL
)
2433 as_bad (".es without preceding .bs");
2435 sym
= symbol_make (".es");
2436 S_SET_SEGMENT (sym
, now_seg
);
2437 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2438 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2439 sym
->sy_tc
.output
= 1;
2441 ppc_frob_label (sym
);
2443 ppc_current_block
= NULL
;
2445 demand_empty_rest_of_line ();
2448 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2457 sym
= symbol_make (".bb");
2458 S_SET_SEGMENT (sym
, text_section
);
2459 sym
->sy_frag
= frag_now
;
2460 S_SET_VALUE (sym
, frag_now_fix ());
2461 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2463 S_SET_NUMBER_AUXILIARY (sym
, 1);
2464 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2466 sym
->sy_tc
.output
= 1;
2468 ppc_frob_label (sym
);
2470 demand_empty_rest_of_line ();
2473 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2482 sym
= symbol_make (".eb");
2483 S_SET_SEGMENT (sym
, text_section
);
2484 sym
->sy_frag
= frag_now
;
2485 S_SET_VALUE (sym
, frag_now_fix ());
2486 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2487 S_SET_NUMBER_AUXILIARY (sym
, 1);
2488 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2489 sym
->sy_tc
.output
= 1;
2491 ppc_frob_label (sym
);
2493 demand_empty_rest_of_line ();
2496 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2502 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2503 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2510 subseg
= ppc_data_subsegment
;
2511 ++ppc_data_subsegment
;
2513 subseg_new (segment_name (data_section
), subseg
);
2514 ppc_toc_frag
= frag_now
;
2516 sym
= symbol_find_or_make ("TOC[TC0]");
2517 sym
->sy_frag
= frag_now
;
2518 S_SET_SEGMENT (sym
, data_section
);
2519 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2520 sym
->sy_tc
.subseg
= subseg
;
2521 sym
->sy_tc
.output
= 1;
2522 sym
->sy_tc
.within
= sym
;
2524 ppc_toc_csect
= sym
;
2526 for (list
= ppc_data_csects
;
2527 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2528 list
= list
->sy_tc
.next
)
2530 list
->sy_tc
.next
= sym
;
2532 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2533 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2536 ppc_current_csect
= ppc_toc_csect
;
2538 demand_empty_rest_of_line ();
2541 #endif /* OBJ_XCOFF */
2543 /* The .tc pseudo-op. This is used when generating either XCOFF or
2544 ELF. This takes two or more arguments.
2546 When generating XCOFF output, the first argument is the name to
2547 give to this location in the toc; this will be a symbol with class
2548 TC. The rest of the arguments are 4 byte values to actually put at
2549 this location in the TOC; often there is just one more argument, a
2550 relocateable symbol reference.
2552 When not generating XCOFF output, the arguments are the same, but
2553 the first argument is simply ignored. */
2561 /* Define the TOC symbol name. */
2567 if (ppc_toc_csect
== (symbolS
*) NULL
2568 || ppc_toc_csect
!= ppc_current_csect
)
2570 as_bad (".tc not in .toc section");
2571 ignore_rest_of_line ();
2575 name
= input_line_pointer
;
2576 endc
= get_symbol_end ();
2578 sym
= symbol_find_or_make (name
);
2580 *input_line_pointer
= endc
;
2582 if (S_IS_DEFINED (sym
))
2586 label
= ppc_current_csect
->sy_tc
.within
;
2587 if (label
->sy_tc
.class != XMC_TC0
)
2589 as_warn (".tc with no label");
2590 ignore_rest_of_line ();
2594 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
2595 label
->sy_frag
= sym
->sy_frag
;
2596 S_SET_VALUE (label
, S_GET_VALUE (sym
));
2598 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2599 ++input_line_pointer
;
2604 S_SET_SEGMENT (sym
, now_seg
);
2605 sym
->sy_frag
= frag_now
;
2606 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2607 sym
->sy_tc
.class = XMC_TC
;
2608 sym
->sy_tc
.output
= 1;
2610 ppc_frob_label (sym
);
2613 #else /* ! defined (OBJ_XCOFF) */
2615 /* Skip the TOC symbol name. */
2616 while (is_part_of_name (*input_line_pointer
)
2617 || *input_line_pointer
== '['
2618 || *input_line_pointer
== ']'
2619 || *input_line_pointer
== '{'
2620 || *input_line_pointer
== '}')
2621 ++input_line_pointer
;
2623 /* Align to a four byte boundary. */
2625 record_alignment (now_seg
, 2);
2627 #endif /* ! defined (OBJ_XCOFF) */
2629 if (*input_line_pointer
!= ',')
2630 demand_empty_rest_of_line ();
2633 ++input_line_pointer
;
2640 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2642 /* Set the current section. */
2644 ppc_set_current_section (new)
2647 ppc_previous_section
= ppc_current_section
;
2648 ppc_current_section
= new;
2651 /* pseudo-op: .previous
2652 behaviour: toggles the current section with the previous section.
2654 warnings: "No previous section"
2657 ppc_previous(ignore
)
2662 if (ppc_previous_section
== NULL
)
2664 as_warn("No previous section to return to. Directive ignored.");
2668 subseg_set(ppc_previous_section
, 0);
2670 ppc_set_current_section(ppc_previous_section
);
2673 /* pseudo-op: .pdata
2674 behaviour: predefined read only data section
2678 initial: .section .pdata "adr3"
2679 a - don't know -- maybe a misprint
2680 d - initialized data
2682 3 - double word aligned (that would be 4 byte boundary)
2685 Tag index tables (also known as the function table) for exception
2686 handling, debugging, etc.
2693 if (pdata_section
== 0)
2695 pdata_section
= subseg_new (".pdata", 0);
2697 bfd_set_section_flags (stdoutput
, pdata_section
,
2698 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2699 | SEC_READONLY
| SEC_DATA
));
2701 bfd_set_section_alignment (stdoutput
, pdata_section
, 3);
2705 pdata_section
= subseg_new(".pdata", 0);
2707 ppc_set_current_section(pdata_section
);
2710 /* pseudo-op: .ydata
2711 behaviour: predefined read only data section
2715 initial: .section .ydata "drw3"
2716 a - don't know -- maybe a misprint
2717 d - initialized data
2719 3 - double word aligned (that would be 4 byte boundary)
2721 Tag tables (also known as the scope table) for exception handling,
2728 if (ydata_section
== 0)
2730 ydata_section
= subseg_new (".ydata", 0);
2731 bfd_set_section_flags (stdoutput
, ydata_section
,
2732 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2733 | SEC_READONLY
| SEC_DATA
));
2735 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
2739 ydata_section
= subseg_new (".ydata", 0);
2741 ppc_set_current_section(ydata_section
);
2744 /* pseudo-op: .reldata
2745 behaviour: predefined read write data section
2746 double word aligned (4-byte)
2747 FIXME: relocation is applied to it
2748 FIXME: what's the difference between this and .data?
2751 initial: .section .reldata "drw3"
2752 d - initialized data
2755 3 - double word aligned (that would be 8 byte boundary)
2758 Like .data, but intended to hold data subject to relocation, such as
2759 function descriptors, etc.
2765 if (reldata_section
== 0)
2767 reldata_section
= subseg_new (".reldata", 0);
2769 bfd_set_section_flags (stdoutput
, reldata_section
,
2770 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2773 bfd_set_section_alignment (stdoutput
, reldata_section
, 3);
2777 reldata_section
= subseg_new (".reldata", 0);
2779 ppc_set_current_section(reldata_section
);
2782 /* pseudo-op: .rdata
2783 behaviour: predefined read only data section
2787 initial: .section .rdata "dr3"
2788 d - initialized data
2790 3 - double word aligned (that would be 4 byte boundary)
2796 if (rdata_section
== 0)
2798 rdata_section
= subseg_new (".rdata", 0);
2799 bfd_set_section_flags (stdoutput
, rdata_section
,
2800 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2801 | SEC_READONLY
| SEC_DATA
));
2803 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
2807 rdata_section
= subseg_new (".rdata", 0);
2809 ppc_set_current_section(rdata_section
);
2812 /* pseudo-op: .ualong
2813 behaviour: much like .int, with the exception that no alignment is
2815 FIXME: test the alignment statement
2827 /* pseudo-op: .znop <symbol name>
2828 behaviour: Issue a nop instruction
2829 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2830 the supplied symbol name.
2832 warnings: Missing symbol name
2839 const struct powerpc_opcode
*opcode
;
2845 /* Strip out the symbol name */
2853 symbol_name
= input_line_pointer
;
2854 c
= get_symbol_end ();
2856 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
2857 strcpy (name
, symbol_name
);
2859 sym
= symbol_find_or_make (name
);
2861 *input_line_pointer
= c
;
2865 /* Look up the opcode in the hash table. */
2866 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
2868 /* stick in the nop */
2869 insn
= opcode
->opcode
;
2871 /* Write out the instruction. */
2873 md_number_to_chars (f
, insn
, 4);
2875 f
- frag_now
->fr_literal
,
2880 BFD_RELOC_16_GOT_PCREL
);
2893 register char *name
;
2897 register symbolS
*symbolP
;
2900 name
= input_line_pointer
;
2901 c
= get_symbol_end ();
2903 /* just after name is now '\0' */
2904 p
= input_line_pointer
;
2907 if (*input_line_pointer
!= ',')
2909 as_bad ("Expected comma after symbol-name: rest of line ignored.");
2910 ignore_rest_of_line ();
2914 input_line_pointer
++; /* skip ',' */
2915 if ((temp
= get_absolute_expression ()) < 0)
2917 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
2918 ignore_rest_of_line ();
2924 /* The third argument to .comm is the alignment. */
2925 if (*input_line_pointer
!= ',')
2929 ++input_line_pointer
;
2930 align
= get_absolute_expression ();
2933 as_warn ("ignoring bad alignment");
2940 symbolP
= symbol_find_or_make (name
);
2943 if (S_IS_DEFINED (symbolP
))
2945 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2946 S_GET_NAME (symbolP
));
2947 ignore_rest_of_line ();
2951 if (S_GET_VALUE (symbolP
))
2953 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
2954 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
2955 S_GET_NAME (symbolP
),
2956 (long) S_GET_VALUE (symbolP
),
2961 S_SET_VALUE (symbolP
, (valueT
) temp
);
2962 S_SET_EXTERNAL (symbolP
);
2965 demand_empty_rest_of_line ();
2969 * implement the .section pseudo op:
2970 * .section name {, "flags"}
2972 * | +--- optional flags: 'b' for bss
2974 * +-- section name 'l' for lib
2978 * 'd' (apparently m88k for data)
2980 * But if the argument is not a quoted string, treat it as a
2981 * subsegment number.
2983 * FIXME: this is a copy of the section processing from obj-coff.c, with
2984 * additions/changes for the moto-pas assembler support. There are three
2987 * FIXME: I just noticed this. This doesn't work at all really. It it
2988 * setting bits that bfd probably neither understands or uses. The
2989 * correct approach (?) will have to incorporate extra fields attached
2990 * to the section to hold the system specific stuff. (krk)
2993 * 'a' - unknown - referred to in documentation, but no definition supplied
2994 * 'c' - section has code
2995 * 'd' - section has initialized data
2996 * 'u' - section has uninitialized data
2997 * 'i' - section contains directives (info)
2998 * 'n' - section can be discarded
2999 * 'R' - remove section at link time
3001 * Section Protection:
3002 * 'r' - section is readable
3003 * 'w' - section is writeable
3004 * 'x' - section is executable
3005 * 's' - section is sharable
3007 * Section Alignment:
3008 * '0' - align to byte boundary
3009 * '1' - align to halfword undary
3010 * '2' - align to word boundary
3011 * '3' - align to doubleword boundary
3012 * '4' - align to quadword boundary
3013 * '5' - align to 32 byte boundary
3014 * '6' - align to 64 byte boundary
3019 ppc_pe_section (ignore
)
3022 /* Strip out the section name */
3031 align
= 4; /* default alignment to 16 byte boundary */
3033 section_name
= input_line_pointer
;
3034 c
= get_symbol_end ();
3036 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3037 strcpy (name
, section_name
);
3039 *input_line_pointer
= c
;
3044 flags
= SEC_NO_FLAGS
;
3046 if (*input_line_pointer
== ',')
3048 ++input_line_pointer
;
3050 if (*input_line_pointer
!= '"')
3051 exp
= get_absolute_expression ();
3054 ++input_line_pointer
;
3055 while (*input_line_pointer
!= '"'
3056 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3058 switch (*input_line_pointer
)
3060 /* Section Contents */
3061 case 'a': /* unknown */
3062 as_warn ("Unsupported section attribute -- 'a'");
3064 case 'c': /* code section */
3067 case 'd': /* section has initialized data */
3070 case 'u': /* section has uninitialized data */
3071 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3075 case 'i': /* section contains directives (info) */
3076 /* FIXME: This is IMAGE_SCN_LNK_INFO
3078 flags
|= SEC_HAS_CONTENTS
;
3080 case 'n': /* section can be discarded */
3083 case 'R': /* Remove section at link time */
3084 flags
|= SEC_NEVER_LOAD
;
3087 /* Section Protection */
3088 case 'r': /* section is readable */
3089 flags
|= IMAGE_SCN_MEM_READ
;
3091 case 'w': /* section is writeable */
3092 flags
|= IMAGE_SCN_MEM_WRITE
;
3094 case 'x': /* section is executable */
3095 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3097 case 's': /* section is sharable */
3098 flags
|= IMAGE_SCN_MEM_SHARED
;
3101 /* Section Alignment */
3102 case '0': /* align to byte boundary */
3103 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3106 case '1': /* align to halfword boundary */
3107 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3110 case '2': /* align to word boundary */
3111 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3114 case '3': /* align to doubleword boundary */
3115 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3118 case '4': /* align to quadword boundary */
3119 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3122 case '5': /* align to 32 byte boundary */
3123 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3126 case '6': /* align to 64 byte boundary */
3127 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3132 as_warn("unknown section attribute '%c'",
3133 *input_line_pointer
);
3136 ++input_line_pointer
;
3138 if (*input_line_pointer
== '"')
3139 ++input_line_pointer
;
3143 sec
= subseg_new (name
, (subsegT
) exp
);
3145 ppc_set_current_section(sec
);
3147 if (flags
!= SEC_NO_FLAGS
)
3149 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3150 as_warn ("error setting flags for \"%s\": %s",
3151 bfd_section_name (stdoutput
, sec
),
3152 bfd_errmsg (bfd_get_error ()));
3155 bfd_set_section_alignment(stdoutput
, sec
, align
);
3160 ppc_pe_function (ignore
)
3167 name
= input_line_pointer
;
3168 endc
= get_symbol_end ();
3170 ext_sym
= symbol_find_or_make (name
);
3172 *input_line_pointer
= endc
;
3174 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3175 SF_SET_FUNCTION (ext_sym
);
3176 SF_SET_PROCESS (ext_sym
);
3177 coff_add_linesym (ext_sym
);
3179 demand_empty_rest_of_line ();
3183 ppc_pe_tocd (ignore
)
3186 if (tocdata_section
== 0)
3188 tocdata_section
= subseg_new (".tocd", 0);
3189 /* FIXME: section flags won't work */
3190 bfd_set_section_flags (stdoutput
, tocdata_section
,
3191 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3192 | SEC_READONLY
| SEC_DATA
));
3194 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3198 rdata_section
= subseg_new (".tocd", 0);
3201 ppc_set_current_section(tocdata_section
);
3203 demand_empty_rest_of_line ();
3206 /* Don't adjust TOC relocs to use the section symbol. */
3209 ppc_pe_fix_adjustable (fix
)
3212 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3219 /* XCOFF specific symbol and file handling. */
3221 /* Canonicalize the symbol name. We use the to force the suffix, if
3222 any, to use square brackets, and to be in upper case. */
3225 ppc_canonicalize_symbol_name (name
)
3230 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3244 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3248 if (*s
== '\0' || s
[1] != '\0')
3249 as_bad ("bad symbol suffix");
3257 /* Set the class of a symbol based on the suffix, if any. This is
3258 called whenever a new symbol is created. */
3261 ppc_symbol_new_hook (sym
)
3266 sym
->sy_tc
.next
= NULL
;
3267 sym
->sy_tc
.output
= 0;
3268 sym
->sy_tc
.class = -1;
3269 sym
->sy_tc
.real_name
= NULL
;
3270 sym
->sy_tc
.subseg
= 0;
3271 sym
->sy_tc
.align
= 0;
3272 sym
->sy_tc
.size
= NULL
;
3273 sym
->sy_tc
.within
= NULL
;
3275 s
= strchr (S_GET_NAME (sym
), '[');
3276 if (s
== (const char *) NULL
)
3278 /* There is no suffix. */
3287 if (strcmp (s
, "BS]") == 0)
3288 sym
->sy_tc
.class = XMC_BS
;
3291 if (strcmp (s
, "DB]") == 0)
3292 sym
->sy_tc
.class = XMC_DB
;
3293 else if (strcmp (s
, "DS]") == 0)
3294 sym
->sy_tc
.class = XMC_DS
;
3297 if (strcmp (s
, "GL]") == 0)
3298 sym
->sy_tc
.class = XMC_GL
;
3301 if (strcmp (s
, "PR]") == 0)
3302 sym
->sy_tc
.class = XMC_PR
;
3305 if (strcmp (s
, "RO]") == 0)
3306 sym
->sy_tc
.class = XMC_RO
;
3307 else if (strcmp (s
, "RW]") == 0)
3308 sym
->sy_tc
.class = XMC_RW
;
3311 if (strcmp (s
, "SV]") == 0)
3312 sym
->sy_tc
.class = XMC_SV
;
3315 if (strcmp (s
, "TC]") == 0)
3316 sym
->sy_tc
.class = XMC_TC
;
3317 else if (strcmp (s
, "TI]") == 0)
3318 sym
->sy_tc
.class = XMC_TI
;
3319 else if (strcmp (s
, "TB]") == 0)
3320 sym
->sy_tc
.class = XMC_TB
;
3321 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3322 sym
->sy_tc
.class = XMC_TC0
;
3325 if (strcmp (s
, "UA]") == 0)
3326 sym
->sy_tc
.class = XMC_UA
;
3327 else if (strcmp (s
, "UC]") == 0)
3328 sym
->sy_tc
.class = XMC_UC
;
3331 if (strcmp (s
, "XO]") == 0)
3332 sym
->sy_tc
.class = XMC_XO
;
3336 if (sym
->sy_tc
.class == -1)
3337 as_bad ("Unrecognized symbol suffix");
3340 /* Set the class of a label based on where it is defined. This
3341 handles symbols without suffixes. Also, move the symbol so that it
3342 follows the csect symbol. */
3345 ppc_frob_label (sym
)
3348 if (ppc_current_csect
!= (symbolS
*) NULL
)
3350 if (sym
->sy_tc
.class == -1)
3351 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3353 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3354 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3356 ppc_current_csect
->sy_tc
.within
= sym
;
3360 /* Change the name of a symbol just before writing it out. Set the
3361 real name if the .rename pseudo-op was used. Otherwise, remove any
3362 class suffix. Return 1 if the symbol should not be included in the
3366 ppc_frob_symbol (sym
)
3369 static symbolS
*ppc_last_function
;
3370 static symbolS
*set_end
;
3372 /* Discard symbols that should not be included in the output symbol
3374 if (! sym
->sy_used_in_reloc
3375 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3376 || (! S_IS_EXTERNAL (sym
)
3377 && ! sym
->sy_tc
.output
3378 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3381 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3382 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3388 name
= S_GET_NAME (sym
);
3389 s
= strchr (name
, '[');
3390 if (s
!= (char *) NULL
)
3396 snew
= xmalloc (len
+ 1);
3397 memcpy (snew
, name
, len
);
3400 S_SET_NAME (sym
, snew
);
3404 if (set_end
!= (symbolS
*) NULL
)
3406 SA_SET_SYM_ENDNDX (set_end
, sym
);
3410 if (SF_GET_FUNCTION (sym
))
3412 if (ppc_last_function
!= (symbolS
*) NULL
)
3413 as_warn ("two .function pseudo-ops with no intervening .ef");
3414 ppc_last_function
= sym
;
3415 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3417 resolve_symbol_value (sym
->sy_tc
.size
);
3418 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3421 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3422 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3424 if (ppc_last_function
== (symbolS
*) NULL
)
3425 as_warn (".ef with no preceding .function");
3428 set_end
= ppc_last_function
;
3429 ppc_last_function
= NULL
;
3431 /* We don't have a C_EFCN symbol, but we need to force the
3432 COFF backend to believe that it has seen one. */
3433 coff_last_function
= NULL
;
3437 if (! S_IS_EXTERNAL (sym
)
3438 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3439 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3440 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3441 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3442 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3443 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
3444 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
3445 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3446 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3448 if ((S_GET_STORAGE_CLASS (sym
) == C_EXT
3449 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3450 && S_GET_SEGMENT (sym
) != absolute_section
)
3453 union internal_auxent
*a
;
3455 /* Create a csect aux. */
3456 i
= S_GET_NUMBER_AUXILIARY (sym
);
3457 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3458 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3459 if (sym
->sy_tc
.class == XMC_TC0
)
3461 /* This is the TOC table. */
3462 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3463 a
->x_csect
.x_scnlen
.l
= 0;
3464 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3466 else if (sym
->sy_tc
.subseg
!= 0)
3468 /* This is a csect symbol. x_scnlen is the size of the
3470 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3471 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3472 S_GET_SEGMENT (sym
))
3473 - S_GET_VALUE (sym
));
3476 resolve_symbol_value (sym
->sy_tc
.next
);
3477 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3478 - S_GET_VALUE (sym
));
3480 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3482 else if (S_GET_SEGMENT (sym
) == bss_section
)
3484 /* This is a common symbol. */
3485 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3486 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3487 if (S_IS_EXTERNAL (sym
))
3488 sym
->sy_tc
.class = XMC_RW
;
3490 sym
->sy_tc
.class = XMC_BS
;
3492 else if (! S_IS_DEFINED (sym
))
3494 /* This is an external symbol. */
3495 a
->x_csect
.x_scnlen
.l
= 0;
3496 a
->x_csect
.x_smtyp
= XTY_ER
;
3498 else if (sym
->sy_tc
.class == XMC_TC
)
3502 /* This is a TOC definition. x_scnlen is the size of the
3504 next
= symbol_next (sym
);
3505 while (next
->sy_tc
.class == XMC_TC0
)
3506 next
= symbol_next (next
);
3507 if (next
== (symbolS
*) NULL
3508 || next
->sy_tc
.class != XMC_TC
)
3510 if (ppc_after_toc_frag
== (fragS
*) NULL
)
3511 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3513 - S_GET_VALUE (sym
));
3515 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
3516 - S_GET_VALUE (sym
));
3520 resolve_symbol_value (next
);
3521 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
3522 - S_GET_VALUE (sym
));
3524 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3530 /* This is a normal symbol definition. x_scnlen is the
3531 symbol index of the containing csect. */
3532 if (S_GET_SEGMENT (sym
) == text_section
)
3533 csect
= ppc_text_csects
;
3534 else if (S_GET_SEGMENT (sym
) == data_section
)
3535 csect
= ppc_data_csects
;
3539 /* Skip the initial dummy symbol. */
3540 csect
= csect
->sy_tc
.next
;
3542 if (csect
== (symbolS
*) NULL
)
3543 a
->x_csect
.x_scnlen
.l
= 0;
3546 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
3548 resolve_symbol_value (csect
->sy_tc
.next
);
3549 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
3551 csect
= csect
->sy_tc
.next
;
3554 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3555 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
3557 a
->x_csect
.x_smtyp
= XTY_LD
;
3560 a
->x_csect
.x_parmhash
= 0;
3561 a
->x_csect
.x_snhash
= 0;
3562 if (sym
->sy_tc
.class == -1)
3563 a
->x_csect
.x_smclas
= XMC_PR
;
3565 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
3566 a
->x_csect
.x_stab
= 0;
3567 a
->x_csect
.x_snstab
= 0;
3569 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
3571 /* We want the value to be the symbol index of the referenced
3572 csect symbol. BFD will do that for us if we set the right
3575 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
3576 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
3578 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
3583 /* The value is the offset from the enclosing csect. */
3584 block
= sym
->sy_tc
.within
;
3585 csect
= block
->sy_tc
.within
;
3586 resolve_symbol_value (csect
);
3587 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
3589 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
3590 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
3592 /* We want the value to be a file offset into the line numbers.
3593 BFD will do that for us if we set the right flags. We have
3594 already set the value correctly. */
3595 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
3601 /* Set the VMA for a section. This is called on all the sections in
3605 ppc_frob_section (sec
)
3608 static bfd_size_type vma
= 0;
3610 bfd_set_section_vma (stdoutput
, sec
, vma
);
3611 vma
+= bfd_section_size (stdoutput
, sec
);
3614 /* Adjust the file by adding a .debug section if needed. */
3619 if (ppc_debug_name_section_size
> 0)
3623 sec
= bfd_make_section (stdoutput
, ".debug");
3624 if (sec
== (asection
*) NULL
3625 || ! bfd_set_section_size (stdoutput
, sec
,
3626 ppc_debug_name_section_size
)
3627 || ! bfd_set_section_flags (stdoutput
, sec
,
3628 SEC_HAS_CONTENTS
| SEC_LOAD
))
3629 as_fatal ("can't make .debug section");
3633 #endif /* OBJ_XCOFF */
3635 /* Turn a string in input_line_pointer into a floating point constant
3636 of type type, and store the appropriate bytes in *litp. The number
3637 of LITTLENUMS emitted is stored in *sizep . An error message is
3638 returned, or NULL on OK. */
3641 md_atof (type
, litp
, sizep
)
3647 LITTLENUM_TYPE words
[4];
3663 return "bad call to md_atof";
3666 t
= atof_ieee (input_line_pointer
, type
, words
);
3668 input_line_pointer
= t
;
3672 if (target_big_endian
)
3674 for (i
= 0; i
< prec
; i
++)
3676 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3682 for (i
= prec
- 1; i
>= 0; i
--)
3684 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3692 /* Write a value out to the object file, using the appropriate
3696 md_number_to_chars (buf
, val
, n
)
3701 if (target_big_endian
)
3702 number_to_chars_bigendian (buf
, val
, n
);
3704 number_to_chars_littleendian (buf
, val
, n
);
3707 /* Align a section (I don't know why this is machine dependent). */
3710 md_section_align (seg
, addr
)
3714 int align
= bfd_get_section_alignment (stdoutput
, seg
);
3716 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
3719 /* We don't have any form of relaxing. */
3722 md_estimate_size_before_relax (fragp
, seg
)
3730 /* Convert a machine dependent frag. We never generate these. */
3733 md_convert_frag (abfd
, sec
, fragp
)
3741 /* We have no need to default values of symbols. */
3745 md_undefined_symbol (name
)
3751 /* Functions concerning relocs. */
3753 /* The location from which a PC relative jump should be calculated,
3754 given a PC relative reloc. */
3757 md_pcrel_from (fixp
)
3761 if (fixp
->fx_addsy
!= (symbolS
*) NULL
3762 && (! S_IS_DEFINED (fixp
->fx_addsy
)
3763 || TC_FORCE_RELOCATION (fixp
)))
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
;