1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "opcode/ppc.h"
36 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
38 /* Tell the main code what the endianness is. */
39 extern int target_big_endian;
41 /* Whether or not, we've set target_big_endian. */
42 static int set_target_endian = 0;
44 static void ppc_set_cpu PARAMS ((void));
45 static unsigned long ppc_insert_operand
46 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
47 offsetT val, char *file, unsigned int line));
48 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
49 static void ppc_byte PARAMS ((int));
50 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
51 static void ppc_tc PARAMS ((int));
54 static void ppc_comm PARAMS ((int));
55 static void ppc_bb PARAMS ((int));
56 static void ppc_bf PARAMS ((int));
57 static void ppc_biei PARAMS ((int));
58 static void ppc_bs PARAMS ((int));
59 static void ppc_eb PARAMS ((int));
60 static void ppc_ef PARAMS ((int));
61 static void ppc_es PARAMS ((int));
62 static void ppc_csect PARAMS ((int));
63 static void ppc_change_csect PARAMS ((symbolS *));
64 static void ppc_function PARAMS ((int));
65 static void ppc_extern PARAMS ((int));
66 static void ppc_lglobl PARAMS ((int));
67 static void ppc_section PARAMS ((int));
68 static void ppc_stabx PARAMS ((int));
69 static void ppc_rename PARAMS ((int));
70 static void ppc_toc PARAMS ((int));
74 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **));
75 static void ppc_elf_cons PARAMS ((int));
76 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
80 static void ppc_set_current_section PARAMS ((segT));
81 static void ppc_previous PARAMS ((int));
82 static void ppc_pdata PARAMS ((int));
83 static void ppc_ydata PARAMS ((int));
84 static void ppc_reldata PARAMS ((int));
85 static void ppc_rdata PARAMS ((int));
86 static void ppc_ualong PARAMS ((int));
87 static void ppc_znop PARAMS ((int));
88 static void ppc_pe_comm PARAMS ((int));
89 static void ppc_pe_section PARAMS ((int));
90 static void ppc_pe_function PARAMS ((int));
91 static void ppc_pe_tocd PARAMS ((int));
94 /* Generic assembler global variables which must be defined by all
97 /* Characters which always start a comment. */
98 const char comment_chars[] = "#";
100 /* Characters which start a comment at the beginning of a line. */
101 const char line_comment_chars[] = "#";
103 /* Characters which may be used to separate multiple commands on a
105 const char line_separator_chars[] = ";";
107 /* Characters which are used to indicate an exponent in a floating
109 const char EXP_CHARS[] = "eE";
111 /* Characters which mean that a number is a floating point constant,
113 const char FLT_CHARS[] = "dD";
115 /* The target specific pseudo-ops which we support. */
117 const pseudo_typeS md_pseudo_table[] =
119 /* Pseudo-ops which must be overridden. */
120 { "byte", ppc_byte, 0 },
123 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
124 legitimately belong in the obj-*.c file. However, XCOFF is based
125 on COFF, and is only implemented for the RS/6000. We just use
126 obj-coff.c, and add what we need here. */
127 { "comm", ppc_comm, 0 },
128 { "lcomm", ppc_comm, 1 },
131 { "bi", ppc_biei, 0 },
133 { "csect", ppc_csect, 0 },
134 { "data", ppc_section, 'd' },
137 { "ei", ppc_biei, 1 },
139 { "extern", ppc_extern, 0 },
140 { "function", ppc_function, 0 },
141 { "lglobl", ppc_lglobl, 0 },
142 { "rename", ppc_rename, 0 },
143 { "stabx", ppc_stabx, 0 },
144 { "text", ppc_section, 't' },
145 { "toc", ppc_toc, 0 },
149 { "long", ppc_elf_cons, 4 },
150 { "word", ppc_elf_cons, 2 },
151 { "short", ppc_elf_cons, 2 },
155 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
156 { "previous", ppc_previous, 0 },
157 { "pdata", ppc_pdata, 0 },
158 { "ydata", ppc_ydata, 0 },
159 { "reldata", ppc_reldata, 0 },
160 { "rdata", ppc_rdata, 0 },
161 { "ualong", ppc_ualong, 0 },
162 { "znop", ppc_znop, 0 },
163 { "comm", ppc_pe_comm, 0 },
164 { "lcomm", ppc_pe_comm, 1 },
165 { "section", ppc_pe_section, 0 },
166 { "function", ppc_pe_function,0 },
167 { "tocd", ppc_pe_tocd, 0 },
170 /* This pseudo-op is used even when not generating XCOFF output. */
178 /* The Windows NT PowerPC assembler uses predefined names. */
180 /* In general, there are lots of them, in an attempt to be compatible */
181 /* with a number of other Windows NT assemblers. */
183 /* Structure to hold information about predefined registers. */
190 /* List of registers that are pre-defined:
192 Each general register has predefined names of the form:
193 1. r<reg_num> which has the value <reg_num>.
194 2. r.<reg_num> which has the value <reg_num>.
197 Each floating point register has predefined names of the form:
198 1. f<reg_num> which has the value <reg_num>.
199 2. f.<reg_num> which has the value <reg_num>.
201 Each condition register has predefined names of the form:
202 1. cr<reg_num> which has the value <reg_num>.
203 2. cr.<reg_num> which has the value <reg_num>.
205 There are individual registers as well:
206 sp or r.sp has the value 1
207 rtoc or r.toc has the value 2
208 fpscr has the value 0
214 dsisr has the value 18
216 sdr1 has the value 25
217 srr0 has the value 26
218 srr1 has the value 27
220 The table is sorted. Suitable for searching by a binary search. */
222 static const struct pd_reg pre_defined_registers[] =
224 { "cr.0", 0 }, /* Condition Registers */
244 { "dar", 19 }, /* Data Access Register */
245 { "dec", 22 }, /* Decrementer */
246 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
248 { "f.0", 0 }, /* Floating point registers */
316 { "lr", 8 }, /* Link Register */
320 { "r.0", 0 }, /* General Purpose Registers */
353 { "r.sp", 1 }, /* Stack Pointer */
355 { "r.toc", 2 }, /* Pointer to the table of contents */
357 { "r0", 0 }, /* More general purpose registers */
390 { "rtoc", 2 }, /* Table of contents */
392 { "sdr1", 25 }, /* Storage Description Register 1 */
396 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
397 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
403 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
405 /* Given NAME, find the register number associated with that name, return
406 the integer value associated with the given name or -1 on failure. */
408 static int reg_name_search PARAMS ( (char * name) );
411 reg_name_search (name)
414 int middle, low, high;
418 high = REG_NAME_CNT - 1;
422 middle = (low + high) / 2;
423 cmp = strcasecmp (name, pre_defined_registers[middle].name);
429 return pre_defined_registers[middle].value;
439 /* Local variables. */
441 /* The type of processor we are assembling for. This is one or more
442 of the PPC_OPCODE flags defined in opcode/ppc.h. */
443 static int ppc_cpu = 0;
445 /* The size of the processor we are assembling for. This is either
446 PPC_OPCODE_32 or PPC_OPCODE_64. */
447 static int ppc_size = PPC_OPCODE_32;
449 /* Opcode hash table. */
450 static struct hash_control *ppc_hash;
452 /* Macro hash table. */
453 static struct hash_control *ppc_macro_hash;
456 /* Whether to warn about non PC relative relocations that aren't
457 in the .got2 section. */
458 static boolean mrelocatable = false;
460 /* Flags to set in the elf header */
461 static flagword ppc_flags = 0;
466 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
467 using a bunch of different sections. These assembler sections,
468 however, are all encompassed within the .text or .data sections of
469 the final output file. We handle this by using different
470 subsegments within these main segments. */
472 /* Next subsegment to allocate within the .text segment. */
473 static subsegT ppc_text_subsegment = 2;
475 /* Linked list of csects in the text section. */
476 static symbolS *ppc_text_csects;
478 /* Next subsegment to allocate within the .data segment. */
479 static subsegT ppc_data_subsegment = 2;
481 /* Linked list of csects in the data section. */
482 static symbolS *ppc_data_csects;
484 /* The current csect. */
485 static symbolS *ppc_current_csect;
487 /* The RS/6000 assembler uses a TOC which holds addresses of functions
488 and variables. Symbols are put in the TOC with the .tc pseudo-op.
489 A special relocation is used when accessing TOC entries. We handle
490 the TOC as a subsegment within the .data segment. We set it up if
491 we see a .toc pseudo-op, and save the csect symbol here. */
492 static symbolS *ppc_toc_csect;
494 /* The first frag in the TOC subsegment. */
495 static fragS *ppc_toc_frag;
497 /* The first frag in the first subsegment after the TOC in the .data
498 segment. NULL if there are no subsegments after the TOC. */
499 static fragS *ppc_after_toc_frag;
501 /* The current static block. */
502 static symbolS *ppc_current_block;
504 /* The COFF debugging section; set by md_begin. This is not the
505 .debug section, but is instead the secret BFD section which will
506 cause BFD to set the section number of a symbol to N_DEBUG. */
507 static asection *ppc_coff_debug_section;
509 /* The size of the .debug section. */
510 static bfd_size_type ppc_debug_name_section_size;
512 #endif /* OBJ_XCOFF */
516 /* Various sections that we need for PE coff support. */
517 static segT ydata_section;
518 static segT pdata_section;
519 static segT reldata_section;
520 static segT rdata_section;
521 static segT tocdata_section;
523 /* The current section and the previous section. See ppc_previous. */
524 static segT ppc_previous_section;
525 static segT ppc_current_section;
530 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
533 #ifndef WORKING_DOT_WORD
534 const int md_short_jump_size = 4;
535 const int md_long_jump_size = 4;
539 CONST char *md_shortopts = "um:VQ:";
541 CONST char *md_shortopts = "um:";
543 struct option md_longopts[] = {
544 {NULL, no_argument, NULL, 0}
546 size_t md_longopts_size = sizeof(md_longopts);
549 md_parse_option (c, arg)
556 /* -u means that any undefined symbols should be treated as
557 external, which is the default for gas anyhow. */
561 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
563 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
564 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
565 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
566 else if (strcmp (arg, "pwr") == 0)
567 ppc_cpu = PPC_OPCODE_POWER;
568 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
569 instructions that are holdovers from the Power. */
570 else if (strcmp (arg, "601") == 0)
571 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
572 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
573 Motorola PowerPC 603/604. */
574 else if (strcmp (arg, "ppc") == 0
575 || strcmp (arg, "ppc32") == 0
576 || strcmp (arg, "403") == 0
577 || strcmp (arg, "603") == 0
578 || strcmp (arg, "604") == 0)
579 ppc_cpu = PPC_OPCODE_PPC;
580 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
582 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
584 ppc_cpu = PPC_OPCODE_PPC;
585 ppc_size = PPC_OPCODE_64;
587 /* -mcom means assemble for the common intersection between Power
588 and PowerPC. At present, we just allow the union, rather
589 than the intersection. */
590 else if (strcmp (arg, "com") == 0)
591 ppc_cpu = PPC_OPCODE_COMMON;
592 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
593 else if (strcmp (arg, "any") == 0)
594 ppc_cpu = PPC_OPCODE_ANY;
597 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
598 else if (strcmp (arg, "relocatable") == 0)
601 ppc_flags |= EF_PPC_RELOCATABLE;
604 else if (strcmp (arg, "relocatable-lib") == 0)
607 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
610 /* -memb, set embedded bit */
611 else if (strcmp (arg, "emb") == 0)
612 ppc_flags |= EF_PPC_EMB;
614 /* -mlittle/-mbig set the endianess */
615 else if (strcmp (arg, "little") == 0 || strcmp (arg, "little-endian") == 0)
617 target_big_endian = 0;
618 set_target_endian = 1;
621 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
623 target_big_endian = 1;
624 set_target_endian = 1;
629 as_bad ("invalid switch -m%s", arg);
635 /* -V: SVR4 argument to print version ID. */
640 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
641 should be emitted or not. FIXME: Not implemented. */
654 md_show_usage (stream)
660 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
661 -mpwr generate code for IBM POWER (RIOS1)\n\
662 -m601 generate code for Motorola PowerPC 601\n\
663 -mppc, -mppc32, -m403, -m603, -m604\n\
664 generate code for Motorola PowerPC 603/604\n\
665 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
666 -mcom generate code Power/PowerPC common instructions\n
667 -many generate code for any architecture (PWR/PWRX/PPC)\n");
670 -mrelocatable support for GCC's -mrelocatble option\n\
671 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
672 -memb set PPC_EMB bit in ELF flags\n\
673 -mlittle, -mlittle-endian\n\
674 generate code for a little endian machine\n\
675 -mbig, -mbig-endian generate code for a big endian machine\n\
676 -V print assembler version number\n\
677 -Qy, -Qn ignored\n");
681 /* Set ppc_cpu if it is not already set. */
686 const char *default_cpu = TARGET_CPU;
690 if (strcmp (default_cpu, "rs6000") == 0)
691 ppc_cpu = PPC_OPCODE_POWER;
692 else if (strcmp (default_cpu, "powerpc") == 0
693 || strcmp (default_cpu, "powerpcle") == 0)
694 ppc_cpu = PPC_OPCODE_PPC;
696 as_fatal ("Unknown default cpu = %s", default_cpu);
700 /* Figure out the BFD architecture to use. */
702 enum bfd_architecture
705 const char *default_cpu = TARGET_CPU;
708 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
709 return bfd_arch_powerpc;
710 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
711 return bfd_arch_rs6000;
712 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
714 if (strcmp (default_cpu, "rs6000") == 0)
715 return bfd_arch_rs6000;
716 else if (strcmp (default_cpu, "powerpc") == 0
717 || strcmp (default_cpu, "powerpcle") == 0)
718 return bfd_arch_powerpc;
721 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
722 return bfd_arch_unknown;
725 /* This function is called when the assembler starts up. It is called
726 after the options have been parsed and the output file has been
732 register const struct powerpc_opcode *op;
733 const struct powerpc_opcode *op_end;
734 const struct powerpc_macro *macro;
735 const struct powerpc_macro *macro_end;
736 boolean dup_insn = false;
741 /* Set the ELF flags if desired. */
743 bfd_set_private_flags (stdoutput, ppc_flags);
746 /* Insert the opcodes into a hash table. */
747 ppc_hash = hash_new ();
749 op_end = powerpc_opcodes + powerpc_num_opcodes;
750 for (op = powerpc_opcodes; op < op_end; op++)
752 know ((op->opcode & op->mask) == op->opcode);
754 if ((op->flags & ppc_cpu) != 0
755 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
756 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size))
760 retval = hash_insert (ppc_hash, op->name, (PTR) op);
761 if (retval != (const char *) NULL)
763 /* Ignore Power duplicates for -m601 */
764 if ((ppc_cpu & PPC_OPCODE_601) != 0
765 && (op->flags & PPC_OPCODE_POWER) != 0)
768 as_bad ("Internal assembler error for instruction %s", op->name);
774 /* Insert the macros into a hash table. */
775 ppc_macro_hash = hash_new ();
777 macro_end = powerpc_macros + powerpc_num_macros;
778 for (macro = powerpc_macros; macro < macro_end; macro++)
780 if ((macro->flags & ppc_cpu) != 0)
784 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
785 if (retval != (const char *) NULL)
787 as_bad ("Internal assembler error for macro %s", macro->name);
796 /* Tell the main code what the endianness is if it is not overidden by the user. */
797 if (!set_target_endian)
799 set_target_endian = 1;
800 target_big_endian = PPC_BIG_ENDIAN;
804 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
806 /* Create dummy symbols to serve as initial csects. This forces the
807 text csects to precede the data csects. These symbols will not
809 ppc_text_csects = symbol_make ("dummy\001");
810 ppc_text_csects->sy_tc.within = ppc_text_csects;
811 ppc_data_csects = symbol_make ("dummy\001");
812 ppc_data_csects->sy_tc.within = ppc_data_csects;
817 ppc_current_section = text_section;
818 ppc_previous_section = 0;
823 /* Insert an operand value into an instruction. */
826 ppc_insert_operand (insn, operand, val, file, line)
828 const struct powerpc_operand *operand;
833 if (operand->bits != 32)
838 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
840 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0
841 && ppc_size == PPC_OPCODE_32)
842 max = (1 << operand->bits) - 1;
844 max = (1 << (operand->bits - 1)) - 1;
845 min = - (1 << (operand->bits - 1));
849 max = (1 << operand->bits) - 1;
853 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
858 if (test < (offsetT) min || test > (offsetT) max)
861 "operand out of range (%s not between %ld and %ld)";
864 sprint_value (buf, test);
865 if (file == (char *) NULL)
866 as_warn (err, buf, min, max);
868 as_warn_where (file, line, err, buf, min, max);
877 insn = (*operand->insert) (insn, (long) val, &errmsg);
878 if (errmsg != (const char *) NULL)
882 insn |= (((long) val & ((1 << operand->bits) - 1))
889 /* Parse @got, etc. and return the desired relocation. */
890 static bfd_reloc_code_real_type
891 ppc_elf_suffix (str_p)
897 bfd_reloc_code_real_type reloc;
907 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
909 static struct map_bfd mapping[] = {
910 MAP ("got", BFD_RELOC_PPC_TOC16),
911 MAP ("l", BFD_RELOC_LO16),
912 MAP ("h", BFD_RELOC_HI16),
913 MAP ("ha", BFD_RELOC_HI16_S),
914 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
915 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
916 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
917 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
918 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
919 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
920 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
921 MAP ("copy", BFD_RELOC_PPC_COPY),
922 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
923 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
924 MAP ("plt", BFD_RELOC_32_PLTOFF),
925 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
926 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
927 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
928 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
929 MAP ("sdarel", BFD_RELOC_GPREL16),
930 MAP ("sectoff", BFD_RELOC_32_BASEREL),
931 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
932 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
933 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
935 { (char *)0, 0, BFD_RELOC_UNUSED }
939 return BFD_RELOC_UNUSED;
941 for (ch = *str, str2 = ident;
942 str2 < ident + sizeof(ident) - 1 && isalnum (ch) || ch == '@';
945 *str2++ = (islower (ch)) ? ch : tolower (ch);
952 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
953 if (ch == ptr->string[0] && len == ptr->length && memcmp (ident, ptr->string, ptr->length) == 0)
959 return BFD_RELOC_UNUSED;
962 /* Like normal .long/.short/.word, except support @got, etc. */
963 /* clobbers input_line_pointer, checks */
966 ppc_elf_cons (nbytes)
967 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
970 bfd_reloc_code_real_type reloc;
972 if (is_it_end_of_statement ())
974 demand_empty_rest_of_line ();
981 if (exp.X_op == O_symbol
982 && *input_line_pointer == '@'
983 && (reloc = ppc_elf_suffix (&input_line_pointer)) != BFD_RELOC_UNUSED)
985 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
986 int size = bfd_get_reloc_size (reloc_howto);
989 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto->name, nbytes);
993 register char *p = frag_more ((int) nbytes);
994 int offset = nbytes - size;
996 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
1000 emit_expr (&exp, (unsigned int) nbytes);
1002 while (*input_line_pointer++ == ',');
1004 input_line_pointer--; /* Put terminator back into stream. */
1005 demand_empty_rest_of_line ();
1008 /* Validate any relocations emitted for -mrelocatable, possibly adding
1009 fixups for word relocations in writable segments, so we can adjust
1012 ppc_elf_validate_fix (fixp, seg)
1019 && fixp->fx_r_type <= BFD_RELOC_UNUSED
1020 && strcmp (segment_name (seg), ".got2") != 0
1021 && strcmp (segment_name (seg), ".dtors") != 0
1022 && strcmp (segment_name (seg), ".ctors") != 0
1023 && strcmp (segment_name (seg), ".fixup") != 0
1024 && strcmp (segment_name (seg), ".stab") != 0)
1026 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1027 || fixp->fx_r_type != BFD_RELOC_CTOR)
1029 as_warn_where (fixp->fx_file, fixp->fx_line,
1030 "Relocation cannot be done when using -mrelocatable");
1035 #endif /* OBJ_ELF */
1039 * Summary of register_name().
1041 * in: Input_line_pointer points to 1st char of operand.
1043 * out: A expressionS.
1044 * The operand may have been a register: in this case, X_op == O_register,
1045 * X_add_number is set to the register number, and truth is returned.
1046 * Input_line_pointer->(next non-blank) char after operand, or is in its
1051 register_name (expressionP)
1052 expressionS *expressionP;
1058 /* Find the spelling of the operand */
1059 name = input_line_pointer;
1060 c = get_symbol_end ();
1061 reg_number = reg_name_search (name);
1063 /* look to see if it's in the register table */
1064 if (reg_number >= 0)
1066 expressionP->X_op = O_register;
1067 expressionP->X_add_number = reg_number;
1069 /* make the rest nice */
1070 expressionP->X_add_symbol = NULL;
1071 expressionP->X_op_symbol = NULL;
1072 *input_line_pointer = c; /* put back the delimiting char */
1077 /* reset the line as if we had not done anything */
1078 *input_line_pointer = c; /* put back the delimiting char */
1079 input_line_pointer = name; /* reset input_line pointer */
1085 * Summary of parse_toc_entry().
1087 * in: Input_line_pointer points to the '[' in one of:
1089 * [toc] [tocv] [toc32] [toc64]
1091 * Anything else is an error of one kind or another.
1094 * return value: success or failure
1095 * toc_kind: kind of toc reference
1096 * input_line_pointer:
1097 * success: first char after the ']'
1098 * failure: unchanged
1102 * [toc] - rv == success, toc_kind = default_toc
1103 * [tocv] - rv == success, toc_kind = data_in_toc
1104 * [toc32] - rv == success, toc_kind = must_be_32
1105 * [toc64] - rv == success, toc_kind = must_be_64
1109 enum toc_size_qualifier
1111 default_toc, /* The toc cell constructed should be the system default size */
1112 data_in_toc, /* This is a direct reference to a toc cell */
1113 must_be_32, /* The toc cell constructed must be 32 bits wide */
1114 must_be_64 /* The toc cell constructed must be 64 bits wide */
1118 parse_toc_entry(toc_kind)
1119 enum toc_size_qualifier *toc_kind;
1124 enum toc_size_qualifier t;
1126 /* save the input_line_pointer */
1127 start = input_line_pointer;
1129 /* skip over the '[' , and whitespace */
1130 ++input_line_pointer;
1133 /* find the spelling of the operand */
1134 toc_spec = input_line_pointer;
1135 c = get_symbol_end ();
1137 if (strcmp(toc_spec, "toc") == 0)
1141 else if (strcmp(toc_spec, "tocv") == 0)
1145 else if (strcmp(toc_spec, "toc32") == 0)
1149 else if (strcmp(toc_spec, "toc64") == 0)
1155 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec);
1156 *input_line_pointer = c; /* put back the delimiting char */
1157 input_line_pointer = start; /* reset input_line pointer */
1161 /* now find the ']' */
1162 *input_line_pointer = c; /* put back the delimiting char */
1164 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1165 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1169 as_bad ("syntax error: expected `]', found `%c'", c);
1170 input_line_pointer = start; /* reset input_line pointer */
1174 *toc_kind = t; /* set return value */
1181 /* We need to keep a list of fixups. We can't simply generate them as
1182 we go, because that would require us to first create the frag, and
1183 that would screw up references to ``.''. */
1189 bfd_reloc_code_real_type reloc;
1192 #define MAX_INSN_FIXUPS (5)
1194 /* This routine is called for each instruction to be assembled. */
1201 const struct powerpc_opcode *opcode;
1203 const unsigned char *opindex_ptr;
1207 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1212 bfd_reloc_code_real_type reloc;
1215 /* Get the opcode. */
1216 for (s = str; *s != '\0' && ! isspace (*s); s++)
1221 /* Look up the opcode in the hash table. */
1222 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1223 if (opcode == (const struct powerpc_opcode *) NULL)
1225 const struct powerpc_macro *macro;
1227 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1228 if (macro == (const struct powerpc_macro *) NULL)
1229 as_bad ("Unrecognized opcode: `%s'", str);
1231 ppc_macro (s, macro);
1236 insn = opcode->opcode;
1239 while (isspace (*str))
1242 /* PowerPC operands are just expressions. The only real issue is
1243 that a few operand types are optional. All cases which might use
1244 an optional operand separate the operands only with commas (in
1245 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1246 cases never have optional operands). There is never more than
1247 one optional operand for an instruction. So, before we start
1248 seriously parsing the operands, we check to see if we have an
1249 optional operand, and, if we do, we count the number of commas to
1250 see whether the operand should be omitted. */
1252 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1254 const struct powerpc_operand *operand;
1256 operand = &powerpc_operands[*opindex_ptr];
1257 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1259 unsigned int opcount;
1261 /* There is an optional operand. Count the number of
1262 commas in the input line. */
1269 while ((s = strchr (s, ',')) != (char *) NULL)
1276 /* If there are fewer operands in the line then are called
1277 for by the instruction, we want to skip the optional
1279 if (opcount < strlen (opcode->operands))
1286 /* Gather the operands. */
1290 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1292 const struct powerpc_operand *operand;
1298 if (next_opindex == 0)
1299 operand = &powerpc_operands[*opindex_ptr];
1302 operand = &powerpc_operands[next_opindex];
1308 /* If this is a fake operand, then we do not expect anything
1310 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1312 insn = (*operand->insert) (insn, 0L, &errmsg);
1313 if (errmsg != (const char *) NULL)
1318 /* If this is an optional operand, and we are skipping it, just
1320 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1323 if (operand->insert)
1325 insn = (*operand->insert) (insn, 0L, &errmsg);
1326 if (errmsg != (const char *) NULL)
1329 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1330 next_opindex = *opindex_ptr + 1;
1334 /* Gather the operand. */
1335 hold = input_line_pointer;
1336 input_line_pointer = str;
1339 if (*input_line_pointer == '[')
1341 /* We are expecting something like the second argument here:
1343 lwz r4,[toc].GS.0.static_int(rtoc)
1344 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1345 The argument following the `]' must be a symbol name, and the
1346 register must be the toc register: 'rtoc' or '2'
1348 The effect is to 0 as the displacement field
1349 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1350 the appropriate variation) reloc against it based on the symbol.
1351 The linker will build the toc, and insert the resolved toc offset.
1354 o The size of the toc entry is currently assumed to be
1355 32 bits. This should not be assumed to be a hard coded
1357 o In an effort to cope with a change from 32 to 64 bits,
1358 there are also toc entries that are specified to be
1359 either 32 or 64 bits:
1360 lwz r4,[toc32].GS.0.static_int(rtoc)
1361 lwz r4,[toc64].GS.0.static_int(rtoc)
1362 These demand toc entries of the specified size, and the
1363 instruction probably requires it.
1367 enum toc_size_qualifier toc_kind;
1368 bfd_reloc_code_real_type toc_reloc;
1370 /* go parse off the [tocXX] part */
1371 valid_toc = parse_toc_entry(&toc_kind);
1375 /* Note: message has already been issued. */
1376 /* FIXME: what sort of recovery should we do? */
1377 /* demand_rest_of_line(); return; ? */
1380 /* Now get the symbol following the ']' */
1386 /* In this case, we may not have seen the symbol yet, since */
1387 /* it is allowed to appear on a .extern or .globl or just be */
1388 /* a label in the .data section. */
1389 toc_reloc = BFD_RELOC_PPC_TOC16;
1392 /* 1. The symbol must be defined and either in the toc */
1393 /* section, or a global. */
1394 /* 2. The reloc generated must have the TOCDEFN flag set in */
1395 /* upper bit mess of the reloc type. */
1396 /* FIXME: It's a little confusing what the tocv qualifier can */
1397 /* be used for. At the very least, I've seen three */
1398 /* uses, only one of which I'm sure I can explain. */
1399 if (ex.X_op == O_symbol)
1401 assert (ex.X_add_symbol != NULL);
1402 if (ex.X_add_symbol->bsym->section != tocdata_section)
1404 as_warn("[tocv] symbol is not a toc symbol");
1408 toc_reloc = BFD_RELOC_PPC_TOC16;
1411 /* FIXME: these next two specifically specify 32/64 bit toc */
1412 /* entries. We don't support them today. Is this the */
1413 /* right way to say that? */
1414 toc_reloc = BFD_RELOC_UNUSED;
1415 as_bad ("Unimplemented toc32 expression modifier");
1418 /* FIXME: see above */
1419 toc_reloc = BFD_RELOC_UNUSED;
1420 as_bad ("Unimplemented toc64 expression modifier");
1424 "Unexpected return value [%d] from parse_toc_entry!\n",
1430 /* We need to generate a fixup for this expression. */
1431 if (fc >= MAX_INSN_FIXUPS)
1432 as_fatal ("too many fixups");
1434 fixups[fc].reloc = toc_reloc;
1435 fixups[fc].exp = ex;
1436 fixups[fc].opindex = *opindex_ptr;
1439 /* Ok. We've set up the fixup for the instruction. Now make it
1440 look like the constant 0 was found here */
1442 ex.X_op = O_constant;
1443 ex.X_add_number = 0;
1444 ex.X_add_symbol = NULL;
1445 ex.X_op_symbol = NULL;
1449 if (!register_name(&ex))
1455 str = input_line_pointer;
1456 input_line_pointer = hold;
1459 str = input_line_pointer;
1460 input_line_pointer = hold;
1463 if (ex.X_op == O_illegal)
1464 as_bad ("illegal operand");
1465 else if (ex.X_op == O_absent)
1466 as_bad ("missing operand");
1467 else if (ex.X_op == O_constant)
1470 /* Allow @HA, @L, @H on constants. */
1471 char *orig_str = str;
1473 if ((reloc = ppc_elf_suffix (&str)) != BFD_RELOC_UNUSED)
1480 case BFD_RELOC_LO16:
1481 ex.X_add_number = ((ex.X_add_number & 0xffff) ^ 0x8000) - 0x8000;
1484 case BFD_RELOC_HI16:
1485 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
1488 case BFD_RELOC_HI16_S:
1489 ex.X_add_number = ((ex.X_add_number >> 16) & 0xffff)
1490 + ((ex.X_add_number >> 15) & 1);
1494 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1498 else if (ex.X_op == O_register)
1500 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1505 else if ((reloc = ppc_elf_suffix (&str)) != BFD_RELOC_UNUSED)
1507 /* For the absoulte forms of branchs, convert the PC relative form back into
1509 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
1512 case BFD_RELOC_PPC_B26: reloc = BFD_RELOC_PPC_BA26; break;
1513 case BFD_RELOC_PPC_B16: reloc = BFD_RELOC_PPC_BA16; break;
1514 case BFD_RELOC_PPC_B16_BRTAKEN: reloc = BFD_RELOC_PPC_BA16_BRTAKEN; break;
1515 case BFD_RELOC_PPC_B16_BRNTAKEN: reloc = BFD_RELOC_PPC_BA16_BRNTAKEN; break;
1518 /* We need to generate a fixup for this expression. */
1519 if (fc >= MAX_INSN_FIXUPS)
1520 as_fatal ("too many fixups");
1521 fixups[fc].exp = ex;
1522 fixups[fc].opindex = 0;
1523 fixups[fc].reloc = reloc;
1526 #endif /* OBJ_ELF */
1530 /* We need to generate a fixup for this expression. */
1531 if (fc >= MAX_INSN_FIXUPS)
1532 as_fatal ("too many fixups");
1533 fixups[fc].exp = ex;
1534 fixups[fc].opindex = *opindex_ptr;
1535 fixups[fc].reloc = BFD_RELOC_UNUSED;
1544 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
1552 /* The call to expression should have advanced str past any
1555 && (endc != ',' || *str != '\0'))
1557 as_bad ("syntax error; found `%c' but expected `%c'", *str, endc);
1565 while (isspace (*str))
1569 as_bad ("junk at end of line: `%s'", str);
1571 /* Write out the instruction. */
1573 md_number_to_chars (f, insn, 4);
1575 /* Create any fixups. At this point we do not use a
1576 bfd_reloc_code_real_type, but instead just use the
1577 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1578 handle fixups for any operand type, although that is admittedly
1579 not a very exciting feature. We pick a BFD reloc type in
1581 for (i = 0; i < fc; i++)
1583 const struct powerpc_operand *operand;
1585 operand = &powerpc_operands[fixups[i].opindex];
1586 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1588 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1596 size = bfd_get_reloc_size (reloc_howto);
1597 offset = target_big_endian ? (4 - size) : 0;
1599 if (size < 1 || size > 4)
1602 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, size,
1603 &fixups[i].exp, reloc_howto->pc_relative,
1606 /* Turn off complaints that the addend is too large for things like
1608 switch (fixups[i].reloc)
1610 case BFD_RELOC_LO16:
1611 case BFD_RELOC_HI16:
1612 case BFD_RELOC_HI16_S:
1613 fixP->fx_no_overflow = 1;
1620 fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1622 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
1623 ((bfd_reloc_code_real_type)
1624 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1628 #ifndef WORKING_DOT_WORD
1629 /* Handle long and short jumps */
1631 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1633 addressT from_addr, to_addr;
1641 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1643 addressT from_addr, to_addr;
1651 /* Handle a macro. Gather all the operands, transform them as
1652 described by the macro, and call md_assemble recursively. All the
1653 operands are separated by commas; we don't accept parentheses
1654 around operands here. */
1657 ppc_macro (str, macro)
1659 const struct powerpc_macro *macro;
1670 /* Gather the users operands into the operands array. */
1675 if (count >= sizeof operands / sizeof operands[0])
1677 operands[count++] = s;
1678 s = strchr (s, ',');
1679 if (s == (char *) NULL)
1684 if (count != macro->operands)
1686 as_bad ("wrong number of operands");
1690 /* Work out how large the string must be (the size is unbounded
1691 because it includes user input). */
1693 format = macro->format;
1694 while (*format != '\0')
1703 arg = strtol (format + 1, &send, 10);
1704 know (send != format && arg >= 0 && arg < count);
1705 len += strlen (operands[arg]);
1710 /* Put the string together. */
1711 complete = s = (char *) alloca (len + 1);
1712 format = macro->format;
1713 while (*format != '\0')
1719 arg = strtol (format + 1, &send, 10);
1720 strcpy (s, operands[arg]);
1727 /* Assemble the constructed instruction. */
1728 md_assemble (complete);
1731 /* Pseudo-op handling. */
1733 /* The .byte pseudo-op. This is similar to the normal .byte
1734 pseudo-op, but it can also take a single ASCII string. */
1740 if (*input_line_pointer != '\"')
1746 /* Gather characters. A real double quote is doubled. Unusual
1747 characters are not permitted. */
1748 ++input_line_pointer;
1753 c = *input_line_pointer++;
1757 if (*input_line_pointer != '\"')
1759 ++input_line_pointer;
1762 FRAG_APPEND_1_CHAR (c);
1765 demand_empty_rest_of_line ();
1770 /* XCOFF specific pseudo-op handling. */
1772 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1773 symbols in the .bss segment as though they were local common
1774 symbols, and uses a different smclas. */
1780 asection *current_seg = now_seg;
1781 subsegT current_subseg = now_subseg;
1787 symbolS *lcomm_sym = NULL;
1791 name = input_line_pointer;
1792 endc = get_symbol_end ();
1793 end_name = input_line_pointer;
1796 if (*input_line_pointer != ',')
1798 as_bad ("missing size");
1799 ignore_rest_of_line ();
1802 ++input_line_pointer;
1804 size = get_absolute_expression ();
1807 as_bad ("negative size");
1808 ignore_rest_of_line ();
1814 /* The third argument to .comm is the alignment. */
1815 if (*input_line_pointer != ',')
1819 ++input_line_pointer;
1820 align = get_absolute_expression ();
1823 as_warn ("ignoring bad alignment");
1842 /* The third argument to .lcomm appears to be the real local
1843 common symbol to create. References to the symbol named in
1844 the first argument are turned into references to the third
1846 if (*input_line_pointer != ',')
1848 as_bad ("missing real symbol name");
1849 ignore_rest_of_line ();
1852 ++input_line_pointer;
1854 lcomm_name = input_line_pointer;
1855 lcomm_endc = get_symbol_end ();
1857 lcomm_sym = symbol_find_or_make (lcomm_name);
1859 *input_line_pointer = lcomm_endc;
1863 sym = symbol_find_or_make (name);
1866 if (S_IS_DEFINED (sym)
1867 || S_GET_VALUE (sym) != 0)
1869 as_bad ("attempt to redefine symbol");
1870 ignore_rest_of_line ();
1874 record_alignment (bss_section, align);
1877 || ! S_IS_DEFINED (lcomm_sym))
1886 S_SET_EXTERNAL (sym);
1890 lcomm_sym->sy_tc.output = 1;
1891 def_sym = lcomm_sym;
1895 subseg_set (bss_section, 1);
1896 frag_align (align, 0);
1898 def_sym->sy_frag = frag_now;
1899 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
1900 def_size, (char *) NULL);
1902 S_SET_SEGMENT (def_sym, bss_section);
1903 def_sym->sy_tc.align = align;
1907 /* Align the size of lcomm_sym. */
1908 lcomm_sym->sy_frag->fr_offset =
1909 ((lcomm_sym->sy_frag->fr_offset + (1 << align) - 1)
1910 &~ ((1 << align) - 1));
1911 if (align > lcomm_sym->sy_tc.align)
1912 lcomm_sym->sy_tc.align = align;
1917 /* Make sym an offset from lcomm_sym. */
1918 S_SET_SEGMENT (sym, bss_section);
1919 sym->sy_frag = lcomm_sym->sy_frag;
1920 S_SET_VALUE (sym, lcomm_sym->sy_frag->fr_offset);
1921 lcomm_sym->sy_frag->fr_offset += size;
1924 subseg_set (current_seg, current_subseg);
1926 demand_empty_rest_of_line ();
1929 /* The .csect pseudo-op. This switches us into a different
1930 subsegment. The first argument is a symbol whose value is the
1931 start of the .csect. In COFF, csect symbols get special aux
1932 entries defined by the x_csect field of union internal_auxent. The
1933 optional second argument is the alignment (the default is 2). */
1943 name = input_line_pointer;
1944 endc = get_symbol_end ();
1946 sym = symbol_find_or_make (name);
1948 *input_line_pointer = endc;
1950 ppc_change_csect (sym);
1952 if (*input_line_pointer == ',')
1954 ++input_line_pointer;
1955 sym->sy_tc.align = get_absolute_expression ();
1958 demand_empty_rest_of_line ();
1961 /* Change to a different csect. */
1964 ppc_change_csect (sym)
1967 if (S_IS_DEFINED (sym))
1968 subseg_set (S_GET_SEGMENT (sym), sym->sy_tc.subseg);
1975 /* This is a new csect. We need to look at the symbol class to
1976 figure out whether it should go in the text section or the
1979 switch (sym->sy_tc.class)
1989 S_SET_SEGMENT (sym, text_section);
1990 sym->sy_tc.subseg = ppc_text_subsegment;
1991 ++ppc_text_subsegment;
1992 list_ptr = &ppc_text_csects;
2001 if (ppc_toc_csect->sy_tc.subseg + 1 == ppc_data_subsegment)
2003 S_SET_SEGMENT (sym, data_section);
2004 sym->sy_tc.subseg = ppc_data_subsegment;
2005 ++ppc_data_subsegment;
2006 list_ptr = &ppc_data_csects;
2012 subseg_new (segment_name (S_GET_SEGMENT (sym)), sym->sy_tc.subseg);
2014 ppc_after_toc_frag = frag_now;
2016 sym->sy_frag = frag_now;
2017 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2019 sym->sy_tc.align = 2;
2020 sym->sy_tc.output = 1;
2021 sym->sy_tc.within = sym;
2023 for (list = *list_ptr;
2024 list->sy_tc.next != (symbolS *) NULL;
2025 list = list->sy_tc.next)
2027 list->sy_tc.next = sym;
2029 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2030 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2033 ppc_current_csect = sym;
2036 /* This function handles the .text and .data pseudo-ops. These
2037 pseudo-ops aren't really used by XCOFF; we implement them for the
2038 convenience of people who aren't used to XCOFF. */
2049 else if (type == 'd')
2054 sym = symbol_find_or_make (name);
2056 ppc_change_csect (sym);
2058 demand_empty_rest_of_line ();
2061 /* The .extern pseudo-op. We create an undefined symbol. */
2070 name = input_line_pointer;
2071 endc = get_symbol_end ();
2073 (void) symbol_find_or_make (name);
2075 *input_line_pointer = endc;
2077 demand_empty_rest_of_line ();
2080 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
2081 this because it can't handle undefined symbols. I think we can
2091 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2092 although I don't know why it bothers. */
2103 name = input_line_pointer;
2104 endc = get_symbol_end ();
2106 sym = symbol_find_or_make (name);
2108 *input_line_pointer = endc;
2110 if (*input_line_pointer != ',')
2112 as_bad ("missing rename string");
2113 ignore_rest_of_line ();
2116 ++input_line_pointer;
2118 sym->sy_tc.real_name = demand_copy_C_string (&len);
2120 demand_empty_rest_of_line ();
2123 /* The .stabx pseudo-op. This is similar to a normal .stabs
2124 pseudo-op, but slightly different. A sample is
2125 .stabx "main:F-1",.main,142,0
2126 The first argument is the symbol name to create. The second is the
2127 value, and the third is the storage class. The fourth seems to be
2128 always zero, and I am assuming it is the type. */
2139 name = demand_copy_C_string (&len);
2141 if (*input_line_pointer != ',')
2143 as_bad ("missing value");
2146 ++input_line_pointer;
2148 sym = symbol_make (name);
2150 (void) expression (&exp);
2157 as_bad ("illegal .stabx expression; zero assumed");
2158 exp.X_add_number = 0;
2161 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2162 sym->sy_frag = &zero_address_frag;
2166 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2167 sym->sy_value = exp;
2171 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2172 sym->sy_frag = exp.X_add_symbol->sy_frag;
2177 /* The value is some complex expression. This will probably
2178 fail at some later point, but this is probably the right
2179 thing to do here. */
2180 sym->sy_value = exp;
2184 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2185 sym->bsym->flags |= BSF_DEBUGGING;
2187 if (*input_line_pointer != ',')
2189 as_bad ("missing class");
2192 ++input_line_pointer;
2194 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2196 if (*input_line_pointer != ',')
2198 as_bad ("missing type");
2201 ++input_line_pointer;
2203 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2205 sym->sy_tc.output = 1;
2207 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
2208 sym->sy_tc.within = ppc_current_block;
2210 if (exp.X_op != O_symbol
2211 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2212 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2213 ppc_frob_label (sym);
2216 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2217 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2218 if (ppc_current_csect->sy_tc.within == exp.X_add_symbol)
2219 ppc_current_csect->sy_tc.within = sym;
2222 if (strlen (name) > SYMNMLEN)
2224 /* For some reason, each name is preceded by a two byte length
2225 and followed by a null byte. */
2226 ppc_debug_name_section_size += strlen (name) + 3;
2229 demand_empty_rest_of_line ();
2232 /* The .function pseudo-op. This takes several arguments. The first
2233 argument seems to be the external name of the symbol. The second
2234 argment seems to be the label for the start of the function. gcc
2235 uses the same name for both. I have no idea what the third and
2236 fourth arguments are meant to be. The optional fifth argument is
2237 an expression for the size of the function. In COFF this symbol
2238 gets an aux entry like that used for a csect. */
2241 ppc_function (ignore)
2250 name = input_line_pointer;
2251 endc = get_symbol_end ();
2253 /* Ignore any [PR] suffix. */
2254 name = ppc_canonicalize_symbol_name (name);
2255 s = strchr (name, '[');
2256 if (s != (char *) NULL
2257 && strcmp (s + 1, "PR]") == 0)
2260 ext_sym = symbol_find_or_make (name);
2262 *input_line_pointer = endc;
2264 if (*input_line_pointer != ',')
2266 as_bad ("missing symbol name");
2267 ignore_rest_of_line ();
2270 ++input_line_pointer;
2272 name = input_line_pointer;
2273 endc = get_symbol_end ();
2275 lab_sym = symbol_find_or_make (name);
2277 *input_line_pointer = endc;
2279 if (ext_sym != lab_sym)
2281 ext_sym->sy_value.X_op = O_symbol;
2282 ext_sym->sy_value.X_add_symbol = lab_sym;
2283 ext_sym->sy_value.X_op_symbol = NULL;
2284 ext_sym->sy_value.X_add_number = 0;
2287 if (ext_sym->sy_tc.class == -1)
2288 ext_sym->sy_tc.class = XMC_PR;
2289 ext_sym->sy_tc.output = 1;
2291 if (*input_line_pointer == ',')
2295 /* Ignore the third argument. */
2296 ++input_line_pointer;
2297 expression (&ignore);
2298 if (*input_line_pointer == ',')
2300 /* Ignore the fourth argument. */
2301 ++input_line_pointer;
2302 expression (&ignore);
2303 if (*input_line_pointer == ',')
2305 /* The fifth argument is the function size. */
2306 ++input_line_pointer;
2307 ext_sym->sy_tc.size = symbol_new ("L0\001",
2310 &zero_address_frag);
2311 pseudo_set (ext_sym->sy_tc.size);
2316 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2317 SF_SET_FUNCTION (ext_sym);
2318 SF_SET_PROCESS (ext_sym);
2319 coff_add_linesym (ext_sym);
2321 demand_empty_rest_of_line ();
2324 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2333 sym = symbol_make (".bf");
2334 S_SET_SEGMENT (sym, text_section);
2335 sym->sy_frag = frag_now;
2336 S_SET_VALUE (sym, frag_now_fix ());
2337 S_SET_STORAGE_CLASS (sym, C_FCN);
2339 coff_line_base = get_absolute_expression ();
2341 S_SET_NUMBER_AUXILIARY (sym, 1);
2342 SA_SET_SYM_LNNO (sym, coff_line_base);
2344 sym->sy_tc.output = 1;
2346 ppc_frob_label (sym);
2348 demand_empty_rest_of_line ();
2351 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2352 ".ef", except that the line number is absolute, not relative to the
2353 most recent ".bf" symbol. */
2361 sym = symbol_make (".ef");
2362 S_SET_SEGMENT (sym, text_section);
2363 sym->sy_frag = frag_now;
2364 S_SET_VALUE (sym, frag_now_fix ());
2365 S_SET_STORAGE_CLASS (sym, C_FCN);
2366 S_SET_NUMBER_AUXILIARY (sym, 1);
2367 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2368 sym->sy_tc.output = 1;
2370 ppc_frob_label (sym);
2372 demand_empty_rest_of_line ();
2375 /* The .bi and .ei pseudo-ops. These take a string argument and
2376 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2388 name = demand_copy_C_string (&len);
2390 /* The value of these symbols is actually file offset. Here we set
2391 the value to the index into the line number entries. In
2392 ppc_frob_symbols we set the fix_line field, which will cause BFD
2393 to do the right thing. */
2395 sym = symbol_make (name);
2396 S_SET_SEGMENT (sym, now_seg);
2397 S_SET_VALUE (sym, coff_n_line_nos);
2398 sym->bsym->flags |= BSF_DEBUGGING;
2400 /* obj-coff.c currently only handles line numbers correctly in the
2402 assert (now_seg == text_section);
2404 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
2405 sym->sy_tc.output = 1;
2407 for (look = symbol_rootP;
2408 (look != (symbolS *) NULL
2409 && (S_GET_STORAGE_CLASS (look) == C_FILE
2410 || S_GET_STORAGE_CLASS (look) == C_BINCL
2411 || S_GET_STORAGE_CLASS (look) == C_EINCL));
2412 look = symbol_next (look))
2414 if (look != (symbolS *) NULL)
2416 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2417 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
2420 demand_empty_rest_of_line ();
2423 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2424 There is one argument, which is a csect symbol. The value of the
2425 .bs symbol is the index of this csect symbol. */
2436 if (ppc_current_block != NULL)
2437 as_bad ("nested .bs blocks");
2439 name = input_line_pointer;
2440 endc = get_symbol_end ();
2442 csect = symbol_find_or_make (name);
2444 *input_line_pointer = endc;
2446 sym = symbol_make (".bs");
2447 S_SET_SEGMENT (sym, now_seg);
2448 S_SET_STORAGE_CLASS (sym, C_BSTAT);
2449 sym->bsym->flags |= BSF_DEBUGGING;
2450 sym->sy_tc.output = 1;
2452 sym->sy_tc.within = csect;
2454 ppc_frob_label (sym);
2456 ppc_current_block = sym;
2458 demand_empty_rest_of_line ();
2461 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2469 if (ppc_current_block == NULL)
2470 as_bad (".es without preceding .bs");
2472 sym = symbol_make (".es");
2473 S_SET_SEGMENT (sym, now_seg);
2474 S_SET_STORAGE_CLASS (sym, C_ESTAT);
2475 sym->bsym->flags |= BSF_DEBUGGING;
2476 sym->sy_tc.output = 1;
2478 ppc_frob_label (sym);
2480 ppc_current_block = NULL;
2482 demand_empty_rest_of_line ();
2485 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2494 sym = symbol_make (".bb");
2495 S_SET_SEGMENT (sym, text_section);
2496 sym->sy_frag = frag_now;
2497 S_SET_VALUE (sym, frag_now_fix ());
2498 S_SET_STORAGE_CLASS (sym, C_BLOCK);
2500 S_SET_NUMBER_AUXILIARY (sym, 1);
2501 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2503 sym->sy_tc.output = 1;
2505 ppc_frob_label (sym);
2507 demand_empty_rest_of_line ();
2510 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2519 sym = symbol_make (".eb");
2520 S_SET_SEGMENT (sym, text_section);
2521 sym->sy_frag = frag_now;
2522 S_SET_VALUE (sym, frag_now_fix ());
2523 S_SET_STORAGE_CLASS (sym, C_FCN);
2524 S_SET_NUMBER_AUXILIARY (sym, 1);
2525 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2526 sym->sy_tc.output = 1;
2528 ppc_frob_label (sym);
2530 demand_empty_rest_of_line ();
2533 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2539 if (ppc_toc_csect != (symbolS *) NULL)
2540 subseg_set (data_section, ppc_toc_csect->sy_tc.subseg);
2547 subseg = ppc_data_subsegment;
2548 ++ppc_data_subsegment;
2550 subseg_new (segment_name (data_section), subseg);
2551 ppc_toc_frag = frag_now;
2553 sym = symbol_find_or_make ("TOC[TC0]");
2554 sym->sy_frag = frag_now;
2555 S_SET_SEGMENT (sym, data_section);
2556 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2557 sym->sy_tc.subseg = subseg;
2558 sym->sy_tc.output = 1;
2559 sym->sy_tc.within = sym;
2561 ppc_toc_csect = sym;
2563 for (list = ppc_data_csects;
2564 list->sy_tc.next != (symbolS *) NULL;
2565 list = list->sy_tc.next)
2567 list->sy_tc.next = sym;
2569 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2570 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2573 ppc_current_csect = ppc_toc_csect;
2575 demand_empty_rest_of_line ();
2578 #endif /* OBJ_XCOFF */
2580 /* The .tc pseudo-op. This is used when generating either XCOFF or
2581 ELF. This takes two or more arguments.
2583 When generating XCOFF output, the first argument is the name to
2584 give to this location in the toc; this will be a symbol with class
2585 TC. The rest of the arguments are 4 byte values to actually put at
2586 this location in the TOC; often there is just one more argument, a
2587 relocateable symbol reference.
2589 When not generating XCOFF output, the arguments are the same, but
2590 the first argument is simply ignored. */
2598 /* Define the TOC symbol name. */
2604 if (ppc_toc_csect == (symbolS *) NULL
2605 || ppc_toc_csect != ppc_current_csect)
2607 as_bad (".tc not in .toc section");
2608 ignore_rest_of_line ();
2612 name = input_line_pointer;
2613 endc = get_symbol_end ();
2615 sym = symbol_find_or_make (name);
2617 *input_line_pointer = endc;
2619 if (S_IS_DEFINED (sym))
2623 label = ppc_current_csect->sy_tc.within;
2624 if (label->sy_tc.class != XMC_TC0)
2626 as_warn (".tc with no label");
2627 ignore_rest_of_line ();
2631 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
2632 label->sy_frag = sym->sy_frag;
2633 S_SET_VALUE (label, S_GET_VALUE (sym));
2635 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2636 ++input_line_pointer;
2641 S_SET_SEGMENT (sym, now_seg);
2642 sym->sy_frag = frag_now;
2643 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2644 sym->sy_tc.class = XMC_TC;
2645 sym->sy_tc.output = 1;
2647 ppc_frob_label (sym);
2650 #else /* ! defined (OBJ_XCOFF) */
2652 /* Skip the TOC symbol name. */
2653 while (is_part_of_name (*input_line_pointer)
2654 || *input_line_pointer == '['
2655 || *input_line_pointer == ']'
2656 || *input_line_pointer == '{'
2657 || *input_line_pointer == '}')
2658 ++input_line_pointer;
2660 /* Align to a four byte boundary. */
2662 record_alignment (now_seg, 2);
2664 #endif /* ! defined (OBJ_XCOFF) */
2666 if (*input_line_pointer != ',')
2667 demand_empty_rest_of_line ();
2670 ++input_line_pointer;
2677 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
2679 /* Set the current section. */
2681 ppc_set_current_section (new)
2684 ppc_previous_section = ppc_current_section;
2685 ppc_current_section = new;
2688 /* pseudo-op: .previous
2689 behaviour: toggles the current section with the previous section.
2691 warnings: "No previous section"
2694 ppc_previous(ignore)
2699 if (ppc_previous_section == NULL)
2701 as_warn("No previous section to return to. Directive ignored.");
2705 subseg_set(ppc_previous_section, 0);
2707 ppc_set_current_section(ppc_previous_section);
2710 /* pseudo-op: .pdata
2711 behaviour: predefined read only data section
2715 initial: .section .pdata "adr3"
2716 a - don't know -- maybe a misprint
2717 d - initialized data
2719 3 - double word aligned (that would be 4 byte boundary)
2722 Tag index tables (also known as the function table) for exception
2723 handling, debugging, etc.
2730 if (pdata_section == 0)
2732 pdata_section = subseg_new (".pdata", 0);
2734 bfd_set_section_flags (stdoutput, pdata_section,
2735 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2736 | SEC_READONLY | SEC_DATA ));
2738 bfd_set_section_alignment (stdoutput, pdata_section, 3);
2742 pdata_section = subseg_new(".pdata", 0);
2744 ppc_set_current_section(pdata_section);
2747 /* pseudo-op: .ydata
2748 behaviour: predefined read only data section
2752 initial: .section .ydata "drw3"
2753 a - don't know -- maybe a misprint
2754 d - initialized data
2756 3 - double word aligned (that would be 4 byte boundary)
2758 Tag tables (also known as the scope table) for exception handling,
2765 if (ydata_section == 0)
2767 ydata_section = subseg_new (".ydata", 0);
2768 bfd_set_section_flags (stdoutput, ydata_section,
2769 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2770 | SEC_READONLY | SEC_DATA ));
2772 bfd_set_section_alignment (stdoutput, ydata_section, 3);
2776 ydata_section = subseg_new (".ydata", 0);
2778 ppc_set_current_section(ydata_section);
2781 /* pseudo-op: .reldata
2782 behaviour: predefined read write data section
2783 double word aligned (4-byte)
2784 FIXME: relocation is applied to it
2785 FIXME: what's the difference between this and .data?
2788 initial: .section .reldata "drw3"
2789 d - initialized data
2792 3 - double word aligned (that would be 8 byte boundary)
2795 Like .data, but intended to hold data subject to relocation, such as
2796 function descriptors, etc.
2802 if (reldata_section == 0)
2804 reldata_section = subseg_new (".reldata", 0);
2806 bfd_set_section_flags (stdoutput, reldata_section,
2807 ( SEC_ALLOC | SEC_LOAD | SEC_RELOC
2810 bfd_set_section_alignment (stdoutput, reldata_section, 3);
2814 reldata_section = subseg_new (".reldata", 0);
2816 ppc_set_current_section(reldata_section);
2819 /* pseudo-op: .rdata
2820 behaviour: predefined read only data section
2824 initial: .section .rdata "dr3"
2825 d - initialized data
2827 3 - double word aligned (that would be 4 byte boundary)
2833 if (rdata_section == 0)
2835 rdata_section = subseg_new (".rdata", 0);
2836 bfd_set_section_flags (stdoutput, rdata_section,
2837 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
2838 | SEC_READONLY | SEC_DATA ));
2840 bfd_set_section_alignment (stdoutput, rdata_section, 2);
2844 rdata_section = subseg_new (".rdata", 0);
2846 ppc_set_current_section(rdata_section);
2849 /* pseudo-op: .ualong
2850 behaviour: much like .int, with the exception that no alignment is
2852 FIXME: test the alignment statement
2864 /* pseudo-op: .znop <symbol name>
2865 behaviour: Issue a nop instruction
2866 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
2867 the supplied symbol name.
2869 warnings: Missing symbol name
2876 const struct powerpc_opcode *opcode;
2882 /* Strip out the symbol name */
2890 symbol_name = input_line_pointer;
2891 c = get_symbol_end ();
2893 name = xmalloc (input_line_pointer - symbol_name + 1);
2894 strcpy (name, symbol_name);
2896 sym = symbol_find_or_make (name);
2898 *input_line_pointer = c;
2902 /* Look up the opcode in the hash table. */
2903 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
2905 /* stick in the nop */
2906 insn = opcode->opcode;
2908 /* Write out the instruction. */
2910 md_number_to_chars (f, insn, 4);
2912 f - frag_now->fr_literal,
2917 BFD_RELOC_16_GOT_PCREL);
2930 register char *name;
2934 register symbolS *symbolP;
2937 name = input_line_pointer;
2938 c = get_symbol_end ();
2940 /* just after name is now '\0' */
2941 p = input_line_pointer;
2944 if (*input_line_pointer != ',')
2946 as_bad ("Expected comma after symbol-name: rest of line ignored.");
2947 ignore_rest_of_line ();
2951 input_line_pointer++; /* skip ',' */
2952 if ((temp = get_absolute_expression ()) < 0)
2954 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
2955 ignore_rest_of_line ();
2961 /* The third argument to .comm is the alignment. */
2962 if (*input_line_pointer != ',')
2966 ++input_line_pointer;
2967 align = get_absolute_expression ();
2970 as_warn ("ignoring bad alignment");
2977 symbolP = symbol_find_or_make (name);
2980 if (S_IS_DEFINED (symbolP))
2982 as_bad ("Ignoring attempt to re-define symbol `%s'.",
2983 S_GET_NAME (symbolP));
2984 ignore_rest_of_line ();
2988 if (S_GET_VALUE (symbolP))
2990 if (S_GET_VALUE (symbolP) != (valueT) temp)
2991 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
2992 S_GET_NAME (symbolP),
2993 (long) S_GET_VALUE (symbolP),
2998 S_SET_VALUE (symbolP, (valueT) temp);
2999 S_SET_EXTERNAL (symbolP);
3002 demand_empty_rest_of_line ();
3006 * implement the .section pseudo op:
3007 * .section name {, "flags"}
3009 * | +--- optional flags: 'b' for bss
3011 * +-- section name 'l' for lib
3015 * 'd' (apparently m88k for data)
3017 * But if the argument is not a quoted string, treat it as a
3018 * subsegment number.
3020 * FIXME: this is a copy of the section processing from obj-coff.c, with
3021 * additions/changes for the moto-pas assembler support. There are three
3024 * FIXME: I just noticed this. This doesn't work at all really. It it
3025 * setting bits that bfd probably neither understands or uses. The
3026 * correct approach (?) will have to incorporate extra fields attached
3027 * to the section to hold the system specific stuff. (krk)
3030 * 'a' - unknown - referred to in documentation, but no definition supplied
3031 * 'c' - section has code
3032 * 'd' - section has initialized data
3033 * 'u' - section has uninitialized data
3034 * 'i' - section contains directives (info)
3035 * 'n' - section can be discarded
3036 * 'R' - remove section at link time
3038 * Section Protection:
3039 * 'r' - section is readable
3040 * 'w' - section is writeable
3041 * 'x' - section is executable
3042 * 's' - section is sharable
3044 * Section Alignment:
3045 * '0' - align to byte boundary
3046 * '1' - align to halfword undary
3047 * '2' - align to word boundary
3048 * '3' - align to doubleword boundary
3049 * '4' - align to quadword boundary
3050 * '5' - align to 32 byte boundary
3051 * '6' - align to 64 byte boundary
3056 ppc_pe_section (ignore)
3059 /* Strip out the section name */
3068 align = 4; /* default alignment to 16 byte boundary */
3070 section_name = input_line_pointer;
3071 c = get_symbol_end ();
3073 name = xmalloc (input_line_pointer - section_name + 1);
3074 strcpy (name, section_name);
3076 *input_line_pointer = c;
3081 flags = SEC_NO_FLAGS;
3083 if (*input_line_pointer == ',')
3085 ++input_line_pointer;
3087 if (*input_line_pointer != '"')
3088 exp = get_absolute_expression ();
3091 ++input_line_pointer;
3092 while (*input_line_pointer != '"'
3093 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3095 switch (*input_line_pointer)
3097 /* Section Contents */
3098 case 'a': /* unknown */
3099 as_warn ("Unsupported section attribute -- 'a'");
3101 case 'c': /* code section */
3104 case 'd': /* section has initialized data */
3107 case 'u': /* section has uninitialized data */
3108 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3112 case 'i': /* section contains directives (info) */
3113 /* FIXME: This is IMAGE_SCN_LNK_INFO
3115 flags |= SEC_HAS_CONTENTS;
3117 case 'n': /* section can be discarded */
3120 case 'R': /* Remove section at link time */
3121 flags |= SEC_NEVER_LOAD;
3124 /* Section Protection */
3125 case 'r': /* section is readable */
3126 flags |= IMAGE_SCN_MEM_READ;
3128 case 'w': /* section is writeable */
3129 flags |= IMAGE_SCN_MEM_WRITE;
3131 case 'x': /* section is executable */
3132 flags |= IMAGE_SCN_MEM_EXECUTE;
3134 case 's': /* section is sharable */
3135 flags |= IMAGE_SCN_MEM_SHARED;
3138 /* Section Alignment */
3139 case '0': /* align to byte boundary */
3140 flags |= IMAGE_SCN_ALIGN_1BYTES;
3143 case '1': /* align to halfword boundary */
3144 flags |= IMAGE_SCN_ALIGN_2BYTES;
3147 case '2': /* align to word boundary */
3148 flags |= IMAGE_SCN_ALIGN_4BYTES;
3151 case '3': /* align to doubleword boundary */
3152 flags |= IMAGE_SCN_ALIGN_8BYTES;
3155 case '4': /* align to quadword boundary */
3156 flags |= IMAGE_SCN_ALIGN_16BYTES;
3159 case '5': /* align to 32 byte boundary */
3160 flags |= IMAGE_SCN_ALIGN_32BYTES;
3163 case '6': /* align to 64 byte boundary */
3164 flags |= IMAGE_SCN_ALIGN_64BYTES;
3169 as_warn("unknown section attribute '%c'",
3170 *input_line_pointer);
3173 ++input_line_pointer;
3175 if (*input_line_pointer == '"')
3176 ++input_line_pointer;
3180 sec = subseg_new (name, (subsegT) exp);
3182 ppc_set_current_section(sec);
3184 if (flags != SEC_NO_FLAGS)
3186 if (! bfd_set_section_flags (stdoutput, sec, flags))
3187 as_warn ("error setting flags for \"%s\": %s",
3188 bfd_section_name (stdoutput, sec),
3189 bfd_errmsg (bfd_get_error ()));
3192 bfd_set_section_alignment(stdoutput, sec, align);
3197 ppc_pe_function (ignore)
3204 name = input_line_pointer;
3205 endc = get_symbol_end ();
3207 ext_sym = symbol_find_or_make (name);
3209 *input_line_pointer = endc;
3211 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3212 SF_SET_FUNCTION (ext_sym);
3213 SF_SET_PROCESS (ext_sym);
3214 coff_add_linesym (ext_sym);
3216 demand_empty_rest_of_line ();
3220 ppc_pe_tocd (ignore)
3223 if (tocdata_section == 0)
3225 tocdata_section = subseg_new (".tocd", 0);
3226 /* FIXME: section flags won't work */
3227 bfd_set_section_flags (stdoutput, tocdata_section,
3228 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3229 | SEC_READONLY | SEC_DATA ));
3231 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
3235 rdata_section = subseg_new (".tocd", 0);
3238 ppc_set_current_section(tocdata_section);
3240 demand_empty_rest_of_line ();
3243 /* Don't adjust TOC relocs to use the section symbol. */
3246 ppc_pe_fix_adjustable (fix)
3249 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
3256 /* XCOFF specific symbol and file handling. */
3258 /* Canonicalize the symbol name. We use the to force the suffix, if
3259 any, to use square brackets, and to be in upper case. */
3262 ppc_canonicalize_symbol_name (name)
3267 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
3281 for (s++; *s != '\0' && *s != brac; s++)
3285 if (*s == '\0' || s[1] != '\0')
3286 as_bad ("bad symbol suffix");
3294 /* Set the class of a symbol based on the suffix, if any. This is
3295 called whenever a new symbol is created. */
3298 ppc_symbol_new_hook (sym)
3303 sym->sy_tc.next = NULL;
3304 sym->sy_tc.output = 0;
3305 sym->sy_tc.class = -1;
3306 sym->sy_tc.real_name = NULL;
3307 sym->sy_tc.subseg = 0;
3308 sym->sy_tc.align = 0;
3309 sym->sy_tc.size = NULL;
3310 sym->sy_tc.within = NULL;
3312 s = strchr (S_GET_NAME (sym), '[');
3313 if (s == (const char *) NULL)
3315 /* There is no suffix. */
3324 if (strcmp (s, "BS]") == 0)
3325 sym->sy_tc.class = XMC_BS;
3328 if (strcmp (s, "DB]") == 0)
3329 sym->sy_tc.class = XMC_DB;
3330 else if (strcmp (s, "DS]") == 0)
3331 sym->sy_tc.class = XMC_DS;
3334 if (strcmp (s, "GL]") == 0)
3335 sym->sy_tc.class = XMC_GL;
3338 if (strcmp (s, "PR]") == 0)
3339 sym->sy_tc.class = XMC_PR;
3342 if (strcmp (s, "RO]") == 0)
3343 sym->sy_tc.class = XMC_RO;
3344 else if (strcmp (s, "RW]") == 0)
3345 sym->sy_tc.class = XMC_RW;
3348 if (strcmp (s, "SV]") == 0)
3349 sym->sy_tc.class = XMC_SV;
3352 if (strcmp (s, "TC]") == 0)
3353 sym->sy_tc.class = XMC_TC;
3354 else if (strcmp (s, "TI]") == 0)
3355 sym->sy_tc.class = XMC_TI;
3356 else if (strcmp (s, "TB]") == 0)
3357 sym->sy_tc.class = XMC_TB;
3358 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
3359 sym->sy_tc.class = XMC_TC0;
3362 if (strcmp (s, "UA]") == 0)
3363 sym->sy_tc.class = XMC_UA;
3364 else if (strcmp (s, "UC]") == 0)
3365 sym->sy_tc.class = XMC_UC;
3368 if (strcmp (s, "XO]") == 0)
3369 sym->sy_tc.class = XMC_XO;
3373 if (sym->sy_tc.class == -1)
3374 as_bad ("Unrecognized symbol suffix");
3377 /* Set the class of a label based on where it is defined. This
3378 handles symbols without suffixes. Also, move the symbol so that it
3379 follows the csect symbol. */
3382 ppc_frob_label (sym)
3385 if (ppc_current_csect != (symbolS *) NULL)
3387 if (sym->sy_tc.class == -1)
3388 sym->sy_tc.class = ppc_current_csect->sy_tc.class;
3390 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3391 symbol_append (sym, ppc_current_csect->sy_tc.within, &symbol_rootP,
3393 ppc_current_csect->sy_tc.within = sym;
3397 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3398 seen. It tells ppc_adjust_symtab whether it needs to look through
3401 static boolean ppc_saw_abs;
3403 /* Change the name of a symbol just before writing it out. Set the
3404 real name if the .rename pseudo-op was used. Otherwise, remove any
3405 class suffix. Return 1 if the symbol should not be included in the
3409 ppc_frob_symbol (sym)
3412 static symbolS *ppc_last_function;
3413 static symbolS *set_end;
3415 /* Discard symbols that should not be included in the output symbol
3417 if (! sym->sy_used_in_reloc
3418 && ((sym->bsym->flags & BSF_SECTION_SYM) != 0
3419 || (! S_IS_EXTERNAL (sym)
3420 && ! sym->sy_tc.output
3421 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
3424 if (sym->sy_tc.real_name != (char *) NULL)
3425 S_SET_NAME (sym, sym->sy_tc.real_name);
3431 name = S_GET_NAME (sym);
3432 s = strchr (name, '[');
3433 if (s != (char *) NULL)
3439 snew = xmalloc (len + 1);
3440 memcpy (snew, name, len);
3443 S_SET_NAME (sym, snew);
3447 if (set_end != (symbolS *) NULL)
3449 SA_SET_SYM_ENDNDX (set_end, sym);
3453 if (SF_GET_FUNCTION (sym))
3455 if (ppc_last_function != (symbolS *) NULL)
3456 as_warn ("two .function pseudo-ops with no intervening .ef");
3457 ppc_last_function = sym;
3458 if (sym->sy_tc.size != (symbolS *) NULL)
3460 resolve_symbol_value (sym->sy_tc.size);
3461 SA_SET_SYM_FSIZE (sym, (long) S_GET_VALUE (sym->sy_tc.size));
3464 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
3465 && strcmp (S_GET_NAME (sym), ".ef") == 0)
3467 if (ppc_last_function == (symbolS *) NULL)
3468 as_warn (".ef with no preceding .function");
3471 set_end = ppc_last_function;
3472 ppc_last_function = NULL;
3474 /* We don't have a C_EFCN symbol, but we need to force the
3475 COFF backend to believe that it has seen one. */
3476 coff_last_function = NULL;
3480 if (! S_IS_EXTERNAL (sym)
3481 && (sym->bsym->flags & BSF_SECTION_SYM) == 0
3482 && S_GET_STORAGE_CLASS (sym) != C_FILE
3483 && S_GET_STORAGE_CLASS (sym) != C_FCN
3484 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
3485 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
3486 && S_GET_STORAGE_CLASS (sym) != C_BINCL
3487 && S_GET_STORAGE_CLASS (sym) != C_EINCL
3488 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
3489 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
3491 if (S_GET_STORAGE_CLASS (sym) == C_EXT
3492 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
3495 union internal_auxent *a;
3497 /* Create a csect aux. */
3498 i = S_GET_NUMBER_AUXILIARY (sym);
3499 S_SET_NUMBER_AUXILIARY (sym, i + 1);
3500 a = &coffsymbol (sym->bsym)->native[i + 1].u.auxent;
3501 if (sym->sy_tc.class == XMC_TC0)
3503 /* This is the TOC table. */
3504 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
3505 a->x_csect.x_scnlen.l = 0;
3506 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
3508 else if (sym->sy_tc.subseg != 0)
3510 /* This is a csect symbol. x_scnlen is the size of the
3512 if (sym->sy_tc.next == (symbolS *) NULL)
3513 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
3514 S_GET_SEGMENT (sym))
3515 - S_GET_VALUE (sym));
3518 resolve_symbol_value (sym->sy_tc.next);
3519 a->x_csect.x_scnlen.l = (S_GET_VALUE (sym->sy_tc.next)
3520 - S_GET_VALUE (sym));
3522 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_SD;
3524 else if (S_GET_SEGMENT (sym) == bss_section)
3526 /* This is a common symbol. */
3527 a->x_csect.x_scnlen.l = sym->sy_frag->fr_offset;
3528 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_CM;
3529 if (S_IS_EXTERNAL (sym))
3530 sym->sy_tc.class = XMC_RW;
3532 sym->sy_tc.class = XMC_BS;
3534 else if (S_GET_SEGMENT (sym) == absolute_section)
3536 /* This is an absolute symbol. The csect will be created by
3537 ppc_adjust_symtab. */
3539 a->x_csect.x_smtyp = XTY_LD;
3540 if (sym->sy_tc.class == -1)
3541 sym->sy_tc.class = XMC_XO;
3543 else if (! S_IS_DEFINED (sym))
3545 /* This is an external symbol. */
3546 a->x_csect.x_scnlen.l = 0;
3547 a->x_csect.x_smtyp = XTY_ER;
3549 else if (sym->sy_tc.class == XMC_TC)
3553 /* This is a TOC definition. x_scnlen is the size of the
3555 next = symbol_next (sym);
3556 while (next->sy_tc.class == XMC_TC0)
3557 next = symbol_next (next);
3558 if (next == (symbolS *) NULL
3559 || next->sy_tc.class != XMC_TC)
3561 if (ppc_after_toc_frag == (fragS *) NULL)
3562 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
3564 - S_GET_VALUE (sym));
3566 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
3567 - S_GET_VALUE (sym));
3571 resolve_symbol_value (next);
3572 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
3573 - S_GET_VALUE (sym));
3575 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
3581 /* This is a normal symbol definition. x_scnlen is the
3582 symbol index of the containing csect. */
3583 if (S_GET_SEGMENT (sym) == text_section)
3584 csect = ppc_text_csects;
3585 else if (S_GET_SEGMENT (sym) == data_section)
3586 csect = ppc_data_csects;
3590 /* Skip the initial dummy symbol. */
3591 csect = csect->sy_tc.next;
3593 if (csect == (symbolS *) NULL)
3595 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym));
3596 a->x_csect.x_scnlen.l = 0;
3600 while (csect->sy_tc.next != (symbolS *) NULL)
3602 resolve_symbol_value (csect->sy_tc.next);
3603 if (S_GET_VALUE (csect->sy_tc.next) > S_GET_VALUE (sym))
3605 csect = csect->sy_tc.next;
3608 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
3609 coffsymbol (sym->bsym)->native[i + 1].fix_scnlen = 1;
3611 a->x_csect.x_smtyp = XTY_LD;
3614 a->x_csect.x_parmhash = 0;
3615 a->x_csect.x_snhash = 0;
3616 if (sym->sy_tc.class == -1)
3617 a->x_csect.x_smclas = XMC_PR;
3619 a->x_csect.x_smclas = sym->sy_tc.class;
3620 a->x_csect.x_stab = 0;
3621 a->x_csect.x_snstab = 0;
3623 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
3625 /* We want the value to be the symbol index of the referenced
3626 csect symbol. BFD will do that for us if we set the right
3629 (valueT) coffsymbol (sym->sy_tc.within->bsym)->native);
3630 coffsymbol (sym->bsym)->native->fix_value = 1;
3632 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
3637 /* The value is the offset from the enclosing csect. */
3638 block = sym->sy_tc.within;
3639 csect = block->sy_tc.within;
3640 resolve_symbol_value (csect);
3641 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
3643 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
3644 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
3646 /* We want the value to be a file offset into the line numbers.
3647 BFD will do that for us if we set the right flags. We have
3648 already set the value correctly. */
3649 coffsymbol (sym->bsym)->native->fix_line = 1;
3655 /* Adjust the symbol table. This creates csect symbols for all
3656 absolute symbols. */
3659 ppc_adjust_symtab ()
3666 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
3670 union internal_auxent *a;
3672 if (S_GET_SEGMENT (sym) != absolute_section)
3675 csect = symbol_create (".abs[XO]", absolute_section,
3676 S_GET_VALUE (sym), &zero_address_frag);
3677 csect->bsym->value = S_GET_VALUE (sym);
3678 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
3679 i = S_GET_NUMBER_AUXILIARY (csect);
3680 S_SET_NUMBER_AUXILIARY (csect, i + 1);
3681 a = &coffsymbol (csect->bsym)->native[i + 1].u.auxent;
3682 a->x_csect.x_scnlen.l = 0;
3683 a->x_csect.x_smtyp = XTY_SD;
3684 a->x_csect.x_parmhash = 0;
3685 a->x_csect.x_snhash = 0;
3686 a->x_csect.x_smclas = XMC_XO;
3687 a->x_csect.x_stab = 0;
3688 a->x_csect.x_snstab = 0;
3690 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
3692 i = S_GET_NUMBER_AUXILIARY (sym);
3693 a = &coffsymbol (sym->bsym)->native[i].u.auxent;
3694 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
3695 coffsymbol (sym->bsym)->native[i].fix_scnlen = 1;
3698 ppc_saw_abs = false;
3701 /* Set the VMA for a section. This is called on all the sections in
3705 ppc_frob_section (sec)
3708 static bfd_size_type vma = 0;
3710 bfd_set_section_vma (stdoutput, sec, vma);
3711 vma += bfd_section_size (stdoutput, sec);
3714 /* Adjust the file by adding a .debug section if needed. */
3719 if (ppc_debug_name_section_size > 0)
3723 sec = bfd_make_section (stdoutput, ".debug");
3724 if (sec == (asection *) NULL
3725 || ! bfd_set_section_size (stdoutput, sec,
3726 ppc_debug_name_section_size)
3727 || ! bfd_set_section_flags (stdoutput, sec,
3728 SEC_HAS_CONTENTS | SEC_LOAD))
3729 as_fatal ("can't make .debug section");
3733 #endif /* OBJ_XCOFF */
3735 /* Turn a string in input_line_pointer into a floating point constant
3736 of type type, and store the appropriate bytes in *litp. The number
3737 of LITTLENUMS emitted is stored in *sizep . An error message is
3738 returned, or NULL on OK. */
3741 md_atof (type, litp, sizep)
3747 LITTLENUM_TYPE words[4];
3763 return "bad call to md_atof";
3766 t = atof_ieee (input_line_pointer, type, words);
3768 input_line_pointer = t;
3772 if (target_big_endian)
3774 for (i = 0; i < prec; i++)
3776 md_number_to_chars (litp, (valueT) words[i], 2);
3782 for (i = prec - 1; i >= 0; i--)
3784 md_number_to_chars (litp, (valueT) words[i], 2);
3792 /* Write a value out to the object file, using the appropriate
3796 md_number_to_chars (buf, val, n)
3801 if (target_big_endian)
3802 number_to_chars_bigendian (buf, val, n);
3804 number_to_chars_littleendian (buf, val, n);
3807 /* Align a section (I don't know why this is machine dependent). */
3810 md_section_align (seg, addr)
3814 int align = bfd_get_section_alignment (stdoutput, seg);
3816 return ((addr + (1 << align) - 1) & (-1 << align));
3819 /* We don't have any form of relaxing. */
3822 md_estimate_size_before_relax (fragp, seg)
3830 /* Convert a machine dependent frag. We never generate these. */
3833 md_convert_frag (abfd, sec, fragp)
3841 /* We have no need to default values of symbols. */
3845 md_undefined_symbol (name)
3851 /* Functions concerning relocs. */
3853 /* The location from which a PC relative jump should be calculated,
3854 given a PC relative reloc. */
3857 md_pcrel_from_section (fixp, sec)
3862 if (fixp->fx_addsy != (symbolS *) NULL
3863 && (! S_IS_DEFINED (fixp->fx_addsy)
3864 || TC_FORCE_RELOCATION_SECTION (fixp, sec)))
3868 return fixp->fx_frag->fr_address + fixp->fx_where;
3873 /* This is called to see whether a fixup should be adjusted to use a
3874 section symbol. We take the opportunity to change a fixup against
3875 a symbol in the TOC subsegment into a reloc against the
3876 corresponding .tc symbol. */
3879 ppc_fix_adjustable (fix)
3884 resolve_symbol_value (fix->fx_addsy);
3885 val = S_GET_VALUE (fix->fx_addsy);
3886 if (ppc_toc_csect != (symbolS *) NULL
3887 && fix->fx_addsy != (symbolS *) NULL
3888 && fix->fx_addsy != ppc_toc_csect
3889 && S_GET_SEGMENT (fix->fx_addsy) == data_section
3890 && val >= ppc_toc_frag->fr_address
3891 && (ppc_after_toc_frag == (fragS *) NULL
3892 || val < ppc_after_toc_frag->fr_address))
3896 for (sy = symbol_next (ppc_toc_csect);
3897 sy != (symbolS *) NULL;
3898 sy = symbol_next (sy))
3900 if (sy->sy_tc.class == XMC_TC0)
3902 if (sy->sy_tc.class != XMC_TC)
3904 resolve_symbol_value (sy);
3905 if (val == S_GET_VALUE (sy))
3908 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
3913 as_bad_where (fix->fx_file, fix->fx_line,
3914 "symbol in .toc does not match any .tc");
3917 /* Possibly adjust the reloc to be against the csect. */
3918 if (fix->fx_addsy != (symbolS *) NULL
3919 && fix->fx_addsy->sy_tc.subseg == 0
3920 && fix->fx_addsy->sy_tc.class != XMC_TC0
3921 && fix->fx_addsy->sy_tc.class != XMC_TC
3922 && S_GET_SEGMENT (fix->fx_addsy) != bss_section)
3926 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
3927 csect = ppc_text_csects;
3928 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
3929 csect = ppc_data_csects;
3933 /* Skip the initial dummy symbol. */
3934 csect = csect->sy_tc.next;
3936 if (csect != (symbolS *) NULL)
3938 while (csect->sy_tc.next != (symbolS *) NULL
3939 && (csect->sy_tc.next->sy_frag->fr_address
3940 <= fix->fx_addsy->sy_frag->fr_address))
3941 csect = csect->sy_tc.next;
3943 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
3944 - csect->sy_frag->fr_address);
3945 fix->fx_addsy = csect;
3949 /* Adjust a reloc against a .lcomm symbol to be against the base
3951 if (fix->fx_addsy != (symbolS *) NULL
3952 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
3953 && ! S_IS_EXTERNAL (fix->fx_addsy))
3955 resolve_symbol_value (fix->fx_addsy->sy_frag->fr_symbol);
3956 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
3957 - S_GET_VALUE (fix->fx_addsy->sy_frag->fr_symbol));
3958 fix->fx_addsy = fix->fx_addsy->sy_frag->fr_symbol;
3966 /* See whether a symbol is in the TOC section. */
3969 ppc_is_toc_sym (sym)
3973 return sym->sy_tc.class == XMC_TC;
3975 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
3979 /* Apply a fixup to the object code. This is called for all the
3980 fixups we generated by the call to fix_new_exp, above. In the call
3981 above we used a reloc code which was the largest legal reloc code
3982 plus the operand index. Here we undo that to recover the operand
3983 index. At this point all symbol values should be fully resolved,
3984 and we attempt to completely resolve the reloc. If we can not do
3985 that, we determine the correct reloc code and put it back in the
3989 md_apply_fix3 (fixp, valuep, seg)
3996 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
3997 the symbol values. Since we are using BFD_ASSEMBLER, if we are
3998 doing this relocation the code in write.c is going to call
3999 bfd_perform_relocation, which is also going to use the symbol
4000 value. That means that if the reloc is fully resolved we want to
4001 use *valuep since bfd_perform_relocation is not being used.
4002 However, if the reloc is not fully resolved we do not want to use
4003 *valuep, and must use fx_offset instead. However, if the reloc
4004 is PC relative, we do want to use *valuep since it includes the
4005 result of md_pcrel_from. This is confusing. */
4007 if (fixp->fx_addsy == (symbolS *) NULL)
4012 else if (fixp->fx_pcrel)
4016 value = fixp->fx_offset;
4017 if (fixp->fx_subsy != (symbolS *) NULL)
4019 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
4020 value -= S_GET_VALUE (fixp->fx_subsy);
4023 /* We can't actually support subtracting a symbol. */
4024 as_bad_where (fixp->fx_file, fixp->fx_line,
4025 "expression too complex");
4030 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
4033 const struct powerpc_operand *operand;
4037 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
4039 operand = &powerpc_operands[opindex];
4042 /* It appears that an instruction like
4044 when LC..1 is not a TOC symbol does not generate a reloc. It
4045 uses the offset of LC..1 within its csect. However, .long
4046 LC..1 will generate a reloc. I can't find any documentation
4047 on how these cases are to be distinguished, so this is a wild
4048 guess. These cases are generated by gcc -mminimal-toc. */
4049 if ((operand->flags & PPC_OPERAND_PARENS) != 0
4050 && operand->bits == 16
4051 && operand->shift == 0
4052 && operand->insert == NULL
4053 && fixp->fx_addsy != NULL
4054 && fixp->fx_addsy->sy_tc.subseg != 0
4055 && fixp->fx_addsy->sy_tc.class != XMC_TC
4056 && fixp->fx_addsy->sy_tc.class != XMC_TC0
4057 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
4059 value = fixp->fx_offset;
4064 /* Fetch the instruction, insert the fully resolved operand
4065 value, and stuff the instruction back again. */
4066 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4067 if (target_big_endian)
4068 insn = bfd_getb32 ((unsigned char *) where);
4070 insn = bfd_getl32 ((unsigned char *) where);
4071 insn = ppc_insert_operand (insn, operand, (offsetT) value,
4072 fixp->fx_file, fixp->fx_line);
4073 if (target_big_endian)
4074 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4076 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4080 /* Nothing else to do here. */
4084 /* Determine a BFD reloc value based on the operand information.
4085 We are only prepared to turn a few of the operands into
4087 FIXME: We need to handle the DS field at the very least.
4088 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4089 there should be a new field in the operand table. */
4090 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4091 && operand->bits == 26
4092 && operand->shift == 0)
4093 fixp->fx_r_type = BFD_RELOC_PPC_B26;
4094 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4095 && operand->bits == 16
4096 && operand->shift == 0)
4097 fixp->fx_r_type = BFD_RELOC_PPC_B16;
4098 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4099 && operand->bits == 26
4100 && operand->shift == 0)
4101 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4102 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4103 && operand->bits == 16
4104 && operand->shift == 0)
4105 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4106 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4107 && operand->bits == 16
4108 && operand->shift == 0
4109 && operand->insert == NULL
4110 && fixp->fx_addsy != NULL
4111 && ppc_is_toc_sym (fixp->fx_addsy))
4114 if (target_big_endian)
4115 fixp->fx_where += 2;
4116 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4120 as_bad_where (fixp->fx_file, fixp->fx_line,
4121 "unresolved expression that must be resolved");
4129 ppc_elf_validate_fix (fixp, seg);
4131 switch (fixp->fx_r_type)
4134 case BFD_RELOC_CTOR:
4137 fixp->fx_r_type = BFD_RELOC_32_PCREL;
4138 value += fixp->fx_frag->fr_address + fixp->fx_where;
4139 } /* fall through */
4141 case BFD_RELOC_32_PCREL:
4142 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4146 case BFD_RELOC_LO16:
4147 case BFD_RELOC_HI16:
4148 case BFD_RELOC_HI16_S:
4149 case BFD_RELOC_PPC_TOC16:
4151 case BFD_RELOC_GPREL16:
4152 case BFD_RELOC_16_GOT_PCREL:
4156 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4164 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4174 fixp->fx_addnumber = value;
4176 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
4177 fixp->fx_addnumber = 0;
4181 fixp->fx_addnumber = 0;
4183 /* We want to use the offset within the data segment of the
4184 symbol, not the actual VMA of the symbol. */
4185 fixp->fx_addnumber =
4186 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
4194 /* Generate a reloc for a fixup. */
4197 tc_gen_reloc (seg, fixp)
4203 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
4205 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
4206 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4207 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
4208 if (reloc->howto == (reloc_howto_type *) NULL)
4210 as_bad_where (fixp->fx_file, fixp->fx_line,
4211 "reloc %d not supported by object file format", (int)fixp->fx_r_type);
4214 reloc->addend = fixp->fx_addnumber;