1 /* tc-s390.c -- Assemble for the S390
2 Copyright 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "safe-ctype.h"
26 #include "struc-symbol.h"
28 #include "opcode/s390.h"
31 /* The default architecture */
33 #define DEFAULT_ARCH "s390"
35 static char *default_arch
= DEFAULT_ARCH
;
36 /* Either 32 or 64, selects file format. */
37 static int s390_arch_size
;
38 /* Current architecture. Start with the smallest instruction set */
39 static enum s390_opcode_arch_val current_architecture
= S390_OPCODE_ESA
;
40 static int current_arch_mask
= 1 << S390_OPCODE_ESA
;
41 static int current_arch_requested
= 0;
43 /* Whether to use user friendly register names. Default is true. */
44 #ifndef TARGET_REG_NAMES_P
45 #define TARGET_REG_NAMES_P true
48 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
50 /* Generic assembler global variables which must be defined by all
53 const char comment_chars
[] = "#";
55 /* Characters which start a comment at the beginning of a line. */
56 const char line_comment_chars
[] = "#";
58 /* Characters which may be used to separate multiple commands on a
60 const char line_separator_chars
[] = ";";
62 /* Characters which are used to indicate an exponent in a floating
64 const char EXP_CHARS
[] = "eE";
66 /* Characters which mean that a number is a floating point constant,
68 const char FLT_CHARS
[] = "dD";
70 /* The target specific pseudo-ops which we support. */
72 /* Define the prototypes for the pseudo-ops */
73 static void s390_byte
PARAMS ((int));
74 static void s390_elf_cons
PARAMS ((int));
75 static void s390_bss
PARAMS ((int));
76 static void s390_insn
PARAMS ((int));
77 static void s390_literals
PARAMS ((int));
79 const pseudo_typeS md_pseudo_table
[] =
81 { "align", s_align_bytes
, 0 },
82 /* Pseudo-ops which must be defined. */
83 { "bss", s390_bss
, 0 },
84 { "insn", s390_insn
, 0 },
85 /* Pseudo-ops which must be overridden. */
86 { "byte", s390_byte
, 0 },
87 { "short", s390_elf_cons
, 2 },
88 { "long", s390_elf_cons
, 4 },
89 { "quad", s390_elf_cons
, 8 },
90 { "ltorg", s390_literals
, 0 },
91 { "string", stringer
, 2 },
96 /* Structure to hold information about predefined registers. */
103 /* List of registers that are pre-defined:
105 Each access register has a predefined name of the form:
106 a<reg_num> which has the value <reg_num>.
108 Each control register has a predefined name of the form:
109 c<reg_num> which has the value <reg_num>.
111 Each general register has a predefined name of the form:
112 r<reg_num> which has the value <reg_num>.
114 Each floating point register a has predefined name of the form:
115 f<reg_num> which has the value <reg_num>.
117 There are individual registers as well:
121 The table is sorted. Suitable for searching by a binary search. */
123 static const struct pd_reg pre_defined_registers
[] =
125 { "a0", 0 }, /* Access registers */
142 { "c0", 0 }, /* Control registers */
159 { "f0", 0 }, /* Floating point registers */
176 { "lit", 13 }, /* Pointer to literal pool */
178 { "r0", 0 }, /* General purpose registers */
195 { "sp", 15 }, /* Stack pointer */
199 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
201 static int reg_name_search
202 PARAMS ((const struct pd_reg
*, int, const char *));
203 static boolean register_name
PARAMS ((expressionS
*));
204 static void init_default_arch
PARAMS ((void));
205 static void s390_insert_operand
206 PARAMS ((unsigned char *, const struct s390_operand
*, offsetT
, char *,
208 static char *md_gather_operands
209 PARAMS ((char *, unsigned char *, const struct s390_opcode
*));
211 /* Given NAME, find the register number associated with that name, return
212 the integer value associated with the given name or -1 on failure. */
215 reg_name_search (regs
, regcount
, name
)
216 const struct pd_reg
*regs
;
220 int middle
, low
, high
;
228 middle
= (low
+ high
) / 2;
229 cmp
= strcasecmp (name
, regs
[middle
].name
);
235 return regs
[middle
].value
;
244 * Summary of register_name().
246 * in: Input_line_pointer points to 1st char of operand.
248 * out: A expressionS.
249 * The operand may have been a register: in this case, X_op == O_register,
250 * X_add_number is set to the register number, and truth is returned.
251 * Input_line_pointer->(next non-blank) char after operand, or is in its
256 register_name (expressionP
)
257 expressionS
*expressionP
;
264 /* Find the spelling of the operand. */
265 start
= name
= input_line_pointer
;
266 if (name
[0] == '%' && ISALPHA (name
[1]))
267 name
= ++input_line_pointer
;
271 c
= get_symbol_end ();
272 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
274 /* Put back the delimiting char. */
275 *input_line_pointer
= c
;
277 /* Look to see if it's in the register table. */
280 expressionP
->X_op
= O_register
;
281 expressionP
->X_add_number
= reg_number
;
283 /* Make the rest nice. */
284 expressionP
->X_add_symbol
= NULL
;
285 expressionP
->X_op_symbol
= NULL
;
289 /* Reset the line as if we had not done anything. */
290 input_line_pointer
= start
;
294 /* Local variables. */
296 /* Opformat hash table. */
297 static struct hash_control
*s390_opformat_hash
;
299 /* Opcode hash table. */
300 static struct hash_control
*s390_opcode_hash
;
302 /* Flags to set in the elf header */
303 static flagword s390_flags
= 0;
305 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
307 #ifndef WORKING_DOT_WORD
308 const int md_short_jump_size
= 4;
309 const int md_long_jump_size
= 4;
312 CONST
char *md_shortopts
= "A:m:kVQ:";
313 struct option md_longopts
[] = {
314 {NULL
, no_argument
, NULL
, 0}
316 size_t md_longopts_size
= sizeof (md_longopts
);
318 /* Initialize the default opcode arch and word size from the default
319 architecture name. */
323 if (current_arch_requested
)
326 if (strcmp (default_arch
, "s390") == 0)
329 current_architecture
= S390_OPCODE_ESA
;
331 else if (strcmp (default_arch
, "s390x") == 0)
334 current_architecture
= S390_OPCODE_ESAME
;
337 as_fatal ("Invalid default architecture, broken assembler.");
338 current_arch_mask
= 1 << current_architecture
;
341 /* Called by TARGET_FORMAT. */
343 s390_target_format ()
345 /* We don't get a chance to initialize anything before we're called,
346 so handle that now. */
347 if (! s390_arch_size
)
348 init_default_arch ();
350 return s390_arch_size
== 64 ? "elf64-s390" : "elf32-s390";
354 md_parse_option (c
, arg
)
360 /* -k: Ignore for FreeBSD compatibility. */
364 if (arg
!= NULL
&& strcmp (arg
, "regnames") == 0)
367 else if (arg
!= NULL
&& strcmp (arg
, "no-regnames") == 0)
372 as_bad (_("invalid switch -m%s"), arg
);
378 if (arg
!= NULL
&& strcmp (arg
, "esa") == 0)
380 current_architecture
= S390_OPCODE_ESA
;
383 else if (arg
!= NULL
&& strcmp (arg
, "esame") == 0)
385 current_architecture
= S390_OPCODE_ESAME
;
389 as_bad ("invalid architecture -A%s", arg
);
390 current_arch_mask
= 1 << current_architecture
;
391 current_arch_requested
= 1;
394 /* -V: SVR4 argument to print version ID. */
399 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
400 should be emitted or not. FIXME: Not implemented. */
412 md_show_usage (stream
)
415 fprintf (stream
, _("\
417 -mregnames \tAllow symbolic names for registers\n\
418 -mno-regnames\tDo not allow symbolic names for registers\n"));
419 fprintf (stream
, _("\
420 -V \tprint assembler version number\n\
421 -Qy, -Qn \tignored\n"));
424 /* This function is called when the assembler starts up. It is called
425 after the options have been parsed and the output file has been
431 register const struct s390_opcode
*op
;
432 const struct s390_opcode
*op_end
;
433 boolean dup_insn
= false;
436 /* Set the ELF flags if desired. */
438 bfd_set_private_flags (stdoutput
, s390_flags
);
440 /* Insert the opcode formats into a hash table. */
441 s390_opformat_hash
= hash_new ();
443 op_end
= s390_opformats
+ s390_num_opformats
;
444 for (op
= s390_opformats
; op
< op_end
; op
++)
446 retval
= hash_insert (s390_opformat_hash
, op
->name
, (PTR
) op
);
447 if (retval
!= (const char *) NULL
)
449 as_bad (_("Internal assembler error for instruction format %s"),
455 /* Insert the opcodes into a hash table. */
456 s390_opcode_hash
= hash_new ();
458 op_end
= s390_opcodes
+ s390_num_opcodes
;
459 for (op
= s390_opcodes
; op
< op_end
; op
++)
461 retval
= hash_insert (s390_opcode_hash
, op
->name
, (PTR
) op
);
462 if (retval
!= (const char *) NULL
)
464 as_bad (_("Internal assembler error for instruction %s"), op
->name
);
472 record_alignment (text_section
, 2);
473 record_alignment (data_section
, 2);
474 record_alignment (bss_section
, 2);
478 /* Called after all assembly has been done. */
482 if (s390_arch_size
== 64)
483 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_esame
);
485 bfd_set_arch_mach (stdoutput
, bfd_arch_s390
, bfd_mach_s390_esa
);
489 s390_align_code (fragP
, count
)
493 /* We use nop pattern 0x0707. */
496 memset (fragP
->fr_literal
+ fragP
->fr_fix
, 0x07, count
);
497 fragP
->fr_var
= count
;
501 /* Insert an operand value into an instruction. */
504 s390_insert_operand (insn
, operand
, val
, file
, line
)
506 const struct s390_operand
*operand
;
514 if (operand
->flags
& (S390_OPERAND_SIGNED
|S390_OPERAND_PCREL
))
518 max
= ((offsetT
) 1 << (operand
->bits
- 1)) - 1;
519 min
= - ((offsetT
) 1 << (operand
->bits
- 1));
520 /* Halve PCREL operands. */
521 if (operand
->flags
& S390_OPERAND_PCREL
)
523 /* Check for underflow / overflow. */
524 if (val
< min
|| val
> max
)
527 "operand out of range (%s not between %ld and %ld)";
530 if (operand
->flags
& S390_OPERAND_PCREL
)
536 sprint_value (buf
, val
);
537 if (file
== (char *) NULL
)
538 as_bad (err
, buf
, (int) min
, (int) max
);
540 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
543 /* val is ok, now restrict it to operand->bits bits. */
544 uval
= (addressT
) val
& ((((addressT
) 1 << (operand
->bits
-1)) << 1) - 1);
550 max
= (((addressT
) 1 << (operand
->bits
- 1))<<1) - 1;
552 uval
= (addressT
) val
;
553 /* Length x in an instructions has real length x+1. */
554 if (operand
->flags
& S390_OPERAND_LENGTH
)
556 /* Check for underflow / overflow. */
557 if (uval
< min
|| uval
> max
)
560 "operand out of range (%s not between %ld and %ld)";
563 if (operand
->flags
& S390_OPERAND_LENGTH
)
569 sprint_value (buf
, uval
);
570 if (file
== (char *) NULL
)
571 as_bad (err
, buf
, (int) min
, (int) max
);
573 as_bad_where (file
, line
, err
, buf
, (int) min
, (int) max
);
578 /* Insert fragments of the operand byte for byte. */
579 offset
= operand
->shift
+ operand
->bits
;
580 uval
<<= (-offset
) & 7;
581 insn
+= (offset
- 1)/8;
589 /* Structure used to hold suffixes. */
603 elf_suffix_type suffix
;
606 static elf_suffix_type s390_elf_suffix
PARAMS ((char **, expressionS
*));
607 static int s390_exp_compare
PARAMS ((expressionS
*exp1
, expressionS
*exp2
));
608 static elf_suffix_type s390_lit_suffix
609 PARAMS ((char **, expressionS
*, elf_suffix_type
));
612 /* Parse @got/@plt/@gotoff. and return the desired relocation. */
613 static elf_suffix_type
614 s390_elf_suffix (str_p
, exp_p
)
618 static struct map_bfd mapping
[] =
620 { "got", 3, ELF_SUFFIX_GOT
},
621 { "got12", 5, ELF_SUFFIX_GOT
},
622 { "plt", 3, ELF_SUFFIX_PLT
},
623 { "gotent", 6, ELF_SUFFIX_GOTENT
},
624 { NULL
, 0, ELF_SUFFIX_NONE
}
633 return ELF_SUFFIX_NONE
;
636 while (ISALNUM (*str
))
640 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
641 if (len
== ptr
->length
&&
642 strncasecmp (ident
, ptr
->string
, ptr
->length
) == 0)
644 if (exp_p
->X_add_number
!= 0)
645 as_warn (_("identifier+constant@%s means identifier@%s+constant"),
646 ptr
->string
, ptr
->string
);
647 /* Now check for identifier@suffix+constant. */
648 if (*str
== '-' || *str
== '+')
650 char *orig_line
= input_line_pointer
;
653 input_line_pointer
= str
;
654 expression (&new_exp
);
656 switch (new_exp
.X_op
)
658 case O_constant
: /* X_add_number (a constant expression). */
659 exp_p
->X_add_number
+= new_exp
.X_add_number
;
660 str
= input_line_pointer
;
662 case O_symbol
: /* X_add_symbol + X_add_number. */
663 /* this case is used for e.g. xyz@PLT+.Label. */
664 exp_p
->X_add_number
+= new_exp
.X_add_number
;
665 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
667 str
= input_line_pointer
;
669 case O_uminus
: /* (- X_add_symbol) + X_add_number. */
670 /* this case is used for e.g. xyz@PLT-.Label. */
671 exp_p
->X_add_number
+= new_exp
.X_add_number
;
672 exp_p
->X_op_symbol
= new_exp
.X_add_symbol
;
673 exp_p
->X_op
= O_subtract
;
674 str
= input_line_pointer
;
680 /* If s390_elf_suffix has not been called with
681 &input_line_pointer as first parameter, we have
682 clobbered the input_line_pointer. We have to
684 if (&input_line_pointer
!= str_p
)
685 input_line_pointer
= orig_line
;
691 return BFD_RELOC_UNUSED
;
694 /* Structure used to hold a literal pool entry. */
697 struct s390_lpe
*next
;
699 FLONUM_TYPE floatnum
; /* used if X_op == O_big && X_add_number <= 0 */
700 LITTLENUM_TYPE bignum
[4]; /* used if X_op == O_big && X_add_number > 0 */
702 bfd_reloc_code_real_type reloc
;
706 static struct s390_lpe
*lpe_free_list
= NULL
;
707 static struct s390_lpe
*lpe_list
= NULL
;
708 static struct s390_lpe
*lpe_list_tail
= NULL
;
709 static symbolS
*lp_sym
= NULL
;
710 static int lp_count
= 0;
711 static int lpe_count
= 0;
714 s390_exp_compare(exp1
, exp2
)
718 if (exp1
->X_op
!= exp2
->X_op
)
723 case O_constant
: /* X_add_number must be equal. */
725 return exp1
->X_add_number
== exp2
->X_add_number
;
728 as_bad (_("Can't handle O_big in s390_exp_compare"));
730 case O_symbol
: /* X_add_symbol & X_add_number must be equal. */
735 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
) &&
736 (exp1
->X_add_number
== exp2
->X_add_number
);
738 case O_multiply
: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */
743 case O_bit_inclusive_or
:
745 case O_bit_exclusive_or
:
757 return (exp1
->X_add_symbol
== exp2
->X_add_symbol
) &&
758 (exp1
->X_op_symbol
== exp2
->X_op_symbol
) &&
759 (exp1
->X_add_number
== exp2
->X_add_number
);
765 /* Test for @lit and if its present make an entry in the literal pool and
766 modify the current expression to be an offset into the literal pool. */
767 static elf_suffix_type
768 s390_lit_suffix (str_p
, exp_p
, suffix
)
771 elf_suffix_type suffix
;
773 bfd_reloc_code_real_type reloc
;
777 struct s390_lpe
*lpe
;
781 return suffix
; /* No modification. */
783 /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */
785 while (ISALNUM (*str
))
788 if (len
!= 4 || strncasecmp (ident
, "lit", 3) != 0 ||
789 (ident
[3]!='1' && ident
[3]!='2' && ident
[3]!='4' && ident
[3]!='8'))
790 return suffix
; /* no modification */
791 nbytes
= ident
[3] - '0';
793 reloc
= BFD_RELOC_UNUSED
;
794 if (suffix
== ELF_SUFFIX_GOT
)
797 reloc
= BFD_RELOC_390_GOT16
;
798 else if (nbytes
== 4)
799 reloc
= BFD_RELOC_32_GOT_PCREL
;
800 else if (nbytes
== 8)
801 reloc
= BFD_RELOC_390_GOT64
;
803 else if (suffix
== ELF_SUFFIX_PLT
)
806 reloc
= BFD_RELOC_390_PLT32
;
807 else if (nbytes
== 8)
808 reloc
= BFD_RELOC_390_PLT64
;
811 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
812 as_bad (_("Invalid suffix for literal pool entry"));
814 /* Search the pool if the new entry is a duplicate. */
815 if (exp_p
->X_op
== O_big
)
817 /* Special processing for big numbers. */
818 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
820 if (lpe
->ex
.X_op
== O_big
)
822 if (exp_p
->X_add_number
<= 0 && lpe
->ex
.X_add_number
<= 0)
824 if (memcmp (&generic_floating_point_number
, &lpe
->floatnum
,
825 sizeof (FLONUM_TYPE
)) == 0)
828 else if (exp_p
->X_add_number
== lpe
->ex
.X_add_number
)
830 if (memcmp (generic_bignum
, lpe
->bignum
,
831 sizeof (LITTLENUM_TYPE
)*exp_p
->X_add_number
) == 0)
839 /* Processing for 'normal' data types. */
840 for (lpe
= lpe_list
; lpe
!= NULL
; lpe
= lpe
->next
)
841 if (lpe
->nbytes
== nbytes
&& lpe
->reloc
== reloc
&&
842 s390_exp_compare(exp_p
, &lpe
->ex
) != 0)
849 if (lpe_free_list
!= NULL
)
852 lpe_free_list
= lpe_free_list
->next
;
856 lpe
= (struct s390_lpe
*) xmalloc(sizeof (struct s390_lpe
));
861 if (exp_p
->X_op
== O_big
)
863 if (exp_p
->X_add_number
<= 0)
864 lpe
->floatnum
= generic_floating_point_number
;
865 else if (exp_p
->X_add_number
<= 4)
866 memcpy (lpe
->bignum
, generic_bignum
,
867 exp_p
->X_add_number
*sizeof (LITTLENUM_TYPE
));
869 as_bad (_("Big number is too big"));
872 lpe
->nbytes
= nbytes
;
874 /* Literal pool name defined ? */
877 sprintf (tmp_name
, ".L\001%i", lp_count
);
878 lp_sym
= symbol_make(tmp_name
);
881 /* Make name for literal pool entry. */
882 sprintf (tmp_name
, ".L\001%i\002%i", lp_count
, lpe_count
);
884 lpe
->sym
= symbol_make(tmp_name
);
886 /* Add to literal pool list. */
888 if (lpe_list_tail
!= NULL
)
890 lpe_list_tail
->next
= lpe
;
894 lpe_list
= lpe_list_tail
= lpe
;
897 /* Now change exp_p to the offset into the literal pool.
898 Thats the expression: .L^Ax^By-.L^Ax */
899 exp_p
->X_add_symbol
= lpe
->sym
;
900 exp_p
->X_op_symbol
= lp_sym
;
901 exp_p
->X_op
= O_subtract
;
902 exp_p
->X_add_number
= 0;
906 /* We change the suffix type to ELF_SUFFIX_NONE, because
907 the difference of two local labels is just a number. */
908 return ELF_SUFFIX_NONE
;
911 /* Like normal .long/.short/.word, except support @got, etc.
912 clobbers input_line_pointer, checks end-of-line. */
914 s390_elf_cons (nbytes
)
915 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
918 elf_suffix_type suffix
;
920 if (is_it_end_of_statement ())
922 demand_empty_rest_of_line ();
930 if (exp
.X_op
== O_symbol
931 && *input_line_pointer
== '@'
932 && (suffix
= s390_elf_suffix (&input_line_pointer
, &exp
)) != ELF_SUFFIX_NONE
)
934 bfd_reloc_code_real_type reloc
;
935 reloc_howto_type
*reloc_howto
;
939 if (nbytes
== 2 && suffix
== ELF_SUFFIX_GOT
)
940 reloc
= BFD_RELOC_390_GOT16
;
941 else if (nbytes
== 4 && suffix
== ELF_SUFFIX_GOT
)
942 reloc
= BFD_RELOC_32_GOT_PCREL
;
943 else if (nbytes
== 8 && suffix
== ELF_SUFFIX_GOT
)
944 reloc
= BFD_RELOC_390_GOT64
;
945 else if (nbytes
== 4 && suffix
== ELF_SUFFIX_PLT
)
946 reloc
= BFD_RELOC_390_PLT32
;
947 else if (nbytes
== 8 && suffix
== ELF_SUFFIX_PLT
)
948 reloc
= BFD_RELOC_390_PLT64
;
950 reloc
= BFD_RELOC_UNUSED
;
952 if (reloc
!= BFD_RELOC_UNUSED
)
954 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
955 size
= bfd_get_reloc_size (reloc_howto
);
957 as_bad (_("%s relocations do not fit in %d bytes"),
958 reloc_howto
->name
, nbytes
);
959 where
= frag_more (nbytes
);
960 md_number_to_chars (where
, 0, size
);
961 /* To make fixup_segment do the pc relative conversion the
962 pcrel parameter on the fix_new_exp call needs to be false. */
963 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
964 size
, &exp
, false, reloc
);
967 as_bad (_("relocation not applicable"));
970 emit_expr (&exp
, (unsigned int) nbytes
);
972 while (*input_line_pointer
++ == ',');
974 input_line_pointer
--; /* Put terminator back into stream. */
975 demand_empty_rest_of_line ();
978 /* We need to keep a list of fixups. We can't simply generate them as
979 we go, because that would require us to first create the frag, and
980 that would screw up references to ``.''. */
986 bfd_reloc_code_real_type reloc
;
989 #define MAX_INSN_FIXUPS (4)
991 /* This routine is called for each instruction to be assembled. */
994 md_gather_operands (str
, insn
, opcode
)
997 const struct s390_opcode
*opcode
;
999 struct s390_fixup fixups
[MAX_INSN_FIXUPS
];
1000 const struct s390_operand
*operand
;
1001 const unsigned char *opindex_ptr
;
1002 elf_suffix_type suffix
;
1003 bfd_reloc_code_real_type reloc
;
1009 while (ISSPACE (*str
)) str
++;
1014 /* Gather the operands. */
1016 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1021 operand
= s390_operands
+ *opindex_ptr
;
1023 if (skip_optional
&& (operand
->flags
& S390_OPERAND_INDEX
))
1025 /* We do an early skip. For D(X,B) constructions the index
1026 register is skipped (X is optional). For D(L,B) the base
1027 register will be the skipped operand, because L is NOT
1033 /* Gather the operand. */
1034 hold
= input_line_pointer
;
1035 input_line_pointer
= str
;
1037 if (! register_name (&ex
)) /* parse the operand */
1040 str
= input_line_pointer
;
1041 input_line_pointer
= hold
;
1043 /* Write the operand to the insn. */
1044 if (ex
.X_op
== O_illegal
)
1045 as_bad (_("illegal operand"));
1046 else if (ex
.X_op
== O_absent
)
1047 as_bad (_("missing operand"));
1048 else if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
1050 s390_lit_suffix (&str
, &ex
, ELF_SUFFIX_NONE
);
1052 if (ex
.X_op
!= O_register
&& ex
.X_op
!= O_constant
)
1054 /* We need to generate a fixup for the
1055 expression returned by s390_lit_suffix. */
1056 if (fc
>= MAX_INSN_FIXUPS
)
1057 as_fatal (_("too many fixups"));
1058 fixups
[fc
].exp
= ex
;
1059 fixups
[fc
].opindex
= *opindex_ptr
;
1060 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1065 if ((operand
->flags
& S390_OPERAND_INDEX
) && ex
.X_add_number
== 0)
1066 as_warn ("index register specified but zero");
1067 if ((operand
->flags
& S390_OPERAND_BASE
) && ex
.X_add_number
== 0)
1068 as_warn ("base register specified but zero");
1069 s390_insert_operand (insn
, operand
, ex
.X_add_number
, NULL
, 0);
1074 suffix
= s390_elf_suffix (&str
, &ex
);
1075 suffix
= s390_lit_suffix (&str
, &ex
, suffix
);
1076 reloc
= BFD_RELOC_UNUSED
;
1078 if (suffix
== ELF_SUFFIX_GOT
)
1080 if (operand
->flags
& S390_OPERAND_DISP
)
1081 reloc
= BFD_RELOC_390_GOT12
;
1082 else if ((operand
->flags
& S390_OPERAND_SIGNED
) &&
1083 (operand
->bits
== 16))
1084 reloc
= BFD_RELOC_390_GOT16
;
1085 else if ((operand
->flags
& S390_OPERAND_PCREL
) &&
1086 (operand
->bits
== 32))
1087 reloc
= BFD_RELOC_390_GOTENT
;
1089 else if (suffix
== ELF_SUFFIX_PLT
)
1091 if ((operand
->flags
& S390_OPERAND_PCREL
) &&
1092 (operand
->bits
== 16))
1093 reloc
= BFD_RELOC_390_PLT16DBL
;
1094 else if ((operand
->flags
& S390_OPERAND_PCREL
) &&
1095 (operand
->bits
== 32))
1096 reloc
= BFD_RELOC_390_PLT32DBL
;
1098 else if (suffix
== ELF_SUFFIX_GOTENT
)
1100 if ((operand
->flags
& S390_OPERAND_PCREL
) &&
1101 (operand
->bits
== 32))
1102 reloc
= BFD_RELOC_390_GOTENT
;
1105 if (suffix
!= ELF_SUFFIX_NONE
&& reloc
== BFD_RELOC_UNUSED
)
1106 as_bad (_("invalid operand suffix"));
1107 /* We need to generate a fixup of type 'reloc' for this
1109 if (fc
>= MAX_INSN_FIXUPS
)
1110 as_fatal (_("too many fixups"));
1111 fixups
[fc
].exp
= ex
;
1112 fixups
[fc
].opindex
= *opindex_ptr
;
1113 fixups
[fc
].reloc
= reloc
;
1117 /* Check the next character. The call to expression has advanced
1118 str past any whitespace. */
1119 if (operand
->flags
& S390_OPERAND_DISP
)
1121 /* After a displacement a block in parentheses can start. */
1124 /* Check if parethesed block can be skipped. If the next
1125 operand is neiter an optional operand nor a base register
1126 then we have a syntax error. */
1127 operand
= s390_operands
+ *(++opindex_ptr
);
1128 if (!(operand
->flags
& (S390_OPERAND_INDEX
|S390_OPERAND_BASE
)))
1129 as_bad (_("syntax error; missing '(' after displacement"));
1131 /* Ok, skip all operands until S390_OPERAND_BASE. */
1132 while (!(operand
->flags
& S390_OPERAND_BASE
))
1133 operand
= s390_operands
+ *(++opindex_ptr
);
1135 /* If there is a next operand it must be seperated by a comma. */
1136 if (opindex_ptr
[1] != '\0')
1139 as_bad (_("syntax error; expected ,"));
1144 /* We found an opening parentheses. */
1146 for (f
= str
; *f
!= '\0'; f
++)
1147 if (*f
== ',' || *f
== ')')
1149 /* If there is no comma until the closing parentheses OR
1150 there is a comma right after the opening parentheses,
1151 we have to skip optional operands. */
1152 if (*f
== ',' && f
== str
)
1154 /* comma directly after '(' ? */
1159 skip_optional
= (*f
!= ',');
1162 else if (operand
->flags
& S390_OPERAND_BASE
)
1164 /* After the base register the parenthesed block ends. */
1166 as_bad (_("syntax error; missing ')' after base register"));
1168 /* If there is a next operand it must be seperated by a comma. */
1169 if (opindex_ptr
[1] != '\0')
1172 as_bad (_("syntax error; expected ,"));
1177 /* We can find an 'early' closing parentheses in e.g. D(L) instead
1178 of D(L,B). In this case the base register has to be skipped. */
1181 operand
= s390_operands
+ *(++opindex_ptr
);
1183 if (!(operand
->flags
& S390_OPERAND_BASE
))
1184 as_bad (_("syntax error; ')' not allowed here"));
1187 /* If there is a next operand it must be seperated by a comma. */
1188 if (opindex_ptr
[1] != '\0')
1191 as_bad (_("syntax error; expected ,"));
1196 while (ISSPACE (*str
))
1203 if ((linefeed
= strchr (str
, '\n')) != NULL
)
1205 as_bad (_("junk at end of line: `%s'"), str
);
1206 if (linefeed
!= NULL
)
1210 /* Write out the instruction. */
1211 f
= frag_more (opcode
->oplen
);
1212 memcpy (f
, insn
, opcode
->oplen
);
1214 /* Create any fixups. At this point we do not use a
1215 bfd_reloc_code_real_type, but instead just use the
1216 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1217 handle fixups for any operand type, although that is admittedly
1218 not a very exciting feature. We pick a BFD reloc type in
1220 for (i
= 0; i
< fc
; i
++)
1222 operand
= s390_operands
+ fixups
[i
].opindex
;
1224 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1226 reloc_howto_type
*reloc_howto
;
1230 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1234 size
= bfd_get_reloc_size (reloc_howto
);
1236 if (size
< 1 || size
> 4)
1239 fixP
= fix_new_exp (frag_now
,
1240 f
- frag_now
->fr_literal
+ (operand
->shift
/8),
1241 size
, &fixups
[i
].exp
, reloc_howto
->pc_relative
,
1243 /* Turn off overflow checking in fixup_segment. This is necessary
1244 because fixup_segment will signal an overflow for large 4 byte
1245 quantities for GOT12 relocations. */
1246 if (fixups
[i
].reloc
== BFD_RELOC_390_GOT12
||
1247 fixups
[i
].reloc
== BFD_RELOC_390_GOT16
)
1248 fixP
->fx_no_overflow
= 1;
1251 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4, &fixups
[i
].exp
,
1252 (operand
->flags
& S390_OPERAND_PCREL
) != 0,
1253 ((bfd_reloc_code_real_type
)
1254 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1259 /* This routine is called for each instruction to be assembled. */
1265 const struct s390_opcode
*opcode
;
1266 unsigned char insn
[6];
1269 /* Get the opcode. */
1270 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1275 /* Look up the opcode in the hash table. */
1276 opcode
= (struct s390_opcode
*) hash_find (s390_opcode_hash
, str
);
1277 if (opcode
== (const struct s390_opcode
*) NULL
)
1279 as_bad (_("Unrecognized opcode: `%s'"), str
);
1282 else if (!(opcode
->architecture
& current_arch_mask
))
1284 as_bad ("Opcode %s not available in this architecture", str
);
1288 memcpy (insn
, opcode
->opcode
, sizeof (insn
));
1289 md_gather_operands (s
, insn
, opcode
);
1292 #ifndef WORKING_DOT_WORD
1293 /* Handle long and short jumps. We don't support these */
1295 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1297 addressT from_addr
, to_addr
;
1305 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1307 addressT from_addr
, to_addr
;
1317 int ignore ATTRIBUTE_UNUSED
;
1319 /* We don't support putting frags in the BSS segment, we fake it
1320 by marking in_bss, then looking at s_skip for clues. */
1322 subseg_set (bss_section
, 0);
1323 demand_empty_rest_of_line ();
1326 /* Pseudo-op handling. */
1330 int ignore ATTRIBUTE_UNUSED
;
1333 const struct s390_opcode
*opformat
;
1334 unsigned char insn
[6];
1337 /* Get the opcode format. */
1338 s
= input_line_pointer
;
1339 while (*s
!= '\0' && *s
!= ',' && ! ISSPACE (*s
))
1342 as_bad (_("Invalid .insn format\n"));
1345 /* Look up the opcode in the hash table. */
1346 opformat
= (struct s390_opcode
*)
1347 hash_find (s390_opformat_hash
, input_line_pointer
);
1348 if (opformat
== (const struct s390_opcode
*) NULL
)
1350 as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer
);
1353 input_line_pointer
= s
;
1355 if (exp
.X_op
== O_constant
)
1357 if ((opformat
->oplen
== 6 && exp
.X_op
> 0 && exp
.X_op
< (1ULL << 48)) ||
1358 (opformat
->oplen
== 4 && exp
.X_op
> 0 && exp
.X_op
< (1ULL << 32)) ||
1359 (opformat
->oplen
== 2 && exp
.X_op
> 0 && exp
.X_op
< (1ULL << 16)))
1360 md_number_to_chars (insn
, exp
.X_add_number
, opformat
->oplen
);
1362 as_bad (_("Invalid .insn format\n"));
1364 else if (exp
.X_op
== O_big
)
1366 if (exp
.X_add_number
> 0 &&
1367 opformat
->oplen
== 6 &&
1368 generic_bignum
[3] == 0)
1370 md_number_to_chars (insn
, generic_bignum
[2], 2);
1371 md_number_to_chars (&insn
[2], generic_bignum
[1], 2);
1372 md_number_to_chars (&insn
[4], generic_bignum
[0], 2);
1375 as_bad (_("Invalid .insn format\n"));
1378 as_bad (_("second operand of .insn not a constant\n"));
1380 if (strcmp (opformat
->name
, "e") != 0 && *input_line_pointer
++ != ',')
1381 as_bad (_("missing comma after insn constant\n"));
1383 if ((s
= strchr (input_line_pointer
, '\n')) != NULL
)
1385 input_line_pointer
= md_gather_operands (input_line_pointer
, insn
,
1389 demand_empty_rest_of_line ();
1392 /* The .byte pseudo-op. This is similar to the normal .byte
1393 pseudo-op, but it can also take a single ASCII string. */
1397 int ignore ATTRIBUTE_UNUSED
;
1399 if (*input_line_pointer
!= '\"')
1405 /* Gather characters. A real double quote is doubled. Unusual
1406 characters are not permitted. */
1407 ++input_line_pointer
;
1412 c
= *input_line_pointer
++;
1416 if (*input_line_pointer
!= '\"')
1418 ++input_line_pointer
;
1421 FRAG_APPEND_1_CHAR (c
);
1424 demand_empty_rest_of_line ();
1427 /* The .ltorg pseudo-op.This emits all literals defined since the last
1428 .ltorg or the invocation of gas. Literals are defined with the
1432 s390_literals (ignore
)
1433 int ignore ATTRIBUTE_UNUSED
;
1435 struct s390_lpe
*lpe
;
1437 if (lp_sym
== NULL
|| lpe_count
== 0)
1438 return; /* nothing to be done */
1440 /* Emit symbol for start of literal pool. */
1441 S_SET_SEGMENT (lp_sym
, now_seg
);
1442 S_SET_VALUE (lp_sym
, (valueT
) frag_now_fix ());
1443 lp_sym
->sy_frag
= frag_now
;
1448 lpe_list
= lpe_list
->next
;
1449 S_SET_SEGMENT (lpe
->sym
, now_seg
);
1450 S_SET_VALUE (lpe
->sym
, (valueT
) frag_now_fix ());
1451 lpe
->sym
->sy_frag
= frag_now
;
1453 /* Emit literal pool entry. */
1454 if (lpe
->reloc
!= BFD_RELOC_UNUSED
)
1456 reloc_howto_type
*reloc_howto
=
1457 bfd_reloc_type_lookup (stdoutput
, lpe
->reloc
);
1458 int size
= bfd_get_reloc_size (reloc_howto
);
1461 if (size
> lpe
->nbytes
)
1462 as_bad (_("%s relocations do not fit in %d bytes"),
1463 reloc_howto
->name
, lpe
->nbytes
);
1464 where
= frag_more (lpe
->nbytes
);
1465 md_number_to_chars (where
, 0, size
);
1466 fix_new_exp (frag_now
, where
- frag_now
->fr_literal
,
1467 size
, &lpe
->ex
, reloc_howto
->pc_relative
, lpe
->reloc
);
1471 if (lpe
->ex
.X_op
== O_big
)
1473 if (lpe
->ex
.X_add_number
<= 0)
1474 generic_floating_point_number
= lpe
->floatnum
;
1476 memcpy (generic_bignum
, lpe
->bignum
,
1477 lpe
->ex
.X_add_number
*sizeof (LITTLENUM_TYPE
));
1479 emit_expr (&lpe
->ex
, lpe
->nbytes
);
1482 lpe
->next
= lpe_free_list
;
1483 lpe_free_list
= lpe
;
1485 lpe_list_tail
= NULL
;
1491 /* Turn a string in input_line_pointer into a floating point constant
1492 of type type, and store the appropriate bytes in *litp. The number
1493 of LITTLENUMS emitted is stored in *sizep . An error message is
1494 returned, or NULL on OK. */
1497 md_atof (type
, litp
, sizep
)
1503 LITTLENUM_TYPE words
[4];
1519 return "bad call to md_atof";
1522 t
= atof_ieee (input_line_pointer
, type
, words
);
1524 input_line_pointer
= t
;
1528 for (i
= 0; i
< prec
; i
++)
1530 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1537 /* Align a section (I don't know why this is machine dependent). */
1540 md_section_align (seg
, addr
)
1544 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1546 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1549 /* We don't have any form of relaxing. */
1552 md_estimate_size_before_relax (fragp
, seg
)
1553 fragS
*fragp ATTRIBUTE_UNUSED
;
1554 asection
*seg ATTRIBUTE_UNUSED
;
1560 /* Convert a machine dependent frag. We never generate these. */
1563 md_convert_frag (abfd
, sec
, fragp
)
1564 bfd
*abfd ATTRIBUTE_UNUSED
;
1565 asection
*sec ATTRIBUTE_UNUSED
;
1566 fragS
*fragp ATTRIBUTE_UNUSED
;
1572 md_undefined_symbol (name
)
1575 if (*name
== '_' && *(name
+1) == 'G'
1576 && strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
1580 if (symbol_find (name
))
1581 as_bad (_("GOT already in symbol table"));
1582 GOT_symbol
= symbol_new (name
, undefined_section
,
1583 (valueT
) 0, &zero_address_frag
);
1590 /* Functions concerning relocs. */
1592 /* The location from which a PC relative jump should be calculated,
1593 given a PC relative reloc. */
1596 md_pcrel_from_section (fixp
, sec
)
1598 segT sec ATTRIBUTE_UNUSED
;
1600 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1603 /* Here we decide which fixups can be adjusted to make them relative to
1604 the beginning of the section instead of the symbol. Basically we need
1605 to make sure that the dynamic relocations are done correctly, so in
1606 some cases we force the original symbol to be used. */
1608 tc_s390_fix_adjustable(fixP
)
1611 /* Prevent all adjustments to global symbols. */
1612 if (S_IS_EXTERN (fixP
->fx_addsy
))
1614 if (S_IS_WEAK (fixP
->fx_addsy
))
1616 /* adjust_reloc_syms doesn't know about the GOT. */
1617 if (fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
1618 || fixP
->fx_r_type
== BFD_RELOC_390_PLT16DBL
1619 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32
1620 || fixP
->fx_r_type
== BFD_RELOC_390_PLT32DBL
1621 || fixP
->fx_r_type
== BFD_RELOC_390_PLT64
1622 || fixP
->fx_r_type
== BFD_RELOC_390_GOT12
1623 || fixP
->fx_r_type
== BFD_RELOC_390_GOT16
1624 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
1625 || fixP
->fx_r_type
== BFD_RELOC_390_GOT64
1626 || fixP
->fx_r_type
== BFD_RELOC_390_GOTENT
1627 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1628 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1633 /* Apply a fixup to the object code. This is called for all the
1634 fixups we generated by the call to fix_new_exp, above. In the call
1635 above we used a reloc code which was the largest legal reloc code
1636 plus the operand index. Here we undo that to recover the operand
1637 index. At this point all symbol values should be fully resolved,
1638 and we attempt to completely resolve the reloc. If we can not do
1639 that, we determine the correct reloc code and put it back in the
1643 md_apply_fix3 (fixp
, valuep
, seg
)
1646 segT seg ATTRIBUTE_UNUSED
;
1652 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1654 if (fixp
->fx_subsy
!= NULL
)
1656 if (!S_IS_DEFINED (fixp
->fx_subsy
))
1657 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1658 _("unresolved fx_subsy symbol that must be resolved"));
1659 value
-= S_GET_VALUE(fixp
->fx_subsy
);
1662 if (fixp
->fx_addsy
!= NULL
)
1664 /* `*valuep' may contain the value of the symbol on which the reloc
1665 will be based; we have to remove it. */
1666 if (fixp
->fx_addsy
->sy_used_in_reloc
1667 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
1668 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
1669 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
1670 value
-= S_GET_VALUE (fixp
->fx_addsy
);
1673 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1678 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1680 const struct s390_operand
*operand
;
1683 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1684 operand
= &s390_operands
[opindex
];
1688 /* Insert the fully resolved operand value. */
1689 s390_insert_operand (where
, operand
, (offsetT
) value
,
1690 fixp
->fx_file
, fixp
->fx_line
);
1695 /* Determine a BFD reloc value based on the operand information.
1696 We are only prepared to turn a few of the operands into
1698 fixp
->fx_offset
= value
;
1699 if (operand
->bits
== 12 && operand
->shift
== 20)
1702 fixp
->fx_where
+= 2;
1703 fixp
->fx_r_type
= BFD_RELOC_390_12
;
1705 else if (operand
->bits
== 12 && operand
->shift
== 36)
1708 fixp
->fx_where
+= 4;
1709 fixp
->fx_r_type
= BFD_RELOC_390_12
;
1711 else if (operand
->bits
== 8 && operand
->shift
== 8)
1714 fixp
->fx_where
+= 1;
1715 fixp
->fx_r_type
= BFD_RELOC_8
;
1717 else if (operand
->bits
== 16 && operand
->shift
== 16)
1720 fixp
->fx_where
+= 2;
1721 if (operand
->flags
& S390_OPERAND_PCREL
)
1723 fixp
->fx_r_type
= BFD_RELOC_390_PC16DBL
;
1724 fixp
->fx_offset
+= 2;
1727 fixp
->fx_r_type
= BFD_RELOC_16
;
1729 else if (operand
->bits
== 32 && operand
->shift
== 16 &&
1730 (operand
->flags
& S390_OPERAND_PCREL
))
1733 fixp
->fx_where
+= 2;
1734 fixp
->fx_offset
+= 2;
1735 fixp
->fx_r_type
= BFD_RELOC_390_PC32DBL
;
1742 /* Use expr_symbol_where to see if this is an expression
1744 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
1745 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1746 _("unresolved expression that must be resolved"));
1748 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1749 _("unsupported relocation type"));
1756 switch (fixp
->fx_r_type
)
1762 md_number_to_chars (where
, value
, 1);
1764 case BFD_RELOC_390_12
:
1765 case BFD_RELOC_390_GOT12
:
1770 mop
= bfd_getb16 ((unsigned char *) where
);
1771 mop
|= (unsigned short) (value
& 0xfff);
1772 bfd_putb16 ((bfd_vma
) mop
, (unsigned char *) where
);
1777 case BFD_RELOC_GPREL16
:
1778 case BFD_RELOC_16_GOT_PCREL
:
1779 case BFD_RELOC_16_GOTOFF
:
1781 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1782 "cannot emit PC relative %s relocation%s%s",
1783 bfd_get_reloc_code_name (fixp
->fx_r_type
),
1784 fixp
->fx_addsy
!= NULL
? " against " : "",
1785 (fixp
->fx_addsy
!= NULL
1786 ? S_GET_NAME (fixp
->fx_addsy
)
1789 md_number_to_chars (where
, value
, 2);
1791 case BFD_RELOC_390_GOT16
:
1793 md_number_to_chars (where
, value
, 2);
1795 case BFD_RELOC_390_PC16DBL
:
1796 case BFD_RELOC_390_PLT16DBL
:
1799 md_number_to_chars (where
, (offsetT
) value
>> 1, 2);
1804 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
1806 fixp
->fx_r_type
= BFD_RELOC_32
;
1808 md_number_to_chars (where
, value
, 4);
1810 case BFD_RELOC_32_PCREL
:
1811 case BFD_RELOC_32_BASEREL
:
1812 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
1814 md_number_to_chars (where
, value
, 4);
1816 case BFD_RELOC_32_GOT_PCREL
:
1817 case BFD_RELOC_390_PLT32
:
1819 md_number_to_chars (where
, value
, 4);
1821 case BFD_RELOC_390_PC32DBL
:
1822 case BFD_RELOC_390_PLT32DBL
:
1823 case BFD_RELOC_390_GOTPCDBL
:
1824 case BFD_RELOC_390_GOTENT
:
1827 md_number_to_chars (where
, (offsetT
) value
>> 1, 4);
1830 case BFD_RELOC_32_GOTOFF
:
1832 md_number_to_chars (where
, value
, sizeof (int));
1835 case BFD_RELOC_390_GOT64
:
1836 case BFD_RELOC_390_PLT64
:
1838 md_number_to_chars (where
, value
, 8);
1843 fixp
->fx_r_type
= BFD_RELOC_64_PCREL
;
1845 fixp
->fx_r_type
= BFD_RELOC_64
;
1847 md_number_to_chars (where
, value
, 8);
1850 case BFD_RELOC_64_PCREL
:
1851 fixp
->fx_r_type
= BFD_RELOC_64_PCREL
;
1853 md_number_to_chars (where
, value
, 8);
1856 case BFD_RELOC_VTABLE_INHERIT
:
1857 case BFD_RELOC_VTABLE_ENTRY
:
1863 const char *reloc_name
= bfd_get_reloc_code_name (fixp
->fx_r_type
);
1865 if (reloc_name
!= NULL
)
1866 fprintf (stderr
, "Gas failure, reloc type %s\n", reloc_name
);
1868 fprintf (stderr
, "Gas failure, reloc type #%i\n", fixp
->fx_r_type
);
1874 fixp
->fx_offset
= value
;
1880 /* Generate a reloc for a fixup. */
1883 tc_gen_reloc (seg
, fixp
)
1884 asection
*seg ATTRIBUTE_UNUSED
;
1887 bfd_reloc_code_real_type code
;
1890 code
= fixp
->fx_r_type
;
1891 if (GOT_symbol
&& fixp
->fx_addsy
== GOT_symbol
)
1893 if ((s390_arch_size
== 32 && code
== BFD_RELOC_32_PCREL
) ||
1894 (s390_arch_size
== 64 && code
== BFD_RELOC_64_PCREL
))
1895 code
= BFD_RELOC_390_GOTPC
;
1896 if (code
== BFD_RELOC_390_PC32DBL
)
1897 code
= BFD_RELOC_390_GOTPCDBL
;
1900 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1901 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1902 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1903 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1904 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
1905 if (reloc
->howto
== NULL
)
1907 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1908 _("cannot represent relocation type %s"),
1909 bfd_get_reloc_code_name (code
));
1910 /* Set howto to a garbage value so that we can keep going. */
1911 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
1912 assert (reloc
->howto
!= NULL
);
1914 reloc
->addend
= fixp
->fx_offset
;