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"
32 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
34 /* Tell the main code what the endianness is. */
35 extern int target_big_endian
;
37 /* Whether or not, we've set target_big_endian. */
38 static int set_target_endian
= 0;
40 static void ppc_set_cpu
PARAMS ((void));
41 static unsigned long ppc_insert_operand
42 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
43 offsetT val
, char *file
, unsigned int line
));
44 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
45 static void ppc_byte
PARAMS ((int));
46 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
47 static void ppc_tc
PARAMS ((int));
50 static void ppc_comm
PARAMS ((int));
51 static void ppc_bb
PARAMS ((int));
52 static void ppc_bf
PARAMS ((int));
53 static void ppc_biei
PARAMS ((int));
54 static void ppc_bs
PARAMS ((int));
55 static void ppc_eb
PARAMS ((int));
56 static void ppc_ef
PARAMS ((int));
57 static void ppc_es
PARAMS ((int));
58 static void ppc_csect
PARAMS ((int));
59 static void ppc_function
PARAMS ((int));
60 static void ppc_extern
PARAMS ((int));
61 static void ppc_lglobl
PARAMS ((int));
62 static void ppc_stabx
PARAMS ((int));
63 static void ppc_rename
PARAMS ((int));
64 static void ppc_toc
PARAMS ((int));
68 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
69 static void ppc_elf_cons
PARAMS ((int));
70 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
74 static void ppc_previous
PARAMS ((int));
75 static void ppc_pdata
PARAMS ((int));
76 static void ppc_ydata
PARAMS ((int));
77 static void ppc_reldata
PARAMS ((int));
78 static void ppc_rdata
PARAMS ((int));
79 static void ppc_ualong
PARAMS ((int));
80 static void ppc_znop
PARAMS ((int));
81 static void ppc_pe_comm
PARAMS ((int));
82 static void ppc_pe_section
PARAMS ((int));
83 static void ppc_pe_section
PARAMS ((int));
84 static void ppc_pe_function
PARAMS ((int));
86 segT ydata_section
, pdata_section
, reldata_section
, rdata_section
;
91 /* Generic assembler global variables which must be defined by all
94 /* Characters which always start a comment. */
95 const char comment_chars
[] = "#";
97 /* Characters which start a comment at the beginning of a line. */
98 const char line_comment_chars
[] = "#";
100 /* Characters which may be used to separate multiple commands on a
102 const char line_separator_chars
[] = ";";
104 /* Characters which are used to indicate an exponent in a floating
106 const char EXP_CHARS
[] = "eE";
108 /* Characters which mean that a number is a floating point constant,
110 const char FLT_CHARS
[] = "dD";
112 /* The target specific pseudo-ops which we support. */
114 const pseudo_typeS md_pseudo_table
[] =
116 /* Pseudo-ops which must be overridden. */
117 { "byte", ppc_byte
, 0 },
120 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
121 legitimately belong in the obj-*.c file. However, XCOFF is based
122 on COFF, and is only implemented for the RS/6000. We just use
123 obj-coff.c, and add what we need here. */
125 { "comm", ppc_comm
, 0 },
126 { "lcomm", ppc_comm
, 1 },
127 { "function", ppc_function
, 0 },
132 { "bi", ppc_biei
, 0 },
136 { "csect", ppc_csect
, 0 },
141 { "ei", ppc_biei
, 1 },
143 { "extern", ppc_extern
, 0 },
144 { "lglobl", ppc_lglobl
, 0 },
145 { "rename", ppc_rename
, 0 },
146 { "stabx", ppc_stabx
, 0 },
147 { "toc", ppc_toc
, 0 },
151 { "long", ppc_elf_cons
, 4 },
152 { "word", ppc_elf_cons
, 2 },
153 { "short", ppc_elf_cons
, 2 },
157 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
158 { "previous", ppc_previous
, 0 },
159 { "pdata", ppc_pdata
, 0 },
160 { "ydata", ppc_ydata
, 0 },
161 { "reldata", ppc_reldata
, 0 },
162 { "rdata", ppc_rdata
, 0 },
163 { "ualong", ppc_ualong
, 0 },
164 { "znop", ppc_znop
, 0 },
165 { "comm", ppc_pe_comm
, 0 },
166 { "lcomm", ppc_pe_comm
, 1 },
167 { "section", ppc_pe_section
, 0 },
168 { "function", ppc_pe_function
,0 },
171 /* This pseudo-op is used even when not generating XCOFF output. */
179 /* The Windows NT PowerPC assembler used predefined names. */
180 /* Structure to hold information about predefined registers. */
188 /* List of registers that are pre-defined:
190 Each general register has one predefined name of the form
191 r<REGNUM> which has the value <REGNUM>.
193 Each floating point register has one predefined name of the form
194 f<REGNUM> which has the value <REGNUM>.
196 Each condition register has one predefined name of the form
197 cr<REGNUM> which has the value <REGNUM>.
199 There are individual registers as well:
202 fpscr has the value 0
207 The table is sorted. Suitable for searching by a binary search. */
209 static const struct pd_reg pre_defined_registers
[] =
300 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
302 /* Given NAME, find the register number associated with that name, return
303 the integer value associated with the given name or -1 on failure. */
305 static int reg_name_search
PARAMS ( (char * name
) );
308 reg_name_search (name
)
311 int middle
, low
, high
;
315 high
= REG_NAME_CNT
- 1;
319 middle
= (low
+ high
) / 2;
320 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
326 return pre_defined_registers
[middle
].value
;
333 static void insert_reg
PARAMS ( (char *regname
, int regnum
) );
336 insert_reg (regname
, regnum
)
343 symbol_table_insert (
350 for (i
= 0; regname
[i
]; i
++)
352 buf
[i
] = islower (regname
[i
]) ? toupper (regname
[i
]) : regname
[i
];
357 symbol_table_insert (
369 for (i
= 0; i
< REG_NAME_CNT
&& pre_defined_registers
[i
].name
; ++i
)
371 insert_reg (pre_defined_registers
[i
].name
,
372 pre_defined_registers
[i
].value
);
378 /* Local variables. */
380 /* The type of processor we are assembling for. This is one or more
381 of the PPC_OPCODE flags defined in opcode/ppc.h. */
382 static int ppc_cpu
= 0;
384 /* The size of the processor we are assembling for. This is either
385 PPC_OPCODE_32 or PPC_OPCODE_64. */
386 static int ppc_size
= PPC_OPCODE_32
;
388 /* Opcode hash table. */
389 static struct hash_control
*ppc_hash
;
391 /* Macro hash table. */
392 static struct hash_control
*ppc_macro_hash
;
395 /* Whether to warn about non PC relative relocations that aren't
396 in the .got2 section. */
397 static boolean mrelocatable
= false;
399 /* Flags to set in the elf header */
400 static flagword ppc_flags
= 0;
405 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
406 using a bunch of different sections. These assembler sections,
407 however, are all encompassed within the .text or .data sections of
408 the final output file. We handle this by using different
409 subsegments within these main segments. */
411 /* Next subsegment to allocate within the .text segment. */
412 static subsegT ppc_text_subsegment
= 2;
414 /* Linked list of csects in the text section. */
415 static symbolS
*ppc_text_csects
;
417 /* Next subsegment to allocate within the .data segment. */
418 static subsegT ppc_data_subsegment
= 2;
420 /* Linked list of csects in the data section. */
421 static symbolS
*ppc_data_csects
;
423 /* The current csect. */
424 static symbolS
*ppc_current_csect
;
426 /* The current csect. */
427 static segT ppc_previous_section
;
428 static segT ppc_current_section
;
430 void setCurrentSection(new)
433 ppc_previous_section
= ppc_current_section
;
434 ppc_current_section
= new;
438 /* The RS/6000 assembler uses a TOC which holds addresses of functions
439 and variables. Symbols are put in the TOC with the .tc pseudo-op.
440 A special relocation is used when accessing TOC entries. We handle
441 the TOC as a subsegment within the .data segment. We set it up if
442 we see a .toc pseudo-op, and save the csect symbol here. */
443 static symbolS
*ppc_toc_csect
;
445 /* The first frag in the TOC subsegment. */
446 static fragS
*ppc_toc_frag
;
448 /* The first frag in the first subsegment after the TOC in the .data
449 segment. NULL if there are no subsegments after the TOC. */
450 static fragS
*ppc_after_toc_frag
;
452 /* The current static block. */
453 static symbolS
*ppc_current_block
;
455 /* The COFF debugging section; set by md_begin. This is not the
456 .debug section, but is instead the secret BFD section which will
457 cause BFD to set the section number of a symbol to N_DEBUG. */
458 static asection
*ppc_coff_debug_section
;
460 /* The size of the .debug section. */
461 static bfd_size_type ppc_debug_name_section_size
;
463 #endif /* OBJ_COFF */
466 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
469 #ifndef WORKING_DOT_WORD
470 const int md_short_jump_size
= 4;
471 const int md_long_jump_size
= 4;
475 CONST
char *md_shortopts
= "um:VQ:";
477 CONST
char *md_shortopts
= "um:";
479 struct option md_longopts
[] = {
480 {NULL
, no_argument
, NULL
, 0}
482 size_t md_longopts_size
= sizeof(md_longopts
);
485 md_parse_option (c
, arg
)
492 /* -u means that any undefined symbols should be treated as
493 external, which is the default for gas anyhow. */
497 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
499 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
500 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
501 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
502 else if (strcmp (arg
, "pwr") == 0)
503 ppc_cpu
= PPC_OPCODE_POWER
;
504 /* -m601 means to assemble for the Motorola PowerPC 601. FIXME: We
505 ignore the option for now, but we should really use it to permit
506 instructions defined on the 601 that are not part of the standard
507 PowerPC architecture (mostly holdovers from the POWER). */
508 else if (strcmp (arg
, "601") == 0)
509 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
510 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
511 Motorola PowerPC 603/604. */
512 else if (strcmp (arg
, "ppc") == 0
513 || strcmp (arg
, "ppc32") == 0
514 || strcmp (arg
, "403") == 0
515 || strcmp (arg
, "603") == 0
516 || strcmp (arg
, "604") == 0)
517 ppc_cpu
= PPC_OPCODE_PPC
;
518 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
520 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
522 ppc_cpu
= PPC_OPCODE_PPC
;
523 ppc_size
= PPC_OPCODE_64
;
525 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
526 else if (strcmp (arg
, "any") == 0)
527 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_PPC
;
530 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
531 else if (strcmp (arg
, "relocatable") == 0)
534 ppc_flags
|= EF_PPC_RELOCATABLE
;
537 else if (strcmp (arg
, "relocatable-lib") == 0)
540 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
543 /* -memb, set embedded bit */
544 else if (strcmp (arg
, "emb") == 0)
545 ppc_flags
|= EF_PPC_EMB
;
547 /* -mlittle/-mbig set the endianess */
548 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
550 target_big_endian
= 0;
551 set_target_endian
= 1;
554 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
556 target_big_endian
= 1;
557 set_target_endian
= 1;
562 as_bad ("invalid switch -m%s", arg
);
568 /* -V: SVR4 argument to print version ID. */
573 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
574 should be emitted or not. FIXME: Not implemented. */
587 md_show_usage (stream
)
593 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
594 -mpwr generate code for IBM POWER (RIOS1)\n\
595 -m601 generate code for Motorola PowerPC 601\n\
596 -mppc, -mppc32, -m403, -m603, -m604\n\
597 generate code for Motorola PowerPC 603/604\n\
598 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
599 -many generate code for any architecture (PWR/PWRX/PPC)\n");
602 -mrelocatable support for GCC's -mrelocatble option\n\
603 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
604 -memb set PPC_EMB bit in ELF flags\n\
605 -mlittle, -mlittle-endian\n\
606 generate code for a little endian machine\n\
607 -mbig, -mbig-endian generate code for a big endian machine\n\
608 -V print assembler version number\n\
609 -Qy, -Qn ignored\n");
613 /* Set ppc_cpu if it is not already set. */
618 const char *default_cpu
= TARGET_CPU
;
622 if (strcmp (default_cpu
, "rs6000") == 0)
623 ppc_cpu
= PPC_OPCODE_POWER
;
624 else if (strcmp (default_cpu
, "powerpc") == 0
625 || strcmp (default_cpu
, "powerpcle") == 0)
626 ppc_cpu
= PPC_OPCODE_PPC
;
628 as_fatal ("Unknown default cpu = %s", default_cpu
);
632 /* Figure out the BFD architecture to use. */
634 enum bfd_architecture
639 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
640 return bfd_arch_powerpc
;
641 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
642 return bfd_arch_rs6000
;
644 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
647 /* This function is called when the assembler starts up. It is called
648 after the options have been parsed and the output file has been
654 register const struct powerpc_opcode
*op
;
655 const struct powerpc_opcode
*op_end
;
656 const struct powerpc_macro
*macro
;
657 const struct powerpc_macro
*macro_end
;
662 /* Set the ELF flags if desired. */
664 bfd_set_private_flags (stdoutput
, ppc_flags
);
667 /* Insert the opcodes into a hash table. */
668 ppc_hash
= hash_new ();
670 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
671 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
673 know ((op
->opcode
& op
->mask
) == op
->opcode
);
675 if ((op
->flags
& ppc_cpu
) != 0
676 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
677 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
681 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
682 if (retval
!= (const char *) NULL
)
684 /* We permit a duplication of the mfdec instruction on
685 the 601, because it seems to have one value on the
686 601 and a different value on other PowerPC
687 processors. It's easier to permit a duplication than
688 to define a new instruction type flag. When using
689 -many, the comparison instructions are a harmless
691 if (strcmp (retval
, "exists") != 0
692 || (((ppc_cpu
& PPC_OPCODE_601
) == 0
693 || strcmp (op
->name
, "mfdec") != 0)
694 && (ppc_cpu
!= (PPC_OPCODE_POWER
697 || (strcmp (op
->name
, "cmpli") != 0
698 && strcmp (op
->name
, "cmpi") != 0
699 && strcmp (op
->name
, "cmp") != 0
700 && strcmp (op
->name
, "cmpl") != 0))))
706 /* Insert the macros into a hash table. */
707 ppc_macro_hash
= hash_new ();
709 macro_end
= powerpc_macros
+ powerpc_num_macros
;
710 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
712 if ((macro
->flags
& ppc_cpu
) != 0)
716 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
717 if (retval
!= (const char *) NULL
)
722 /* Tell the main code what the endianness is if it is not overidden by the user. */
723 if (!set_target_endian
)
725 set_target_endian
= 1;
726 target_big_endian
= PPC_BIG_ENDIAN
;
730 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
732 /* Create dummy symbols to serve as initial csects. This forces the
733 text csects to precede the data csects. These symbols will not
735 ppc_text_csects
= symbol_make ("dummy\001");
736 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
737 ppc_data_csects
= symbol_make ("dummy\001");
738 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
743 #ifndef NO_SYMBOL_NAMES
744 /* FIXME: currently, if you enable the names, you cannot have variables
745 with the same names as the symbolic register names.
750 ppc_current_section
= text_section
;
751 ppc_previous_section
= 0;
756 /* Insert an operand value into an instruction. */
759 ppc_insert_operand (insn
, operand
, val
, file
, line
)
761 const struct powerpc_operand
*operand
;
766 if (operand
->bits
!= 32)
771 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
773 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
774 && ppc_size
== PPC_OPCODE_32
)
775 max
= (1 << operand
->bits
) - 1;
777 max
= (1 << (operand
->bits
- 1)) - 1;
778 min
= - (1 << (operand
->bits
- 1));
782 max
= (1 << operand
->bits
) - 1;
786 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
791 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
794 "operand out of range (%s not between %ld and %ld)";
797 sprint_value (buf
, test
);
798 if (file
== (char *) NULL
)
799 as_warn (err
, buf
, min
, max
);
801 as_warn_where (file
, line
, err
, buf
, min
, max
);
810 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
811 if (errmsg
!= (const char *) NULL
)
815 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
822 /* Parse @got, etc. and return the desired relocation. */
823 static bfd_reloc_code_real_type
824 ppc_elf_suffix (str_p
)
830 bfd_reloc_code_real_type reloc
;
840 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
842 static struct map_bfd mapping
[] = {
843 MAP ("got", BFD_RELOC_PPC_TOC16
),
844 MAP ("l", BFD_RELOC_LO16
),
845 MAP ("h", BFD_RELOC_HI16
),
846 MAP ("ha", BFD_RELOC_HI16_S
),
847 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
848 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
849 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
850 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
851 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
852 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
853 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
854 MAP ("copy", BFD_RELOC_PPC_COPY
),
855 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
856 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
857 MAP ("plt", BFD_RELOC_32_PLTOFF
),
858 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL
),
859 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
860 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
861 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
862 MAP ("sdarel", BFD_RELOC_GPREL16
),
863 MAP ("sectoff", BFD_RELOC_32_BASEREL
),
864 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
865 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
866 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
868 { (char *)0, 0, BFD_RELOC_UNUSED
}
872 return BFD_RELOC_UNUSED
;
874 for (ch
= *str
, str2
= ident
;
875 str2
< ident
+ sizeof(ident
) - 1 && isalnum (ch
) || ch
== '@';
878 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
885 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
886 if (ch
== ptr
->string
[0] && len
== ptr
->length
&& memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
892 return BFD_RELOC_UNUSED
;
895 /* Like normal .long/.short/.word, except support @got, etc. */
896 /* clobbers input_line_pointer, checks */
899 ppc_elf_cons (nbytes
)
900 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
903 bfd_reloc_code_real_type reloc
;
905 if (is_it_end_of_statement ())
907 demand_empty_rest_of_line ();
914 if (exp
.X_op
== O_symbol
915 && *input_line_pointer
== '@'
916 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
918 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
919 int size
= bfd_get_reloc_size (reloc_howto
);
922 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
926 register char *p
= frag_more ((int) nbytes
);
927 int offset
= nbytes
- size
;
929 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
933 emit_expr (&exp
, (unsigned int) nbytes
);
935 while (*input_line_pointer
++ == ',');
937 input_line_pointer
--; /* Put terminator back into stream. */
938 demand_empty_rest_of_line ();
941 /* Validate any relocations emitted for -mrelocatable, possibly adding
942 fixups for word relocations in writable segments, so we can adjust
945 ppc_elf_validate_fix (fixp
, seg
)
952 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
953 && strcmp (segment_name (seg
), ".got2") != 0
954 && strcmp (segment_name (seg
), ".dtors") != 0
955 && strcmp (segment_name (seg
), ".ctors") != 0
956 && strcmp (segment_name (seg
), ".fixup") != 0
957 && strcmp (segment_name (seg
), ".stab") != 0)
959 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
960 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
962 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
963 "Relocation cannot be done when using -mrelocatable");
970 /* We need to keep a list of fixups. We can't simply generate them as
971 we go, because that would require us to first create the frag, and
972 that would screw up references to ``.''. */
978 bfd_reloc_code_real_type reloc
;
981 #define MAX_INSN_FIXUPS (5)
983 /* This routine is called for each instruction to be assembled. */
990 const struct powerpc_opcode
*opcode
;
992 const unsigned char *opindex_ptr
;
996 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
1000 bfd_reloc_code_real_type reloc
;
1002 /* Get the opcode. */
1003 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1008 /* Look up the opcode in the hash table. */
1009 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
1010 if (opcode
== (const struct powerpc_opcode
*) NULL
)
1012 const struct powerpc_macro
*macro
;
1014 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
1015 if (macro
== (const struct powerpc_macro
*) NULL
)
1016 as_bad ("Unrecognized opcode: `%s'", str
);
1018 ppc_macro (s
, macro
);
1023 insn
= opcode
->opcode
;
1026 while (isspace (*str
))
1029 /* PowerPC operands are just expressions. The only real issue is
1030 that a few operand types are optional. All cases which might use
1031 an optional operand separate the operands only with commas (in
1032 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1033 cases never have optional operands). There is never more than
1034 one optional operand for an instruction. So, before we start
1035 seriously parsing the operands, we check to see if we have an
1036 optional operand, and, if we do, we count the number of commas to
1037 see whether the operand should be omitted. */
1039 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1041 const struct powerpc_operand
*operand
;
1043 operand
= &powerpc_operands
[*opindex_ptr
];
1044 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
1046 unsigned int opcount
;
1048 /* There is an optional operand. Count the number of
1049 commas in the input line. */
1056 while ((s
= strchr (s
, ',')) != (char *) NULL
)
1063 /* If there are fewer operands in the line then are called
1064 for by the instruction, we want to skip the optional
1066 if (opcount
< strlen (opcode
->operands
))
1073 /* Gather the operands. */
1077 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1079 const struct powerpc_operand
*operand
;
1085 if (next_opindex
== 0)
1086 operand
= &powerpc_operands
[*opindex_ptr
];
1089 operand
= &powerpc_operands
[next_opindex
];
1095 /* If this is a fake operand, then we do not expect anything
1097 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
1099 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1100 if (errmsg
!= (const char *) NULL
)
1105 /* If this is an optional operand, and we are skipping it, just
1107 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
1110 if (operand
->insert
)
1112 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
1113 if (errmsg
!= (const char *) NULL
)
1116 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
1117 next_opindex
= *opindex_ptr
+ 1;
1121 /* Gather the operand. */
1122 hold
= input_line_pointer
;
1123 input_line_pointer
= str
;
1126 if (*input_line_pointer
== '[')
1128 /* Expecting something like the second argument here:
1130 lwz r4,[toc].GS.0.static_int(rtoc)
1132 The only legal thing between the '[]' sequence is
1133 'toc'. The second arg must be a symbol name, and the
1134 register must be the toc register: 'rtoc' or '2'
1136 The effect is to 0 as the displacement field
1137 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16
1138 reloc against it based on the symbol. The linker will
1139 build the toc, and insert the resolved toc offset.
1142 To support "data in toc", we need to allow for the following:
1144 # open up the toc section, and put "gorp" in it
1151 In this case, r4 is loaded with the displacement of gorp in
1155 o The size of the toc entry is currently assumed to be
1156 32 bits. This should not be assumed to be a hard coded
1158 o In an effort to cope with a change from 32 to 64 bits,
1159 there are also toc entries that are specified to be
1160 either 32 or 64 bits:
1161 lwz r4,[toc32].GS.0.static_int(rtoc)
1162 lwz r4,[toc64].GS.0.static_int(rtoc)
1163 These demand toc entries of the specified size, and the
1164 instruction probably requires it.
1168 input_line_pointer
+= 5; /* FIXME: parse and semantics needed */
1171 /* We need to generate a fixup for this expression. */
1172 if (fc
>= MAX_INSN_FIXUPS
)
1173 as_fatal ("too many fixups");
1174 fixups
[fc
].exp
= ex
;
1175 fixups
[fc
].opindex
= *opindex_ptr
;
1176 fixups
[fc
].reloc
= BFD_RELOC_PPC_TOC16
;
1179 /* Ok. We've set up the fixup for the instruction. Now make it
1180 look like the constant 0 was found here */
1182 ex
.X_op
= O_constant
;
1183 ex
.X_add_number
= 0;
1184 ex
.X_add_symbol
= NULL
;
1185 ex
.X_op_symbol
= NULL
;
1192 str
= input_line_pointer
;
1193 input_line_pointer
= hold
;
1196 str
= input_line_pointer
;
1197 input_line_pointer
= hold
;
1200 if (ex
.X_op
== O_illegal
)
1201 as_bad ("illegal operand");
1202 else if (ex
.X_op
== O_absent
)
1203 as_bad ("missing operand");
1204 else if (ex
.X_op
== O_constant
)
1207 /* Allow @HA, @L, @H on constants. */
1208 char *orig_str
= str
;
1209 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1216 case BFD_RELOC_LO16
:
1217 ex
.X_add_number
= ((ex
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1220 case BFD_RELOC_HI16
:
1221 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
1224 case BFD_RELOC_HI16_S
:
1225 ex
.X_add_number
= ((ex
.X_add_number
>> 16) & 0xffff)
1226 + ((ex
.X_add_number
>> 15) & 1);
1230 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1234 else if (ex
.X_op
== O_register
)
1236 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
1241 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
1243 /* For the absoulte forms of branchs, convert the PC relative form back into
1245 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
1248 case BFD_RELOC_PPC_B26
: reloc
= BFD_RELOC_PPC_BA26
; break;
1249 case BFD_RELOC_PPC_B16
: reloc
= BFD_RELOC_PPC_BA16
; break;
1250 case BFD_RELOC_PPC_B16_BRTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
; break;
1251 case BFD_RELOC_PPC_B16_BRNTAKEN
: reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
; break;
1254 /* We need to generate a fixup for this expression. */
1255 if (fc
>= MAX_INSN_FIXUPS
)
1256 as_fatal ("too many fixups");
1257 fixups
[fc
].exp
= ex
;
1258 fixups
[fc
].opindex
= 0;
1259 fixups
[fc
].reloc
= reloc
;
1262 #endif /* OBJ_ELF */
1266 /* We need to generate a fixup for this expression. */
1267 if (fc
>= MAX_INSN_FIXUPS
)
1268 as_fatal ("too many fixups");
1269 fixups
[fc
].exp
= ex
;
1270 fixups
[fc
].opindex
= *opindex_ptr
;
1271 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1280 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
1288 /* The call to expression should have advanced str past any
1291 && (endc
!= ',' || *str
!= '\0'))
1293 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
1301 while (isspace (*str
))
1305 as_bad ("junk at end of line: `%s'", str
);
1307 /* Write out the instruction. */
1309 md_number_to_chars (f
, insn
, 4);
1311 /* Create any fixups. At this point we do not use a
1312 bfd_reloc_code_real_type, but instead just use the
1313 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1314 handle fixups for any operand type, although that is admittedly
1315 not a very exciting feature. We pick a BFD reloc type in
1317 for (i
= 0; i
< fc
; i
++)
1319 const struct powerpc_operand
*operand
;
1321 operand
= &powerpc_operands
[fixups
[i
].opindex
];
1322 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1324 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1332 size
= bfd_get_reloc_size (reloc_howto
);
1333 offset
= target_big_endian
? (4 - size
) : 0;
1335 if (size
< 1 || size
> 4)
1338 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1339 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1342 /* Turn off complaints that the addend is too large for things like
1344 switch (fixups
[i
].reloc
)
1346 case BFD_RELOC_LO16
:
1347 case BFD_RELOC_HI16
:
1348 case BFD_RELOC_HI16_S
:
1349 fixP
->fx_no_overflow
= 1;
1354 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1356 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
1357 ((bfd_reloc_code_real_type
)
1358 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1362 #ifndef WORKING_DOT_WORD
1363 /* Handle long and short jumps */
1365 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1367 addressT from_addr
, to_addr
;
1375 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1377 addressT from_addr
, to_addr
;
1385 /* Handle a macro. Gather all the operands, transform them as
1386 described by the macro, and call md_assemble recursively. All the
1387 operands are separated by commas; we don't accept parentheses
1388 around operands here. */
1391 ppc_macro (str
, macro
)
1393 const struct powerpc_macro
*macro
;
1404 /* Gather the users operands into the operands array. */
1409 if (count
>= sizeof operands
/ sizeof operands
[0])
1411 operands
[count
++] = s
;
1412 s
= strchr (s
, ',');
1413 if (s
== (char *) NULL
)
1418 if (count
!= macro
->operands
)
1420 as_bad ("wrong number of operands");
1424 /* Work out how large the string must be (the size is unbounded
1425 because it includes user input). */
1427 format
= macro
->format
;
1428 while (*format
!= '\0')
1437 arg
= strtol (format
+ 1, &send
, 10);
1438 know (send
!= format
&& arg
>= 0 && arg
< count
);
1439 len
+= strlen (operands
[arg
]);
1444 /* Put the string together. */
1445 complete
= s
= (char *) alloca (len
+ 1);
1446 format
= macro
->format
;
1447 while (*format
!= '\0')
1453 arg
= strtol (format
+ 1, &send
, 10);
1454 strcpy (s
, operands
[arg
]);
1461 /* Assemble the constructed instruction. */
1462 md_assemble (complete
);
1465 /* Pseudo-op handling. */
1467 /* The .byte pseudo-op. This is similar to the normal .byte
1468 pseudo-op, but it can also take a single ASCII string. */
1474 if (*input_line_pointer
!= '\"')
1480 /* Gather characters. A real double quote is doubled. Unusual
1481 characters are not permitted. */
1482 ++input_line_pointer
;
1487 c
= *input_line_pointer
++;
1491 if (*input_line_pointer
!= '\"')
1493 ++input_line_pointer
;
1496 FRAG_APPEND_1_CHAR (c
);
1499 demand_empty_rest_of_line ();
1504 /* XCOFF specific pseudo-op handling. */
1506 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1507 symbols in the .bss segment as though they were local common
1508 symbols, and uses a different smclas. */
1514 asection
*current_seg
= now_seg
;
1515 subsegT current_subseg
= now_subseg
;
1521 symbolS
*lcomm_sym
= NULL
;
1525 name
= input_line_pointer
;
1526 endc
= get_symbol_end ();
1527 end_name
= input_line_pointer
;
1530 if (*input_line_pointer
!= ',')
1532 as_bad ("missing size");
1533 ignore_rest_of_line ();
1536 ++input_line_pointer
;
1538 size
= get_absolute_expression ();
1541 as_bad ("negative size");
1542 ignore_rest_of_line ();
1548 /* The third argument to .comm is the alignment. */
1549 if (*input_line_pointer
!= ',')
1553 ++input_line_pointer
;
1554 align
= get_absolute_expression ();
1557 as_warn ("ignoring bad alignment");
1576 /* The third argument to .lcomm appears to be the real local
1577 common symbol to create. References to the symbol named in
1578 the first argument are turned into references to the third
1580 if (*input_line_pointer
!= ',')
1582 as_bad ("missing real symbol name");
1583 ignore_rest_of_line ();
1586 ++input_line_pointer
;
1588 lcomm_name
= input_line_pointer
;
1589 lcomm_endc
= get_symbol_end ();
1591 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1593 *input_line_pointer
= lcomm_endc
;
1597 sym
= symbol_find_or_make (name
);
1600 if (S_IS_DEFINED (sym
)
1601 || S_GET_VALUE (sym
) != 0)
1603 as_bad ("attempt to redefine symbol");
1604 ignore_rest_of_line ();
1608 record_alignment (bss_section
, align
);
1611 || ! S_IS_DEFINED (lcomm_sym
))
1620 S_SET_EXTERNAL (sym
);
1624 lcomm_sym
->sy_tc
.output
= 1;
1625 def_sym
= lcomm_sym
;
1629 subseg_set (bss_section
, 1);
1630 frag_align (align
, 0);
1632 def_sym
->sy_frag
= frag_now
;
1633 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1634 def_size
, (char *) NULL
);
1636 S_SET_SEGMENT (def_sym
, bss_section
);
1637 def_sym
->sy_tc
.align
= align
;
1641 /* Align the size of lcomm_sym. */
1642 lcomm_sym
->sy_frag
->fr_offset
=
1643 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1644 &~ ((1 << align
) - 1));
1645 if (align
> lcomm_sym
->sy_tc
.align
)
1646 lcomm_sym
->sy_tc
.align
= align
;
1651 /* Make sym an offset from lcomm_sym. */
1652 S_SET_SEGMENT (sym
, bss_section
);
1653 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1654 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1655 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1658 subseg_set (current_seg
, current_subseg
);
1660 demand_empty_rest_of_line ();
1663 /* The .csect pseudo-op. This switches us into a different
1664 subsegment. The first argument is a symbol whose value is the
1665 start of the .csect. In COFF, csect symbols get special aux
1666 entries defined by the x_csect field of union internal_auxent. The
1667 optional second argument is the alignment (the default is 2). */
1677 name
= input_line_pointer
;
1678 endc
= get_symbol_end ();
1680 sym
= symbol_find_or_make (name
);
1682 *input_line_pointer
= endc
;
1684 if (S_IS_DEFINED (sym
))
1685 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1692 /* This is a new csect. We need to look at the symbol class to
1693 figure out whether it should go in the text section or the
1696 switch (sym
->sy_tc
.class)
1706 S_SET_SEGMENT (sym
, text_section
);
1707 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1708 ++ppc_text_subsegment
;
1709 list_ptr
= &ppc_text_csects
;
1718 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1720 S_SET_SEGMENT (sym
, data_section
);
1721 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1722 ++ppc_data_subsegment
;
1723 list_ptr
= &ppc_data_csects
;
1729 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1731 ppc_after_toc_frag
= frag_now
;
1733 sym
->sy_frag
= frag_now
;
1734 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1736 sym
->sy_tc
.align
= 2;
1737 sym
->sy_tc
.output
= 1;
1738 sym
->sy_tc
.within
= sym
;
1740 for (list
= *list_ptr
;
1741 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1742 list
= list
->sy_tc
.next
)
1744 list
->sy_tc
.next
= sym
;
1746 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1747 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1750 if (*input_line_pointer
== ',')
1752 ++input_line_pointer
;
1753 sym
->sy_tc
.align
= get_absolute_expression ();
1756 ppc_current_csect
= sym
;
1758 demand_empty_rest_of_line ();
1761 /* The .extern pseudo-op. We create an undefined symbol. */
1770 name
= input_line_pointer
;
1771 endc
= get_symbol_end ();
1773 (void) symbol_find_or_make (name
);
1775 *input_line_pointer
= endc
;
1777 demand_empty_rest_of_line ();
1780 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
1781 this because it can't handle undefined symbols. I think we can
1791 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
1792 although I don't know why it bothers. */
1803 name
= input_line_pointer
;
1804 endc
= get_symbol_end ();
1806 sym
= symbol_find_or_make (name
);
1808 *input_line_pointer
= endc
;
1810 if (*input_line_pointer
!= ',')
1812 as_bad ("missing rename string");
1813 ignore_rest_of_line ();
1816 ++input_line_pointer
;
1818 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
1820 demand_empty_rest_of_line ();
1823 /* The .stabx pseudo-op. This is similar to a normal .stabs
1824 pseudo-op, but slightly different. A sample is
1825 .stabx "main:F-1",.main,142,0
1826 The first argument is the symbol name to create. The second is the
1827 value, and the third is the storage class. The fourth seems to be
1828 always zero, and I am assuming it is the type. */
1839 name
= demand_copy_C_string (&len
);
1841 if (*input_line_pointer
!= ',')
1843 as_bad ("missing value");
1846 ++input_line_pointer
;
1848 sym
= symbol_make (name
);
1850 (void) expression (&exp
);
1857 as_bad ("illegal .stabx expression; zero assumed");
1858 exp
.X_add_number
= 0;
1861 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
1862 sym
->sy_frag
= &zero_address_frag
;
1866 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
1867 sym
->sy_value
= exp
;
1871 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1872 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1877 /* The value is some complex expression. This will probably
1878 fail at some later point, but this is probably the right
1879 thing to do here. */
1880 sym
->sy_value
= exp
;
1884 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1885 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1887 if (*input_line_pointer
!= ',')
1889 as_bad ("missing class");
1892 ++input_line_pointer
;
1894 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
1896 if (*input_line_pointer
!= ',')
1898 as_bad ("missing type");
1901 ++input_line_pointer
;
1903 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
1905 sym
->sy_tc
.output
= 1;
1907 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
1908 sym
->sy_tc
.within
= ppc_current_block
;
1910 if (exp
.X_op
!= O_symbol
1911 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
1912 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
1913 ppc_frob_label (sym
);
1916 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1917 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
1918 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
1919 ppc_current_csect
->sy_tc
.within
= sym
;
1922 if (strlen (name
) > SYMNMLEN
)
1924 /* For some reason, each name is preceded by a two byte length
1925 and followed by a null byte. */
1926 ppc_debug_name_section_size
+= strlen (name
) + 3;
1929 demand_empty_rest_of_line ();
1932 /* The .function pseudo-op. This takes several arguments. The first
1933 argument seems to be the external name of the symbol. The second
1934 argment seems to be the label for the start of the function. gcc
1935 uses the same name for both. I have no idea what the third and
1936 fourth arguments are meant to be. The optional fifth argument is
1937 an expression for the size of the function. In COFF this symbol
1938 gets an aux entry like that used for a csect. */
1941 ppc_function (ignore
)
1950 name
= input_line_pointer
;
1951 endc
= get_symbol_end ();
1953 /* Ignore any [PR] suffix. */
1954 name
= ppc_canonicalize_symbol_name (name
);
1955 s
= strchr (name
, '[');
1956 if (s
!= (char *) NULL
1957 && strcmp (s
+ 1, "PR]") == 0)
1960 ext_sym
= symbol_find_or_make (name
);
1962 *input_line_pointer
= endc
;
1964 if (*input_line_pointer
!= ',')
1966 as_bad ("missing symbol name");
1967 ignore_rest_of_line ();
1970 ++input_line_pointer
;
1972 name
= input_line_pointer
;
1973 endc
= get_symbol_end ();
1975 lab_sym
= symbol_find_or_make (name
);
1977 *input_line_pointer
= endc
;
1979 if (ext_sym
!= lab_sym
)
1981 ext_sym
->sy_value
.X_op
= O_symbol
;
1982 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
1983 ext_sym
->sy_value
.X_op_symbol
= NULL
;
1984 ext_sym
->sy_value
.X_add_number
= 0;
1987 if (ext_sym
->sy_tc
.class == -1)
1988 ext_sym
->sy_tc
.class = XMC_PR
;
1989 ext_sym
->sy_tc
.output
= 1;
1991 if (*input_line_pointer
== ',')
1995 /* Ignore the third argument. */
1996 ++input_line_pointer
;
1997 expression (&ignore
);
1998 if (*input_line_pointer
== ',')
2000 /* Ignore the fourth argument. */
2001 ++input_line_pointer
;
2002 expression (&ignore
);
2003 if (*input_line_pointer
== ',')
2005 /* The fifth argument is the function size. */
2006 ++input_line_pointer
;
2007 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2010 &zero_address_frag
);
2011 pseudo_set (ext_sym
->sy_tc
.size
);
2016 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2017 SF_SET_FUNCTION (ext_sym
);
2018 SF_SET_PROCESS (ext_sym
);
2019 coff_add_linesym (ext_sym
);
2021 demand_empty_rest_of_line ();
2024 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2033 sym
= symbol_make (".bf");
2034 S_SET_SEGMENT (sym
, text_section
);
2035 sym
->sy_frag
= frag_now
;
2036 S_SET_VALUE (sym
, frag_now_fix ());
2037 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2039 coff_line_base
= get_absolute_expression ();
2041 S_SET_NUMBER_AUXILIARY (sym
, 1);
2042 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2044 sym
->sy_tc
.output
= 1;
2046 ppc_frob_label (sym
);
2048 demand_empty_rest_of_line ();
2051 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2052 ".ef", except that the line number is absolute, not relative to the
2053 most recent ".bf" symbol. */
2061 sym
= symbol_make (".ef");
2062 S_SET_SEGMENT (sym
, text_section
);
2063 sym
->sy_frag
= frag_now
;
2064 S_SET_VALUE (sym
, frag_now_fix ());
2065 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2066 S_SET_NUMBER_AUXILIARY (sym
, 1);
2067 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2068 sym
->sy_tc
.output
= 1;
2070 ppc_frob_label (sym
);
2072 demand_empty_rest_of_line ();
2075 /* The .bi and .ei pseudo-ops. These take a string argument and
2076 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2088 name
= demand_copy_C_string (&len
);
2090 sym
= symbol_make (name
);
2091 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2092 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2094 /* FIXME: The value of the .bi or .ei symbol is supposed to be the
2095 offset in the file to the line number entry to use. That is
2096 quite difficult to implement using BFD, so I'm just not doing it.
2097 Sorry. Please add it if you can figure out how. Note that this
2098 approach is the only way to support multiple files in COFF, since
2099 line numbers are associated with function symbols. Note further
2100 that it still doesn't work, since the line numbers are stored as
2101 offsets from a base line number. */
2103 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2104 sym
->sy_tc
.output
= 1;
2106 for (look
= symbol_rootP
;
2107 (look
!= (symbolS
*) NULL
2108 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2109 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2110 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2111 look
= symbol_next (look
))
2113 if (look
!= (symbolS
*) NULL
)
2115 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2116 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2119 demand_empty_rest_of_line ();
2122 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2123 There is one argument, which is a csect symbol. The value of the
2124 .bs symbol is the index of this csect symbol. */
2135 if (ppc_current_block
!= NULL
)
2136 as_bad ("nested .bs blocks");
2138 name
= input_line_pointer
;
2139 endc
= get_symbol_end ();
2141 csect
= symbol_find_or_make (name
);
2143 *input_line_pointer
= endc
;
2145 sym
= symbol_make (".bs");
2146 S_SET_SEGMENT (sym
, now_seg
);
2147 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2148 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2149 sym
->sy_tc
.output
= 1;
2151 sym
->sy_tc
.within
= csect
;
2153 ppc_frob_label (sym
);
2155 ppc_current_block
= sym
;
2157 demand_empty_rest_of_line ();
2160 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2168 if (ppc_current_block
== NULL
)
2169 as_bad (".es without preceding .bs");
2171 sym
= symbol_make (".es");
2172 S_SET_SEGMENT (sym
, now_seg
);
2173 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2174 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2175 sym
->sy_tc
.output
= 1;
2177 ppc_frob_label (sym
);
2179 ppc_current_block
= NULL
;
2181 demand_empty_rest_of_line ();
2184 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2193 sym
= symbol_make (".bb");
2194 S_SET_SEGMENT (sym
, text_section
);
2195 sym
->sy_frag
= frag_now
;
2196 S_SET_VALUE (sym
, frag_now_fix ());
2197 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2199 S_SET_NUMBER_AUXILIARY (sym
, 1);
2200 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2202 sym
->sy_tc
.output
= 1;
2204 ppc_frob_label (sym
);
2206 demand_empty_rest_of_line ();
2209 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2218 sym
= symbol_make (".eb");
2219 S_SET_SEGMENT (sym
, text_section
);
2220 sym
->sy_frag
= frag_now
;
2221 S_SET_VALUE (sym
, frag_now_fix ());
2222 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2223 S_SET_NUMBER_AUXILIARY (sym
, 1);
2224 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2225 sym
->sy_tc
.output
= 1;
2227 ppc_frob_label (sym
);
2229 demand_empty_rest_of_line ();
2232 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2238 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2239 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2246 subseg
= ppc_data_subsegment
;
2247 ++ppc_data_subsegment
;
2249 subseg_new (segment_name (data_section
), subseg
);
2250 ppc_toc_frag
= frag_now
;
2252 sym
= symbol_find_or_make ("TOC[TC0]");
2253 sym
->sy_frag
= frag_now
;
2254 S_SET_SEGMENT (sym
, data_section
);
2255 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2256 sym
->sy_tc
.subseg
= subseg
;
2257 sym
->sy_tc
.output
= 1;
2258 sym
->sy_tc
.within
= sym
;
2260 ppc_toc_csect
= sym
;
2262 for (list
= ppc_data_csects
;
2263 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2264 list
= list
->sy_tc
.next
)
2266 list
->sy_tc
.next
= sym
;
2268 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2269 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2272 ppc_current_csect
= ppc_toc_csect
;
2274 demand_empty_rest_of_line ();
2277 #endif /* OBJ_COFF */
2279 /* The .tc pseudo-op. This is used when generating either XCOFF or
2280 ELF. This takes two or more arguments.
2282 When generating XCOFF output, the first argument is the name to
2283 give to this location in the toc; this will be a symbol with class
2284 TC. The rest of the arguments are 4 byte values to actually put at
2285 this location in the TOC; often there is just one more argument, a
2286 relocateable symbol reference.
2288 When not generating XCOFF output, the arguments are the same, but
2289 the first argument is simply ignored. */
2297 /* Define the TOC symbol name. */
2303 if (ppc_toc_csect
== (symbolS
*) NULL
2304 || ppc_toc_csect
!= ppc_current_csect
)
2306 as_bad (".tc not in .toc section");
2307 ignore_rest_of_line ();
2311 name
= input_line_pointer
;
2312 endc
= get_symbol_end ();
2314 sym
= symbol_find_or_make (name
);
2316 *input_line_pointer
= endc
;
2318 if (S_IS_DEFINED (sym
))
2322 label
= ppc_current_csect
->sy_tc
.within
;
2323 if (label
->sy_tc
.class != XMC_TC0
)
2325 as_warn (".tc with no label");
2326 ignore_rest_of_line ();
2330 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
2331 label
->sy_frag
= sym
->sy_frag
;
2332 S_SET_VALUE (label
, S_GET_VALUE (sym
));
2334 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2335 ++input_line_pointer
;
2340 S_SET_SEGMENT (sym
, now_seg
);
2341 sym
->sy_frag
= frag_now
;
2342 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2343 sym
->sy_tc
.class = XMC_TC
;
2344 sym
->sy_tc
.output
= 1;
2346 ppc_frob_label (sym
);
2349 #else /* ! defined (OBJ_COFF) */
2351 /* Skip the TOC symbol name. */
2352 while (is_part_of_name (*input_line_pointer
)
2353 || *input_line_pointer
== '['
2354 || *input_line_pointer
== ']'
2355 || *input_line_pointer
== '{'
2356 || *input_line_pointer
== '}')
2357 ++input_line_pointer
;
2359 /* Align to a four byte boundary. */
2361 record_alignment (now_seg
, 2);
2363 #endif /* ! defined (OBJ_COFF) */
2365 if (*input_line_pointer
!= ',')
2366 demand_empty_rest_of_line ();
2369 ++input_line_pointer
;
2376 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2379 * Section characteristics
2382 #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
2384 #define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
2385 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
2386 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
2388 #define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved.
2389 #define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
2390 #define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
2391 #define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
2393 #define IMAGE_SCN_MEM_FARDATA 0x00008000
2395 #define IMAGE_SCN_MEM_PURGEABLE 0x00020000
2396 #define IMAGE_SCN_MEM_16BIT 0x00020000
2397 #define IMAGE_SCN_MEM_LOCKED 0x00040000
2398 #define IMAGE_SCN_MEM_PRELOAD 0x00080000
2400 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
2401 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
2402 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
2403 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
2404 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */
2405 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
2406 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
2409 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
2410 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 /* Section can be discarded. */
2411 #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
2412 #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */
2413 #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
2414 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 /* Section is executable. */
2415 #define IMAGE_SCN_MEM_READ 0x40000000 /* Section is readable. */
2416 #define IMAGE_SCN_MEM_WRITE 0x80000000 /* Section is writeable. */
2419 /* pseudo-op: .previous
2420 behaviour: toggles the current section with the previous section.
2422 warnings: "No previous section"
2425 ppc_previous(ignore
)
2430 if (ppc_previous_section
== NULL
)
2432 as_warn("No previous section to return to. Directive ignored.");
2436 subseg_set(ppc_previous_section
, 0);
2438 setCurrentSection(ppc_previous_section
);
2441 /* pseudo-op: .pdata
2442 behaviour: predefined read only data section
2446 initial: .section .pdata "adr3"
2447 a - don't know -- maybe a misprint
2448 d - initialized data
2450 3 - double word aligned (that would be 4 byte boundary)
2453 Tag index tables (also known as the function table) for exception
2454 handling, debugging, etc.
2461 if (pdata_section
== 0)
2463 pdata_section
= subseg_new (".pdata", 0);
2465 bfd_set_section_flags (stdoutput
, pdata_section
,
2466 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2467 | SEC_READONLY
| SEC_DATA
));
2469 bfd_set_section_alignment (stdoutput
, pdata_section
, 3);
2473 pdata_section
= subseg_new(".pdata", 0);
2475 setCurrentSection(pdata_section
);
2478 /* pseudo-op: .ydata
2479 behaviour: predefined read only data section
2483 initial: .section .ydata "drw3"
2484 a - don't know -- maybe a misprint
2485 d - initialized data
2487 3 - double word aligned (that would be 4 byte boundary)
2489 Tag tables (also known as the scope table) for exception handling,
2496 if (ydata_section
== 0)
2498 ydata_section
= subseg_new (".ydata", 0);
2499 bfd_set_section_flags (stdoutput
, ydata_section
,
2500 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2501 | SEC_READONLY
| SEC_DATA
));
2503 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
2507 ydata_section
= subseg_new (".ydata", 0);
2509 setCurrentSection(ydata_section
);
2512 /* pseudo-op: .reldata
2513 behaviour: predefined read write data section
2514 double word aligned (4-byte)
2515 FIXME: relocation is applied to it
2516 FIXME: what's the difference between this and .data?
2519 initial: .section .reldata "drw3"
2520 d - initialized data
2523 3 - double word aligned (that would be 8 byte boundary)
2526 Like .data, but intended to hold data subject to relocation, such as
2527 function descriptors, etc.
2533 if (reldata_section
== 0)
2535 reldata_section
= subseg_new (".reldata", 0);
2537 bfd_set_section_flags (stdoutput
, reldata_section
,
2538 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2541 bfd_set_section_alignment (stdoutput
, reldata_section
, 3);
2545 reldata_section
= subseg_new (".reldata", 0);
2547 setCurrentSection(reldata_section
);
2550 /* pseudo-op: .rdata
2551 behaviour: predefined read only data section
2555 initial: .section .rdata "dr3"
2556 d - initialized data
2558 3 - double word aligned (that would be 4 byte boundary)
2564 if (rdata_section
== 0)
2566 rdata_section
= subseg_new (".rdata", 0);
2567 bfd_set_section_flags (stdoutput
, rdata_section
,
2568 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2569 | SEC_READONLY
| SEC_DATA
));
2571 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
2575 rdata_section
= subseg_new (".rdata", 0);
2577 setCurrentSection(rdata_section
);
2580 /* pseudo-op: .ualong
2581 behaviour: much like .int, with the exception that no alignment is
2583 FIXME: test the alignment statement
2595 /* pseudo-op: .znop <symbol name>
2596 behaviour: Issue a nop instruction
2597 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2598 the supplied symbol name.
2600 warnings: Missing symbol name
2607 const struct powerpc_opcode
*opcode
;
2613 /* Strip out the symbol name */
2621 symbol_name
= input_line_pointer
;
2622 c
= get_symbol_end ();
2624 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
2625 strcpy (name
, symbol_name
);
2627 sym
= symbol_find_or_make (name
);
2629 *input_line_pointer
= c
;
2633 /* Look up the opcode in the hash table. */
2634 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
2636 /* stick in the nop */
2637 insn
= opcode
->opcode
;
2639 /* Write out the instruction. */
2641 md_number_to_chars (f
, insn
, 4);
2643 f
- frag_now
->fr_literal
,
2648 BFD_RELOC_16_GOT_PCREL
);
2660 register char *name
;
2664 register symbolS
*symbolP
;
2667 name
= input_line_pointer
;
2668 c
= get_symbol_end ();
2670 /* just after name is now '\0' */
2671 p
= input_line_pointer
;
2674 if (*input_line_pointer
!= ',')
2676 as_bad ("Expected comma after symbol-name: rest of line ignored.");
2677 ignore_rest_of_line ();
2681 input_line_pointer
++; /* skip ',' */
2682 if ((temp
= get_absolute_expression ()) < 0)
2684 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
2685 ignore_rest_of_line ();
2691 /* The third argument to .comm is the alignment. */
2692 if (*input_line_pointer
!= ',')
2696 ++input_line_pointer
;
2697 align
= get_absolute_expression ();
2700 as_warn ("ignoring bad alignment");
2707 symbolP
= symbol_find_or_make (name
);
2710 if (S_IS_DEFINED (symbolP
))
2712 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2713 S_GET_NAME (symbolP
));
2714 ignore_rest_of_line ();
2718 if (S_GET_VALUE (symbolP
))
2720 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
2721 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
2722 S_GET_NAME (symbolP
),
2723 (long) S_GET_VALUE (symbolP
),
2728 S_SET_VALUE (symbolP
, (valueT
) temp
);
2729 S_SET_EXTERNAL (symbolP
);
2732 demand_empty_rest_of_line ();
2736 * implement the .section pseudo op:
2737 * .section name {, "flags"}
2739 * | +--- optional flags: 'b' for bss
2741 * +-- section name 'l' for lib
2745 * 'd' (apparently m88k for data)
2747 * But if the argument is not a quoted string, treat it as a
2748 * subsegment number.
2750 * FIXME: this is a copy of the section processing from obj-coff.c, with
2751 * additions/changes for the moto-pas assembler support. There are three
2755 * 'a' - unknown - referred to in documentation, but no definition supplied
2756 * 'c' - section has code
2757 * 'd' - section has initialized data
2758 * 'u' - section has uninitialized data
2759 * 'i' - section contains directives (info)
2760 * 'n' - section can be discarded
2761 * 'R' - remove section at link time
2763 * Section Protection:
2764 * 'r' - section is readable
2765 * 'w' - section is writeable
2766 * 'x' - section is executable
2767 * 's' - section is sharable
2769 * Section Alignment:
2770 * '0' - align to byte boundary
2771 * '1' - align to halfword undary
2772 * '2' - align to word boundary
2773 * '3' - align to doubleword boundary
2774 * '4' - align to quadword boundary
2775 * '5' - align to 32 byte boundary
2776 * '6' - align to 64 byte boundary
2781 ppc_pe_section (ignore
)
2784 /* Strip out the section name */
2793 align
= 4; /* default alignment to 16 byte boundary */
2795 section_name
= input_line_pointer
;
2796 c
= get_symbol_end ();
2798 name
= xmalloc (input_line_pointer
- section_name
+ 1);
2799 strcpy (name
, section_name
);
2801 *input_line_pointer
= c
;
2806 flags
= SEC_NO_FLAGS
;
2808 if (*input_line_pointer
== ',')
2810 ++input_line_pointer
;
2812 if (*input_line_pointer
!= '"')
2813 exp
= get_absolute_expression ();
2816 ++input_line_pointer
;
2817 while (*input_line_pointer
!= '"'
2818 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
2820 switch (*input_line_pointer
)
2822 /* Section Contents */
2823 case 'a': /* unknown */
2824 as_warn ("Unsupported section attribute -- 'a'");
2826 case 'c': /* code section */
2829 case 'd': /* section has initialized data */
2832 case 'u': /* section has uninitialized data */
2833 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
2837 case 'i': /* section contains directives (info) */
2838 /* FIXME: This is IMAGE_SCN_LNK_INFO
2840 flags
|= SEC_HAS_CONTENTS
;
2842 case 'n': /* section can be discarded */
2845 case 'R': /* Remove section at link time */
2846 flags
|= SEC_NEVER_LOAD
;
2848 /* Section Protection */
2851 #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
2852 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 /* Section is executable. */
2853 #define IMAGE_SCN_MEM_READ 0x40000000 /* Section is readable. */
2854 #define IMAGE_SCN_MEM_WRITE 0x80000000 /* Section is writeable. */
2857 case 'r': /* section is readable */
2858 flags
|= IMAGE_SCN_MEM_READ
;
2860 case 'w': /* section is writeable */
2861 flags
|= IMAGE_SCN_MEM_WRITE
;
2863 case 'x': /* section is executable */
2864 flags
|= IMAGE_SCN_MEM_EXECUTE
;
2866 case 's': /* section is sharable */
2867 flags
|= IMAGE_SCN_MEM_SHARED
;
2870 /* Section Alignment */
2872 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
2873 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
2874 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
2875 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
2876 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */
2877 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
2878 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
2881 case '0': /* align to byte boundary */
2882 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
2885 case '1': /* align to halfword boundary */
2886 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
2889 case '2': /* align to word boundary */
2890 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
2893 case '3': /* align to doubleword boundary */
2894 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
2897 case '4': /* align to quadword boundary */
2898 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
2901 case '5': /* align to 32 byte boundary */
2902 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
2905 case '6': /* align to 64 byte boundary */
2906 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
2911 as_warn("unknown section attribute '%c'",
2912 *input_line_pointer
);
2915 ++input_line_pointer
;
2917 if (*input_line_pointer
== '"')
2918 ++input_line_pointer
;
2922 sec
= subseg_new (name
, (subsegT
) exp
);
2924 setCurrentSection(sec
);
2926 if (flags
!= SEC_NO_FLAGS
)
2928 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
2929 as_warn ("error setting flags for \"%s\": %s",
2930 bfd_section_name (stdoutput
, sec
),
2931 bfd_errmsg (bfd_get_error ()));
2935 /* FIXME: Make sure the winnt alignment bits get set */
2937 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
2938 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
2939 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
2940 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
2941 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */
2942 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
2943 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
2946 bfd_set_section_alignment(stdoutput
, sec
, align
);
2951 ppc_pe_function (ignore
)
2960 name
= input_line_pointer
;
2961 endc
= get_symbol_end ();
2963 /* Ignore any [PR] suffix. */
2964 name
= ppc_canonicalize_symbol_name (name
);
2965 s
= strchr (name
, '[');
2966 if (s
!= (char *) NULL
2967 && strcmp (s
+ 1, "PR]") == 0)
2970 ext_sym
= symbol_find_or_make (name
);
2972 *input_line_pointer
= endc
;
2974 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2975 SF_SET_FUNCTION (ext_sym
);
2976 SF_SET_PROCESS (ext_sym
);
2977 coff_add_linesym (ext_sym
);
2979 demand_empty_rest_of_line ();
2990 /* XCOFF specific symbol and file handling. */
2992 /* Canonicalize the symbol name. We use the to force the suffix, if
2993 any, to use square brackets, and to be in upper case. */
2996 ppc_canonicalize_symbol_name (name
)
3001 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3015 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3019 if (*s
== '\0' || s
[1] != '\0')
3020 as_bad ("bad symbol suffix");
3028 /* Set the class of a symbol based on the suffix, if any. This is
3029 called whenever a new symbol is created. */
3032 ppc_symbol_new_hook (sym
)
3037 sym
->sy_tc
.next
= NULL
;
3038 sym
->sy_tc
.output
= 0;
3039 sym
->sy_tc
.class = -1;
3040 sym
->sy_tc
.real_name
= NULL
;
3041 sym
->sy_tc
.subseg
= 0;
3042 sym
->sy_tc
.align
= 0;
3043 sym
->sy_tc
.size
= NULL
;
3044 sym
->sy_tc
.within
= NULL
;
3046 s
= strchr (S_GET_NAME (sym
), '[');
3047 if (s
== (const char *) NULL
)
3049 /* There is no suffix. */
3058 if (strcmp (s
, "BS]") == 0)
3059 sym
->sy_tc
.class = XMC_BS
;
3062 if (strcmp (s
, "DB]") == 0)
3063 sym
->sy_tc
.class = XMC_DB
;
3064 else if (strcmp (s
, "DS]") == 0)
3065 sym
->sy_tc
.class = XMC_DS
;
3068 if (strcmp (s
, "GL]") == 0)
3069 sym
->sy_tc
.class = XMC_GL
;
3072 if (strcmp (s
, "PR]") == 0)
3073 sym
->sy_tc
.class = XMC_PR
;
3076 if (strcmp (s
, "RO]") == 0)
3077 sym
->sy_tc
.class = XMC_RO
;
3078 else if (strcmp (s
, "RW]") == 0)
3079 sym
->sy_tc
.class = XMC_RW
;
3082 if (strcmp (s
, "SV]") == 0)
3083 sym
->sy_tc
.class = XMC_SV
;
3086 if (strcmp (s
, "TC]") == 0)
3087 sym
->sy_tc
.class = XMC_TC
;
3088 else if (strcmp (s
, "TI]") == 0)
3089 sym
->sy_tc
.class = XMC_TI
;
3090 else if (strcmp (s
, "TB]") == 0)
3091 sym
->sy_tc
.class = XMC_TB
;
3092 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3093 sym
->sy_tc
.class = XMC_TC0
;
3096 if (strcmp (s
, "UA]") == 0)
3097 sym
->sy_tc
.class = XMC_UA
;
3098 else if (strcmp (s
, "UC]") == 0)
3099 sym
->sy_tc
.class = XMC_UC
;
3102 if (strcmp (s
, "XO]") == 0)
3103 sym
->sy_tc
.class = XMC_XO
;
3107 if (sym
->sy_tc
.class == -1)
3108 as_bad ("Unrecognized symbol suffix");
3111 /* Set the class of a label based on where it is defined. This
3112 handles symbols without suffixes. Also, move the symbol so that it
3113 follows the csect symbol. */
3116 ppc_frob_label (sym
)
3120 if (ppc_current_csect
!= (symbolS
*) NULL
)
3122 if (sym
->sy_tc
.class == -1)
3123 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3125 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3126 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3128 ppc_current_csect
->sy_tc
.within
= sym
;
3133 /* Change the name of a symbol just before writing it out. Set the
3134 real name if the .rename pseudo-op was used. Otherwise, remove any
3135 class suffix. Return 1 if the symbol should not be included in the
3139 ppc_frob_symbol (sym
)
3142 static symbolS
*ppc_last_function
;
3143 static symbolS
*set_end
;
3145 /* Discard symbols that should not be included in the output symbol
3147 if (! sym
->sy_used_in_reloc
3148 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3149 || (! S_IS_EXTERNAL (sym
)
3150 && ! sym
->sy_tc
.output
3151 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3154 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3155 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3161 name
= S_GET_NAME (sym
);
3162 s
= strchr (name
, '[');
3163 if (s
!= (char *) NULL
)
3169 snew
= xmalloc (len
+ 1);
3170 memcpy (snew
, name
, len
);
3173 S_SET_NAME (sym
, snew
);
3177 if (set_end
!= (symbolS
*) NULL
)
3179 SA_SET_SYM_ENDNDX (set_end
, sym
);
3183 if (SF_GET_FUNCTION (sym
))
3185 if (ppc_last_function
!= (symbolS
*) NULL
)
3186 as_warn ("two .function pseudo-ops with no intervening .ef");
3187 ppc_last_function
= sym
;
3188 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3190 resolve_symbol_value (sym
->sy_tc
.size
);
3191 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3194 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3195 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3197 if (ppc_last_function
== (symbolS
*) NULL
)
3198 as_warn (".ef with no preceding .function");
3201 set_end
= ppc_last_function
;
3202 ppc_last_function
= NULL
;
3204 /* We don't have a C_EFCN symbol, but we need to force the
3205 COFF backend to believe that it has seen one. */
3206 coff_last_function
= NULL
;
3211 if (! S_IS_EXTERNAL (sym
)
3212 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3213 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3214 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3215 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3216 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3217 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3218 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3221 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
3222 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3225 union internal_auxent
*a
;
3227 /* Create a csect aux. */
3228 i
= S_GET_NUMBER_AUXILIARY (sym
);
3229 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3230 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3231 if (sym
->sy_tc
.class == XMC_TC0
)
3233 /* This is the TOC table. */
3234 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3235 a
->x_csect
.x_scnlen
.l
= 0;
3236 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3238 else if (sym
->sy_tc
.subseg
!= 0)
3240 /* This is a csect symbol. x_scnlen is the size of the
3242 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3243 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3244 S_GET_SEGMENT (sym
))
3245 - S_GET_VALUE (sym
));
3248 resolve_symbol_value (sym
->sy_tc
.next
);
3249 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3250 - S_GET_VALUE (sym
));
3252 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3254 else if (S_GET_SEGMENT (sym
) == bss_section
)
3256 /* This is a common symbol. */
3257 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3258 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3259 if (S_IS_EXTERNAL (sym
))
3260 sym
->sy_tc
.class = XMC_RW
;
3262 sym
->sy_tc
.class = XMC_BS
;
3264 else if (! S_IS_DEFINED (sym
))
3266 /* This is an external symbol. */
3267 a
->x_csect
.x_scnlen
.l
= 0;
3268 a
->x_csect
.x_smtyp
= XTY_ER
;
3270 else if (sym
->sy_tc
.class == XMC_TC
)
3274 /* This is a TOC definition. x_scnlen is the size of the
3276 next
= symbol_next (sym
);
3277 while (next
->sy_tc
.class == XMC_TC0
)
3278 next
= symbol_next (next
);
3279 if (next
== (symbolS
*) NULL
3280 || next
->sy_tc
.class != XMC_TC
)
3282 if (ppc_after_toc_frag
== (fragS
*) NULL
)
3283 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3285 - S_GET_VALUE (sym
));
3287 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
3288 - S_GET_VALUE (sym
));
3292 resolve_symbol_value (next
);
3293 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
3294 - S_GET_VALUE (sym
));
3296 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3300 else if (S_GET_SEGMENT (sym
) == pdata_section
)
3302 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3303 S_GET_SEGMENT (sym
))
3304 - S_GET_VALUE (sym
));
3306 else if (S_GET_SEGMENT (sym
) == rdata_section
)
3308 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3309 S_GET_SEGMENT (sym
))
3310 - S_GET_VALUE (sym
));
3312 else if (S_GET_SEGMENT (sym
) == reldata_section
)
3314 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3315 S_GET_SEGMENT (sym
))
3316 - S_GET_VALUE (sym
));
3324 /* This is a normal symbol definition. x_scnlen is the
3325 symbol index of the containing csect. */
3326 if (S_GET_SEGMENT (sym
) == text_section
)
3327 csect
= ppc_text_csects
;
3328 else if (S_GET_SEGMENT (sym
) == data_section
)
3329 csect
= ppc_data_csects
;
3333 /* Skip the initial dummy symbol. */
3334 csect
= csect
->sy_tc
.next
;
3336 if (csect
== (symbolS
*) NULL
)
3337 a
->x_csect
.x_scnlen
.l
= 0;
3340 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
3342 resolve_symbol_value (csect
->sy_tc
.next
);
3343 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
3345 csect
= csect
->sy_tc
.next
;
3348 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3349 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
3351 a
->x_csect
.x_smtyp
= XTY_LD
;
3355 a
->x_csect
.x_parmhash
= 0;
3356 a
->x_csect
.x_snhash
= 0;
3357 if (sym
->sy_tc
.class == -1)
3358 a
->x_csect
.x_smclas
= XMC_PR
;
3360 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
3361 a
->x_csect
.x_stab
= 0;
3362 a
->x_csect
.x_snstab
= 0;
3364 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
3366 /* We want the value to be the symbol index of the referenced
3367 csect symbol. BFD will do that for us if we set the right
3370 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
3371 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
3373 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
3378 /* The value is the offset from the enclosing csect. */
3379 block
= sym
->sy_tc
.within
;
3380 csect
= block
->sy_tc
.within
;
3381 resolve_symbol_value (csect
);
3382 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
3388 /* Set the VMA for a section. This is called on all the sections in
3392 ppc_frob_section (sec
)
3396 static bfd_size_type vma
= 0;
3398 bfd_set_section_vma (stdoutput
, sec
, vma
);
3399 vma
+= bfd_section_size (stdoutput
, sec
);
3403 /* Adjust the file by adding a .debug section if needed. */
3408 if (ppc_debug_name_section_size
> 0)
3412 sec
= bfd_make_section (stdoutput
, ".debug");
3413 if (sec
== (asection
*) NULL
3414 || ! bfd_set_section_size (stdoutput
, sec
,
3415 ppc_debug_name_section_size
)
3416 || ! bfd_set_section_flags (stdoutput
, sec
,
3417 SEC_HAS_CONTENTS
| SEC_LOAD
))
3418 as_fatal ("can't make .debug section");
3422 #endif /* OBJ_COFF */
3424 /* Turn a string in input_line_pointer into a floating point constant
3425 of type type, and store the appropriate bytes in *litp. The number
3426 of LITTLENUMS emitted is stored in *sizep . An error message is
3427 returned, or NULL on OK. */
3430 md_atof (type
, litp
, sizep
)
3436 LITTLENUM_TYPE words
[4];
3452 return "bad call to md_atof";
3455 t
= atof_ieee (input_line_pointer
, type
, words
);
3457 input_line_pointer
= t
;
3461 if (target_big_endian
)
3463 for (i
= 0; i
< prec
; i
++)
3465 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3471 for (i
= prec
- 1; i
>= 0; i
--)
3473 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3481 /* Write a value out to the object file, using the appropriate
3485 md_number_to_chars (buf
, val
, n
)
3490 if (target_big_endian
)
3491 number_to_chars_bigendian (buf
, val
, n
);
3493 number_to_chars_littleendian (buf
, val
, n
);
3496 /* Align a section (I don't know why this is machine dependent). */
3499 md_section_align (seg
, addr
)
3503 int align
= bfd_get_section_alignment (stdoutput
, seg
);
3505 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
3508 /* We don't have any form of relaxing. */
3511 md_estimate_size_before_relax (fragp
, seg
)
3518 /* Convert a machine dependent frag. We never generate these. */
3521 md_convert_frag (abfd
, sec
, fragp
)
3529 /* We have no need to default values of symbols. */
3533 md_undefined_symbol (name
)
3539 /* Functions concerning relocs. */
3541 /* The location from which a PC relative jump should be calculated,
3542 given a PC relative reloc. */
3545 md_pcrel_from (fixp
)
3549 if (fixp
->fx_addsy
!= (symbolS
*) NULL
3550 && (! S_IS_DEFINED (fixp
->fx_addsy
)
3551 || TC_FORCE_RELOCATION (fixp
)))
3555 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3560 /* This is called to see whether a fixup should be adjusted to use a
3561 section symbol. We take the opportunity to change a fixup against
3562 a symbol in the TOC subsegment into a reloc against the
3563 corresponding .tc symbol. */
3566 ppc_fix_adjustable (fix
)
3572 /* FIXME: Certainly the toc stuff gets us into trouble, and should
3573 not be executed. Not sure about the reloc adjustments. */
3577 resolve_symbol_value (fix
->fx_addsy
);
3578 val
= S_GET_VALUE (fix
->fx_addsy
);
3579 if (ppc_toc_csect
!= (symbolS
*) NULL
3580 && fix
->fx_addsy
!= (symbolS
*) NULL
3581 && fix
->fx_addsy
!= ppc_toc_csect
3582 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
3583 && val
>= ppc_toc_frag
->fr_address
3584 && (ppc_after_toc_frag
== (fragS
*) NULL
3585 || val
< ppc_after_toc_frag
->fr_address
))
3589 for (sy
= symbol_next (ppc_toc_csect
);
3590 sy
!= (symbolS
*) NULL
;
3591 sy
= symbol_next (sy
))
3593 if (sy
->sy_tc
.class == XMC_TC0
)
3595 if (sy
->sy_tc
.class != XMC_TC
)
3597 resolve_symbol_value (sy
);
3598 if (val
== S_GET_VALUE (sy
))
3601 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
3606 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3607 "symbol in .toc does not match any .tc");
3610 /* Possibly adjust the reloc to be against the csect. */
3611 if (fix
->fx_addsy
!= (symbolS
*) NULL
3612 && fix
->fx_addsy
->sy_tc
.subseg
== 0
3613 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
3614 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
3615 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
3619 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
3620 csect
= ppc_text_csects
;
3621 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
3622 csect
= ppc_data_csects
;
3626 /* Skip the initial dummy symbol. */
3627 csect
= csect
->sy_tc
.next
;
3629 if (csect
!= (symbolS
*) NULL
)
3631 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
3632 && (csect
->sy_tc
.next
->sy_frag
->fr_address
3633 <= fix
->fx_addsy
->sy_frag
->fr_address
))
3634 csect
= csect
->sy_tc
.next
;
3636 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3637 - csect
->sy_frag
->fr_address
);
3638 fix
->fx_addsy
= csect
;
3642 /* Adjust a reloc against a .lcomm symbol to be against the base
3644 if (fix
->fx_addsy
!= (symbolS
*) NULL
3645 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
3646 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
3648 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
3649 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3650 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
3651 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
3659 /* See whether a symbol is in the TOC section. */
3662 ppc_is_toc_sym (sym
)
3666 return sym
->sy_tc
.class == XMC_TC
;
3668 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
3672 /* Apply a fixup to the object code. This is called for all the
3673 fixups we generated by the call to fix_new_exp, above. In the call
3674 above we used a reloc code which was the largest legal reloc code
3675 plus the operand index. Here we undo that to recover the operand
3676 index. At this point all symbol values should be fully resolved,
3677 and we attempt to completely resolve the reloc. If we can not do
3678 that, we determine the correct reloc code and put it back in the
3682 md_apply_fix3 (fixp
, valuep
, seg
)
3689 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
3690 the symbol values. Since we are using BFD_ASSEMBLER, if we are
3691 doing this relocation the code in write.c is going to call
3692 bfd_perform_relocation, which is also going to use the symbol
3693 value. That means that if the reloc is fully resolved we want to
3694 use *valuep since bfd_perform_relocation is not being used.
3695 However, if the reloc is not fully resolved we do not want to use
3696 *valuep, and must use fx_offset instead. However, if the reloc
3697 is PC relative, we do want to use *valuep since it includes the
3698 result of md_pcrel_from. This is confusing. */
3700 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
3705 else if (fixp
->fx_pcrel
)
3709 value
= fixp
->fx_offset
;
3710 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
3712 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
3713 value
-= S_GET_VALUE (fixp
->fx_subsy
);
3716 /* We can't actually support subtracting a symbol. */
3717 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3718 "expression too complex");
3723 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
3726 const struct powerpc_operand
*operand
;
3730 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
3732 operand
= &powerpc_operands
[opindex
];
3735 /* It appears that an instruction like
3737 when LC..1 is not a TOC symbol does not generate a reloc. It
3738 uses the offset of LC..1 within its csect. However, .long
3739 LC..1 will generate a reloc. I can't find any documentation
3740 on how these cases are to be distinguished, so this is a wild
3741 guess. These cases are generated by gcc -mminimal-toc. */
3742 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
3743 && operand
->bits
== 16
3744 && operand
->shift
== 0
3745 && operand
->insert
== NULL
3746 && fixp
->fx_addsy
!= NULL
3747 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
3748 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
3749 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
3750 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
3752 value
= fixp
->fx_offset
;
3757 /* Fetch the instruction, insert the fully resolved operand
3758 value, and stuff the instruction back again. */
3759 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
3760 if (target_big_endian
)
3761 insn
= bfd_getb32 ((unsigned char *) where
);
3763 insn
= bfd_getl32 ((unsigned char *) where
);
3764 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
3765 fixp
->fx_file
, fixp
->fx_line
);
3766 if (target_big_endian
)
3767 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
3769 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
3773 /* Nothing else to do here. */
3777 /* Determine a BFD reloc value based on the operand information.
3778 We are only prepared to turn a few of the operands into
3780 FIXME: We need to handle the DS field at the very least.
3781 FIXME: Selecting the reloc type is a bit haphazard; perhaps
3782 there should be a new field in the operand table. */
3783 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3784 && operand
->bits
== 26
3785 && operand
->shift
== 0)
3786 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
3787 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3788 && operand
->bits
== 16
3789 && operand
->shift
== 0)
3790 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
3791 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3792 && operand
->bits
== 26
3793 && operand
->shift
== 0)
3794 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
3795 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3796 && operand
->bits
== 16
3797 && operand
->shift
== 0)
3798 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
3799 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
3800 && operand
->bits
== 16
3801 && operand
->shift
== 0
3802 && operand
->insert
== NULL
3803 && fixp
->fx_addsy
!= NULL
3804 && ppc_is_toc_sym (fixp
->fx_addsy
))
3807 if (target_big_endian
)
3808 fixp
->fx_where
+= 2;
3809 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
3813 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3814 "unresolved expression that must be resolved");
3822 ppc_elf_validate_fix (fixp
, seg
);
3824 switch (fixp
->fx_r_type
)
3827 case BFD_RELOC_CTOR
:
3830 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
3831 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3832 } /* fall through */
3834 case BFD_RELOC_32_PCREL
:
3835 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
3839 case BFD_RELOC_LO16
:
3840 case BFD_RELOC_HI16
:
3841 case BFD_RELOC_HI16_S
:
3842 case BFD_RELOC_PPC_TOC16
:
3844 case BFD_RELOC_GPREL16
:
3848 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
3856 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
3866 fixp
->fx_addnumber
= value
;
3868 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
3869 fixp
->fx_addnumber
= 0;
3873 fixp
->fx_addnumber
= 0;
3875 /* We want to use the offset within the data segment of the
3876 symbol, not the actual VMA of the symbol. */
3877 fixp
->fx_addnumber
=
3878 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
3886 /* Generate a reloc for a fixup. */
3889 tc_gen_reloc (seg
, fixp
)
3895 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
3897 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
3898 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3899 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
3900 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
3902 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3903 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
3906 reloc
->addend
= fixp
->fx_addnumber
;