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 demand_empty_rest_of_line ();
1759 /* The .extern pseudo-op. We create an undefined symbol. */
1768 name
= input_line_pointer
;
1769 endc
= get_symbol_end ();
1771 (void) symbol_find_or_make (name
);
1773 *input_line_pointer
= endc
;
1775 demand_empty_rest_of_line ();
1778 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
1779 this because it can't handle undefined symbols. I think we can
1789 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
1790 although I don't know why it bothers. */
1801 name
= input_line_pointer
;
1802 endc
= get_symbol_end ();
1804 sym
= symbol_find_or_make (name
);
1806 *input_line_pointer
= endc
;
1808 if (*input_line_pointer
!= ',')
1810 as_bad ("missing rename string");
1811 ignore_rest_of_line ();
1814 ++input_line_pointer
;
1816 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
1818 demand_empty_rest_of_line ();
1821 /* The .stabx pseudo-op. This is similar to a normal .stabs
1822 pseudo-op, but slightly different. A sample is
1823 .stabx "main:F-1",.main,142,0
1824 The first argument is the symbol name to create. The second is the
1825 value, and the third is the storage class. The fourth seems to be
1826 always zero, and I am assuming it is the type. */
1837 name
= demand_copy_C_string (&len
);
1839 if (*input_line_pointer
!= ',')
1841 as_bad ("missing value");
1844 ++input_line_pointer
;
1846 sym
= symbol_make (name
);
1848 (void) expression (&exp
);
1855 as_bad ("illegal .stabx expression; zero assumed");
1856 exp
.X_add_number
= 0;
1859 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
1860 sym
->sy_frag
= &zero_address_frag
;
1864 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
1865 sym
->sy_value
= exp
;
1869 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1870 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1875 /* The value is some complex expression. This will probably
1876 fail at some later point, but this is probably the right
1877 thing to do here. */
1878 sym
->sy_value
= exp
;
1882 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1883 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1885 if (*input_line_pointer
!= ',')
1887 as_bad ("missing class");
1890 ++input_line_pointer
;
1892 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
1894 if (*input_line_pointer
!= ',')
1896 as_bad ("missing type");
1899 ++input_line_pointer
;
1901 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
1903 sym
->sy_tc
.output
= 1;
1905 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
1906 sym
->sy_tc
.within
= ppc_current_block
;
1908 if (exp
.X_op
!= O_symbol
1909 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
1910 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
1911 ppc_frob_label (sym
);
1914 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1915 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
1916 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
1917 ppc_current_csect
->sy_tc
.within
= sym
;
1920 if (strlen (name
) > SYMNMLEN
)
1922 /* For some reason, each name is preceded by a two byte length
1923 and followed by a null byte. */
1924 ppc_debug_name_section_size
+= strlen (name
) + 3;
1927 demand_empty_rest_of_line ();
1930 /* The .function pseudo-op. This takes several arguments. The first
1931 argument seems to be the external name of the symbol. The second
1932 argment seems to be the label for the start of the function. gcc
1933 uses the same name for both. I have no idea what the third and
1934 fourth arguments are meant to be. The optional fifth argument is
1935 an expression for the size of the function. In COFF this symbol
1936 gets an aux entry like that used for a csect. */
1939 ppc_function (ignore
)
1948 name
= input_line_pointer
;
1949 endc
= get_symbol_end ();
1951 /* Ignore any [PR] suffix. */
1952 name
= ppc_canonicalize_symbol_name (name
);
1953 s
= strchr (name
, '[');
1954 if (s
!= (char *) NULL
1955 && strcmp (s
+ 1, "PR]") == 0)
1958 ext_sym
= symbol_find_or_make (name
);
1960 *input_line_pointer
= endc
;
1962 if (*input_line_pointer
!= ',')
1964 as_bad ("missing symbol name");
1965 ignore_rest_of_line ();
1968 ++input_line_pointer
;
1970 name
= input_line_pointer
;
1971 endc
= get_symbol_end ();
1973 lab_sym
= symbol_find_or_make (name
);
1975 *input_line_pointer
= endc
;
1977 if (ext_sym
!= lab_sym
)
1979 ext_sym
->sy_value
.X_op
= O_symbol
;
1980 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
1981 ext_sym
->sy_value
.X_op_symbol
= NULL
;
1982 ext_sym
->sy_value
.X_add_number
= 0;
1985 if (ext_sym
->sy_tc
.class == -1)
1986 ext_sym
->sy_tc
.class = XMC_PR
;
1987 ext_sym
->sy_tc
.output
= 1;
1989 if (*input_line_pointer
== ',')
1993 /* Ignore the third argument. */
1994 ++input_line_pointer
;
1995 expression (&ignore
);
1996 if (*input_line_pointer
== ',')
1998 /* Ignore the fourth argument. */
1999 ++input_line_pointer
;
2000 expression (&ignore
);
2001 if (*input_line_pointer
== ',')
2003 /* The fifth argument is the function size. */
2004 ++input_line_pointer
;
2005 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
2008 &zero_address_frag
);
2009 pseudo_set (ext_sym
->sy_tc
.size
);
2014 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2015 SF_SET_FUNCTION (ext_sym
);
2016 SF_SET_PROCESS (ext_sym
);
2017 coff_add_linesym (ext_sym
);
2019 demand_empty_rest_of_line ();
2022 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2031 sym
= symbol_make (".bf");
2032 S_SET_SEGMENT (sym
, text_section
);
2033 sym
->sy_frag
= frag_now
;
2034 S_SET_VALUE (sym
, frag_now_fix ());
2035 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2037 coff_line_base
= get_absolute_expression ();
2039 S_SET_NUMBER_AUXILIARY (sym
, 1);
2040 SA_SET_SYM_LNNO (sym
, coff_line_base
);
2042 sym
->sy_tc
.output
= 1;
2044 ppc_frob_label (sym
);
2046 demand_empty_rest_of_line ();
2049 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2050 ".ef", except that the line number is absolute, not relative to the
2051 most recent ".bf" symbol. */
2059 sym
= symbol_make (".ef");
2060 S_SET_SEGMENT (sym
, text_section
);
2061 sym
->sy_frag
= frag_now
;
2062 S_SET_VALUE (sym
, frag_now_fix ());
2063 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2064 S_SET_NUMBER_AUXILIARY (sym
, 1);
2065 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2066 sym
->sy_tc
.output
= 1;
2068 ppc_frob_label (sym
);
2070 demand_empty_rest_of_line ();
2073 /* The .bi and .ei pseudo-ops. These take a string argument and
2074 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2086 name
= demand_copy_C_string (&len
);
2088 sym
= symbol_make (name
);
2089 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
2090 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2092 /* FIXME: The value of the .bi or .ei symbol is supposed to be the
2093 offset in the file to the line number entry to use. That is
2094 quite difficult to implement using BFD, so I'm just not doing it.
2095 Sorry. Please add it if you can figure out how. Note that this
2096 approach is the only way to support multiple files in COFF, since
2097 line numbers are associated with function symbols. Note further
2098 that it still doesn't work, since the line numbers are stored as
2099 offsets from a base line number. */
2101 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
2102 sym
->sy_tc
.output
= 1;
2104 for (look
= symbol_rootP
;
2105 (look
!= (symbolS
*) NULL
2106 && (S_GET_STORAGE_CLASS (look
) == C_FILE
2107 || S_GET_STORAGE_CLASS (look
) == C_BINCL
2108 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
2109 look
= symbol_next (look
))
2111 if (look
!= (symbolS
*) NULL
)
2113 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2114 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
2117 demand_empty_rest_of_line ();
2120 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2121 There is one argument, which is a csect symbol. The value of the
2122 .bs symbol is the index of this csect symbol. */
2133 if (ppc_current_block
!= NULL
)
2134 as_bad ("nested .bs blocks");
2136 name
= input_line_pointer
;
2137 endc
= get_symbol_end ();
2139 csect
= symbol_find_or_make (name
);
2141 *input_line_pointer
= endc
;
2143 sym
= symbol_make (".bs");
2144 S_SET_SEGMENT (sym
, now_seg
);
2145 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
2146 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2147 sym
->sy_tc
.output
= 1;
2149 sym
->sy_tc
.within
= csect
;
2151 ppc_frob_label (sym
);
2153 ppc_current_block
= sym
;
2155 demand_empty_rest_of_line ();
2158 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2166 if (ppc_current_block
== NULL
)
2167 as_bad (".es without preceding .bs");
2169 sym
= symbol_make (".es");
2170 S_SET_SEGMENT (sym
, now_seg
);
2171 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
2172 sym
->bsym
->flags
|= BSF_DEBUGGING
;
2173 sym
->sy_tc
.output
= 1;
2175 ppc_frob_label (sym
);
2177 ppc_current_block
= NULL
;
2179 demand_empty_rest_of_line ();
2182 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2191 sym
= symbol_make (".bb");
2192 S_SET_SEGMENT (sym
, text_section
);
2193 sym
->sy_frag
= frag_now
;
2194 S_SET_VALUE (sym
, frag_now_fix ());
2195 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
2197 S_SET_NUMBER_AUXILIARY (sym
, 1);
2198 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2200 sym
->sy_tc
.output
= 1;
2202 ppc_frob_label (sym
);
2204 demand_empty_rest_of_line ();
2207 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2216 sym
= symbol_make (".eb");
2217 S_SET_SEGMENT (sym
, text_section
);
2218 sym
->sy_frag
= frag_now
;
2219 S_SET_VALUE (sym
, frag_now_fix ());
2220 S_SET_STORAGE_CLASS (sym
, C_FCN
);
2221 S_SET_NUMBER_AUXILIARY (sym
, 1);
2222 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
2223 sym
->sy_tc
.output
= 1;
2225 ppc_frob_label (sym
);
2227 demand_empty_rest_of_line ();
2230 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2236 if (ppc_toc_csect
!= (symbolS
*) NULL
)
2237 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
2244 subseg
= ppc_data_subsegment
;
2245 ++ppc_data_subsegment
;
2247 subseg_new (segment_name (data_section
), subseg
);
2248 ppc_toc_frag
= frag_now
;
2250 sym
= symbol_find_or_make ("TOC[TC0]");
2251 sym
->sy_frag
= frag_now
;
2252 S_SET_SEGMENT (sym
, data_section
);
2253 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2254 sym
->sy_tc
.subseg
= subseg
;
2255 sym
->sy_tc
.output
= 1;
2256 sym
->sy_tc
.within
= sym
;
2258 ppc_toc_csect
= sym
;
2260 for (list
= ppc_data_csects
;
2261 list
->sy_tc
.next
!= (symbolS
*) NULL
;
2262 list
= list
->sy_tc
.next
)
2264 list
->sy_tc
.next
= sym
;
2266 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2267 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
2270 demand_empty_rest_of_line ();
2273 #endif /* OBJ_COFF */
2275 /* The .tc pseudo-op. This is used when generating either XCOFF or
2276 ELF. This takes two or more arguments.
2278 When generating XCOFF output, the first argument is the name to
2279 give to this location in the toc; this will be a symbol with class
2280 TC. The rest of the arguments are 4 byte values to actually put at
2281 this location in the TOC; often there is just one more argument, a
2282 relocateable symbol reference.
2284 When not generating XCOFF output, the arguments are the same, but
2285 the first argument is simply ignored. */
2293 /* Define the TOC symbol name. */
2299 if (ppc_toc_csect
== (symbolS
*) NULL
2300 || ppc_toc_csect
!= ppc_current_csect
)
2302 as_bad (".tc not in .toc section");
2303 ignore_rest_of_line ();
2307 name
= input_line_pointer
;
2308 endc
= get_symbol_end ();
2310 sym
= symbol_find_or_make (name
);
2312 *input_line_pointer
= endc
;
2314 if (S_IS_DEFINED (sym
))
2318 label
= ppc_current_csect
->sy_tc
.within
;
2319 if (label
->sy_tc
.class != XMC_TC0
)
2321 as_warn (".tc with no label");
2322 ignore_rest_of_line ();
2326 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
2327 label
->sy_frag
= sym
->sy_frag
;
2328 S_SET_VALUE (label
, S_GET_VALUE (sym
));
2330 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2331 ++input_line_pointer
;
2336 S_SET_SEGMENT (sym
, now_seg
);
2337 sym
->sy_frag
= frag_now
;
2338 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
2339 sym
->sy_tc
.class = XMC_TC
;
2340 sym
->sy_tc
.output
= 1;
2342 ppc_frob_label (sym
);
2345 #else /* ! defined (OBJ_COFF) */
2347 /* Skip the TOC symbol name. */
2348 while (is_part_of_name (*input_line_pointer
)
2349 || *input_line_pointer
== '['
2350 || *input_line_pointer
== ']'
2351 || *input_line_pointer
== '{'
2352 || *input_line_pointer
== '}')
2353 ++input_line_pointer
;
2355 /* Align to a four byte boundary. */
2357 record_alignment (now_seg
, 2);
2359 #endif /* ! defined (OBJ_COFF) */
2361 if (*input_line_pointer
!= ',')
2362 demand_empty_rest_of_line ();
2365 ++input_line_pointer
;
2372 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2375 * Section characteristics
2378 #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
2380 #define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
2381 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
2382 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
2384 #define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved.
2385 #define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
2386 #define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
2387 #define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
2389 #define IMAGE_SCN_MEM_FARDATA 0x00008000
2391 #define IMAGE_SCN_MEM_PURGEABLE 0x00020000
2392 #define IMAGE_SCN_MEM_16BIT 0x00020000
2393 #define IMAGE_SCN_MEM_LOCKED 0x00040000
2394 #define IMAGE_SCN_MEM_PRELOAD 0x00080000
2396 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
2397 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
2398 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
2399 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
2400 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */
2401 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
2402 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
2405 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
2406 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 /* Section can be discarded. */
2407 #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
2408 #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */
2409 #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
2410 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 /* Section is executable. */
2411 #define IMAGE_SCN_MEM_READ 0x40000000 /* Section is readable. */
2412 #define IMAGE_SCN_MEM_WRITE 0x80000000 /* Section is writeable. */
2415 /* pseudo-op: .previous
2416 behaviour: toggles the current section with the previous section.
2418 warnings: "No previous section"
2421 ppc_previous(ignore
)
2426 if (ppc_previous_section
== NULL
)
2428 as_warn("No previous section to return to. Directive ignored.");
2432 subseg_set(ppc_previous_section
, 0);
2434 setCurrentSection(ppc_previous_section
);
2437 /* pseudo-op: .pdata
2438 behaviour: predefined read only data section
2442 initial: .section .pdata "adr3"
2443 a - don't know -- maybe a misprint
2444 d - initialized data
2446 3 - double word aligned (that would be 4 byte boundary)
2449 Tag index tables (also known as the function table) for exception
2450 handling, debugging, etc.
2457 if (pdata_section
== 0)
2459 pdata_section
= subseg_new (".pdata", 0);
2461 bfd_set_section_flags (stdoutput
, pdata_section
,
2462 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2463 | SEC_READONLY
| SEC_DATA
));
2465 bfd_set_section_alignment (stdoutput
, pdata_section
, 3);
2469 pdata_section
= subseg_new(".pdata", 0);
2471 setCurrentSection(pdata_section
);
2474 /* pseudo-op: .ydata
2475 behaviour: predefined read only data section
2479 initial: .section .ydata "drw3"
2480 a - don't know -- maybe a misprint
2481 d - initialized data
2483 3 - double word aligned (that would be 4 byte boundary)
2485 Tag tables (also known as the scope table) for exception handling,
2492 if (ydata_section
== 0)
2494 ydata_section
= subseg_new (".ydata", 0);
2495 bfd_set_section_flags (stdoutput
, ydata_section
,
2496 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2497 | SEC_READONLY
| SEC_DATA
));
2499 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
2503 ydata_section
= subseg_new (".ydata", 0);
2505 setCurrentSection(ydata_section
);
2508 /* pseudo-op: .reldata
2509 behaviour: predefined read write data section
2510 double word aligned (4-byte)
2511 FIXME: relocation is applied to it
2512 FIXME: what's the difference between this and .data?
2515 initial: .section .reldata "drw3"
2516 d - initialized data
2519 3 - double word aligned (that would be 8 byte boundary)
2522 Like .data, but intended to hold data subject to relocation, such as
2523 function descriptors, etc.
2529 if (reldata_section
== 0)
2531 reldata_section
= subseg_new (".reldata", 0);
2533 bfd_set_section_flags (stdoutput
, reldata_section
,
2534 ( SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2537 bfd_set_section_alignment (stdoutput
, reldata_section
, 3);
2541 reldata_section
= subseg_new (".reldata", 0);
2543 setCurrentSection(reldata_section
);
2546 /* pseudo-op: .rdata
2547 behaviour: predefined read only data section
2551 initial: .section .rdata "dr3"
2552 d - initialized data
2554 3 - double word aligned (that would be 4 byte boundary)
2560 if (rdata_section
== 0)
2562 rdata_section
= subseg_new (".rdata", 0);
2563 bfd_set_section_flags (stdoutput
, rdata_section
,
2564 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2565 | SEC_READONLY
| SEC_DATA
));
2567 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
2571 rdata_section
= subseg_new (".rdata", 0);
2573 setCurrentSection(rdata_section
);
2576 /* pseudo-op: .ualong
2577 behaviour: much like .int, with the exception that no alignment is
2579 FIXME: test the alignment statement
2591 /* pseudo-op: .znop <symbol name>
2592 behaviour: Issue a nop instruction
2593 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2594 the supplied symbol name.
2596 warnings: Missing symbol name
2603 const struct powerpc_opcode
*opcode
;
2609 /* Strip out the symbol name */
2617 symbol_name
= input_line_pointer
;
2618 c
= get_symbol_end ();
2620 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
2621 strcpy (name
, symbol_name
);
2623 sym
= symbol_find_or_make (name
);
2625 *input_line_pointer
= c
;
2629 /* Look up the opcode in the hash table. */
2630 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
2632 /* stick in the nop */
2633 insn
= opcode
->opcode
;
2635 /* Write out the instruction. */
2637 md_number_to_chars (f
, insn
, 4);
2639 f
- frag_now
->fr_literal
,
2644 BFD_RELOC_16_GOT_PCREL
);
2656 register char *name
;
2660 register symbolS
*symbolP
;
2663 name
= input_line_pointer
;
2664 c
= get_symbol_end ();
2666 /* just after name is now '\0' */
2667 p
= input_line_pointer
;
2670 if (*input_line_pointer
!= ',')
2672 as_bad ("Expected comma after symbol-name: rest of line ignored.");
2673 ignore_rest_of_line ();
2677 input_line_pointer
++; /* skip ',' */
2678 if ((temp
= get_absolute_expression ()) < 0)
2680 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp
);
2681 ignore_rest_of_line ();
2687 /* The third argument to .comm is the alignment. */
2688 if (*input_line_pointer
!= ',')
2692 ++input_line_pointer
;
2693 align
= get_absolute_expression ();
2696 as_warn ("ignoring bad alignment");
2703 symbolP
= symbol_find_or_make (name
);
2706 if (S_IS_DEFINED (symbolP
))
2708 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2709 S_GET_NAME (symbolP
));
2710 ignore_rest_of_line ();
2714 if (S_GET_VALUE (symbolP
))
2716 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
2717 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
2718 S_GET_NAME (symbolP
),
2719 (long) S_GET_VALUE (symbolP
),
2724 S_SET_VALUE (symbolP
, (valueT
) temp
);
2725 S_SET_EXTERNAL (symbolP
);
2728 demand_empty_rest_of_line ();
2732 * implement the .section pseudo op:
2733 * .section name {, "flags"}
2735 * | +--- optional flags: 'b' for bss
2737 * +-- section name 'l' for lib
2741 * 'd' (apparently m88k for data)
2743 * But if the argument is not a quoted string, treat it as a
2744 * subsegment number.
2746 * FIXME: this is a copy of the section processing from obj-coff.c, with
2747 * additions/changes for the moto-pas assembler support. There are three
2751 * 'a' - unknown - referred to in documentation, but no definition supplied
2752 * 'c' - section has code
2753 * 'd' - section has initialized data
2754 * 'u' - section has uninitialized data
2755 * 'i' - section contains directives (info)
2756 * 'n' - section can be discarded
2757 * 'R' - remove section at link time
2759 * Section Protection:
2760 * 'r' - section is readable
2761 * 'w' - section is writeable
2762 * 'x' - section is executable
2763 * 's' - section is sharable
2765 * Section Alignment:
2766 * '0' - align to byte boundary
2767 * '1' - align to halfword undary
2768 * '2' - align to word boundary
2769 * '3' - align to doubleword boundary
2770 * '4' - align to quadword boundary
2771 * '5' - align to 32 byte boundary
2772 * '6' - align to 64 byte boundary
2777 ppc_pe_section (ignore
)
2780 /* Strip out the section name */
2789 align
= 4; /* default alignment to 16 byte boundary */
2791 section_name
= input_line_pointer
;
2792 c
= get_symbol_end ();
2794 name
= xmalloc (input_line_pointer
- section_name
+ 1);
2795 strcpy (name
, section_name
);
2797 *input_line_pointer
= c
;
2802 flags
= SEC_NO_FLAGS
;
2804 if (*input_line_pointer
== ',')
2806 ++input_line_pointer
;
2808 if (*input_line_pointer
!= '"')
2809 exp
= get_absolute_expression ();
2812 ++input_line_pointer
;
2813 while (*input_line_pointer
!= '"'
2814 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
2816 switch (*input_line_pointer
)
2818 /* Section Contents */
2819 case 'a': /* unknown */
2820 as_warn ("Unsupported section attribute -- 'a'");
2822 case 'c': /* code section */
2825 case 'd': /* section has initialized data */
2828 case 'u': /* section has uninitialized data */
2829 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
2833 case 'i': /* section contains directives (info) */
2834 /* FIXME: This is IMAGE_SCN_LNK_INFO
2836 flags
|= SEC_HAS_CONTENTS
;
2838 case 'n': /* section can be discarded */
2841 case 'R': /* Remove section at link time */
2842 flags
|= SEC_NEVER_LOAD
;
2844 /* Section Protection */
2847 #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
2848 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 /* Section is executable. */
2849 #define IMAGE_SCN_MEM_READ 0x40000000 /* Section is readable. */
2850 #define IMAGE_SCN_MEM_WRITE 0x80000000 /* Section is writeable. */
2853 case 'r': /* section is readable */
2854 flags
|= IMAGE_SCN_MEM_READ
;
2856 case 'w': /* section is writeable */
2857 flags
|= IMAGE_SCN_MEM_WRITE
;
2859 case 'x': /* section is executable */
2860 flags
|= IMAGE_SCN_MEM_EXECUTE
;
2862 case 's': /* section is sharable */
2863 flags
|= IMAGE_SCN_MEM_SHARED
;
2866 /* Section Alignment */
2868 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
2869 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
2870 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
2871 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
2872 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */
2873 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
2874 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
2877 case '0': /* align to byte boundary */
2878 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
2881 case '1': /* align to halfword boundary */
2882 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
2885 case '2': /* align to word boundary */
2886 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
2889 case '3': /* align to doubleword boundary */
2890 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
2893 case '4': /* align to quadword boundary */
2894 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
2897 case '5': /* align to 32 byte boundary */
2898 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
2901 case '6': /* align to 64 byte boundary */
2902 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
2907 as_warn("unknown section attribute '%c'",
2908 *input_line_pointer
);
2911 ++input_line_pointer
;
2913 if (*input_line_pointer
== '"')
2914 ++input_line_pointer
;
2918 sec
= subseg_new (name
, (subsegT
) exp
);
2920 setCurrentSection(sec
);
2922 if (flags
!= SEC_NO_FLAGS
)
2924 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
2925 as_warn ("error setting flags for \"%s\": %s",
2926 bfd_section_name (stdoutput
, sec
),
2927 bfd_errmsg (bfd_get_error ()));
2931 /* FIXME: Make sure the winnt alignment bits get set */
2933 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
2934 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
2935 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
2936 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
2937 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default alignment if no others are specified. */
2938 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
2939 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
2942 bfd_set_section_alignment(stdoutput
, sec
, align
);
2947 ppc_pe_function (ignore
)
2956 name
= input_line_pointer
;
2957 endc
= get_symbol_end ();
2959 /* Ignore any [PR] suffix. */
2960 name
= ppc_canonicalize_symbol_name (name
);
2961 s
= strchr (name
, '[');
2962 if (s
!= (char *) NULL
2963 && strcmp (s
+ 1, "PR]") == 0)
2966 ext_sym
= symbol_find_or_make (name
);
2968 *input_line_pointer
= endc
;
2970 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
2971 SF_SET_FUNCTION (ext_sym
);
2972 SF_SET_PROCESS (ext_sym
);
2973 coff_add_linesym (ext_sym
);
2975 demand_empty_rest_of_line ();
2986 /* XCOFF specific symbol and file handling. */
2988 /* Canonicalize the symbol name. We use the to force the suffix, if
2989 any, to use square brackets, and to be in upper case. */
2992 ppc_canonicalize_symbol_name (name
)
2997 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
3011 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
3015 if (*s
== '\0' || s
[1] != '\0')
3016 as_bad ("bad symbol suffix");
3024 /* Set the class of a symbol based on the suffix, if any. This is
3025 called whenever a new symbol is created. */
3028 ppc_symbol_new_hook (sym
)
3033 sym
->sy_tc
.next
= NULL
;
3034 sym
->sy_tc
.output
= 0;
3035 sym
->sy_tc
.class = -1;
3036 sym
->sy_tc
.real_name
= NULL
;
3037 sym
->sy_tc
.subseg
= 0;
3038 sym
->sy_tc
.align
= 0;
3039 sym
->sy_tc
.size
= NULL
;
3040 sym
->sy_tc
.within
= NULL
;
3042 s
= strchr (S_GET_NAME (sym
), '[');
3043 if (s
== (const char *) NULL
)
3045 /* There is no suffix. */
3054 if (strcmp (s
, "BS]") == 0)
3055 sym
->sy_tc
.class = XMC_BS
;
3058 if (strcmp (s
, "DB]") == 0)
3059 sym
->sy_tc
.class = XMC_DB
;
3060 else if (strcmp (s
, "DS]") == 0)
3061 sym
->sy_tc
.class = XMC_DS
;
3064 if (strcmp (s
, "GL]") == 0)
3065 sym
->sy_tc
.class = XMC_GL
;
3068 if (strcmp (s
, "PR]") == 0)
3069 sym
->sy_tc
.class = XMC_PR
;
3072 if (strcmp (s
, "RO]") == 0)
3073 sym
->sy_tc
.class = XMC_RO
;
3074 else if (strcmp (s
, "RW]") == 0)
3075 sym
->sy_tc
.class = XMC_RW
;
3078 if (strcmp (s
, "SV]") == 0)
3079 sym
->sy_tc
.class = XMC_SV
;
3082 if (strcmp (s
, "TC]") == 0)
3083 sym
->sy_tc
.class = XMC_TC
;
3084 else if (strcmp (s
, "TI]") == 0)
3085 sym
->sy_tc
.class = XMC_TI
;
3086 else if (strcmp (s
, "TB]") == 0)
3087 sym
->sy_tc
.class = XMC_TB
;
3088 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
3089 sym
->sy_tc
.class = XMC_TC0
;
3092 if (strcmp (s
, "UA]") == 0)
3093 sym
->sy_tc
.class = XMC_UA
;
3094 else if (strcmp (s
, "UC]") == 0)
3095 sym
->sy_tc
.class = XMC_UC
;
3098 if (strcmp (s
, "XO]") == 0)
3099 sym
->sy_tc
.class = XMC_XO
;
3103 if (sym
->sy_tc
.class == -1)
3104 as_bad ("Unrecognized symbol suffix");
3107 /* Set the class of a label based on where it is defined. This
3108 handles symbols without suffixes. Also, move the symbol so that it
3109 follows the csect symbol. */
3112 ppc_frob_label (sym
)
3116 if (ppc_current_csect
!= (symbolS
*) NULL
)
3118 if (sym
->sy_tc
.class == -1)
3119 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
3121 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3122 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
3124 ppc_current_csect
->sy_tc
.within
= sym
;
3129 /* Change the name of a symbol just before writing it out. Set the
3130 real name if the .rename pseudo-op was used. Otherwise, remove any
3131 class suffix. Return 1 if the symbol should not be included in the
3135 ppc_frob_symbol (sym
)
3138 static symbolS
*ppc_last_function
;
3139 static symbolS
*set_end
;
3141 /* Discard symbols that should not be included in the output symbol
3143 if (! sym
->sy_used_in_reloc
3144 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
3145 || (! S_IS_EXTERNAL (sym
)
3146 && ! sym
->sy_tc
.output
3147 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
3150 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
3151 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
3157 name
= S_GET_NAME (sym
);
3158 s
= strchr (name
, '[');
3159 if (s
!= (char *) NULL
)
3165 snew
= xmalloc (len
+ 1);
3166 memcpy (snew
, name
, len
);
3169 S_SET_NAME (sym
, snew
);
3173 if (set_end
!= (symbolS
*) NULL
)
3175 SA_SET_SYM_ENDNDX (set_end
, sym
);
3179 if (SF_GET_FUNCTION (sym
))
3181 if (ppc_last_function
!= (symbolS
*) NULL
)
3182 as_warn ("two .function pseudo-ops with no intervening .ef");
3183 ppc_last_function
= sym
;
3184 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
3186 resolve_symbol_value (sym
->sy_tc
.size
);
3187 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
3190 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
3191 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
3193 if (ppc_last_function
== (symbolS
*) NULL
)
3194 as_warn (".ef with no preceding .function");
3197 set_end
= ppc_last_function
;
3198 ppc_last_function
= NULL
;
3200 /* We don't have a C_EFCN symbol, but we need to force the
3201 COFF backend to believe that it has seen one. */
3202 coff_last_function
= NULL
;
3207 if (! S_IS_EXTERNAL (sym
)
3208 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
3209 && S_GET_STORAGE_CLASS (sym
) != C_FILE
3210 && S_GET_STORAGE_CLASS (sym
) != C_FCN
3211 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
3212 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
3213 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
3214 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
3217 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
3218 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
3221 union internal_auxent
*a
;
3223 /* Create a csect aux. */
3224 i
= S_GET_NUMBER_AUXILIARY (sym
);
3225 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
3226 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
3227 if (sym
->sy_tc
.class == XMC_TC0
)
3229 /* This is the TOC table. */
3230 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
3231 a
->x_csect
.x_scnlen
.l
= 0;
3232 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3234 else if (sym
->sy_tc
.subseg
!= 0)
3236 /* This is a csect symbol. x_scnlen is the size of the
3238 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
3239 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3240 S_GET_SEGMENT (sym
))
3241 - S_GET_VALUE (sym
));
3244 resolve_symbol_value (sym
->sy_tc
.next
);
3245 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
3246 - S_GET_VALUE (sym
));
3248 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
3250 else if (S_GET_SEGMENT (sym
) == bss_section
)
3252 /* This is a common symbol. */
3253 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
3254 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
3255 if (S_IS_EXTERNAL (sym
))
3256 sym
->sy_tc
.class = XMC_RW
;
3258 sym
->sy_tc
.class = XMC_BS
;
3260 else if (! S_IS_DEFINED (sym
))
3262 /* This is an external symbol. */
3263 a
->x_csect
.x_scnlen
.l
= 0;
3264 a
->x_csect
.x_smtyp
= XTY_ER
;
3266 else if (sym
->sy_tc
.class == XMC_TC
)
3270 /* This is a TOC definition. x_scnlen is the size of the
3272 next
= symbol_next (sym
);
3273 while (next
->sy_tc
.class == XMC_TC0
)
3274 next
= symbol_next (next
);
3275 if (next
== (symbolS
*) NULL
3276 || next
->sy_tc
.class != XMC_TC
)
3278 if (ppc_after_toc_frag
== (fragS
*) NULL
)
3279 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3281 - S_GET_VALUE (sym
));
3283 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
3284 - S_GET_VALUE (sym
));
3288 resolve_symbol_value (next
);
3289 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
3290 - S_GET_VALUE (sym
));
3292 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
3296 else if (S_GET_SEGMENT (sym
) == pdata_section
)
3298 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3299 S_GET_SEGMENT (sym
))
3300 - S_GET_VALUE (sym
));
3302 else if (S_GET_SEGMENT (sym
) == rdata_section
)
3304 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3305 S_GET_SEGMENT (sym
))
3306 - S_GET_VALUE (sym
));
3308 else if (S_GET_SEGMENT (sym
) == reldata_section
)
3310 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
3311 S_GET_SEGMENT (sym
))
3312 - S_GET_VALUE (sym
));
3320 /* This is a normal symbol definition. x_scnlen is the
3321 symbol index of the containing csect. */
3322 if (S_GET_SEGMENT (sym
) == text_section
)
3323 csect
= ppc_text_csects
;
3324 else if (S_GET_SEGMENT (sym
) == data_section
)
3325 csect
= ppc_data_csects
;
3329 /* Skip the initial dummy symbol. */
3330 csect
= csect
->sy_tc
.next
;
3332 if (csect
== (symbolS
*) NULL
)
3333 a
->x_csect
.x_scnlen
.l
= 0;
3336 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
3338 resolve_symbol_value (csect
->sy_tc
.next
);
3339 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
3341 csect
= csect
->sy_tc
.next
;
3344 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
3345 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
3347 a
->x_csect
.x_smtyp
= XTY_LD
;
3351 a
->x_csect
.x_parmhash
= 0;
3352 a
->x_csect
.x_snhash
= 0;
3353 if (sym
->sy_tc
.class == -1)
3354 a
->x_csect
.x_smclas
= XMC_PR
;
3356 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
3357 a
->x_csect
.x_stab
= 0;
3358 a
->x_csect
.x_snstab
= 0;
3360 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
3362 /* We want the value to be the symbol index of the referenced
3363 csect symbol. BFD will do that for us if we set the right
3366 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
3367 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
3369 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
3374 /* The value is the offset from the enclosing csect. */
3375 block
= sym
->sy_tc
.within
;
3376 csect
= block
->sy_tc
.within
;
3377 resolve_symbol_value (csect
);
3378 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
3384 /* Set the VMA for a section. This is called on all the sections in
3388 ppc_frob_section (sec
)
3392 static bfd_size_type vma
= 0;
3394 bfd_set_section_vma (stdoutput
, sec
, vma
);
3395 vma
+= bfd_section_size (stdoutput
, sec
);
3399 /* Adjust the file by adding a .debug section if needed. */
3404 if (ppc_debug_name_section_size
> 0)
3408 sec
= bfd_make_section (stdoutput
, ".debug");
3409 if (sec
== (asection
*) NULL
3410 || ! bfd_set_section_size (stdoutput
, sec
,
3411 ppc_debug_name_section_size
)
3412 || ! bfd_set_section_flags (stdoutput
, sec
,
3413 SEC_HAS_CONTENTS
| SEC_LOAD
))
3414 as_fatal ("can't make .debug section");
3418 #endif /* OBJ_COFF */
3420 /* Turn a string in input_line_pointer into a floating point constant
3421 of type type, and store the appropriate bytes in *litp. The number
3422 of LITTLENUMS emitted is stored in *sizep . An error message is
3423 returned, or NULL on OK. */
3426 md_atof (type
, litp
, sizep
)
3432 LITTLENUM_TYPE words
[4];
3448 return "bad call to md_atof";
3451 t
= atof_ieee (input_line_pointer
, type
, words
);
3453 input_line_pointer
= t
;
3457 if (target_big_endian
)
3459 for (i
= 0; i
< prec
; i
++)
3461 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3467 for (i
= prec
- 1; i
>= 0; i
--)
3469 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
3477 /* Write a value out to the object file, using the appropriate
3481 md_number_to_chars (buf
, val
, n
)
3486 if (target_big_endian
)
3487 number_to_chars_bigendian (buf
, val
, n
);
3489 number_to_chars_littleendian (buf
, val
, n
);
3492 /* Align a section (I don't know why this is machine dependent). */
3495 md_section_align (seg
, addr
)
3499 int align
= bfd_get_section_alignment (stdoutput
, seg
);
3501 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
3504 /* We don't have any form of relaxing. */
3507 md_estimate_size_before_relax (fragp
, seg
)
3514 /* Convert a machine dependent frag. We never generate these. */
3517 md_convert_frag (abfd
, sec
, fragp
)
3525 /* We have no need to default values of symbols. */
3529 md_undefined_symbol (name
)
3535 /* Functions concerning relocs. */
3537 /* The location from which a PC relative jump should be calculated,
3538 given a PC relative reloc. */
3541 md_pcrel_from (fixp
)
3545 if (fixp
->fx_addsy
!= (symbolS
*) NULL
3546 && (! S_IS_DEFINED (fixp
->fx_addsy
)
3547 || TC_FORCE_RELOCATION (fixp
)))
3551 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3556 /* This is called to see whether a fixup should be adjusted to use a
3557 section symbol. We take the opportunity to change a fixup against
3558 a symbol in the TOC subsegment into a reloc against the
3559 corresponding .tc symbol. */
3562 ppc_fix_adjustable (fix
)
3568 /* FIXME: Certainly the toc stuff gets us into trouble, and should
3569 not be executed. Not sure about the reloc adjustments. */
3573 resolve_symbol_value (fix
->fx_addsy
);
3574 val
= S_GET_VALUE (fix
->fx_addsy
);
3575 if (ppc_toc_csect
!= (symbolS
*) NULL
3576 && fix
->fx_addsy
!= (symbolS
*) NULL
3577 && fix
->fx_addsy
!= ppc_toc_csect
3578 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
3579 && val
>= ppc_toc_frag
->fr_address
3580 && (ppc_after_toc_frag
== (fragS
*) NULL
3581 || val
< ppc_after_toc_frag
->fr_address
))
3585 for (sy
= symbol_next (ppc_toc_csect
);
3586 sy
!= (symbolS
*) NULL
;
3587 sy
= symbol_next (sy
))
3589 if (sy
->sy_tc
.class == XMC_TC0
)
3591 if (sy
->sy_tc
.class != XMC_TC
)
3593 resolve_symbol_value (sy
);
3594 if (val
== S_GET_VALUE (sy
))
3597 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
3602 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3603 "symbol in .toc does not match any .tc");
3606 /* Possibly adjust the reloc to be against the csect. */
3607 if (fix
->fx_addsy
!= (symbolS
*) NULL
3608 && fix
->fx_addsy
->sy_tc
.subseg
== 0
3609 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
3610 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
3611 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
3615 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
3616 csect
= ppc_text_csects
;
3617 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
3618 csect
= ppc_data_csects
;
3622 /* Skip the initial dummy symbol. */
3623 csect
= csect
->sy_tc
.next
;
3625 if (csect
!= (symbolS
*) NULL
)
3627 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
3628 && (csect
->sy_tc
.next
->sy_frag
->fr_address
3629 <= fix
->fx_addsy
->sy_frag
->fr_address
))
3630 csect
= csect
->sy_tc
.next
;
3632 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3633 - csect
->sy_frag
->fr_address
);
3634 fix
->fx_addsy
= csect
;
3638 /* Adjust a reloc against a .lcomm symbol to be against the base
3640 if (fix
->fx_addsy
!= (symbolS
*) NULL
3641 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
3642 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
3644 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
3645 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
3646 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
3647 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
3655 /* See whether a symbol is in the TOC section. */
3658 ppc_is_toc_sym (sym
)
3662 return sym
->sy_tc
.class == XMC_TC
;
3664 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
3668 /* Apply a fixup to the object code. This is called for all the
3669 fixups we generated by the call to fix_new_exp, above. In the call
3670 above we used a reloc code which was the largest legal reloc code
3671 plus the operand index. Here we undo that to recover the operand
3672 index. At this point all symbol values should be fully resolved,
3673 and we attempt to completely resolve the reloc. If we can not do
3674 that, we determine the correct reloc code and put it back in the
3678 md_apply_fix3 (fixp
, valuep
, seg
)
3685 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
3686 the symbol values. Since we are using BFD_ASSEMBLER, if we are
3687 doing this relocation the code in write.c is going to call
3688 bfd_perform_relocation, which is also going to use the symbol
3689 value. That means that if the reloc is fully resolved we want to
3690 use *valuep since bfd_perform_relocation is not being used.
3691 However, if the reloc is not fully resolved we do not want to use
3692 *valuep, and must use fx_offset instead. However, if the reloc
3693 is PC relative, we do want to use *valuep since it includes the
3694 result of md_pcrel_from. This is confusing. */
3696 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
3701 else if (fixp
->fx_pcrel
)
3705 value
= fixp
->fx_offset
;
3706 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
3708 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
3709 value
-= S_GET_VALUE (fixp
->fx_subsy
);
3712 /* We can't actually support subtracting a symbol. */
3713 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3714 "expression too complex");
3719 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
3722 const struct powerpc_operand
*operand
;
3726 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
3728 operand
= &powerpc_operands
[opindex
];
3731 /* It appears that an instruction like
3733 when LC..1 is not a TOC symbol does not generate a reloc. It
3734 uses the offset of LC..1 within its csect. However, .long
3735 LC..1 will generate a reloc. I can't find any documentation
3736 on how these cases are to be distinguished, so this is a wild
3737 guess. These cases are generated by gcc -mminimal-toc. */
3738 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
3739 && operand
->bits
== 16
3740 && operand
->shift
== 0
3741 && operand
->insert
== NULL
3742 && fixp
->fx_addsy
!= NULL
3743 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
3744 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
3745 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
3746 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
3748 value
= fixp
->fx_offset
;
3753 /* Fetch the instruction, insert the fully resolved operand
3754 value, and stuff the instruction back again. */
3755 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
3756 if (target_big_endian
)
3757 insn
= bfd_getb32 ((unsigned char *) where
);
3759 insn
= bfd_getl32 ((unsigned char *) where
);
3760 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
3761 fixp
->fx_file
, fixp
->fx_line
);
3762 if (target_big_endian
)
3763 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
3765 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
3769 /* Nothing else to do here. */
3773 /* Determine a BFD reloc value based on the operand information.
3774 We are only prepared to turn a few of the operands into
3776 FIXME: We need to handle the DS field at the very least.
3777 FIXME: Selecting the reloc type is a bit haphazard; perhaps
3778 there should be a new field in the operand table. */
3779 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3780 && operand
->bits
== 26
3781 && operand
->shift
== 0)
3782 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
3783 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3784 && operand
->bits
== 16
3785 && operand
->shift
== 0)
3786 fixp
->fx_r_type
= BFD_RELOC_PPC_B16
;
3787 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3788 && operand
->bits
== 26
3789 && operand
->shift
== 0)
3790 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
3791 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3792 && operand
->bits
== 16
3793 && operand
->shift
== 0)
3794 fixp
->fx_r_type
= BFD_RELOC_PPC_BA16
;
3795 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
3796 && operand
->bits
== 16
3797 && operand
->shift
== 0
3798 && operand
->insert
== NULL
3799 && fixp
->fx_addsy
!= NULL
3800 && ppc_is_toc_sym (fixp
->fx_addsy
))
3803 if (target_big_endian
)
3804 fixp
->fx_where
+= 2;
3805 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
3809 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3810 "unresolved expression that must be resolved");
3818 ppc_elf_validate_fix (fixp
, seg
);
3820 switch (fixp
->fx_r_type
)
3823 case BFD_RELOC_CTOR
:
3826 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
3827 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3828 } /* fall through */
3830 case BFD_RELOC_32_PCREL
:
3831 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
3835 case BFD_RELOC_LO16
:
3836 case BFD_RELOC_HI16
:
3837 case BFD_RELOC_HI16_S
:
3838 case BFD_RELOC_PPC_TOC16
:
3840 case BFD_RELOC_GPREL16
:
3844 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
3852 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
3862 fixp
->fx_addnumber
= value
;
3864 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
3865 fixp
->fx_addnumber
= 0;
3869 fixp
->fx_addnumber
= 0;
3871 /* We want to use the offset within the data segment of the
3872 symbol, not the actual VMA of the symbol. */
3873 fixp
->fx_addnumber
=
3874 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
3882 /* Generate a reloc for a fixup. */
3885 tc_gen_reloc (seg
, fixp
)
3891 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
3893 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
3894 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3895 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
3896 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
3898 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3899 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
3902 reloc
->addend
= fixp
->fx_addnumber
;