1 /* BFD back-end for Sparc COFF files.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "coff/sparc.h"
26 #include "coff/internal.h"
29 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
31 #define BADMAG(x) ((x).f_magic != SPARCMAGIC && (x).f_magic != LYNXCOFFMAGIC)
33 /* The page size is a guess based on ELF. */
34 #define COFF_PAGE_SIZE 0x10000
39 R_SPARC_8
, R_SPARC_16
, R_SPARC_32
,
40 R_SPARC_DISP8
, R_SPARC_DISP16
, R_SPARC_DISP32
,
41 R_SPARC_WDISP30
, R_SPARC_WDISP22
,
42 R_SPARC_HI22
, R_SPARC_22
,
43 R_SPARC_13
, R_SPARC_LO10
,
44 R_SPARC_GOT10
, R_SPARC_GOT13
, R_SPARC_GOT22
,
45 R_SPARC_PC10
, R_SPARC_PC22
,
48 R_SPARC_GLOB_DAT
, R_SPARC_JMP_SLOT
,
55 static CONST
char *CONST reloc_type_names
[] =
58 "R_SPARC_8", "R_SPARC_16", "R_SPARC_32",
59 "R_SPARC_DISP8", "R_SPARC_DISP16", "R_SPARC_DISP32",
60 "R_SPARC_WDISP30", "R_SPARC_WDISP22",
61 "R_SPARC_HI22", "R_SPARC_22",
62 "R_SPARC_13", "R_SPARC_LO10",
63 "R_SPARC_GOT10", "R_SPARC_GOT13", "R_SPARC_GOT22",
64 "R_SPARC_PC10", "R_SPARC_PC22",
67 "R_SPARC_GLOB_DAT", "R_SPARC_JMP_SLOT",
73 /* This is stolen pretty directly from elf.c. */
74 static bfd_reloc_status_type
75 bfd_coff_generic_reloc
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
76 asection
*, bfd
*, char **));
78 static bfd_reloc_status_type
79 bfd_coff_generic_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
80 output_bfd
, error_message
)
81 bfd
*abfd ATTRIBUTE_UNUSED
;
84 PTR data ATTRIBUTE_UNUSED
;
85 asection
*input_section
;
87 char **error_message ATTRIBUTE_UNUSED
;
89 if (output_bfd
!= (bfd
*) NULL
90 && (symbol
->flags
& BSF_SECTION_SYM
) == 0)
92 reloc_entry
->address
+= input_section
->output_offset
;
96 return bfd_reloc_continue
;
99 static reloc_howto_type coff_sparc_howto_table
[] =
101 HOWTO(R_SPARC_NONE
, 0,0, 0,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_NONE", false,0,0x00000000,true),
102 HOWTO(R_SPARC_8
, 0,0, 8,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_8", false,0,0x000000ff,true),
103 HOWTO(R_SPARC_16
, 0,1,16,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_16", false,0,0x0000ffff,true),
104 HOWTO(R_SPARC_32
, 0,2,32,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_32", false,0,0xffffffff,true),
105 HOWTO(R_SPARC_DISP8
, 0,0, 8,true, 0,complain_overflow_signed
, bfd_coff_generic_reloc
,"R_SPARC_DISP8", false,0,0x000000ff,true),
106 HOWTO(R_SPARC_DISP16
, 0,1,16,true, 0,complain_overflow_signed
, bfd_coff_generic_reloc
,"R_SPARC_DISP16", false,0,0x0000ffff,true),
107 HOWTO(R_SPARC_DISP32
, 0,2,32,true, 0,complain_overflow_signed
, bfd_coff_generic_reloc
,"R_SPARC_DISP32", false,0,0x00ffffff,true),
108 HOWTO(R_SPARC_WDISP30
, 2,2,30,true, 0,complain_overflow_signed
, bfd_coff_generic_reloc
,"R_SPARC_WDISP30", false,0,0x3fffffff,true),
109 HOWTO(R_SPARC_WDISP22
, 2,2,22,true, 0,complain_overflow_signed
, bfd_coff_generic_reloc
,"R_SPARC_WDISP22", false,0,0x003fffff,true),
110 HOWTO(R_SPARC_HI22
, 10,2,22,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_HI22", false,0,0x003fffff,true),
111 HOWTO(R_SPARC_22
, 0,2,22,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_22", false,0,0x003fffff,true),
112 HOWTO(R_SPARC_13
, 0,2,13,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_13", false,0,0x00001fff,true),
113 HOWTO(R_SPARC_LO10
, 0,2,10,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_LO10", false,0,0x000003ff,true),
114 HOWTO(R_SPARC_GOT10
, 0,2,10,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_GOT10", false,0,0x000003ff,true),
115 HOWTO(R_SPARC_GOT13
, 0,2,13,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_GOT13", false,0,0x00001fff,true),
116 HOWTO(R_SPARC_GOT22
, 10,2,22,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_GOT22", false,0,0x003fffff,true),
117 HOWTO(R_SPARC_PC10
, 0,2,10,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_PC10", false,0,0x000003ff,true),
118 HOWTO(R_SPARC_PC22
, 0,2,22,false,0,complain_overflow_bitfield
,bfd_coff_generic_reloc
,"R_SPARC_PC22", false,0,0x003fffff,true),
119 HOWTO(R_SPARC_WPLT30
, 0,0,00,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_WPLT30", false,0,0x00000000,true),
120 HOWTO(R_SPARC_COPY
, 0,0,00,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_COPY", false,0,0x00000000,true),
121 HOWTO(R_SPARC_GLOB_DAT
,0,0,00,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_GLOB_DAT",false,0,0x00000000,true),
122 HOWTO(R_SPARC_JMP_SLOT
,0,0,00,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_JMP_SLOT",false,0,0x00000000,true),
123 HOWTO(R_SPARC_RELATIVE
,0,0,00,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_RELATIVE",false,0,0x00000000,true),
124 HOWTO(R_SPARC_UA32
, 0,0,00,false,0,complain_overflow_dont
, bfd_coff_generic_reloc
,"R_SPARC_UA32", false,0,0x00000000,true),
127 struct coff_reloc_map
{
128 bfd_reloc_code_real_type bfd_reloc_val
;
129 unsigned char coff_reloc_val
;
132 static CONST
struct coff_reloc_map sparc_reloc_map
[] =
134 { BFD_RELOC_NONE
, R_SPARC_NONE
, },
135 { BFD_RELOC_16
, R_SPARC_16
, },
136 { BFD_RELOC_8
, R_SPARC_8
},
137 { BFD_RELOC_8_PCREL
, R_SPARC_DISP8
},
138 { BFD_RELOC_CTOR
, R_SPARC_32
}, /* @@ Assumes 32 bits. */
139 { BFD_RELOC_32
, R_SPARC_32
},
140 { BFD_RELOC_32_PCREL
, R_SPARC_DISP32
},
141 { BFD_RELOC_HI22
, R_SPARC_HI22
},
142 { BFD_RELOC_LO10
, R_SPARC_LO10
, },
143 { BFD_RELOC_32_PCREL_S2
, R_SPARC_WDISP30
},
144 { BFD_RELOC_SPARC22
, R_SPARC_22
},
145 { BFD_RELOC_SPARC13
, R_SPARC_13
},
146 { BFD_RELOC_SPARC_GOT10
, R_SPARC_GOT10
},
147 { BFD_RELOC_SPARC_GOT13
, R_SPARC_GOT13
},
148 { BFD_RELOC_SPARC_GOT22
, R_SPARC_GOT22
},
149 { BFD_RELOC_SPARC_PC10
, R_SPARC_PC10
},
150 { BFD_RELOC_SPARC_PC22
, R_SPARC_PC22
},
151 { BFD_RELOC_SPARC_WPLT30
, R_SPARC_WPLT30
},
152 { BFD_RELOC_SPARC_COPY
, R_SPARC_COPY
},
153 { BFD_RELOC_SPARC_GLOB_DAT
, R_SPARC_GLOB_DAT
},
154 { BFD_RELOC_SPARC_JMP_SLOT
, R_SPARC_JMP_SLOT
},
155 { BFD_RELOC_SPARC_RELATIVE
, R_SPARC_RELATIVE
},
156 { BFD_RELOC_SPARC_WDISP22
, R_SPARC_WDISP22
},
157 /* { BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
160 static reloc_howto_type
*
161 coff_sparc_reloc_type_lookup (abfd
, code
)
162 bfd
*abfd ATTRIBUTE_UNUSED
;
163 bfd_reloc_code_real_type code
;
166 for (i
= 0; i
< sizeof (sparc_reloc_map
) / sizeof (struct coff_reloc_map
); i
++)
168 if (sparc_reloc_map
[i
].bfd_reloc_val
== code
)
169 return &coff_sparc_howto_table
[(int) sparc_reloc_map
[i
].coff_reloc_val
];
173 #define coff_bfd_reloc_type_lookup coff_sparc_reloc_type_lookup
176 rtype2howto (cache_ptr
, dst
)
178 struct internal_reloc
*dst
;
180 BFD_ASSERT (dst
->r_type
< (unsigned int) R_SPARC_max
);
181 cache_ptr
->howto
= &coff_sparc_howto_table
[dst
->r_type
];
184 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
186 #define SWAP_IN_RELOC_OFFSET bfd_h_get_32
187 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
188 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
189 cache_ptr->addend = reloc.r_offset;
191 /* Clear the r_spare field in relocs. */
192 #define SWAP_OUT_RELOC_EXTRA(abfd,src,dst) \
194 dst->r_spare[0] = 0; \
195 dst->r_spare[1] = 0; \
198 #define __A_MAGIC_SET__
200 /* Enable Sparc-specific hacks in coffcode.h. */
204 #include "coffcode.h"
207 #define TARGET_SYM sparccoff_vec
211 #define TARGET_NAME "coff-sparc"
214 CREATE_BIG_COFF_TARGET_VEC (TARGET_SYM
, TARGET_NAME
, D_PAGED
, 0, '_', NULL
)