1 /* SPARC-specific support for 32-bit ELF
2 Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "elf/sparc.h"
27 static reloc_howto_type
*elf32_sparc_reloc_type_lookup
28 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
29 static void elf32_sparc_info_to_howto
30 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
31 static boolean elf32_sparc_check_relocs
32 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
33 const Elf_Internal_Rela
*));
34 static boolean elf32_sparc_adjust_dynamic_symbol
35 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
36 static boolean elf32_sparc_adjust_dynindx
37 PARAMS ((struct elf_link_hash_entry
*, PTR
));
38 static boolean elf32_sparc_size_dynamic_sections
39 PARAMS ((bfd
*, struct bfd_link_info
*));
40 static boolean elf32_sparc_relocate_section
41 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
42 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
43 static boolean elf32_sparc_finish_dynamic_symbol
44 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
46 static boolean elf32_sparc_finish_dynamic_sections
47 PARAMS ((bfd
*, struct bfd_link_info
*));
48 static boolean elf32_sparc_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
49 static boolean elf32_sparc_object_p
51 static void elf32_sparc_final_write_processing
52 PARAMS ((bfd
*, boolean
));
54 /* The howto table and associated functions.
55 ??? elf64-sparc.c has its own copy for the moment to ease transition
56 since some of the relocation values have changed. At some point we'll
57 want elf64-sparc.c to switch over and use this table.
58 ??? Do we want to recognize (or flag as errors) some of the 64 bit entries
59 if the target is elf32-sparc.
62 static bfd_reloc_status_type sparc_elf_notsupported_reloc
63 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
64 static bfd_reloc_status_type sparc_elf_wdisp16_reloc
65 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
67 reloc_howto_type _bfd_sparc_elf_howto_table
[] =
69 HOWTO(R_SPARC_NONE
, 0,0, 0,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_NONE", false,0,0x00000000,true),
70 HOWTO(R_SPARC_8
, 0,0, 8,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_8", false,0,0x000000ff,true),
71 HOWTO(R_SPARC_16
, 0,1,16,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_16", false,0,0x0000ffff,true),
72 HOWTO(R_SPARC_32
, 0,2,32,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_32", false,0,0xffffffff,true),
73 HOWTO(R_SPARC_DISP8
, 0,0, 8,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP8", false,0,0x000000ff,true),
74 HOWTO(R_SPARC_DISP16
, 0,1,16,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP16", false,0,0x0000ffff,true),
75 HOWTO(R_SPARC_DISP32
, 0,2,32,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP32", false,0,0x00ffffff,true),
76 HOWTO(R_SPARC_WDISP30
, 2,2,30,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP30", false,0,0x3fffffff,true),
77 HOWTO(R_SPARC_WDISP22
, 2,2,22,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP22", false,0,0x003fffff,true),
78 HOWTO(R_SPARC_HI22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HI22", false,0,0x003fffff,true),
79 HOWTO(R_SPARC_22
, 0,2,22,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_22", false,0,0x003fffff,true),
80 HOWTO(R_SPARC_13
, 0,2,13,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_13", false,0,0x00001fff,true),
81 HOWTO(R_SPARC_LO10
, 0,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LO10", false,0,0x000003ff,true),
82 HOWTO(R_SPARC_GOT10
, 0,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GOT10", false,0,0x000003ff,true),
83 HOWTO(R_SPARC_GOT13
, 0,2,13,false,0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_GOT13", false,0,0x00001fff,true),
84 HOWTO(R_SPARC_GOT22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GOT22", false,0,0x003fffff,true),
85 HOWTO(R_SPARC_PC10
, 0,2,10,true, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_PC10", false,0,0x000003ff,true),
86 HOWTO(R_SPARC_PC22
, 10,2,22,true, 0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_PC22", false,0,0x003fffff,true),
87 HOWTO(R_SPARC_WPLT30
, 2,2,30,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WPLT30", false,0,0x3fffffff,true),
88 HOWTO(R_SPARC_COPY
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_COPY", false,0,0x00000000,true),
89 HOWTO(R_SPARC_GLOB_DAT
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GLOB_DAT",false,0,0x00000000,true),
90 HOWTO(R_SPARC_JMP_SLOT
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_JMP_SLOT",false,0,0x00000000,true),
91 HOWTO(R_SPARC_RELATIVE
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_RELATIVE",false,0,0x00000000,true),
92 HOWTO(R_SPARC_UA32
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_UA32", false,0,0x00000000,true),
93 HOWTO(R_SPARC_PLT32
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_PLT32", false,0,0x00000000,true),
94 HOWTO(R_SPARC_HIPLT22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_HIPLT22", false,0,0x00000000,true),
95 HOWTO(R_SPARC_LOPLT10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_LOPLT10", false,0,0x00000000,true),
96 HOWTO(R_SPARC_PCPLT32
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_PCPLT32", false,0,0x00000000,true),
97 HOWTO(R_SPARC_PCPLT22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_PCPLT22", false,0,0x00000000,true),
98 HOWTO(R_SPARC_PCPLT10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_PCPLT10", false,0,0x00000000,true),
99 HOWTO(R_SPARC_10
, 0,2,10,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_10", false,0,0x000003ff,true),
100 HOWTO(R_SPARC_11
, 0,2,11,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_11", false,0,0x000007ff,true),
101 /* ??? If we need to handle R_SPARC_64 then we need (figuratively)
102 --enable-64-bit-bfd. That causes objdump to print address as 64 bits
103 which we really don't want on an elf32-sparc system. There may be other
104 consequences which we may not want (at least not until it's proven they're
105 necessary) so for now these are only enabled ifdef BFD64. */
107 HOWTO(R_SPARC_64
, 0,4,00,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_64", false,0,~ (bfd_vma
) 0, true),
108 /* ??? These don't make sense except in 64 bit systems so they're disabled
109 ifndef BFD64 too (for now). */
110 HOWTO(R_SPARC_OLO10
, 0,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_OLO10", false,0,0x000003ff,true),
111 HOWTO(R_SPARC_HH22
, 42,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HH22", false,0,0x003fffff,true),
112 HOWTO(R_SPARC_HM10
, 32,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HM10", false,0,0x000003ff,true),
113 HOWTO(R_SPARC_LM22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LM22", false,0,0x003fffff,true),
114 HOWTO(R_SPARC_PC_HH22
, 42,2,22,true, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HH22", false,0,0x003fffff,true),
115 HOWTO(R_SPARC_PC_HM10
, 32,2,10,true, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HM10", false,0,0x000003ff,true),
116 HOWTO(R_SPARC_PC_LM22
, 10,2,22,true, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LM22", false,0,0x003fffff,true),
118 HOWTO(R_SPARC_64
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_64", false,0,0x00000000,true),
119 HOWTO(R_SPARC_OLO10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_OLO10", false,0,0x00000000,true),
120 HOWTO(R_SPARC_HH22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_HH22", false,0,0x00000000,true),
121 HOWTO(R_SPARC_HM10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_HM10", false,0,0x00000000,true),
122 HOWTO(R_SPARC_LM22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_LM22", false,0,0x00000000,true),
123 HOWTO(R_SPARC_PC_HH22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_PC_HH22", false,0,0x00000000,true),
124 HOWTO(R_SPARC_PC_HM10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_PC_HM10", false,0,0x00000000,true),
125 HOWTO(R_SPARC_PC_LM22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsupported_reloc
, "R_SPARC_PC_LM22", false,0,0x00000000,true),
127 HOWTO(R_SPARC_WDISP16
, 2,2,16,true, 0,complain_overflow_signed
, sparc_elf_wdisp16_reloc
,"R_SPARC_WDISP16", false,0,0x00000000,true),
128 HOWTO(R_SPARC_WDISP19
, 2,2,22,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP19", false,0,0x0007ffff,true),
129 HOWTO(R_SPARC_GLOB_JMP
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GLOB_JMP",false,0,0x00000000,true),
130 HOWTO(R_SPARC_7
, 0,2, 7,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_7", false,0,0x0000007f,true),
131 HOWTO(R_SPARC_5
, 0,2, 5,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_5", false,0,0x0000001f,true),
132 HOWTO(R_SPARC_6
, 0,2, 6,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_6", false,0,0x0000003f,true),
135 struct elf_reloc_map
{
136 unsigned char bfd_reloc_val
;
137 unsigned char elf_reloc_val
;
140 static CONST
struct elf_reloc_map sparc_reloc_map
[] =
142 { BFD_RELOC_NONE
, R_SPARC_NONE
, },
143 { BFD_RELOC_16
, R_SPARC_16
, },
144 { BFD_RELOC_8
, R_SPARC_8
},
145 { BFD_RELOC_8_PCREL
, R_SPARC_DISP8
},
146 /* ??? This might cause us to need separate functions in elf{32,64}-sparc.c
147 (we could still have just one table), but is this reloc ever used? */
148 { BFD_RELOC_CTOR
, R_SPARC_32
}, /* @@ Assumes 32 bits. */
149 { BFD_RELOC_32
, R_SPARC_32
},
150 { BFD_RELOC_32_PCREL
, R_SPARC_DISP32
},
151 { BFD_RELOC_HI22
, R_SPARC_HI22
},
152 { BFD_RELOC_LO10
, R_SPARC_LO10
, },
153 { BFD_RELOC_32_PCREL_S2
, R_SPARC_WDISP30
},
154 { BFD_RELOC_SPARC22
, R_SPARC_22
},
155 { BFD_RELOC_SPARC13
, R_SPARC_13
},
156 { BFD_RELOC_SPARC_GOT10
, R_SPARC_GOT10
},
157 { BFD_RELOC_SPARC_GOT13
, R_SPARC_GOT13
},
158 { BFD_RELOC_SPARC_GOT22
, R_SPARC_GOT22
},
159 { BFD_RELOC_SPARC_PC10
, R_SPARC_PC10
},
160 { BFD_RELOC_SPARC_PC22
, R_SPARC_PC22
},
161 { BFD_RELOC_SPARC_WPLT30
, R_SPARC_WPLT30
},
162 { BFD_RELOC_SPARC_COPY
, R_SPARC_COPY
},
163 { BFD_RELOC_SPARC_GLOB_DAT
, R_SPARC_GLOB_DAT
},
164 { BFD_RELOC_SPARC_JMP_SLOT
, R_SPARC_JMP_SLOT
},
165 { BFD_RELOC_SPARC_RELATIVE
, R_SPARC_RELATIVE
},
166 { BFD_RELOC_SPARC_WDISP22
, R_SPARC_WDISP22
},
167 /* ??? Doesn't dwarf use this? */
168 /*{ BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
169 {BFD_RELOC_SPARC_10
, R_SPARC_10
},
170 {BFD_RELOC_SPARC_11
, R_SPARC_11
},
171 {BFD_RELOC_SPARC_64
, R_SPARC_64
},
172 {BFD_RELOC_SPARC_OLO10
, R_SPARC_OLO10
},
173 {BFD_RELOC_SPARC_HH22
, R_SPARC_HH22
},
174 {BFD_RELOC_SPARC_HM10
, R_SPARC_HM10
},
175 {BFD_RELOC_SPARC_LM22
, R_SPARC_LM22
},
176 {BFD_RELOC_SPARC_PC_HH22
, R_SPARC_PC_HH22
},
177 {BFD_RELOC_SPARC_PC_HM10
, R_SPARC_PC_HM10
},
178 {BFD_RELOC_SPARC_PC_LM22
, R_SPARC_PC_LM22
},
179 {BFD_RELOC_SPARC_WDISP16
, R_SPARC_WDISP16
},
180 {BFD_RELOC_SPARC_WDISP19
, R_SPARC_WDISP19
},
181 {BFD_RELOC_SPARC_GLOB_JMP
, R_SPARC_GLOB_JMP
},
182 {BFD_RELOC_SPARC_7
, R_SPARC_7
},
183 {BFD_RELOC_SPARC_5
, R_SPARC_5
},
184 {BFD_RELOC_SPARC_6
, R_SPARC_6
},
187 static reloc_howto_type
*
188 elf32_sparc_reloc_type_lookup (abfd
, code
)
190 bfd_reloc_code_real_type code
;
193 for (i
= 0; i
< sizeof (sparc_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
195 if (sparc_reloc_map
[i
].bfd_reloc_val
== code
)
196 return &_bfd_sparc_elf_howto_table
[(int) sparc_reloc_map
[i
].elf_reloc_val
];
201 /* We need to use ELF32_R_TYPE so we have our own copy of this function,
202 and elf64-sparc.c has its own copy. */
205 elf32_sparc_info_to_howto (abfd
, cache_ptr
, dst
)
208 Elf_Internal_Rela
*dst
;
210 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_SPARC_max
);
211 cache_ptr
->howto
= &_bfd_sparc_elf_howto_table
[ELF32_R_TYPE(dst
->r_info
)];
214 /* For unsupported relocs. */
216 static bfd_reloc_status_type
217 sparc_elf_notsupported_reloc (abfd
,
225 arelent
*reloc_entry
;
228 asection
*input_section
;
230 char **error_message
;
232 return bfd_reloc_notsupported
;
235 /* Handle the WDISP16 reloc. */
237 static bfd_reloc_status_type
238 sparc_elf_wdisp16_reloc (abfd
,
246 arelent
*reloc_entry
;
249 asection
*input_section
;
251 char **error_message
;
256 if (output_bfd
!= (bfd
*) NULL
257 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
258 && (! reloc_entry
->howto
->partial_inplace
259 || reloc_entry
->addend
== 0))
261 reloc_entry
->address
+= input_section
->output_offset
;
265 if (output_bfd
!= NULL
)
266 return bfd_reloc_continue
;
268 if (reloc_entry
->address
> input_section
->_cooked_size
)
269 return bfd_reloc_outofrange
;
271 relocation
= (symbol
->value
272 + symbol
->section
->output_section
->vma
273 + symbol
->section
->output_offset
);
274 relocation
+= reloc_entry
->addend
;
275 relocation
-= (input_section
->output_section
->vma
276 + input_section
->output_offset
);
277 relocation
-= reloc_entry
->address
;
279 x
= bfd_get_32 (abfd
, (char *) data
+ reloc_entry
->address
);
280 x
|= ((((relocation
>> 2) & 0xc000) << 6)
281 | ((relocation
>> 2) & 0x3fff));
282 bfd_put_32 (abfd
, x
, (char *) data
+ reloc_entry
->address
);
284 if ((bfd_signed_vma
) relocation
< - 0x40000
285 || (bfd_signed_vma
) relocation
> 0x3ffff)
286 return bfd_reloc_overflow
;
291 /* Functions for the SPARC ELF linker. */
293 /* The name of the dynamic interpreter. This is put in the .interp
296 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
298 /* The nop opcode we use. */
300 #define SPARC_NOP 0x01000000
302 /* The size in bytes of an entry in the procedure linkage table. */
304 #define PLT_ENTRY_SIZE 12
306 /* The first four entries in a procedure linkage table are reserved,
307 and the initial contents are unimportant (we zero them out).
308 Subsequent entries look like this. See the SVR4 ABI SPARC
309 supplement to see how this works. */
311 /* sethi %hi(.-.plt0),%g1. We fill in the address later. */
312 #define PLT_ENTRY_WORD0 0x03000000
313 /* b,a .plt0. We fill in the offset later. */
314 #define PLT_ENTRY_WORD1 0x30800000
316 #define PLT_ENTRY_WORD2 SPARC_NOP
318 /* Look through the relocs for a section during the first phase, and
319 allocate space in the global offset table or procedure linkage
323 elf32_sparc_check_relocs (abfd
, info
, sec
, relocs
)
325 struct bfd_link_info
*info
;
327 const Elf_Internal_Rela
*relocs
;
330 Elf_Internal_Shdr
*symtab_hdr
;
331 struct elf_link_hash_entry
**sym_hashes
;
332 bfd_vma
*local_got_offsets
;
333 const Elf_Internal_Rela
*rel
;
334 const Elf_Internal_Rela
*rel_end
;
339 if (info
->relocateable
)
342 dynobj
= elf_hash_table (info
)->dynobj
;
343 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
344 sym_hashes
= elf_sym_hashes (abfd
);
345 local_got_offsets
= elf_local_got_offsets (abfd
);
351 rel_end
= relocs
+ sec
->reloc_count
;
352 for (rel
= relocs
; rel
< rel_end
; rel
++)
354 unsigned long r_symndx
;
355 struct elf_link_hash_entry
*h
;
357 r_symndx
= ELF32_R_SYM (rel
->r_info
);
358 if (r_symndx
< symtab_hdr
->sh_info
)
361 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
363 switch (ELF32_R_TYPE (rel
->r_info
))
368 /* This symbol requires a global offset table entry. */
372 /* Create the .got section. */
373 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
374 if (! _bfd_elf_create_got_section (dynobj
, info
))
380 sgot
= bfd_get_section_by_name (dynobj
, ".got");
381 BFD_ASSERT (sgot
!= NULL
);
385 && (h
!= NULL
|| info
->shared
))
387 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
390 srelgot
= bfd_make_section (dynobj
, ".rela.got");
392 || ! bfd_set_section_flags (dynobj
, srelgot
,
399 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
406 if (h
->got_offset
!= (bfd_vma
) -1)
408 /* We have already allocated space in the .got. */
411 h
->got_offset
= sgot
->_raw_size
;
413 /* Make sure this symbol is output as a dynamic symbol. */
414 if (h
->dynindx
== -1)
416 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
420 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
424 /* This is a global offset table entry for a local
426 if (local_got_offsets
== NULL
)
429 register unsigned int i
;
431 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
432 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
433 if (local_got_offsets
== NULL
)
435 elf_local_got_offsets (abfd
) = local_got_offsets
;
436 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
437 local_got_offsets
[i
] = (bfd_vma
) -1;
439 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
441 /* We have already allocated space in the .got. */
444 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
448 /* If we are generating a shared object, we need to
449 output a R_SPARC_RELATIVE reloc so that the
450 dynamic linker can adjust this GOT entry. */
451 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
455 sgot
->_raw_size
+= 4;
457 /* If the .got section is more than 0x1000 bytes, we add
458 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
459 bit relocations have a greater chance of working. */
460 if (sgot
->_raw_size
>= 0x1000
461 && elf_hash_table (info
)->hgot
->root
.u
.def
.value
== 0)
462 elf_hash_table (info
)->hgot
->root
.u
.def
.value
= 0x1000;
467 /* This symbol requires a procedure linkage table entry. We
468 actually build the entry in adjust_dynamic_symbol,
469 because this might be a case of linking PIC code without
470 linking in any dynamic objects, in which case we don't
471 need to generate a procedure linkage table after all. */
475 /* It does not make sense to have a procedure linkage
476 table entry for a local symbol. */
477 bfd_set_error (bfd_error_bad_value
);
481 /* Make sure this symbol is output as a dynamic symbol. */
482 if (h
->dynindx
== -1)
484 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
488 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
495 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
501 case R_SPARC_WDISP30
:
502 case R_SPARC_WDISP22
:
503 case R_SPARC_WDISP19
:
504 case R_SPARC_WDISP16
:
518 /* When creating a shared object, we must copy these
519 relocs into the output file. We create a reloc
520 section in dynobj and make room for the reloc. */
525 name
= (bfd_elf_string_from_elf_section
527 elf_elfheader (abfd
)->e_shstrndx
,
528 elf_section_data (sec
)->rel_hdr
.sh_name
));
532 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
533 && strcmp (bfd_get_section_name (abfd
, sec
),
536 sreloc
= bfd_get_section_by_name (dynobj
, name
);
541 sreloc
= bfd_make_section (dynobj
, name
);
542 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
543 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
544 if ((sec
->flags
& SEC_ALLOC
) != 0)
545 flags
|= SEC_ALLOC
| SEC_LOAD
;
547 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
548 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
553 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
566 /* Adjust a symbol defined by a dynamic object and referenced by a
567 regular object. The current definition is in some section of the
568 dynamic object, but we're not including those sections. We have to
569 change the definition to something the rest of the link can
573 elf32_sparc_adjust_dynamic_symbol (info
, h
)
574 struct bfd_link_info
*info
;
575 struct elf_link_hash_entry
*h
;
579 unsigned int power_of_two
;
581 dynobj
= elf_hash_table (info
)->dynobj
;
583 /* Make sure we know what is going on here. */
584 BFD_ASSERT (dynobj
!= NULL
585 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
586 || h
->weakdef
!= NULL
587 || ((h
->elf_link_hash_flags
588 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
589 && (h
->elf_link_hash_flags
590 & ELF_LINK_HASH_REF_REGULAR
) != 0
591 && (h
->elf_link_hash_flags
592 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
594 /* If this is a function, put it in the procedure linkage table. We
595 will fill in the contents of the procedure linkage table later
596 (although we could actually do it here). The STT_NOTYPE
597 condition is a hack specifically for the Oracle libraries
598 delivered for Solaris; for some inexplicable reason, they define
599 some of their functions as STT_NOTYPE when they really should be
601 if (h
->type
== STT_FUNC
602 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
603 || (h
->type
== STT_NOTYPE
604 && (h
->root
.type
== bfd_link_hash_defined
605 || h
->root
.type
== bfd_link_hash_defweak
)
606 && (h
->root
.u
.def
.section
->flags
& SEC_CODE
) != 0))
608 if (! elf_hash_table (info
)->dynamic_sections_created
)
610 /* This case can occur if we saw a WPLT30 reloc in an input
611 file, but none of the input files were dynamic objects.
612 In such a case, we don't actually need to build a
613 procedure linkage table, and we can just do a WDISP30
615 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
619 s
= bfd_get_section_by_name (dynobj
, ".plt");
620 BFD_ASSERT (s
!= NULL
);
622 /* The first four entries in .plt are reserved. */
623 if (s
->_raw_size
== 0)
624 s
->_raw_size
= 4 * PLT_ENTRY_SIZE
;
626 /* The procedure linkage table has a maximum size. */
627 if (s
->_raw_size
>= 0x400000)
629 bfd_set_error (bfd_error_bad_value
);
633 /* If this symbol is not defined in a regular file, and we are
634 not generating a shared library, then set the symbol to this
635 location in the .plt. This is required to make function
636 pointers compare as equal between the normal executable and
637 the shared library. */
639 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
641 h
->root
.u
.def
.section
= s
;
642 h
->root
.u
.def
.value
= s
->_raw_size
;
645 h
->plt_offset
= s
->_raw_size
;
647 /* Make room for this entry. */
648 s
->_raw_size
+= PLT_ENTRY_SIZE
;
650 /* We also need to make an entry in the .rela.plt section. */
652 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
653 BFD_ASSERT (s
!= NULL
);
654 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
659 /* If this is a weak symbol, and there is a real definition, the
660 processor independent code will have arranged for us to see the
661 real definition first, and we can just use the same value. */
662 if (h
->weakdef
!= NULL
)
664 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
665 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
666 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
667 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
671 /* This is a reference to a symbol defined by a dynamic object which
672 is not a function. */
674 /* If we are creating a shared library, we must presume that the
675 only references to the symbol are via the global offset table.
676 For such cases we need not do anything here; the relocations will
677 be handled correctly by relocate_section. */
681 /* We must allocate the symbol in our .dynbss section, which will
682 become part of the .bss section of the executable. There will be
683 an entry for this symbol in the .dynsym section. The dynamic
684 object will contain position independent code, so all references
685 from the dynamic object to this symbol will go through the global
686 offset table. The dynamic linker will use the .dynsym entry to
687 determine the address it must put in the global offset table, so
688 both the dynamic object and the regular object will refer to the
689 same memory location for the variable. */
691 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
692 BFD_ASSERT (s
!= NULL
);
694 /* If the symbol is currently defined in the .bss section of the
695 dynamic object, then it is OK to simply initialize it to zero.
696 If the symbol is in some other section, we must generate a
697 R_SPARC_COPY reloc to tell the dynamic linker to copy the initial
698 value out of the dynamic object and into the runtime process
699 image. We need to remember the offset into the .rel.bss section
700 we are going to use. */
701 if ((h
->root
.u
.def
.section
->flags
& SEC_LOAD
) != 0)
705 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
706 BFD_ASSERT (srel
!= NULL
);
707 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
708 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
711 /* We need to figure out the alignment required for this symbol. I
712 have no idea how ELF linkers handle this. */
713 power_of_two
= bfd_log2 (h
->size
);
714 if (power_of_two
> 3)
717 /* Apply the required alignment. */
718 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
719 (bfd_size_type
) (1 << power_of_two
));
720 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
722 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
726 /* Define the symbol as being at this point in the section. */
727 h
->root
.u
.def
.section
= s
;
728 h
->root
.u
.def
.value
= s
->_raw_size
;
730 /* Increment the section size to make room for the symbol. */
731 s
->_raw_size
+= h
->size
;
736 /* Set the sizes of the dynamic sections. */
739 elf32_sparc_size_dynamic_sections (output_bfd
, info
)
741 struct bfd_link_info
*info
;
748 dynobj
= elf_hash_table (info
)->dynobj
;
749 BFD_ASSERT (dynobj
!= NULL
);
751 if (elf_hash_table (info
)->dynamic_sections_created
)
753 /* Set the contents of the .interp section to the interpreter. */
756 s
= bfd_get_section_by_name (dynobj
, ".interp");
757 BFD_ASSERT (s
!= NULL
);
758 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
759 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
762 /* Make space for the trailing nop in .plt. */
763 s
= bfd_get_section_by_name (dynobj
, ".plt");
764 BFD_ASSERT (s
!= NULL
);
765 if (s
->_raw_size
> 0)
770 /* We may have created entries in the .rela.got section.
771 However, if we are not creating the dynamic sections, we will
772 not actually use these entries. Reset the size of .rela.got,
773 which will cause it to get stripped from the output file
775 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
780 /* The check_relocs and adjust_dynamic_symbol entry points have
781 determined the sizes of the various dynamic sections. Allocate
785 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
790 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
793 /* It's OK to base decisions on the section name, because none
794 of the dynobj section names depend upon the input files. */
795 name
= bfd_get_section_name (dynobj
, s
);
799 if (strncmp (name
, ".rela", 5) == 0)
801 if (s
->_raw_size
== 0)
803 /* If we don't need this section, strip it from the
804 output file. This is to handle .rela.bss and
805 .rel.plt. We must create it in
806 create_dynamic_sections, because it must be created
807 before the linker maps input sections to output
808 sections. The linker does that before
809 adjust_dynamic_symbol is called, and it is that
810 function which decides whether anything needs to go
811 into these sections. */
819 /* If this relocation section applies to a read only
820 section, then we probably need a DT_TEXTREL entry. */
821 outname
= bfd_get_section_name (output_bfd
,
823 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
825 && (target
->flags
& SEC_READONLY
) != 0)
828 if (strcmp (name
, ".rela.plt") == 0)
831 /* We use the reloc_count field as a counter if we need
832 to copy relocs into the output file. */
836 else if (strcmp (name
, ".plt") != 0
837 && strcmp (name
, ".got") != 0)
839 /* It's not one of our sections, so don't allocate space. */
847 for (spp
= &s
->output_section
->owner
->sections
;
848 *spp
!= s
->output_section
;
851 *spp
= s
->output_section
->next
;
852 --s
->output_section
->owner
->section_count
;
857 /* Allocate memory for the section contents. */
858 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
859 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
863 if (elf_hash_table (info
)->dynamic_sections_created
)
865 /* Add some entries to the .dynamic section. We fill in the
866 values later, in elf32_sparc_finish_dynamic_sections, but we
867 must add the entries now so that we get the correct size for
868 the .dynamic section. The DT_DEBUG entry is filled in by the
869 dynamic linker and used by the debugger. */
872 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
878 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
879 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
880 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
881 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
885 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
886 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
887 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
888 sizeof (Elf32_External_Rela
)))
893 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
898 /* If we are generating a shared library, we generate a section
899 symbol for each output section. These are local symbols, which
900 means that they must come first in the dynamic symbol table.
901 That means we must increment the dynamic symbol index of every
902 other dynamic symbol. */
907 c
= bfd_count_sections (output_bfd
);
908 elf_link_hash_traverse (elf_hash_table (info
),
909 elf32_sparc_adjust_dynindx
,
911 elf_hash_table (info
)->dynsymcount
+= c
;
913 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
915 elf_section_data (s
)->dynindx
= i
;
916 /* These symbols will have no names, so we don't need to
917 fiddle with dynstr_index. */
924 /* Increment the index of a dynamic symbol by a given amount. Called
925 via elf_link_hash_traverse. */
928 elf32_sparc_adjust_dynindx (h
, cparg
)
929 struct elf_link_hash_entry
*h
;
932 int *cp
= (int *) cparg
;
934 if (h
->dynindx
!= -1)
939 /* Relocate a SPARC ELF section. */
942 elf32_sparc_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
943 contents
, relocs
, local_syms
, local_sections
)
945 struct bfd_link_info
*info
;
947 asection
*input_section
;
949 Elf_Internal_Rela
*relocs
;
950 Elf_Internal_Sym
*local_syms
;
951 asection
**local_sections
;
954 Elf_Internal_Shdr
*symtab_hdr
;
955 struct elf_link_hash_entry
**sym_hashes
;
956 bfd_vma
*local_got_offsets
;
961 Elf_Internal_Rela
*rel
;
962 Elf_Internal_Rela
*relend
;
964 dynobj
= elf_hash_table (info
)->dynobj
;
965 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
966 sym_hashes
= elf_sym_hashes (input_bfd
);
967 local_got_offsets
= elf_local_got_offsets (input_bfd
);
969 if (elf_hash_table (info
)->hgot
== NULL
)
972 got_base
= elf_hash_table (info
)->hgot
->root
.u
.def
.value
;
979 relend
= relocs
+ input_section
->reloc_count
;
980 for (; rel
< relend
; rel
++)
983 reloc_howto_type
*howto
;
984 unsigned long r_symndx
;
985 struct elf_link_hash_entry
*h
;
986 Elf_Internal_Sym
*sym
;
989 bfd_reloc_status_type r
;
991 r_type
= ELF32_R_TYPE (rel
->r_info
);
992 if (r_type
< 0 || r_type
>= (int) R_SPARC_max
)
994 bfd_set_error (bfd_error_bad_value
);
997 howto
= _bfd_sparc_elf_howto_table
+ r_type
;
999 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1001 if (info
->relocateable
)
1003 /* This is a relocateable link. We don't have to change
1004 anything, unless the reloc is against a section symbol,
1005 in which case we have to adjust according to where the
1006 section symbol winds up in the output section. */
1007 if (r_symndx
< symtab_hdr
->sh_info
)
1009 sym
= local_syms
+ r_symndx
;
1010 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1012 sec
= local_sections
[r_symndx
];
1013 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1020 /* This is a final link. */
1024 if (r_symndx
< symtab_hdr
->sh_info
)
1026 sym
= local_syms
+ r_symndx
;
1027 sec
= local_sections
[r_symndx
];
1028 relocation
= (sec
->output_section
->vma
1029 + sec
->output_offset
1034 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1035 while (h
->root
.type
== bfd_link_hash_indirect
1036 || h
->root
.type
== bfd_link_hash_warning
)
1037 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1038 if (h
->root
.type
== bfd_link_hash_defined
1039 || h
->root
.type
== bfd_link_hash_defweak
)
1041 sec
= h
->root
.u
.def
.section
;
1042 if ((r_type
== R_SPARC_WPLT30
1043 && h
->plt_offset
!= (bfd_vma
) -1)
1044 || ((r_type
== R_SPARC_GOT10
1045 || r_type
== R_SPARC_GOT13
1046 || r_type
== R_SPARC_GOT22
)
1047 && elf_hash_table (info
)->dynamic_sections_created
1050 || (h
->elf_link_hash_flags
1051 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1053 && (! info
->symbolic
1054 || (h
->elf_link_hash_flags
1055 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
1056 && (r_type
== R_SPARC_8
1057 || r_type
== R_SPARC_16
1058 || r_type
== R_SPARC_32
1059 || r_type
== R_SPARC_DISP8
1060 || r_type
== R_SPARC_DISP16
1061 || r_type
== R_SPARC_DISP32
1062 || r_type
== R_SPARC_WDISP30
1063 || r_type
== R_SPARC_WDISP22
1064 || r_type
== R_SPARC_WDISP19
1065 || r_type
== R_SPARC_WDISP16
1066 || r_type
== R_SPARC_HI22
1067 || r_type
== R_SPARC_22
1068 || r_type
== R_SPARC_13
1069 || r_type
== R_SPARC_LO10
1070 || r_type
== R_SPARC_UA32
1071 || ((r_type
== R_SPARC_PC10
1072 || r_type
== R_SPARC_PC22
)
1073 && strcmp (h
->root
.root
.string
,
1074 "_GLOBAL_OFFSET_TABLE_") != 0))))
1076 /* In these cases, we don't need the relocation
1077 value. We check specially because in some
1078 obscure cases sec->output_section will be NULL. */
1082 relocation
= (h
->root
.u
.def
.value
1083 + sec
->output_section
->vma
1084 + sec
->output_offset
);
1086 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1088 else if (info
->shared
&& !info
->symbolic
)
1092 if (! ((*info
->callbacks
->undefined_symbol
)
1093 (info
, h
->root
.root
.string
, input_bfd
,
1094 input_section
, rel
->r_offset
)))
1105 /* Relocation is to the entry for this symbol in the global
1109 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1110 BFD_ASSERT (sgot
!= NULL
);
1117 off
= h
->got_offset
;
1118 BFD_ASSERT (off
!= (bfd_vma
) -1);
1120 if (! elf_hash_table (info
)->dynamic_sections_created
1123 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1125 /* This is actually a static link, or it is a
1126 -Bsymbolic link and the symbol is defined
1127 locally. We must initialize this entry in the
1128 global offset table. Since the offset must
1129 always be a multiple of 4, we use the least
1130 significant bit to record whether we have
1131 initialized it already.
1133 When doing a dynamic link, we create a .rela.got
1134 relocation entry to initialize the value. This
1135 is done in the finish_dynamic_symbol routine. */
1140 bfd_put_32 (output_bfd
, relocation
,
1141 sgot
->contents
+ off
);
1146 relocation
= sgot
->output_offset
+ off
- got_base
;
1152 BFD_ASSERT (local_got_offsets
!= NULL
1153 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1155 off
= local_got_offsets
[r_symndx
];
1157 /* The offset must always be a multiple of 4. We use
1158 the least significant bit to record whether we have
1159 already processed this entry. */
1164 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1169 Elf_Internal_Rela outrel
;
1171 /* We need to generate a R_SPARC_RELATIVE reloc
1172 for the dynamic linker. */
1173 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1174 BFD_ASSERT (srelgot
!= NULL
);
1176 outrel
.r_offset
= (sgot
->output_section
->vma
1177 + sgot
->output_offset
1179 outrel
.r_info
= ELF32_R_INFO (0, R_SPARC_RELATIVE
);
1180 outrel
.r_addend
= 0;
1181 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1182 (((Elf32_External_Rela
*)
1184 + srelgot
->reloc_count
));
1185 ++srelgot
->reloc_count
;
1188 local_got_offsets
[r_symndx
] |= 1;
1191 relocation
= sgot
->output_offset
+ off
- got_base
;
1196 case R_SPARC_WPLT30
:
1197 /* Relocation is to the entry for this symbol in the
1198 procedure linkage table. */
1199 BFD_ASSERT (h
!= NULL
);
1201 if (h
->plt_offset
== (bfd_vma
) -1)
1203 /* We didn't make a PLT entry for this symbol. This
1204 happens when statically linking PIC code, or when
1205 using -Bsymbolic. */
1211 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1212 BFD_ASSERT (splt
!= NULL
);
1215 relocation
= (splt
->output_section
->vma
1216 + splt
->output_offset
1223 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1227 case R_SPARC_DISP16
:
1228 case R_SPARC_DISP32
:
1229 case R_SPARC_WDISP30
:
1230 case R_SPARC_WDISP22
:
1231 case R_SPARC_WDISP19
:
1232 case R_SPARC_WDISP16
:
1246 Elf_Internal_Rela outrel
;
1248 /* When generating a shared object, these relocations
1249 are copied into the output file to be resolved at run
1256 name
= (bfd_elf_string_from_elf_section
1258 elf_elfheader (input_bfd
)->e_shstrndx
,
1259 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1263 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1264 && strcmp (bfd_get_section_name (input_bfd
,
1268 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1269 BFD_ASSERT (sreloc
!= NULL
);
1272 outrel
.r_offset
= (rel
->r_offset
1273 + input_section
->output_section
->vma
1274 + input_section
->output_offset
);
1275 /* h->dynindx may be -1 if the symbol was marked to
1278 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1279 || (h
->elf_link_hash_flags
1280 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1282 BFD_ASSERT (h
->dynindx
!= -1);
1283 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1284 outrel
.r_addend
= rel
->r_addend
;
1288 if (r_type
== R_SPARC_32
)
1290 outrel
.r_info
= ELF32_R_INFO (0, R_SPARC_RELATIVE
);
1291 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1298 sec
= local_sections
[r_symndx
];
1301 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
1303 == bfd_link_hash_defweak
));
1304 sec
= h
->root
.u
.def
.section
;
1306 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1308 else if (sec
== NULL
|| sec
->owner
== NULL
)
1310 bfd_set_error (bfd_error_bad_value
);
1317 osec
= sec
->output_section
;
1318 indx
= elf_section_data (osec
)->dynindx
;
1323 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
1324 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1328 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1329 (((Elf32_External_Rela
*)
1331 + sreloc
->reloc_count
));
1332 ++sreloc
->reloc_count
;
1334 /* This reloc will be computed at runtime, so there's no
1335 need to do anything now. */
1343 if (r_type
!= R_SPARC_WDISP16
)
1344 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1345 contents
, rel
->r_offset
,
1346 relocation
, rel
->r_addend
);
1351 relocation
+= rel
->r_addend
;
1352 relocation
-= (input_section
->output_section
->vma
1353 + input_section
->output_offset
);
1354 relocation
-= rel
->r_offset
;
1356 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1357 x
|= ((((relocation
>> 2) & 0xc000) << 6)
1358 | ((relocation
>> 2) & 0x3fff));
1359 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1361 if ((bfd_signed_vma
) relocation
< - 0x40000
1362 || (bfd_signed_vma
) relocation
> 0x3ffff)
1363 r
= bfd_reloc_overflow
;
1368 if (r
!= bfd_reloc_ok
)
1373 case bfd_reloc_outofrange
:
1375 case bfd_reloc_overflow
:
1380 name
= h
->root
.root
.string
;
1383 name
= bfd_elf_string_from_elf_section (input_bfd
,
1384 symtab_hdr
->sh_link
,
1389 name
= bfd_section_name (input_bfd
, sec
);
1391 if (! ((*info
->callbacks
->reloc_overflow
)
1392 (info
, name
, howto
->name
, (bfd_vma
) 0,
1393 input_bfd
, input_section
, rel
->r_offset
)))
1404 /* Finish up dynamic symbol handling. We set the contents of various
1405 dynamic sections here. */
1408 elf32_sparc_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1410 struct bfd_link_info
*info
;
1411 struct elf_link_hash_entry
*h
;
1412 Elf_Internal_Sym
*sym
;
1416 dynobj
= elf_hash_table (info
)->dynobj
;
1418 if (h
->plt_offset
!= (bfd_vma
) -1)
1422 Elf_Internal_Rela rela
;
1424 /* This symbol has an entry in the procedure linkage table. Set
1427 BFD_ASSERT (h
->dynindx
!= -1);
1429 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1430 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1431 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
1433 /* Fill in the entry in the procedure linkage table. */
1434 bfd_put_32 (output_bfd
,
1435 PLT_ENTRY_WORD0
+ h
->plt_offset
,
1436 splt
->contents
+ h
->plt_offset
);
1437 bfd_put_32 (output_bfd
,
1439 + (((- (h
->plt_offset
+ 4)) >> 2) & 0x3fffff)),
1440 splt
->contents
+ h
->plt_offset
+ 4);
1441 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD2
,
1442 splt
->contents
+ h
->plt_offset
+ 8);
1444 /* Fill in the entry in the .rela.plt section. */
1445 rela
.r_offset
= (splt
->output_section
->vma
1446 + splt
->output_offset
1448 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
1450 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1451 ((Elf32_External_Rela
*) srela
->contents
1452 + h
->plt_offset
/ PLT_ENTRY_SIZE
- 4));
1454 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1456 /* Mark the symbol as undefined, rather than as defined in
1457 the .plt section. Leave the value alone. */
1458 sym
->st_shndx
= SHN_UNDEF
;
1462 if (h
->got_offset
!= (bfd_vma
) -1)
1466 Elf_Internal_Rela rela
;
1468 /* This symbol has an entry in the global offset table. Set it
1471 BFD_ASSERT (h
->dynindx
!= -1);
1473 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1474 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1475 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1477 rela
.r_offset
= (sgot
->output_section
->vma
1478 + sgot
->output_offset
1479 + (h
->got_offset
&~ 1));
1481 /* If this is a -Bsymbolic link, and the symbol is defined
1482 locally, we just want to emit a RELATIVE reloc. The entry in
1483 the global offset table will already have been initialized in
1484 the relocate_section function. */
1487 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1488 rela
.r_info
= ELF32_R_INFO (0, R_SPARC_RELATIVE
);
1491 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got_offset
);
1492 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SPARC_GLOB_DAT
);
1496 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1497 ((Elf32_External_Rela
*) srela
->contents
1498 + srela
->reloc_count
));
1499 ++srela
->reloc_count
;
1502 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1505 Elf_Internal_Rela rela
;
1507 /* This symbols needs a copy reloc. Set it up. */
1509 BFD_ASSERT (h
->dynindx
!= -1);
1511 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1513 BFD_ASSERT (s
!= NULL
);
1515 rela
.r_offset
= (h
->root
.u
.def
.value
1516 + h
->root
.u
.def
.section
->output_section
->vma
1517 + h
->root
.u
.def
.section
->output_offset
);
1518 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SPARC_COPY
);
1520 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1521 ((Elf32_External_Rela
*) s
->contents
1526 /* Mark some specially defined symbols as absolute. */
1527 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1528 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
1529 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1530 sym
->st_shndx
= SHN_ABS
;
1535 /* Finish up the dynamic sections. */
1538 elf32_sparc_finish_dynamic_sections (output_bfd
, info
)
1540 struct bfd_link_info
*info
;
1546 dynobj
= elf_hash_table (info
)->dynobj
;
1548 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1550 if (elf_hash_table (info
)->dynamic_sections_created
)
1553 Elf32_External_Dyn
*dyncon
, *dynconend
;
1555 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1556 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1558 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1559 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1560 for (; dyncon
< dynconend
; dyncon
++)
1562 Elf_Internal_Dyn dyn
;
1566 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1570 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
1571 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
1572 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
1573 default: name
= NULL
; size
= false; break;
1580 s
= bfd_get_section_by_name (output_bfd
, name
);
1586 dyn
.d_un
.d_ptr
= s
->vma
;
1589 if (s
->_cooked_size
!= 0)
1590 dyn
.d_un
.d_val
= s
->_cooked_size
;
1592 dyn
.d_un
.d_val
= s
->_raw_size
;
1595 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1599 /* Clear the first four entries in the procedure linkage table,
1600 and put a nop in the last four bytes. */
1601 if (splt
->_raw_size
> 0)
1603 memset (splt
->contents
, 0, 4 * PLT_ENTRY_SIZE
);
1604 bfd_put_32 (output_bfd
, SPARC_NOP
,
1605 splt
->contents
+ splt
->_raw_size
- 4);
1608 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
1612 /* Set the first entry in the global offset table to the address of
1613 the dynamic section. */
1614 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1615 BFD_ASSERT (sgot
!= NULL
);
1616 if (sgot
->_raw_size
> 0)
1619 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1621 bfd_put_32 (output_bfd
,
1622 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1626 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1632 Elf_Internal_Sym sym
;
1634 /* Set up the section symbols for the output sections. */
1636 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
1637 BFD_ASSERT (sdynsym
!= NULL
);
1641 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
1644 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1648 sym
.st_value
= s
->vma
;
1650 indx
= elf_section_data (s
)->this_idx
;
1651 BFD_ASSERT (indx
> 0);
1652 sym
.st_shndx
= indx
;
1654 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
1655 (PTR
) (((Elf32_External_Sym
*)
1657 + elf_section_data (s
)->dynindx
));
1660 /* Set the sh_info field of the output .dynsym section to the
1661 index of the first global symbol. */
1662 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
1663 bfd_count_sections (output_bfd
) + 1;
1669 /* Functions for dealing with the e_flags field.
1671 We don't define set_private_flags or copy_private_bfd_data because
1672 the only currently defined values are based on the bfd mach number,
1673 so we use the latter instead and defer setting e_flags until the
1674 file is written out. */
1676 /* Merge backend specific data from an object file to the output
1677 object file when linking. */
1680 elf32_sparc_merge_private_bfd_data (ibfd
, obfd
)
1686 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1687 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1693 /* ??? The native linker doesn't do this so we can't (otherwise gcc would
1694 have to know which linker is being used). Instead, the native linker
1695 bumps up the architecture level when it has to. However, I still think
1696 warnings like these are good, so it would be nice to have them turned on
1699 /* If the output machine is normal sparc, we can't allow v9 input files. */
1700 if (bfd_get_mach (obfd
) == bfd_mach_sparc
1701 && (bfd_get_mach (ibfd
) == bfd_mach_sparc_v8plus
1702 || bfd_get_mach (ibfd
) == bfd_mach_sparc_v8plusa
))
1705 (*_bfd_error_handler
)
1706 ("%s: compiled for a v8plus system and target is v8",
1707 bfd_get_filename (ibfd
));
1709 /* If the output machine is v9, we can't allow v9+vis input files. */
1710 if (bfd_get_mach (obfd
) == bfd_mach_sparc_v8plus
1711 && bfd_get_mach (ibfd
) == bfd_mach_sparc_v8plusa
)
1714 (*_bfd_error_handler
)
1715 ("%s: compiled for a v8plusa system and target is v8plus",
1716 bfd_get_filename (ibfd
));
1719 if (bfd_get_mach (ibfd
) >= bfd_mach_sparc_v9
)
1722 (*_bfd_error_handler
)
1723 ("%s: compiled for a 64 bit system and target is 32 bit",
1724 bfd_get_filename (ibfd
));
1726 else if (bfd_get_mach (obfd
) < bfd_get_mach (ibfd
))
1727 bfd_set_arch_mach (obfd
, bfd_arch_sparc
, bfd_get_mach (ibfd
));
1732 bfd_set_error (bfd_error_bad_value
);
1739 /* Set the right machine number. */
1742 elf32_sparc_object_p (abfd
)
1745 if (elf_elfheader (abfd
)->e_machine
== EM_SPARC32PLUS
)
1747 if (elf_elfheader (abfd
)->e_flags
& EF_SPARC_SUN_US1
)
1748 return bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
,
1749 bfd_mach_sparc_v8plusa
);
1750 else if (elf_elfheader (abfd
)->e_flags
& EF_SPARC_32PLUS
)
1751 return bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
,
1752 bfd_mach_sparc_v8plus
);
1757 return bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
, bfd_mach_sparc
);
1760 /* The final processing done just before writing out the object file.
1761 We need to set the e_machine field appropriately. */
1764 elf32_sparc_final_write_processing (abfd
, linker
)
1768 switch (bfd_get_mach (abfd
))
1770 case bfd_mach_sparc
:
1771 break; /* nothing to do */
1772 case bfd_mach_sparc_v8plus
:
1773 elf_elfheader (abfd
)->e_machine
= EM_SPARC32PLUS
;
1774 elf_elfheader (abfd
)->e_flags
&=~ EF_SPARC_32PLUS_MASK
;
1775 elf_elfheader (abfd
)->e_flags
|= EF_SPARC_32PLUS
;
1777 case bfd_mach_sparc_v8plusa
:
1778 elf_elfheader (abfd
)->e_machine
= EM_SPARC32PLUS
;
1779 elf_elfheader (abfd
)->e_flags
&=~ EF_SPARC_32PLUS_MASK
;
1780 elf_elfheader (abfd
)->e_flags
|= EF_SPARC_32PLUS
| EF_SPARC_SUN_US1
;
1787 #define TARGET_BIG_SYM bfd_elf32_sparc_vec
1788 #define TARGET_BIG_NAME "elf32-sparc"
1789 #define ELF_ARCH bfd_arch_sparc
1790 #define ELF_MACHINE_CODE EM_SPARC
1791 #define ELF_MACHINE_ALT1 EM_SPARC32PLUS
1792 #define ELF_MAXPAGESIZE 0x10000
1794 #define bfd_elf32_bfd_reloc_type_lookup elf32_sparc_reloc_type_lookup
1795 #define elf_info_to_howto elf32_sparc_info_to_howto
1796 #define elf_backend_create_dynamic_sections \
1797 _bfd_elf_create_dynamic_sections
1798 #define elf_backend_check_relocs elf32_sparc_check_relocs
1799 #define elf_backend_adjust_dynamic_symbol \
1800 elf32_sparc_adjust_dynamic_symbol
1801 #define elf_backend_size_dynamic_sections \
1802 elf32_sparc_size_dynamic_sections
1803 #define elf_backend_relocate_section elf32_sparc_relocate_section
1804 #define elf_backend_finish_dynamic_symbol \
1805 elf32_sparc_finish_dynamic_symbol
1806 #define elf_backend_finish_dynamic_sections \
1807 elf32_sparc_finish_dynamic_sections
1808 #define bfd_elf32_bfd_merge_private_bfd_data \
1809 elf32_sparc_merge_private_bfd_data
1810 #define elf_backend_object_p elf32_sparc_object_p
1811 #define elf_backend_final_write_processing \
1812 elf32_sparc_final_write_processing
1813 #define elf_backend_want_got_plt 0
1814 #define elf_backend_plt_readonly 0
1815 #define elf_backend_want_plt_sym 1
1817 #include "elf32-target.h"