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 present, 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/-mcom, 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_POWER2
)
764 == (PPC_OPCODE_POWER
| PPC_OPCODE_PPC
))
765 || (strcmp (op
->name
, "cmpli") != 0
766 && strcmp (op
->name
, "cmpi") != 0
767 && strcmp (op
->name
, "cmp") != 0
768 && strcmp (op
->name
, "cmpl") != 0))))
769 as_fatal ("Internal assembler error for instruction %s", op
->name
);
774 /* Insert the macros into a hash table. */
775 ppc_macro_hash
= hash_new ();
777 macro_end
= powerpc_macros
+ powerpc_num_macros
;
778 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
780 if ((macro
->flags
& ppc_cpu
) != 0)
784 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
785 if (retval
!= (const char *) NULL
)
790 /* Tell the main code what the endianness is if it is not overidden by the user. */
791 if (!set_target_endian
)
793 set_target_endian
= 1;
794 target_big_endian
= PPC_BIG_ENDIAN
;
798 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
800 /* Create dummy symbols to serve as initial csects. This forces the
801 text csects to precede the data csects. These symbols will not
803 ppc_text_csects
= symbol_make ("dummy\001");
804 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
805 ppc_data_csects
= symbol_make ("dummy\001");
806 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
811 ppc_current_section
= text_section
;
812 ppc_previous_section
= 0;
817 /* Insert an operand value into an instruction. */
820 ppc_insert_operand (insn
, operand
, val
, file
, line
)
822 const struct powerpc_operand
*operand
;
827 if (operand
->bits
!= 32)
832 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
834 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
835 && ppc_size
== PPC_OPCODE_32
)
836 max
= (1 << operand
->bits
) - 1;
838 max
= (1 << (operand
->bits
- 1)) - 1;
839 min
= - (1 << (operand
->bits
- 1));
843 max
= (1 << operand
->bits
) - 1;
847 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
852 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
855 "operand out of range (%s not between %ld and %ld)";
858 sprint_value (buf
, test
);
859 if (file
== (char *) NULL
)
860 as_warn (err
, buf
, min
, max
);
862 as_warn_where (file
, line
, err
, buf
, min
, max
);
871 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
872 if (errmsg
!= (const char *) NULL
)
876 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
883 /* Parse @got, etc. and return the desired relocation. */
884 static bfd_reloc_code_real_type
885 ppc_elf_suffix (str_p
)
891 bfd_reloc_code_real_type reloc
;
901 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
903 static struct map_bfd mapping
[] = {
904 MAP ("got", BFD_RELOC_PPC_TOC16
),
905 MAP ("l", BFD_RELOC_LO16
),
906 MAP ("h", BFD_RELOC_HI16
),
907 MAP ("ha", BFD_RELOC_HI16_S
),
908 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
909 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
910 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
911 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
912 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
913 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
914 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
915 MAP ("copy", BFD_RELOC_PPC_COPY
),
916 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
917 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
918 MAP ("plt", BFD_RELOC_32_PLTOFF
),
919 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
920 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
921 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
922 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
923 MAP ("sdarel", BFD_RELOC_GPREL16
),
924 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
925 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
926 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
927 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
929 { (char *)0, 0, BFD_RELOC_UNUSED
}
933 return BFD_RELOC_UNUSED
;
935 for (ch
= *str
, str2
= ident
;
936 str2
< ident
+ sizeof(ident
) - 1 && isalnum (ch
) || ch
== '@';
939 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
946 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
947 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
953 return BFD_RELOC_UNUSED
;
956 /* Like normal .long/.short/.word, except support @got, etc. */
957 /* clobbers input_line_pointer, checks */
960 ppc_elf_cons (nbytes
)
961 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
964 bfd_reloc_code_real_type reloc
;
966 if (is_it_end_of_statement ())
968 demand_empty_rest_of_line ();
975 if (exp
.X_op
== O_symbol
976 && *input_line_pointer
== '@'
977 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
979 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
980 int size
= bfd_get_reloc_size (reloc_howto
);
983 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
987 register char *p
= frag_more ((int) nbytes
);
988 int offset
= nbytes
- size
;
990 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
994 emit_expr (&exp
, (unsigned int) nbytes
);
996 while (*input_line_pointer
++ == ',');
998 input_line_pointer
--; /* Put terminator back into stream. */
999 demand_empty_rest_of_line ();
1002 /* Validate any relocations emitted for -mrelocatable, possibly adding
1003 fixups for word relocations in writable segments, so we can adjust
1006 ppc_elf_validate_fix (fixp
, seg
)
1013 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1014 && strcmp (segment_name (seg
), ".got2") != 0
1015 && strcmp (segment_name (seg
), ".dtors") != 0
1016 && strcmp (segment_name (seg
), ".ctors") != 0
1017 && strcmp (segment_name (seg
), ".fixup") != 0
1018 && strcmp (segment_name (seg
), ".stab") != 0)
1020 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1021 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1023 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
1024 "Relocation cannot be done when using -mrelocatable");
1029 #endif /* OBJ_ELF */
1033 * Summary of register_name().
1035 * in: Input_line_pointer points to 1st char of operand.
1037 * out: A expressionS.
1038 * The operand may have been a register: in this case, X_op == O_register,
1039 * X_add_number is set to the register number, and truth is returned.
1040 * Input_line_pointer->(next non-blank) char after operand, or is in its
1045 register_name (expressionP
)
1046 expressionS
*expressionP
;
1052 /* Find the spelling of the operand */
1053 name
= input_line_pointer
;
1054 c
= get_symbol_end ();
1055 reg_number
= reg_name_search (name
);
1057 /* look to see if it's in the register table */
1058 if (reg_number
>= 0)
1060 expressionP
->X_op
= O_register
;
1061 expressionP
->X_add_number
= reg_number
;
1063 /* make the rest nice */
1064 expressionP
->X_add_symbol
= NULL
;
1065 expressionP
->X_op_symbol
= NULL
;
1066 *input_line_pointer
= c
; /* put back the delimiting char */
1071 /* reset the line as if we had not done anything */
1072 *input_line_pointer
= c
; /* put back the delimiting char */
1073 input_line_pointer
= name
; /* reset input_line pointer */
1079 * Summary of parse_toc_entry().
1081 * in: Input_line_pointer points to the '[' in one of:
1083 * [toc] [tocv] [toc32] [toc64]
1085 * Anything else is an error of one kind or another.
1088 * return value: success or failure
1089 * toc_kind: kind of toc reference
1090 * input_line_pointer:
1091 * success: first char after the ']'
1092 * failure: unchanged
1096 * [toc] - rv == success, toc_kind = default_toc
1097 * [tocv] - rv == success, toc_kind = data_in_toc
1098 * [toc32] - rv == success, toc_kind = must_be_32
1099 * [toc64] - rv == success, toc_kind = must_be_64
1103 enum toc_size_qualifier
1105 default_toc
, /* The toc cell constructed should be the system default size */
1106 data_in_toc
, /* This is a direct reference to a toc cell */
1107 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1108 must_be_64
/* The toc cell constructed must be 64 bits wide */
1112 parse_toc_entry(toc_kind
)
1113 enum toc_size_qualifier
*toc_kind
;
1118 enum toc_size_qualifier t
;
1120 /* save the input_line_pointer */
1121 start
= input_line_pointer
;
1123 /* skip over the '[' , and whitespace */
1124 ++input_line_pointer
;
1127 /* find the spelling of the operand */
1128 toc_spec
= input_line_pointer
;
1129 c
= get_symbol_end ();
1131 if (strcmp(toc_spec
, "toc") == 0)
1135 else if (strcmp(toc_spec
, "tocv") == 0)
1139 else if (strcmp(toc_spec
, "toc32") == 0)
1143 else if (strcmp(toc_spec
, "toc64") == 0)
1149 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec
);
1150 *input_line_pointer
= c
; /* put back the delimiting char */
1151 input_line_pointer
= start
; /* reset input_line pointer */
1155 /* now find the ']' */
1156 *input_line_pointer
= c
; /* put back the delimiting char */
1158 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1159 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
1163 as_bad ("syntax error: expected `]', found `%c'", c
);
1164 input_line_pointer
= start
; /* reset input_line pointer */
1168 *toc_kind
= t
; /* set return value */
1175 /* We need to keep a list of fixups. We can't simply generate them as
1176 we go, because that would require us to first create the frag, and
1177 that would screw up references to ``.''. */
1183 bfd_reloc_code_real_type reloc
;
1186 #define MAX_INSN_FIXUPS (5)
1188 /* This routine is called for each instruction to be assembled. */
1195 const struct powerpc_opcode
*opcode
;
1197 const unsigned char *opindex_ptr
;
1201 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1206 bfd_reloc_code_real_type reloc
;
1209 /* Get the opcode. */
1210 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1215 /* Look up the opcode in the hash table. */
1216 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1217 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1219 const struct powerpc_macro
*macro
;
1221 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1222 if (macro
== (const struct powerpc_macro
*) NULL
)
1223 as_bad ("Unrecognized opcode: `%s'", str
);
1225 ppc_macro (s
, macro
);
1230 insn
= opcode
->opcode
;
1233 while (isspace (*str
))
1236 /* PowerPC operands are just expressions. The only real issue is
1237 that a few operand types are optional. All cases which might use
1238 an optional operand separate the operands only with commas (in
1239 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1240 cases never have optional operands). There is never more than
1241 one optional operand for an instruction. So, before we start
1242 seriously parsing the operands, we check to see if we have an
1243 optional operand, and, if we do, we count the number of commas to
1244 see whether the operand should be omitted. */
1246 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1248 const struct powerpc_operand
*operand
;
1250 operand
= &powerpc_operands
[*opindex_ptr
];
1251 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1253 unsigned int opcount
;
1255 /* There is an optional operand. Count the number of
1256 commas in the input line. */
1263 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1270 /* If there are fewer operands in the line then are called
1271 for by the instruction, we want to skip the optional
1273 if (opcount
< strlen (opcode
->operands
))
1280 /* Gather the operands. */
1284 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1286 const struct powerpc_operand
*operand
;
1292 if (next_opindex
== 0)
1293 operand
= &powerpc_operands
[*opindex_ptr
];
1296 operand
= &powerpc_operands
[next_opindex
];
1302 /* If this is a fake operand, then we do not expect anything
1304 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1306 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1307 if (errmsg
!= (const char *) NULL
)
1312 /* If this is an optional operand, and we are skipping it, just
1314 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1317 if (operand
->insert
)
1319 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1320 if (errmsg
!= (const char *) NULL
)
1323 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1324 next_opindex
= *opindex_ptr
+ 1;
1328 /* Gather the operand. */
1329 hold
= input_line_pointer
;
1330 input_line_pointer
= str
;
1333 if (*input_line_pointer
== '[')
1335 /* We are expecting something like the second argument here:
1337 lwz r4,[toc].GS.0.static_int(rtoc)
1338 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1339 The argument following the `]' must be a symbol name, and the
1340 register must be the toc register: 'rtoc' or '2'
1342 The effect is to 0 as the displacement field
1343 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1344 the appropriate variation) reloc against it based on the symbol.
1345 The linker will build the toc, and insert the resolved toc offset.
1348 o The size of the toc entry is currently assumed to be
1349 32 bits. This should not be assumed to be a hard coded
1351 o In an effort to cope with a change from 32 to 64 bits,
1352 there are also toc entries that are specified to be
1353 either 32 or 64 bits:
1354 lwz r4,[toc32].GS.0.static_int(rtoc)
1355 lwz r4,[toc64].GS.0.static_int(rtoc)
1356 These demand toc entries of the specified size, and the
1357 instruction probably requires it.
1361 enum toc_size_qualifier toc_kind
;
1362 bfd_reloc_code_real_type toc_reloc
;
1364 /* go parse off the [tocXX] part */
1365 valid_toc
= parse_toc_entry(&toc_kind
);
1369 /* Note: message has already been issued. */
1370 /* FIXME: what sort of recovery should we do? */
1371 /* demand_rest_of_line(); return; ? */
1374 /* Now get the symbol following the ']' */
1380 /* In this case, we may not have seen the symbol yet, since */
1381 /* it is allowed to appear on a .extern or .globl or just be */
1382 /* a label in the .data section. */
1383 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1386 /* 1. The symbol must be defined and either in the toc */
1387 /* section, or a global. */
1388 /* 2. The reloc generated must have the TOCDEFN flag set in */
1389 /* upper bit mess of the reloc type. */
1390 /* FIXME: It's a little confusing what the tocv qualifier can */
1391 /* be used for. At the very least, I've seen three */
1392 /* uses, only one of which I'm sure I can explain. */
1393 if (ex
.X_op
== O_symbol
)
1395 assert (ex
.X_add_symbol
!= NULL
);
1396 if (ex
.X_add_symbol
->bsym
->section
!= tocdata_section
)
1398 as_warn("[tocv] symbol is not a toc symbol");
1402 toc_reloc
= BFD_RELOC_PPC_TOC16
;
1405 /* FIXME: these next two specifically specify 32/64 bit toc */
1406 /* entries. We don't support them today. Is this the */
1407 /* right way to say that? */
1408 toc_reloc
= BFD_RELOC_UNUSED
;
1409 as_bad ("Unimplemented toc32 expression modifier");
1412 /* FIXME: see above */
1413 toc_reloc
= BFD_RELOC_UNUSED
;
1414 as_bad ("Unimplemented toc64 expression modifier");
1418 "Unexpected return value [%d] from parse_toc_entry!\n",
1424 /* We need to generate a fixup for this expression. */
1425 if (fc
>= MAX_INSN_FIXUPS
)
1426 as_fatal ("too many fixups");
1428 fixups
[fc
].reloc
= toc_reloc
;
1429 fixups
[fc
].exp
= ex
;
1430 fixups
[fc
].opindex
= *opindex_ptr
;
1433 /* Ok. We've set up the fixup for the instruction. Now make it
1434 look like the constant 0 was found here */
1436 ex
.X_op
= O_constant
;
1437 ex
.X_add_number
= 0;
1438 ex
.X_add_symbol
= NULL
;
1439 ex
.X_op_symbol
= NULL
;
1443 if (!register_name(&ex
))
1449 str
= input_line_pointer
;
1450 input_line_pointer
= hold
;
1453 str
= input_line_pointer
;
1454 input_line_pointer
= hold
;
1457 if (ex
.X_op
== O_illegal
)
1458 as_bad ("illegal operand");
1459 else if (ex
.X_op
== O_absent
)
1460 as_bad ("missing operand");
1461 else if (ex
.X_op
== O_constant
)
1464 /* Allow @HA, @L, @H on constants. */
1465 char *orig_str
= str
;
1467 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1474 case BFD_RELOC_LO16
:
1475 ex
.X_add_number
= ((ex
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1478 case BFD_RELOC_HI16
:
1479 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1482 case BFD_RELOC_HI16_S
:
1483 ex
.X_add_number
= ((ex
.X_add_number
>> 16) & 0xffff)
1484 + ((ex
.X_add_number
>> 15) & 1);
1488 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1492 else if (ex
.X_op
== O_register
)
1494 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1499 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1501 /* For the absoulte forms of branchs, convert the PC relative form back into
1503 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1506 case BFD_RELOC_PPC_B26
: reloc
= BFD_RELOC_PPC_BA26
; break;
1507 case BFD_RELOC_PPC_B16
: reloc
= BFD_RELOC_PPC_BA16
; break;
1508 case BFD_RELOC_PPC_B16_BRTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
; break;
1509 case BFD_RELOC_PPC_B16_BRNTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
; break;
1512 /* We need to generate a fixup for this expression. */
1513 if (fc
>= MAX_INSN_FIXUPS
)
1514 as_fatal ("too many fixups");
1515 fixups
[fc
].exp
= ex
;
1516 fixups
[fc
].opindex
= 0;
1517 fixups
[fc
].reloc
= reloc
;
1520 #endif /* OBJ_ELF */
1524 /* We need to generate a fixup for this expression. */
1525 if (fc
>= MAX_INSN_FIXUPS
)
1526 as_fatal ("too many fixups");
1527 fixups
[fc
].exp
= ex
;
1528 fixups
[fc
].opindex
= *opindex_ptr
;
1529 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1538 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1546 /* The call to expression should have advanced str past any
1549 && (endc
!= ',' || *str
!= '\0'))
1551 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1559 while (isspace (*str
))
1563 as_bad ("junk at end of line: `%s'", str
);
1565 /* Write out the instruction. */
1567 md_number_to_chars (f
, insn
, 4);
1569 /* Create any fixups. At this point we do not use a
1570 bfd_reloc_code_real_type, but instead just use the
1571 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1572 handle fixups for any operand type, although that is admittedly
1573 not a very exciting feature. We pick a BFD reloc type in
1575 for (i
= 0; i
< fc
; i
++)
1577 const struct powerpc_operand
*operand
;
1579 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1580 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1582 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1590 size
= bfd_get_reloc_size (reloc_howto
);
1591 offset
= target_big_endian
? (4 - size
) : 0;
1593 if (size
< 1 || size
> 4)
1596 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1597 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1600 /* Turn off complaints that the addend is too large for things like
1602 switch (fixups
[i
].reloc
)
1604 case BFD_RELOC_LO16
:
1605 case BFD_RELOC_HI16
:
1606 case BFD_RELOC_HI16_S
:
1607 fixP
->fx_no_overflow
= 1;
1614 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1616 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1617 ((bfd_reloc_code_real_type
)
1618 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1622 #ifndef WORKING_DOT_WORD
1623 /* Handle long and short jumps */
1625 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1627 addressT from_addr
, to_addr
;
1635 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1637 addressT from_addr
, to_addr
;
1645 /* Handle a macro. Gather all the operands, transform them as
1646 described by the macro, and call md_assemble recursively. All the
1647 operands are separated by commas; we don't accept parentheses
1648 around operands here. */
1651 ppc_macro (str
, macro
)
1653 const struct powerpc_macro
*macro
;
1664 /* Gather the users operands into the operands array. */
1669 if (count
>= sizeof operands
/ sizeof operands
[0])
1671 operands
[count
++] = s
;
1672 s
= strchr (s
, ',');
1673 if (s
== (char *) NULL
)
1678 if (count
!= macro
->operands
)
1680 as_bad ("wrong number of operands");
1684 /* Work out how large the string must be (the size is unbounded
1685 because it includes user input). */
1687 format
= macro
->format
;
1688 while (*format
!= '\0')
1697 arg
= strtol (format
+ 1, &send
, 10);
1698 know (send
!= format
&& arg
>= 0 && arg
< count
);
1699 len
+= strlen (operands
[arg
]);
1704 /* Put the string together. */
1705 complete
= s
= (char *) alloca (len
+ 1);
1706 format
= macro
->format
;
1707 while (*format
!= '\0')
1713 arg
= strtol (format
+ 1, &send
, 10);
1714 strcpy (s
, operands
[arg
]);
1721 /* Assemble the constructed instruction. */
1722 md_assemble (complete
);
1725 /* Pseudo-op handling. */
1727 /* The .byte pseudo-op. This is similar to the normal .byte
1728 pseudo-op, but it can also take a single ASCII string. */
1734 if (*input_line_pointer
!= '\"')
1740 /* Gather characters. A real double quote is doubled. Unusual
1741 characters are not permitted. */
1742 ++input_line_pointer
;
1747 c
= *input_line_pointer
++;
1751 if (*input_line_pointer
!= '\"')
1753 ++input_line_pointer
;
1756 FRAG_APPEND_1_CHAR (c
);
1759 demand_empty_rest_of_line ();
1764 /* XCOFF specific pseudo-op handling. */
1766 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1767 symbols in the .bss segment as though they were local common
1768 symbols, and uses a different smclas. */
1774 asection
*current_seg
= now_seg
;
1775 subsegT current_subseg
= now_subseg
;
1781 symbolS
*lcomm_sym
= NULL
;
1785 name
= input_line_pointer
;
1786 endc
= get_symbol_end ();
1787 end_name
= input_line_pointer
;
1790 if (*input_line_pointer
!= ',')
1792 as_bad ("missing size");
1793 ignore_rest_of_line ();
1796 ++input_line_pointer
;
1798 size
= get_absolute_expression ();
1801 as_bad ("negative size");
1802 ignore_rest_of_line ();
1808 /* The third argument to .comm is the alignment. */
1809 if (*input_line_pointer
!= ',')
1813 ++input_line_pointer
;
1814 align
= get_absolute_expression ();
1817 as_warn ("ignoring bad alignment");
1836 /* The third argument to .lcomm appears to be the real local
1837 common symbol to create. References to the symbol named in
1838 the first argument are turned into references to the third
1840 if (*input_line_pointer
!= ',')
1842 as_bad ("missing real symbol name");
1843 ignore_rest_of_line ();
1846 ++input_line_pointer
;
1848 lcomm_name
= input_line_pointer
;
1849 lcomm_endc
= get_symbol_end ();
1851 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1853 *input_line_pointer
= lcomm_endc
;
1857 sym
= symbol_find_or_make (name
);
1860 if (S_IS_DEFINED (sym
)
1861 || S_GET_VALUE (sym
) != 0)
1863 as_bad ("attempt to redefine symbol");
1864 ignore_rest_of_line ();
1868 record_alignment (bss_section
, align
);
1871 || ! S_IS_DEFINED (lcomm_sym
))
1880 S_SET_EXTERNAL (sym
);
1884 lcomm_sym
->sy_tc
.output
= 1;
1885 def_sym
= lcomm_sym
;
1889 subseg_set (bss_section
, 1);
1890 frag_align (align
, 0);
1892 def_sym
->sy_frag
= frag_now
;
1893 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1894 def_size
, (char *) NULL
);
1896 S_SET_SEGMENT (def_sym
, bss_section
);
1897 def_sym
->sy_tc
.align
= align
;
1901 /* Align the size of lcomm_sym. */
1902 lcomm_sym
->sy_frag
->fr_offset
=
1903 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1904 &~ ((1 << align
) - 1));
1905 if (align
> lcomm_sym
->sy_tc
.align
)
1906 lcomm_sym
->sy_tc
.align
= align
;
1911 /* Make sym an offset from lcomm_sym. */
1912 S_SET_SEGMENT (sym
, bss_section
);
1913 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1914 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1915 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1918 subseg_set (current_seg
, current_subseg
);
1920 demand_empty_rest_of_line ();
1923 /* The .csect pseudo-op. This switches us into a different
1924 subsegment. The first argument is a symbol whose value is the
1925 start of the .csect. In COFF, csect symbols get special aux
1926 entries defined by the x_csect field of union internal_auxent. The
1927 optional second argument is the alignment (the default is 2). */
1937 name
= input_line_pointer
;
1938 endc
= get_symbol_end ();
1940 sym
= symbol_find_or_make (name
);
1942 *input_line_pointer
= endc
;
1944 if (S_IS_DEFINED (sym
))
1945 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1952 /* This is a new csect. We need to look at the symbol class to
1953 figure out whether it should go in the text section or the
1956 switch (sym
->sy_tc
.class)
1966 S_SET_SEGMENT (sym
, text_section
);
1967 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1968 ++ppc_text_subsegment
;
1969 list_ptr
= &ppc_text_csects
;
1978 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1980 S_SET_SEGMENT (sym
, data_section
);
1981 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1982 ++ppc_data_subsegment
;
1983 list_ptr
= &ppc_data_csects
;
1989 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1991 ppc_after_toc_frag
= frag_now
;
1993 sym
->sy_frag
= frag_now
;
1994 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1996 sym
->sy_tc
.align
= 2;
1997 sym
->sy_tc
.output
= 1;
1998 sym
->sy_tc
.within
= sym
;
2000 for (list
= *list_ptr
;
2001 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2002 list
= list
->sy_tc
.next
)
2004 list
->sy_tc
.next
= sym
;
2006 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2007 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2010 if (*input_line_pointer
== ',')
2012 ++input_line_pointer
;
2013 sym
->sy_tc
.align
= get_absolute_expression ();
2016 ppc_current_csect
= sym
;
2018 demand_empty_rest_of_line ();
2021 /* The .extern pseudo-op. We create an undefined symbol. */
2030 name
= input_line_pointer
;
2031 endc
= get_symbol_end ();
2033 (void) symbol_find_or_make (name
);
2035 *input_line_pointer
= endc
;
2037 demand_empty_rest_of_line ();
2040 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
2041 this because it can't handle undefined symbols. I think we can
2051 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2052 although I don't know why it bothers. */
2063 name
= input_line_pointer
;
2064 endc
= get_symbol_end ();
2066 sym
= symbol_find_or_make (name
);
2068 *input_line_pointer
= endc
;
2070 if (*input_line_pointer
!= ',')
2072 as_bad ("missing rename string");
2073 ignore_rest_of_line ();
2076 ++input_line_pointer
;
2078 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
2080 demand_empty_rest_of_line ();
2083 /* The .stabx pseudo-op. This is similar to a normal .stabs
2084 pseudo-op, but slightly different. A sample is
2085 .stabx "main:F-1",.main,142,0
2086 The first argument is the symbol name to create. The second is the
2087 value, and the third is the storage class. The fourth seems to be
2088 always zero, and I am assuming it is the type. */
2099 name
= demand_copy_C_string (&len
);
2101 if (*input_line_pointer
!= ',')
2103 as_bad ("missing value");
2106 ++input_line_pointer
;
2108 sym
= symbol_make (name
);
2110 (void) expression (&exp
);
2117 as_bad ("illegal .stabx expression; zero assumed");
2118 exp
.X_add_number
= 0;
2121 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
2122 sym
->sy_frag
= &zero_address_frag
;
2126 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
2127 sym
->sy_value
= exp
;
2131 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
2132 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
2137 /* The value is some complex expression. This will probably
2138 fail at some later point, but this is probably the right
2139 thing to do here. */
2140 sym
->sy_value
= exp
;
2144 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2145 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2147 if (*input_line_pointer
!= ',')
2149 as_bad ("missing class");
2152 ++input_line_pointer
;
2154 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
2156 if (*input_line_pointer
!= ',')
2158 as_bad ("missing type");
2161 ++input_line_pointer
;
2163 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
2165 sym
->sy_tc
.output
= 1;
2167 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2168 sym
->sy_tc
.within
= ppc_current_block
;
2170 if (exp
.X_op
!= O_symbol
2171 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
2172 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
2173 ppc_frob_label (sym
);
2176 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2177 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
2178 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
2179 ppc_current_csect
->sy_tc
.within
= sym
;
2182 if (strlen (name
) > SYMNMLEN
)
2184 /* For some reason, each name is preceded by a two byte length
2185 and followed by a null byte. */
2186 ppc_debug_name_section_size
+= strlen (name
) + 3;
2189 demand_empty_rest_of_line ();
2192 /* The .function pseudo-op. This takes several arguments. The first
2193 argument seems to be the external name of the symbol. The second
2194 argment seems to be the label for the start of the function. gcc
2195 uses the same name for both. I have no idea what the third and
2196 fourth arguments are meant to be. The optional fifth argument is
2197 an expression for the size of the function. In COFF this symbol
2198 gets an aux entry like that used for a csect. */
2201 ppc_function (ignore
)
2210 name
= input_line_pointer
;
2211 endc
= get_symbol_end ();
2213 /* Ignore any [PR] suffix. */
2214 name
= ppc_canonicalize_symbol_name (name
);
2215 s
= strchr (name
, '[');
2216 if (s
!= (char *) NULL
2217 && strcmp (s
+ 1, "PR]") == 0)
2220 ext_sym
= symbol_find_or_make (name
);
2222 *input_line_pointer
= endc
;
2224 if (*input_line_pointer
!= ',')
2226 as_bad ("missing symbol name");
2227 ignore_rest_of_line ();
2230 ++input_line_pointer
;
2232 name
= input_line_pointer
;
2233 endc
= get_symbol_end ();
2235 lab_sym
= symbol_find_or_make (name
);
2237 *input_line_pointer
= endc
;
2239 if (ext_sym
!= lab_sym
)
2241 ext_sym
->sy_value
.X_op
= O_symbol
;
2242 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
2243 ext_sym
->sy_value
.X_op_symbol
= NULL
;
2244 ext_sym
->sy_value
.X_add_number
= 0;
2247 if (ext_sym
->sy_tc
.class == -1)
2248 ext_sym
->sy_tc
.class = XMC_PR
;
2249 ext_sym
->sy_tc
.output
= 1;
2251 if (*input_line_pointer
== ',')
2255 /* Ignore the third argument. */
2256 ++input_line_pointer
;
2257 expression (&ignore
);
2258 if (*input_line_pointer
== ',')
2260 /* Ignore the fourth argument. */
2261 ++input_line_pointer
;
2262 expression (&ignore
);
2263 if (*input_line_pointer
== ',')
2265 /* The fifth argument is the function size. */
2266 ++input_line_pointer
;
2267 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2270 &zero_address_frag
);
2271 pseudo_set (ext_sym
->sy_tc
.size
);
2276 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2277 SF_SET_FUNCTION (ext_sym
);
2278 SF_SET_PROCESS (ext_sym
);
2279 coff_add_linesym (ext_sym
);
2281 demand_empty_rest_of_line ();
2284 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2293 sym
= symbol_make (".bf");
2294 S_SET_SEGMENT (sym
, text_section
);
2295 sym
->sy_frag
= frag_now
;
2296 S_SET_VALUE (sym
, frag_now_fix ());
2297 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2299 coff_line_base
= get_absolute_expression ();
2301 S_SET_NUMBER_AUXILIARY (sym
, 1);
2302 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2304 sym
->sy_tc
.output
= 1;
2306 ppc_frob_label (sym
);
2308 demand_empty_rest_of_line ();
2311 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2312 ".ef", except that the line number is absolute, not relative to the
2313 most recent ".bf" symbol. */
2321 sym
= symbol_make (".ef");
2322 S_SET_SEGMENT (sym
, text_section
);
2323 sym
->sy_frag
= frag_now
;
2324 S_SET_VALUE (sym
, frag_now_fix ());
2325 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2326 S_SET_NUMBER_AUXILIARY (sym
, 1);
2327 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2328 sym
->sy_tc
.output
= 1;
2330 ppc_frob_label (sym
);
2332 demand_empty_rest_of_line ();
2335 /* The .bi and .ei pseudo-ops. These take a string argument and
2336 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2348 name
= demand_copy_C_string (&len
);
2350 /* The value of these symbols is actually file offset. Here we set
2351 the value to the index into the line number entries. In
2352 ppc_frob_symbols we set the fix_line field, which will cause BFD
2353 to do the right thing. */
2355 sym
= symbol_make (name
);
2356 S_SET_SEGMENT (sym
, now_seg
);
2357 S_SET_VALUE (sym
, coff_n_line_nos
);
2358 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2360 /* obj-coff.c currently only handles line numbers correctly in the
2362 assert (now_seg
== text_section
);
2364 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2365 sym
->sy_tc
.output
= 1;
2367 for (look
= symbol_rootP
;
2368 (look
!= (symbolS
*) NULL
2369 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2370 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2371 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2372 look
= symbol_next (look
))
2374 if (look
!= (symbolS
*) NULL
)
2376 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2377 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2380 demand_empty_rest_of_line ();
2383 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2384 There is one argument, which is a csect symbol. The value of the
2385 .bs symbol is the index of this csect symbol. */
2396 if (ppc_current_block
!= NULL
)
2397 as_bad ("nested .bs blocks");
2399 name
= input_line_pointer
;
2400 endc
= get_symbol_end ();
2402 csect
= symbol_find_or_make (name
);
2404 *input_line_pointer
= endc
;
2406 sym
= symbol_make (".bs");
2407 S_SET_SEGMENT (sym
, now_seg
);
2408 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2409 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2410 sym
->sy_tc
.output
= 1;
2412 sym
->sy_tc
.within
= csect
;
2414 ppc_frob_label (sym
);
2416 ppc_current_block
= sym
;
2418 demand_empty_rest_of_line ();
2421 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2429 if (ppc_current_block
== NULL
)
2430 as_bad (".es without preceding .bs");
2432 sym
= symbol_make (".es");
2433 S_SET_SEGMENT (sym
, now_seg
);
2434 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2435 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2436 sym
->sy_tc
.output
= 1;
2438 ppc_frob_label (sym
);
2440 ppc_current_block
= NULL
;
2442 demand_empty_rest_of_line ();
2445 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2454 sym
= symbol_make (".bb");
2455 S_SET_SEGMENT (sym
, text_section
);
2456 sym
->sy_frag
= frag_now
;
2457 S_SET_VALUE (sym
, frag_now_fix ());
2458 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2460 S_SET_NUMBER_AUXILIARY (sym
, 1);
2461 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2463 sym
->sy_tc
.output
= 1;
2465 ppc_frob_label (sym
);
2467 demand_empty_rest_of_line ();
2470 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2479 sym
= symbol_make (".eb");
2480 S_SET_SEGMENT (sym
, text_section
);
2481 sym
->sy_frag
= frag_now
;
2482 S_SET_VALUE (sym
, frag_now_fix ());
2483 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2484 S_SET_NUMBER_AUXILIARY (sym
, 1);
2485 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2486 sym
->sy_tc
.output
= 1;
2488 ppc_frob_label (sym
);
2490 demand_empty_rest_of_line ();
2493 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2499 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2500 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2507 subseg
= ppc_data_subsegment
;
2508 ++ppc_data_subsegment
;
2510 subseg_new (segment_name (data_section
), subseg
);
2511 ppc_toc_frag
= frag_now
;
2513 sym
= symbol_find_or_make ("TOC[TC0]");
2514 sym
->sy_frag
= frag_now
;
2515 S_SET_SEGMENT (sym
, data_section
);
2516 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2517 sym
->sy_tc
.subseg
= subseg
;
2518 sym
->sy_tc
.output
= 1;
2519 sym
->sy_tc
.within
= sym
;
2521 ppc_toc_csect
= sym
;
2523 for (list
= ppc_data_csects
;
2524 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2525 list
= list
->sy_tc
.next
)
2527 list
->sy_tc
.next
= sym
;
2529 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2530 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2533 ppc_current_csect
= ppc_toc_csect
;
2535 demand_empty_rest_of_line ();
2538 #endif /* OBJ_XCOFF */
2540 /* The .tc pseudo-op. This is used when generating either XCOFF or
2541 ELF. This takes two or more arguments.
2543 When generating XCOFF output, the first argument is the name to
2544 give to this location in the toc; this will be a symbol with class
2545 TC. The rest of the arguments are 4 byte values to actually put at
2546 this location in the TOC; often there is just one more argument, a
2547 relocateable symbol reference.
2549 When not generating XCOFF output, the arguments are the same, but
2550 the first argument is simply ignored. */
2558 /* Define the TOC symbol name. */
2564 if (ppc_toc_csect
== (symbolS
*) NULL
2565 || ppc_toc_csect
!= ppc_current_csect
)
2567 as_bad (".tc not in .toc section");
2568 ignore_rest_of_line ();
2572 name
= input_line_pointer
;
2573 endc
= get_symbol_end ();
2575 sym
= symbol_find_or_make (name
);
2577 *input_line_pointer
= endc
;
2579 if (S_IS_DEFINED (sym
))
2583 label
= ppc_current_csect
->sy_tc
.within
;
2584 if (label
->sy_tc
.class != XMC_TC0
)
2586 as_warn (".tc with no label");
2587 ignore_rest_of_line ();
2591 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
2592 label
->sy_frag
= sym
->sy_frag
;
2593 S_SET_VALUE (label
, S_GET_VALUE (sym
));
2595 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2596 ++input_line_pointer
;
2601 S_SET_SEGMENT (sym
, now_seg
);
2602 sym
->sy_frag
= frag_now
;
2603 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2604 sym
->sy_tc
.class = XMC_TC
;
2605 sym
->sy_tc
.output
= 1;
2607 ppc_frob_label (sym
);
2610 #else /* ! defined (OBJ_XCOFF) */
2612 /* Skip the TOC symbol name. */
2613 while (is_part_of_name (*input_line_pointer
)
2614 || *input_line_pointer
== '['
2615 || *input_line_pointer
== ']'
2616 || *input_line_pointer
== '{'
2617 || *input_line_pointer
== '}')
2618 ++input_line_pointer
;
2620 /* Align to a four byte boundary. */
2622 record_alignment (now_seg
, 2);
2624 #endif /* ! defined (OBJ_XCOFF) */
2626 if (*input_line_pointer
!= ',')
2627 demand_empty_rest_of_line ();
2630 ++input_line_pointer
;
2637 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2639 /* Set the current section. */
2641 ppc_set_current_section (new)
2644 ppc_previous_section
= ppc_current_section
;
2645 ppc_current_section
= new;
2648 /* pseudo-op: .previous
2649 behaviour: toggles the current section with the previous section.
2651 warnings: "No previous section"
2654 ppc_previous(ignore
)
2659 if (ppc_previous_section
== NULL
)
2661 as_warn("No previous section to return to. Directive ignored.");
2665 subseg_set(ppc_previous_section
, 0);
2667 ppc_set_current_section(ppc_previous_section
);
2670 /* pseudo-op: .pdata
2671 behaviour: predefined read only data section
2675 initial: .section .pdata "adr3"
2676 a - don't know -- maybe a misprint
2677 d - initialized data
2679 3 - double word aligned (that would be 4 byte boundary)
2682 Tag index tables (also known as the function table) for exception
2683 handling, debugging, etc.
2690 if (pdata_section
== 0)
2692 pdata_section
= subseg_new (".pdata", 0);
2694 bfd_set_section_flags (stdoutput
, pdata_section
,
2695 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2696 | SEC_READONLY
| SEC_DATA
));
2698 bfd_set_section_alignment (stdoutput
, pdata_section
, 3);
2702 pdata_section
= subseg_new(".pdata", 0);
2704 ppc_set_current_section(pdata_section
);
2707 /* pseudo-op: .ydata
2708 behaviour: predefined read only data section
2712 initial: .section .ydata "drw3"
2713 a - don't know -- maybe a misprint
2714 d - initialized data
2716 3 - double word aligned (that would be 4 byte boundary)
2718 Tag tables (also known as the scope table) for exception handling,
2725 if (ydata_section
== 0)
2727 ydata_section
= subseg_new (".ydata", 0);
2728 bfd_set_section_flags (stdoutput
, ydata_section
,
2729 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2730 | SEC_READONLY
| SEC_DATA
));
2732 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
2736 ydata_section
= subseg_new (".ydata", 0);
2738 ppc_set_current_section(ydata_section
);
2741 /* pseudo-op: .reldata
2742 behaviour: predefined read write data section
2743 double word aligned (4-byte)
2744 FIXME: relocation is applied to it
2745 FIXME: what's the difference between this and .data?
2748 initial: .section .reldata "drw3"
2749 d - initialized data
2752 3 - double word aligned (that would be 8 byte boundary)
2755 Like .data, but intended to hold data subject to relocation, such as
2756 function descriptors, etc.
2762 if (reldata_section
== 0)
2764 reldata_section
= subseg_new (".reldata", 0);
2766 bfd_set_section_flags (stdoutput
, reldata_section
,
2767 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2770 bfd_set_section_alignment (stdoutput
, reldata_section
, 3);
2774 reldata_section
= subseg_new (".reldata", 0);
2776 ppc_set_current_section(reldata_section
);
2779 /* pseudo-op: .rdata
2780 behaviour: predefined read only data section
2784 initial: .section .rdata "dr3"
2785 d - initialized data
2787 3 - double word aligned (that would be 4 byte boundary)
2793 if (rdata_section
== 0)
2795 rdata_section
= subseg_new (".rdata", 0);
2796 bfd_set_section_flags (stdoutput
, rdata_section
,
2797 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2798 | SEC_READONLY
| SEC_DATA
));
2800 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
2804 rdata_section
= subseg_new (".rdata", 0);
2806 ppc_set_current_section(rdata_section
);
2809 /* pseudo-op: .ualong
2810 behaviour: much like .int, with the exception that no alignment is
2812 FIXME: test the alignment statement
2824 /* pseudo-op: .znop <symbol name>
2825 behaviour: Issue a nop instruction
2826 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2827 the supplied symbol name.
2829 warnings: Missing symbol name
2836 const struct powerpc_opcode
*opcode
;
2842 /* Strip out the symbol name */
2850 symbol_name
= input_line_pointer
;
2851 c
= get_symbol_end ();
2853 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
2854 strcpy (name
, symbol_name
);
2856 sym
= symbol_find_or_make (name
);
2858 *input_line_pointer
= c
;
2862 /* Look up the opcode in the hash table. */
2863 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
2865 /* stick in the nop */
2866 insn
= opcode
->opcode
;
2868 /* Write out the instruction. */
2870 md_number_to_chars (f
, insn
, 4);
2872 f
- frag_now
->fr_literal
,
2877 BFD_RELOC_16_GOT_PCREL
);
2890 register char *name
;
2894 register symbolS
*symbolP
;
2897 name
= input_line_pointer
;
2898 c
= get_symbol_end ();
2900 /* just after name is now '\0' */
2901 p
= input_line_pointer
;
2904 if (*input_line_pointer
!= ',')
2906 as_bad ("Expected comma after symbol-name: rest of line ignored.");
2907 ignore_rest_of_line ();
2911 input_line_pointer
++; /* skip ',' */
2912 if ((temp
= get_absolute_expression ()) < 0)
2914 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
2915 ignore_rest_of_line ();
2921 /* The third argument to .comm is the alignment. */
2922 if (*input_line_pointer
!= ',')
2926 ++input_line_pointer
;
2927 align
= get_absolute_expression ();
2930 as_warn ("ignoring bad alignment");
2937 symbolP
= symbol_find_or_make (name
);
2940 if (S_IS_DEFINED (symbolP
))
2942 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2943 S_GET_NAME (symbolP
));
2944 ignore_rest_of_line ();
2948 if (S_GET_VALUE (symbolP
))
2950 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
2951 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
2952 S_GET_NAME (symbolP
),
2953 (long) S_GET_VALUE (symbolP
),
2958 S_SET_VALUE (symbolP
, (valueT
) temp
);
2959 S_SET_EXTERNAL (symbolP
);
2962 demand_empty_rest_of_line ();
2966 * implement the .section pseudo op:
2967 * .section name {, "flags"}
2969 * | +--- optional flags: 'b' for bss
2971 * +-- section name 'l' for lib
2975 * 'd' (apparently m88k for data)
2977 * But if the argument is not a quoted string, treat it as a
2978 * subsegment number.
2980 * FIXME: this is a copy of the section processing from obj-coff.c, with
2981 * additions/changes for the moto-pas assembler support. There are three
2984 * FIXME: I just noticed this. This doesn't work at all really. It it
2985 * setting bits that bfd probably neither understands or uses. The
2986 * correct approach (?) will have to incorporate extra fields attached
2987 * to the section to hold the system specific stuff. (krk)
2990 * 'a' - unknown - referred to in documentation, but no definition supplied
2991 * 'c' - section has code
2992 * 'd' - section has initialized data
2993 * 'u' - section has uninitialized data
2994 * 'i' - section contains directives (info)
2995 * 'n' - section can be discarded
2996 * 'R' - remove section at link time
2998 * Section Protection:
2999 * 'r' - section is readable
3000 * 'w' - section is writeable
3001 * 'x' - section is executable
3002 * 's' - section is sharable
3004 * Section Alignment:
3005 * '0' - align to byte boundary
3006 * '1' - align to halfword undary
3007 * '2' - align to word boundary
3008 * '3' - align to doubleword boundary
3009 * '4' - align to quadword boundary
3010 * '5' - align to 32 byte boundary
3011 * '6' - align to 64 byte boundary
3016 ppc_pe_section (ignore
)
3019 /* Strip out the section name */
3028 align
= 4; /* default alignment to 16 byte boundary */
3030 section_name
= input_line_pointer
;
3031 c
= get_symbol_end ();
3033 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3034 strcpy (name
, section_name
);
3036 *input_line_pointer
= c
;
3041 flags
= SEC_NO_FLAGS
;
3043 if (*input_line_pointer
== ',')
3045 ++input_line_pointer
;
3047 if (*input_line_pointer
!= '"')
3048 exp
= get_absolute_expression ();
3051 ++input_line_pointer
;
3052 while (*input_line_pointer
!= '"'
3053 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3055 switch (*input_line_pointer
)
3057 /* Section Contents */
3058 case 'a': /* unknown */
3059 as_warn ("Unsupported section attribute -- 'a'");
3061 case 'c': /* code section */
3064 case 'd': /* section has initialized data */
3067 case 'u': /* section has uninitialized data */
3068 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3072 case 'i': /* section contains directives (info) */
3073 /* FIXME: This is IMAGE_SCN_LNK_INFO
3075 flags
|= SEC_HAS_CONTENTS
;
3077 case 'n': /* section can be discarded */
3080 case 'R': /* Remove section at link time */
3081 flags
|= SEC_NEVER_LOAD
;
3084 /* Section Protection */
3085 case 'r': /* section is readable */
3086 flags
|= IMAGE_SCN_MEM_READ
;
3088 case 'w': /* section is writeable */
3089 flags
|= IMAGE_SCN_MEM_WRITE
;
3091 case 'x': /* section is executable */
3092 flags
|= IMAGE_SCN_MEM_EXECUTE
;
3094 case 's': /* section is sharable */
3095 flags
|= IMAGE_SCN_MEM_SHARED
;
3098 /* Section Alignment */
3099 case '0': /* align to byte boundary */
3100 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
3103 case '1': /* align to halfword boundary */
3104 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
3107 case '2': /* align to word boundary */
3108 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
3111 case '3': /* align to doubleword boundary */
3112 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
3115 case '4': /* align to quadword boundary */
3116 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
3119 case '5': /* align to 32 byte boundary */
3120 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
3123 case '6': /* align to 64 byte boundary */
3124 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
3129 as_warn("unknown section attribute '%c'",
3130 *input_line_pointer
);
3133 ++input_line_pointer
;
3135 if (*input_line_pointer
== '"')
3136 ++input_line_pointer
;
3140 sec
= subseg_new (name
, (subsegT
) exp
);
3142 ppc_set_current_section(sec
);
3144 if (flags
!= SEC_NO_FLAGS
)
3146 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
3147 as_warn ("error setting flags for \"%s\": %s",
3148 bfd_section_name (stdoutput
, sec
),
3149 bfd_errmsg (bfd_get_error ()));
3152 bfd_set_section_alignment(stdoutput
, sec
, align
);
3157 ppc_pe_function (ignore
)
3164 name
= input_line_pointer
;
3165 endc
= get_symbol_end ();
3167 ext_sym
= symbol_find_or_make (name
);
3169 *input_line_pointer
= endc
;
3171 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3172 SF_SET_FUNCTION (ext_sym
);
3173 SF_SET_PROCESS (ext_sym
);
3174 coff_add_linesym (ext_sym
);
3176 demand_empty_rest_of_line ();
3180 ppc_pe_tocd (ignore
)
3183 if (tocdata_section
== 0)
3185 tocdata_section
= subseg_new (".tocd", 0);
3186 /* FIXME: section flags won't work */
3187 bfd_set_section_flags (stdoutput
, tocdata_section
,
3188 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
3189 | SEC_READONLY
| SEC_DATA
));
3191 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
3195 rdata_section
= subseg_new (".tocd", 0);
3198 ppc_set_current_section(tocdata_section
);
3200 demand_empty_rest_of_line ();
3203 /* Don't adjust TOC relocs to use the section symbol. */
3206 ppc_pe_fix_adjustable (fix
)
3209 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
3216 /* XCOFF specific symbol and file handling. */
3218 /* Canonicalize the symbol name. We use the to force the suffix, if
3219 any, to use square brackets, and to be in upper case. */
3222 ppc_canonicalize_symbol_name (name
)
3227 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3241 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3245 if (*s
== '\0' || s
[1] != '\0')
3246 as_bad ("bad symbol suffix");
3254 /* Set the class of a symbol based on the suffix, if any. This is
3255 called whenever a new symbol is created. */
3258 ppc_symbol_new_hook (sym
)
3263 sym
->sy_tc
.next
= NULL
;
3264 sym
->sy_tc
.output
= 0;
3265 sym
->sy_tc
.class = -1;
3266 sym
->sy_tc
.real_name
= NULL
;
3267 sym
->sy_tc
.subseg
= 0;
3268 sym
->sy_tc
.align
= 0;
3269 sym
->sy_tc
.size
= NULL
;
3270 sym
->sy_tc
.within
= NULL
;
3272 s
= strchr (S_GET_NAME (sym
), '[');
3273 if (s
== (const char *) NULL
)
3275 /* There is no suffix. */
3284 if (strcmp (s
, "BS]") == 0)
3285 sym
->sy_tc
.class = XMC_BS
;
3288 if (strcmp (s
, "DB]") == 0)
3289 sym
->sy_tc
.class = XMC_DB
;
3290 else if (strcmp (s
, "DS]") == 0)
3291 sym
->sy_tc
.class = XMC_DS
;
3294 if (strcmp (s
, "GL]") == 0)
3295 sym
->sy_tc
.class = XMC_GL
;
3298 if (strcmp (s
, "PR]") == 0)
3299 sym
->sy_tc
.class = XMC_PR
;
3302 if (strcmp (s
, "RO]") == 0)
3303 sym
->sy_tc
.class = XMC_RO
;
3304 else if (strcmp (s
, "RW]") == 0)
3305 sym
->sy_tc
.class = XMC_RW
;
3308 if (strcmp (s
, "SV]") == 0)
3309 sym
->sy_tc
.class = XMC_SV
;
3312 if (strcmp (s
, "TC]") == 0)
3313 sym
->sy_tc
.class = XMC_TC
;
3314 else if (strcmp (s
, "TI]") == 0)
3315 sym
->sy_tc
.class = XMC_TI
;
3316 else if (strcmp (s
, "TB]") == 0)
3317 sym
->sy_tc
.class = XMC_TB
;
3318 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3319 sym
->sy_tc
.class = XMC_TC0
;
3322 if (strcmp (s
, "UA]") == 0)
3323 sym
->sy_tc
.class = XMC_UA
;
3324 else if (strcmp (s
, "UC]") == 0)
3325 sym
->sy_tc
.class = XMC_UC
;
3328 if (strcmp (s
, "XO]") == 0)
3329 sym
->sy_tc
.class = XMC_XO
;
3333 if (sym
->sy_tc
.class == -1)
3334 as_bad ("Unrecognized symbol suffix");
3337 /* Set the class of a label based on where it is defined. This
3338 handles symbols without suffixes. Also, move the symbol so that it
3339 follows the csect symbol. */
3342 ppc_frob_label (sym
)
3345 if (ppc_current_csect
!= (symbolS
*) NULL
)
3347 if (sym
->sy_tc
.class == -1)
3348 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3350 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3351 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3353 ppc_current_csect
->sy_tc
.within
= sym
;
3357 /* Change the name of a symbol just before writing it out. Set the
3358 real name if the .rename pseudo-op was used. Otherwise, remove any
3359 class suffix. Return 1 if the symbol should not be included in the
3363 ppc_frob_symbol (sym
)
3366 static symbolS
*ppc_last_function
;
3367 static symbolS
*set_end
;
3369 /* Discard symbols that should not be included in the output symbol
3371 if (! sym
->sy_used_in_reloc
3372 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3373 || (! S_IS_EXTERNAL (sym
)
3374 && ! sym
->sy_tc
.output
3375 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3378 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3379 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3385 name
= S_GET_NAME (sym
);
3386 s
= strchr (name
, '[');
3387 if (s
!= (char *) NULL
)
3393 snew
= xmalloc (len
+ 1);
3394 memcpy (snew
, name
, len
);
3397 S_SET_NAME (sym
, snew
);
3401 if (set_end
!= (symbolS
*) NULL
)
3403 SA_SET_SYM_ENDNDX (set_end
, sym
);
3407 if (SF_GET_FUNCTION (sym
))
3409 if (ppc_last_function
!= (symbolS
*) NULL
)
3410 as_warn ("two .function pseudo-ops with no intervening .ef");
3411 ppc_last_function
= sym
;
3412 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3414 resolve_symbol_value (sym
->sy_tc
.size
);
3415 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3418 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3419 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3421 if (ppc_last_function
== (symbolS
*) NULL
)
3422 as_warn (".ef with no preceding .function");
3425 set_end
= ppc_last_function
;
3426 ppc_last_function
= NULL
;
3428 /* We don't have a C_EFCN symbol, but we need to force the
3429 COFF backend to believe that it has seen one. */
3430 coff_last_function
= NULL
;
3434 if (! S_IS_EXTERNAL (sym
)
3435 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3436 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3437 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3438 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3439 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3440 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
3441 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
3442 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3443 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3445 if ((S_GET_STORAGE_CLASS (sym
) == C_EXT
3446 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3447 && S_GET_SEGMENT (sym
) != absolute_section
)
3450 union internal_auxent
*a
;
3452 /* Create a csect aux. */
3453 i
= S_GET_NUMBER_AUXILIARY (sym
);
3454 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3455 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3456 if (sym
->sy_tc
.class == XMC_TC0
)
3458 /* This is the TOC table. */
3459 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3460 a
->x_csect
.x_scnlen
.l
= 0;
3461 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3463 else if (sym
->sy_tc
.subseg
!= 0)
3465 /* This is a csect symbol. x_scnlen is the size of the
3467 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3468 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3469 S_GET_SEGMENT (sym
))
3470 - S_GET_VALUE (sym
));
3473 resolve_symbol_value (sym
->sy_tc
.next
);
3474 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3475 - S_GET_VALUE (sym
));
3477 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3479 else if (S_GET_SEGMENT (sym
) == bss_section
)
3481 /* This is a common symbol. */
3482 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3483 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3484 if (S_IS_EXTERNAL (sym
))
3485 sym
->sy_tc
.class = XMC_RW
;
3487 sym
->sy_tc
.class = XMC_BS
;
3489 else if (! S_IS_DEFINED (sym
))
3491 /* This is an external symbol. */
3492 a
->x_csect
.x_scnlen
.l
= 0;
3493 a
->x_csect
.x_smtyp
= XTY_ER
;
3495 else if (sym
->sy_tc
.class == XMC_TC
)
3499 /* This is a TOC definition. x_scnlen is the size of the
3501 next
= symbol_next (sym
);
3502 while (next
->sy_tc
.class == XMC_TC0
)
3503 next
= symbol_next (next
);
3504 if (next
== (symbolS
*) NULL
3505 || next
->sy_tc
.class != XMC_TC
)
3507 if (ppc_after_toc_frag
== (fragS
*) NULL
)
3508 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3510 - S_GET_VALUE (sym
));
3512 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
3513 - S_GET_VALUE (sym
));
3517 resolve_symbol_value (next
);
3518 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
3519 - S_GET_VALUE (sym
));
3521 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3527 /* This is a normal symbol definition. x_scnlen is the
3528 symbol index of the containing csect. */
3529 if (S_GET_SEGMENT (sym
) == text_section
)
3530 csect
= ppc_text_csects
;
3531 else if (S_GET_SEGMENT (sym
) == data_section
)
3532 csect
= ppc_data_csects
;
3536 /* Skip the initial dummy symbol. */
3537 csect
= csect
->sy_tc
.next
;
3539 if (csect
== (symbolS
*) NULL
)
3540 a
->x_csect
.x_scnlen
.l
= 0;
3543 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
3545 resolve_symbol_value (csect
->sy_tc
.next
);
3546 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
3548 csect
= csect
->sy_tc
.next
;
3551 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3552 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
3554 a
->x_csect
.x_smtyp
= XTY_LD
;
3557 a
->x_csect
.x_parmhash
= 0;
3558 a
->x_csect
.x_snhash
= 0;
3559 if (sym
->sy_tc
.class == -1)
3560 a
->x_csect
.x_smclas
= XMC_PR
;
3562 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
3563 a
->x_csect
.x_stab
= 0;
3564 a
->x_csect
.x_snstab
= 0;
3566 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
3568 /* We want the value to be the symbol index of the referenced
3569 csect symbol. BFD will do that for us if we set the right
3572 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
3573 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
3575 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
3580 /* The value is the offset from the enclosing csect. */
3581 block
= sym
->sy_tc
.within
;
3582 csect
= block
->sy_tc
.within
;
3583 resolve_symbol_value (csect
);
3584 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
3586 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
3587 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
3589 /* We want the value to be a file offset into the line numbers.
3590 BFD will do that for us if we set the right flags. We have
3591 already set the value correctly. */
3592 coffsymbol (sym
->bsym
)->native
->fix_line
= 1;
3598 /* Set the VMA for a section. This is called on all the sections in
3602 ppc_frob_section (sec
)
3605 static bfd_size_type vma
= 0;
3607 bfd_set_section_vma (stdoutput
, sec
, vma
);
3608 vma
+= bfd_section_size (stdoutput
, sec
);
3611 /* Adjust the file by adding a .debug section if needed. */
3616 if (ppc_debug_name_section_size
> 0)
3620 sec
= bfd_make_section (stdoutput
, ".debug");
3621 if (sec
== (asection
*) NULL
3622 || ! bfd_set_section_size (stdoutput
, sec
,
3623 ppc_debug_name_section_size
)
3624 || ! bfd_set_section_flags (stdoutput
, sec
,
3625 SEC_HAS_CONTENTS
| SEC_LOAD
))
3626 as_fatal ("can't make .debug section");
3630 #endif /* OBJ_XCOFF */
3632 /* Turn a string in input_line_pointer into a floating point constant
3633 of type type, and store the appropriate bytes in *litp. The number
3634 of LITTLENUMS emitted is stored in *sizep . An error message is
3635 returned, or NULL on OK. */
3638 md_atof (type
, litp
, sizep
)
3644 LITTLENUM_TYPE words
[4];
3660 return "bad call to md_atof";
3663 t
= atof_ieee (input_line_pointer
, type
, words
);
3665 input_line_pointer
= t
;
3669 if (target_big_endian
)
3671 for (i
= 0; i
< prec
; i
++)
3673 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3679 for (i
= prec
- 1; i
>= 0; i
--)
3681 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3689 /* Write a value out to the object file, using the appropriate
3693 md_number_to_chars (buf
, val
, n
)
3698 if (target_big_endian
)
3699 number_to_chars_bigendian (buf
, val
, n
);
3701 number_to_chars_littleendian (buf
, val
, n
);
3704 /* Align a section (I don't know why this is machine dependent). */
3707 md_section_align (seg
, addr
)
3711 int align
= bfd_get_section_alignment (stdoutput
, seg
);
3713 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
3716 /* We don't have any form of relaxing. */
3719 md_estimate_size_before_relax (fragp
, seg
)
3727 /* Convert a machine dependent frag. We never generate these. */
3730 md_convert_frag (abfd
, sec
, fragp
)
3738 /* We have no need to default values of symbols. */
3742 md_undefined_symbol (name
)
3748 /* Functions concerning relocs. */
3750 /* The location from which a PC relative jump should be calculated,
3751 given a PC relative reloc. */
3754 md_pcrel_from (fixp
)
3758 if (fixp
->fx_addsy
!= (symbolS
*) NULL
3759 && (! S_IS_DEFINED (fixp
->fx_addsy
)
3760 || TC_FORCE_RELOCATION (fixp
)))
3764 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3769 /* This is called to see whether a fixup should be adjusted to use a
3770 section symbol. We take the opportunity to change a fixup against
3771 a symbol in the TOC subsegment into a reloc against the
3772 corresponding .tc symbol. */
3775 ppc_fix_adjustable (fix
)
3780 resolve_symbol_value (fix
->fx_addsy
);
3781 val
= S_GET_VALUE (fix
->fx_addsy
);
3782 if (ppc_toc_csect
!= (symbolS
*) NULL
3783 && fix
->fx_addsy
!= (symbolS
*) NULL
3784 && fix
->fx_addsy
!= ppc_toc_csect
3785 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
3786 && val
>= ppc_toc_frag
->fr_address
3787 && (ppc_after_toc_frag
== (fragS
*) NULL
3788 || val
< ppc_after_toc_frag
->fr_address
))
3792 for (sy
= symbol_next (ppc_toc_csect
);
3793 sy
!= (symbolS
*) NULL
;
3794 sy
= symbol_next (sy
))
3796 if (sy
->sy_tc
.class == XMC_TC0
)
3798 if (sy
->sy_tc
.class != XMC_TC
)
3800 resolve_symbol_value (sy
);
3801 if (val
== S_GET_VALUE (sy
))
3804 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
3809 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3810 "symbol in .toc does not match any .tc");
3813 /* Possibly adjust the reloc to be against the csect. */
3814 if (fix
->fx_addsy
!= (symbolS
*) NULL
3815 && fix
->fx_addsy
->sy_tc
.subseg
== 0
3816 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
3817 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
3818 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
3822 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
3823 csect
= ppc_text_csects
;
3824 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
3825 csect
= ppc_data_csects
;
3829 /* Skip the initial dummy symbol. */
3830 csect
= csect
->sy_tc
.next
;
3832 if (csect
!= (symbolS
*) NULL
)
3834 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
3835 && (csect
->sy_tc
.next
->sy_frag
->fr_address
3836 <= fix
->fx_addsy
->sy_frag
->fr_address
))
3837 csect
= csect
->sy_tc
.next
;
3839 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3840 - csect
->sy_frag
->fr_address
);
3841 fix
->fx_addsy
= csect
;
3845 /* Adjust a reloc against a .lcomm symbol to be against the base
3847 if (fix
->fx_addsy
!= (symbolS
*) NULL
3848 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
3849 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
3851 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
3852 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3853 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
3854 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
3862 /* See whether a symbol is in the TOC section. */
3865 ppc_is_toc_sym (sym
)
3869 return sym
->sy_tc
.class == XMC_TC
;
3871 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
3875 /* Apply a fixup to the object code. This is called for all the
3876 fixups we generated by the call to fix_new_exp, above. In the call
3877 above we used a reloc code which was the largest legal reloc code
3878 plus the operand index. Here we undo that to recover the operand
3879 index. At this point all symbol values should be fully resolved,
3880 and we attempt to completely resolve the reloc. If we can not do
3881 that, we determine the correct reloc code and put it back in the
3885 md_apply_fix3 (fixp
, valuep
, seg
)
3892 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
3893 the symbol values. Since we are using BFD_ASSEMBLER, if we are
3894 doing this relocation the code in write.c is going to call
3895 bfd_perform_relocation, which is also going to use the symbol
3896 value. That means that if the reloc is fully resolved we want to
3897 use *valuep since bfd_perform_relocation is not being used.
3898 However, if the reloc is not fully resolved we do not want to use
3899 *valuep, and must use fx_offset instead. However, if the reloc
3900 is PC relative, we do want to use *valuep since it includes the
3901 result of md_pcrel_from. This is confusing. */
3903 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
3908 else if (fixp
->fx_pcrel
)
3912 value
= fixp
->fx_offset
;
3913 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
3915 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
3916 value
-= S_GET_VALUE (fixp
->fx_subsy
);
3919 /* We can't actually support subtracting a symbol. */
3920 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3921 "expression too complex");
3926 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
3929 const struct powerpc_operand
*operand
;
3933 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
3935 operand
= &powerpc_operands
[opindex
];
3938 /* It appears that an instruction like
3940 when LC..1 is not a TOC symbol does not generate a reloc. It
3941 uses the offset of LC..1 within its csect. However, .long
3942 LC..1 will generate a reloc. I can't find any documentation
3943 on how these cases are to be distinguished, so this is a wild
3944 guess. These cases are generated by gcc -mminimal-toc. */
3945 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
3946 && operand
->bits
== 16
3947 && operand
->shift
== 0
3948 && operand
->insert
== NULL
3949 && fixp
->fx_addsy
!= NULL
3950 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
3951 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
3952 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
3953 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
3955 value
= fixp
->fx_offset
;
3960 /* Fetch the instruction, insert the fully resolved operand
3961 value, and stuff the instruction back again. */
3962 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
3963 if (target_big_endian
)
3964 insn
= bfd_getb32 ((unsigned char *) where
);
3966 insn
= bfd_getl32 ((unsigned char *) where
);
3967 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
3968 fixp
->fx_file
, fixp
->fx_line
);
3969 if (target_big_endian
)
3970 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
3972 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
3976 /* Nothing else to do here. */
3980 /* Determine a BFD reloc value based on the operand information.
3981 We are only prepared to turn a few of the operands into
3983 FIXME: We need to handle the DS field at the very least.
3984 FIXME: Selecting the reloc type is a bit haphazard; perhaps
3985 there should be a new field in the operand table. */
3986 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3987 && operand
->bits
== 26
3988 && operand
->shift
== 0)
3989 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
3990 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3991 && operand
->bits
== 16
3992 && operand
->shift
== 0)
3993 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
3994 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3995 && operand
->bits
== 26
3996 && operand
->shift
== 0)
3997 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
3998 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3999 && operand
->bits
== 16
4000 && operand
->shift
== 0)
4001 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
4002 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
4003 && operand
->bits
== 16
4004 && operand
->shift
== 0
4005 && operand
->insert
== NULL
4006 && fixp
->fx_addsy
!= NULL
4007 && ppc_is_toc_sym (fixp
->fx_addsy
))
4010 if (target_big_endian
)
4011 fixp
->fx_where
+= 2;
4012 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
4016 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4017 "unresolved expression that must be resolved");
4025 ppc_elf_validate_fix (fixp
, seg
);
4027 switch (fixp
->fx_r_type
)
4030 case BFD_RELOC_CTOR
:
4033 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
4034 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4035 } /* fall through */
4037 case BFD_RELOC_32_PCREL
:
4038 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4042 case BFD_RELOC_LO16
:
4043 case BFD_RELOC_HI16
:
4044 case BFD_RELOC_HI16_S
:
4045 case BFD_RELOC_PPC_TOC16
:
4047 case BFD_RELOC_GPREL16
:
4048 case BFD_RELOC_16_GOT_PCREL
:
4052 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4060 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
4070 fixp
->fx_addnumber
= value
;
4072 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
4073 fixp
->fx_addnumber
= 0;
4077 fixp
->fx_addnumber
= 0;
4079 /* We want to use the offset within the data segment of the
4080 symbol, not the actual VMA of the symbol. */
4081 fixp
->fx_addnumber
=
4082 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
4090 /* Generate a reloc for a fixup. */
4093 tc_gen_reloc (seg
, fixp
)
4099 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
4101 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
4102 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4103 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
4104 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
4106 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4107 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
4110 reloc
->addend
= fixp
->fx_addnumber
;