1 |
578 |
markom |
/* i370-specific support for 32-bit ELF
|
2 |
|
|
Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001
|
3 |
|
|
Free Software Foundation, Inc.
|
4 |
|
|
Written by Ian Lance Taylor, Cygnus Support.
|
5 |
|
|
Hacked by Linas Vepstas for i370 linas@linas.org
|
6 |
|
|
|
7 |
|
|
This file is part of BFD, the Binary File Descriptor library.
|
8 |
|
|
|
9 |
|
|
This program is free software; you can redistribute it and/or modify
|
10 |
|
|
it under the terms of the GNU General Public License as published by
|
11 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
12 |
|
|
(at your option) any later version.
|
13 |
|
|
|
14 |
|
|
This program is distributed in the hope that it will be useful,
|
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
GNU General Public License for more details.
|
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU General Public License
|
20 |
|
|
along with this program; if not, write to the Free Software
|
21 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
22 |
|
|
|
23 |
|
|
/* This file is based on a preliminary PowerPC ELF ABI.
|
24 |
|
|
But its been hacked on for the IBM 360/370 architectures.
|
25 |
|
|
Basically, the 31bit relocation works, and just about everything
|
26 |
|
|
else is a wild card. In particular, don't expect shared libs or
|
27 |
|
|
dynamic loading to work ... its never been tested ...
|
28 |
|
|
*/
|
29 |
|
|
|
30 |
|
|
#include "bfd.h"
|
31 |
|
|
#include "sysdep.h"
|
32 |
|
|
#include "bfdlink.h"
|
33 |
|
|
#include "libbfd.h"
|
34 |
|
|
#include "elf-bfd.h"
|
35 |
|
|
#include "elf/i370.h"
|
36 |
|
|
|
37 |
|
|
#define USE_RELA /* we want RELA relocations, not REL */
|
38 |
|
|
|
39 |
|
|
/* i370 relocations */
|
40 |
|
|
/* Note that there is really just one relocation that we currently
|
41 |
|
|
* support (and only one that we seem to need, at the moment), and
|
42 |
|
|
* that is the 31-bit address relocation. Note that the 370/390
|
43 |
|
|
* only supports a 31-bit (2GB) address space.
|
44 |
|
|
*/
|
45 |
|
|
enum i370_reloc_type
|
46 |
|
|
{
|
47 |
|
|
R_I370_NONE = 0,
|
48 |
|
|
R_I370_ADDR31 = 1,
|
49 |
|
|
R_I370_ADDR32 = 2,
|
50 |
|
|
R_I370_ADDR16 = 3,
|
51 |
|
|
R_I370_REL31 = 4,
|
52 |
|
|
R_I370_REL32 = 5,
|
53 |
|
|
R_I370_ADDR12 = 6,
|
54 |
|
|
R_I370_REL12 = 7,
|
55 |
|
|
R_I370_ADDR8 = 8,
|
56 |
|
|
R_I370_REL8 = 9,
|
57 |
|
|
R_I370_COPY = 10,
|
58 |
|
|
R_I370_RELATIVE = 11,
|
59 |
|
|
|
60 |
|
|
R_I370_max
|
61 |
|
|
};
|
62 |
|
|
|
63 |
|
|
static reloc_howto_type *i370_elf_howto_table[ (int)R_I370_max ];
|
64 |
|
|
|
65 |
|
|
static reloc_howto_type i370_elf_howto_raw[] =
|
66 |
|
|
{
|
67 |
|
|
/* This reloc does nothing. */
|
68 |
|
|
HOWTO (R_I370_NONE, /* type */
|
69 |
|
|
0, /* rightshift */
|
70 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
71 |
|
|
32, /* bitsize */
|
72 |
|
|
false, /* pc_relative */
|
73 |
|
|
0, /* bitpos */
|
74 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
75 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
76 |
|
|
"R_I370_NONE", /* name */
|
77 |
|
|
false, /* partial_inplace */
|
78 |
|
|
0, /* src_mask */
|
79 |
|
|
0, /* dst_mask */
|
80 |
|
|
false), /* pcrel_offset */
|
81 |
|
|
|
82 |
|
|
/* A standard 31 bit relocation. */
|
83 |
|
|
HOWTO (R_I370_ADDR31, /* type */
|
84 |
|
|
0, /* rightshift */
|
85 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
86 |
|
|
31, /* bitsize */
|
87 |
|
|
false, /* pc_relative */
|
88 |
|
|
0, /* bitpos */
|
89 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
90 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
91 |
|
|
"R_I370_ADDR31", /* name */
|
92 |
|
|
false, /* partial_inplace */
|
93 |
|
|
0, /* src_mask */
|
94 |
|
|
0x7fffffff, /* dst_mask */
|
95 |
|
|
false), /* pcrel_offset */
|
96 |
|
|
|
97 |
|
|
/* A standard 32 bit relocation. */
|
98 |
|
|
HOWTO (R_I370_ADDR32, /* type */
|
99 |
|
|
0, /* rightshift */
|
100 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
101 |
|
|
32, /* bitsize */
|
102 |
|
|
false, /* pc_relative */
|
103 |
|
|
0, /* bitpos */
|
104 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
105 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
106 |
|
|
"R_I370_ADDR32", /* name */
|
107 |
|
|
false, /* partial_inplace */
|
108 |
|
|
0, /* src_mask */
|
109 |
|
|
0xffffffff, /* dst_mask */
|
110 |
|
|
false), /* pcrel_offset */
|
111 |
|
|
|
112 |
|
|
/* A standard 16 bit relocation. */
|
113 |
|
|
HOWTO (R_I370_ADDR16, /* type */
|
114 |
|
|
0, /* rightshift */
|
115 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
116 |
|
|
16, /* bitsize */
|
117 |
|
|
false, /* pc_relative */
|
118 |
|
|
0, /* bitpos */
|
119 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
120 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
121 |
|
|
"R_I370_ADDR16", /* name */
|
122 |
|
|
false, /* partial_inplace */
|
123 |
|
|
0, /* src_mask */
|
124 |
|
|
0xffff, /* dst_mask */
|
125 |
|
|
false), /* pcrel_offset */
|
126 |
|
|
|
127 |
|
|
/* 31-bit PC relative */
|
128 |
|
|
HOWTO (R_I370_REL31, /* type */
|
129 |
|
|
0, /* rightshift */
|
130 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
131 |
|
|
31, /* bitsize */
|
132 |
|
|
true, /* pc_relative */
|
133 |
|
|
0, /* bitpos */
|
134 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
135 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
136 |
|
|
"R_I370_REL31", /* name */
|
137 |
|
|
false, /* partial_inplace */
|
138 |
|
|
0, /* src_mask */
|
139 |
|
|
0x7fffffff, /* dst_mask */
|
140 |
|
|
true), /* pcrel_offset */
|
141 |
|
|
|
142 |
|
|
/* 32-bit PC relative */
|
143 |
|
|
HOWTO (R_I370_REL32, /* type */
|
144 |
|
|
0, /* rightshift */
|
145 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
146 |
|
|
32, /* bitsize */
|
147 |
|
|
true, /* pc_relative */
|
148 |
|
|
0, /* bitpos */
|
149 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
150 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
151 |
|
|
"R_I370_REL32", /* name */
|
152 |
|
|
false, /* partial_inplace */
|
153 |
|
|
0, /* src_mask */
|
154 |
|
|
0xffffffff, /* dst_mask */
|
155 |
|
|
true), /* pcrel_offset */
|
156 |
|
|
|
157 |
|
|
/* A standard 12 bit relocation. */
|
158 |
|
|
HOWTO (R_I370_ADDR12, /* type */
|
159 |
|
|
0, /* rightshift */
|
160 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
161 |
|
|
12, /* bitsize */
|
162 |
|
|
false, /* pc_relative */
|
163 |
|
|
0, /* bitpos */
|
164 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
165 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
166 |
|
|
"R_I370_ADDR12", /* name */
|
167 |
|
|
false, /* partial_inplace */
|
168 |
|
|
0, /* src_mask */
|
169 |
|
|
0xfff, /* dst_mask */
|
170 |
|
|
false), /* pcrel_offset */
|
171 |
|
|
|
172 |
|
|
/* 12-bit PC relative */
|
173 |
|
|
HOWTO (R_I370_REL12, /* type */
|
174 |
|
|
0, /* rightshift */
|
175 |
|
|
1, /* size (0 = byte, 1 = short, 2 = long) */
|
176 |
|
|
12, /* bitsize */
|
177 |
|
|
true, /* pc_relative */
|
178 |
|
|
0, /* bitpos */
|
179 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
180 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
181 |
|
|
"R_I370_REL12", /* name */
|
182 |
|
|
false, /* partial_inplace */
|
183 |
|
|
0, /* src_mask */
|
184 |
|
|
0xfff, /* dst_mask */
|
185 |
|
|
true), /* pcrel_offset */
|
186 |
|
|
|
187 |
|
|
/* A standard 8 bit relocation. */
|
188 |
|
|
HOWTO (R_I370_ADDR8, /* type */
|
189 |
|
|
0, /* rightshift */
|
190 |
|
|
0, /* size (0 = byte, 1 = short, 2 = long) */
|
191 |
|
|
8, /* bitsize */
|
192 |
|
|
false, /* pc_relative */
|
193 |
|
|
0, /* bitpos */
|
194 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
195 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
196 |
|
|
"R_I370_ADDR8", /* name */
|
197 |
|
|
false, /* partial_inplace */
|
198 |
|
|
0, /* src_mask */
|
199 |
|
|
0xff, /* dst_mask */
|
200 |
|
|
false), /* pcrel_offset */
|
201 |
|
|
|
202 |
|
|
/* 8-bit PC relative */
|
203 |
|
|
HOWTO (R_I370_REL8, /* type */
|
204 |
|
|
0, /* rightshift */
|
205 |
|
|
0, /* size (0 = byte, 1 = short, 2 = long) */
|
206 |
|
|
8, /* bitsize */
|
207 |
|
|
true, /* pc_relative */
|
208 |
|
|
0, /* bitpos */
|
209 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
210 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
211 |
|
|
"R_I370_REL8", /* name */
|
212 |
|
|
false, /* partial_inplace */
|
213 |
|
|
0, /* src_mask */
|
214 |
|
|
0xff, /* dst_mask */
|
215 |
|
|
true), /* pcrel_offset */
|
216 |
|
|
|
217 |
|
|
/* This is used only by the dynamic linker. The symbol should exist
|
218 |
|
|
both in the object being run and in some shared library. The
|
219 |
|
|
dynamic linker copies the data addressed by the symbol from the
|
220 |
|
|
shared library into the object, because the object being
|
221 |
|
|
run has to have the data at some particular address. */
|
222 |
|
|
HOWTO (R_I370_COPY, /* type */
|
223 |
|
|
0, /* rightshift */
|
224 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
225 |
|
|
32, /* bitsize */
|
226 |
|
|
false, /* pc_relative */
|
227 |
|
|
0, /* bitpos */
|
228 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
229 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
230 |
|
|
"R_I370_COPY", /* name */
|
231 |
|
|
false, /* partial_inplace */
|
232 |
|
|
0, /* src_mask */
|
233 |
|
|
0, /* dst_mask */
|
234 |
|
|
false), /* pcrel_offset */
|
235 |
|
|
|
236 |
|
|
/* Used only by the dynamic linker. When the object is run, this
|
237 |
|
|
longword is set to the load address of the object, plus the
|
238 |
|
|
addend. */
|
239 |
|
|
HOWTO (R_I370_RELATIVE, /* type */
|
240 |
|
|
0, /* rightshift */
|
241 |
|
|
2, /* size (0 = byte, 1 = short, 2 = long) */
|
242 |
|
|
32, /* bitsize */
|
243 |
|
|
false, /* pc_relative */
|
244 |
|
|
0, /* bitpos */
|
245 |
|
|
complain_overflow_bitfield, /* complain_on_overflow */
|
246 |
|
|
bfd_elf_generic_reloc, /* special_function */
|
247 |
|
|
"R_I370_RELATIVE", /* name */
|
248 |
|
|
false, /* partial_inplace */
|
249 |
|
|
0, /* src_mask */
|
250 |
|
|
0xffffffff, /* dst_mask */
|
251 |
|
|
false), /* pcrel_offset */
|
252 |
|
|
|
253 |
|
|
};
|
254 |
|
|
|
255 |
|
|
static void i370_elf_howto_init PARAMS ((void));
|
256 |
|
|
static void i370_elf_info_to_howto PARAMS ((bfd *abfd, arelent *cache_ptr,
|
257 |
|
|
Elf32_Internal_Rela *dst));
|
258 |
|
|
static boolean i370_elf_set_private_flags PARAMS ((bfd *, flagword));
|
259 |
|
|
|
260 |
|
|
/* Initialize the i370_elf_howto_table, so that linear accesses can be done. */
|
261 |
|
|
|
262 |
|
|
static void
|
263 |
|
|
i370_elf_howto_init ()
|
264 |
|
|
{
|
265 |
|
|
unsigned int i, type;
|
266 |
|
|
|
267 |
|
|
for (i = 0; i < sizeof (i370_elf_howto_raw) / sizeof (i370_elf_howto_raw[0]); i++)
|
268 |
|
|
{
|
269 |
|
|
type = i370_elf_howto_raw[i].type;
|
270 |
|
|
BFD_ASSERT (type < sizeof (i370_elf_howto_table) / sizeof (i370_elf_howto_table[0]));
|
271 |
|
|
i370_elf_howto_table[type] = &i370_elf_howto_raw[i];
|
272 |
|
|
}
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
static reloc_howto_type *
|
276 |
|
|
i370_elf_reloc_type_lookup (abfd, code)
|
277 |
|
|
bfd *abfd ATTRIBUTE_UNUSED;
|
278 |
|
|
bfd_reloc_code_real_type code;
|
279 |
|
|
{
|
280 |
|
|
enum i370_reloc_type i370_reloc = R_I370_NONE;
|
281 |
|
|
|
282 |
|
|
if (!i370_elf_howto_table[ R_I370_ADDR31 ]) /* Initialize howto table if needed */
|
283 |
|
|
i370_elf_howto_init ();
|
284 |
|
|
|
285 |
|
|
switch ((int)code)
|
286 |
|
|
{
|
287 |
|
|
default:
|
288 |
|
|
return (reloc_howto_type *)NULL;
|
289 |
|
|
|
290 |
|
|
case BFD_RELOC_NONE: i370_reloc = R_I370_NONE; break;
|
291 |
|
|
case BFD_RELOC_32: i370_reloc = R_I370_ADDR31; break;
|
292 |
|
|
case BFD_RELOC_16: i370_reloc = R_I370_ADDR16; break;
|
293 |
|
|
case BFD_RELOC_32_PCREL: i370_reloc = R_I370_REL31; break;
|
294 |
|
|
case BFD_RELOC_CTOR: i370_reloc = R_I370_ADDR31; break;
|
295 |
|
|
case BFD_RELOC_I370_D12: i370_reloc = R_I370_ADDR12; break;
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
return i370_elf_howto_table[ (int)i370_reloc ];
|
299 |
|
|
};
|
300 |
|
|
|
301 |
|
|
static boolean i370_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
|
302 |
|
|
static boolean i370_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
|
303 |
|
|
|
304 |
|
|
static boolean i370_elf_relocate_section PARAMS ((bfd *,
|
305 |
|
|
struct bfd_link_info *info,
|
306 |
|
|
bfd *,
|
307 |
|
|
asection *,
|
308 |
|
|
bfd_byte *,
|
309 |
|
|
Elf_Internal_Rela *relocs,
|
310 |
|
|
Elf_Internal_Sym *local_syms,
|
311 |
|
|
asection **));
|
312 |
|
|
|
313 |
|
|
static boolean i370_elf_create_dynamic_sections PARAMS ((bfd *,
|
314 |
|
|
struct bfd_link_info *));
|
315 |
|
|
|
316 |
|
|
static boolean i370_elf_section_from_shdr PARAMS ((bfd *,
|
317 |
|
|
Elf32_Internal_Shdr *,
|
318 |
|
|
char *));
|
319 |
|
|
static boolean i370_elf_fake_sections PARAMS ((bfd *,
|
320 |
|
|
Elf32_Internal_Shdr *,
|
321 |
|
|
asection *));
|
322 |
|
|
#if 0
|
323 |
|
|
static elf_linker_section_t *i370_elf_create_linker_section
|
324 |
|
|
PARAMS ((bfd *abfd,
|
325 |
|
|
struct bfd_link_info *info,
|
326 |
|
|
enum elf_linker_section_enum));
|
327 |
|
|
#endif
|
328 |
|
|
static boolean i370_elf_check_relocs PARAMS ((bfd *,
|
329 |
|
|
struct bfd_link_info *,
|
330 |
|
|
asection *,
|
331 |
|
|
const Elf_Internal_Rela *));
|
332 |
|
|
|
333 |
|
|
static boolean i370_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
|
334 |
|
|
struct elf_link_hash_entry *));
|
335 |
|
|
|
336 |
|
|
static boolean i370_elf_adjust_dynindx PARAMS ((struct elf_link_hash_entry *, PTR));
|
337 |
|
|
|
338 |
|
|
static boolean i370_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
|
339 |
|
|
|
340 |
|
|
static boolean i370_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
|
341 |
|
|
|
342 |
|
|
/* The name of the dynamic interpreter. This is put in the .interp
|
343 |
|
|
section. */
|
344 |
|
|
|
345 |
|
|
#define ELF_DYNAMIC_INTERPRETER "/lib/ld.so"
|
346 |
|
|
|
347 |
|
|
/* Set the howto pointer for an i370 ELF reloc. */
|
348 |
|
|
|
349 |
|
|
static void
|
350 |
|
|
i370_elf_info_to_howto (abfd, cache_ptr, dst)
|
351 |
|
|
bfd *abfd ATTRIBUTE_UNUSED;
|
352 |
|
|
arelent *cache_ptr;
|
353 |
|
|
Elf32_Internal_Rela *dst;
|
354 |
|
|
{
|
355 |
|
|
if (!i370_elf_howto_table[ R_I370_ADDR31 ]) /* Initialize howto table */
|
356 |
|
|
i370_elf_howto_init ();
|
357 |
|
|
|
358 |
|
|
BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_I370_max);
|
359 |
|
|
cache_ptr->howto = i370_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
|
360 |
|
|
}
|
361 |
|
|
|
362 |
|
|
/* hack alert -- the following several routines look generic to me ...
|
363 |
|
|
* why are we bothering with them ???
|
364 |
|
|
*/
|
365 |
|
|
/* Function to set whether a module needs the -mrelocatable bit set. */
|
366 |
|
|
static boolean
|
367 |
|
|
i370_elf_set_private_flags (abfd, flags)
|
368 |
|
|
bfd *abfd;
|
369 |
|
|
flagword flags;
|
370 |
|
|
{
|
371 |
|
|
BFD_ASSERT (!elf_flags_init (abfd)
|
372 |
|
|
|| elf_elfheader (abfd)->e_flags == flags);
|
373 |
|
|
|
374 |
|
|
elf_elfheader (abfd)->e_flags = flags;
|
375 |
|
|
elf_flags_init (abfd) = true;
|
376 |
|
|
return true;
|
377 |
|
|
}
|
378 |
|
|
|
379 |
|
|
/* Copy backend specific data from one object module to another */
|
380 |
|
|
static boolean
|
381 |
|
|
i370_elf_copy_private_bfd_data (ibfd, obfd)
|
382 |
|
|
bfd *ibfd;
|
383 |
|
|
bfd *obfd;
|
384 |
|
|
{
|
385 |
|
|
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|
386 |
|
|
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
|
387 |
|
|
return true;
|
388 |
|
|
|
389 |
|
|
BFD_ASSERT (!elf_flags_init (obfd)
|
390 |
|
|
|| elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
|
391 |
|
|
|
392 |
|
|
elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
|
393 |
|
|
elf_flags_init (obfd) = true;
|
394 |
|
|
return true;
|
395 |
|
|
}
|
396 |
|
|
|
397 |
|
|
/* Merge backend specific data from an object file to the output
|
398 |
|
|
object file when linking */
|
399 |
|
|
static boolean
|
400 |
|
|
i370_elf_merge_private_bfd_data (ibfd, obfd)
|
401 |
|
|
bfd *ibfd;
|
402 |
|
|
bfd *obfd;
|
403 |
|
|
{
|
404 |
|
|
flagword old_flags;
|
405 |
|
|
flagword new_flags;
|
406 |
|
|
|
407 |
|
|
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|
408 |
|
|
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
|
409 |
|
|
return true;
|
410 |
|
|
|
411 |
|
|
new_flags = elf_elfheader (ibfd)->e_flags;
|
412 |
|
|
old_flags = elf_elfheader (obfd)->e_flags;
|
413 |
|
|
if (!elf_flags_init (obfd)) /* First call, no flags set */
|
414 |
|
|
{
|
415 |
|
|
elf_flags_init (obfd) = true;
|
416 |
|
|
elf_elfheader (obfd)->e_flags = new_flags;
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
else if (new_flags == old_flags) /* Compatible flags are ok */
|
420 |
|
|
;
|
421 |
|
|
|
422 |
|
|
else /* Incompatible flags */
|
423 |
|
|
{
|
424 |
|
|
(*_bfd_error_handler)
|
425 |
|
|
("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
|
426 |
|
|
bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
|
427 |
|
|
|
428 |
|
|
bfd_set_error (bfd_error_bad_value);
|
429 |
|
|
return false;
|
430 |
|
|
}
|
431 |
|
|
|
432 |
|
|
return true;
|
433 |
|
|
}
|
434 |
|
|
|
435 |
|
|
/* Handle an i370 specific section when reading an object file. This
|
436 |
|
|
is called when elfcode.h finds a section with an unknown type. */
|
437 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
438 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
439 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
440 |
|
|
*/
|
441 |
|
|
|
442 |
|
|
static boolean
|
443 |
|
|
i370_elf_section_from_shdr (abfd, hdr, name)
|
444 |
|
|
bfd *abfd;
|
445 |
|
|
Elf32_Internal_Shdr *hdr;
|
446 |
|
|
char *name;
|
447 |
|
|
{
|
448 |
|
|
asection *newsect;
|
449 |
|
|
flagword flags;
|
450 |
|
|
|
451 |
|
|
if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
|
452 |
|
|
return false;
|
453 |
|
|
|
454 |
|
|
newsect = hdr->bfd_section;
|
455 |
|
|
flags = bfd_get_section_flags (abfd, newsect);
|
456 |
|
|
if (hdr->sh_flags & SHF_EXCLUDE)
|
457 |
|
|
flags |= SEC_EXCLUDE;
|
458 |
|
|
|
459 |
|
|
if (hdr->sh_type == SHT_ORDERED)
|
460 |
|
|
flags |= SEC_SORT_ENTRIES;
|
461 |
|
|
|
462 |
|
|
bfd_set_section_flags (abfd, newsect, flags);
|
463 |
|
|
return true;
|
464 |
|
|
}
|
465 |
|
|
|
466 |
|
|
/* Set up any other section flags and such that may be necessary. */
|
467 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
468 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
469 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
470 |
|
|
*/
|
471 |
|
|
|
472 |
|
|
static boolean
|
473 |
|
|
i370_elf_fake_sections (abfd, shdr, asect)
|
474 |
|
|
bfd *abfd ATTRIBUTE_UNUSED;
|
475 |
|
|
Elf32_Internal_Shdr *shdr;
|
476 |
|
|
asection *asect;
|
477 |
|
|
{
|
478 |
|
|
if ((asect->flags & SEC_EXCLUDE) != 0)
|
479 |
|
|
shdr->sh_flags |= SHF_EXCLUDE;
|
480 |
|
|
|
481 |
|
|
if ((asect->flags & SEC_SORT_ENTRIES) != 0)
|
482 |
|
|
shdr->sh_type = SHT_ORDERED;
|
483 |
|
|
|
484 |
|
|
return true;
|
485 |
|
|
}
|
486 |
|
|
|
487 |
|
|
#if 0
|
488 |
|
|
/* Create a special linker section */
|
489 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
490 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
491 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
492 |
|
|
*/
|
493 |
|
|
|
494 |
|
|
static elf_linker_section_t *
|
495 |
|
|
i370_elf_create_linker_section (abfd, info, which)
|
496 |
|
|
bfd *abfd;
|
497 |
|
|
struct bfd_link_info *info;
|
498 |
|
|
enum elf_linker_section_enum which;
|
499 |
|
|
{
|
500 |
|
|
bfd *dynobj = elf_hash_table (info)->dynobj;
|
501 |
|
|
elf_linker_section_t *lsect;
|
502 |
|
|
|
503 |
|
|
/* Record the first bfd section that needs the special section */
|
504 |
|
|
if (!dynobj)
|
505 |
|
|
dynobj = elf_hash_table (info)->dynobj = abfd;
|
506 |
|
|
|
507 |
|
|
/* If this is the first time, create the section */
|
508 |
|
|
lsect = elf_linker_section (dynobj, which);
|
509 |
|
|
if (!lsect)
|
510 |
|
|
{
|
511 |
|
|
elf_linker_section_t defaults;
|
512 |
|
|
static elf_linker_section_t zero_section;
|
513 |
|
|
|
514 |
|
|
defaults = zero_section;
|
515 |
|
|
defaults.which = which;
|
516 |
|
|
defaults.hole_written_p = false;
|
517 |
|
|
defaults.alignment = 2;
|
518 |
|
|
|
519 |
|
|
/* Both of these sections are (technically) created by the user
|
520 |
|
|
putting data in them, so they shouldn't be marked
|
521 |
|
|
SEC_LINKER_CREATED.
|
522 |
|
|
|
523 |
|
|
The linker creates them so it has somewhere to attach their
|
524 |
|
|
respective symbols. In fact, if they were empty it would
|
525 |
|
|
be OK to leave the symbol set to 0 (or any random number), because
|
526 |
|
|
the appropriate register should never be used. */
|
527 |
|
|
defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
|
528 |
|
|
| SEC_IN_MEMORY);
|
529 |
|
|
|
530 |
|
|
switch (which)
|
531 |
|
|
{
|
532 |
|
|
default:
|
533 |
|
|
(*_bfd_error_handler) ("%s: Unknown special linker type %d",
|
534 |
|
|
bfd_get_filename (abfd),
|
535 |
|
|
(int)which);
|
536 |
|
|
|
537 |
|
|
bfd_set_error (bfd_error_bad_value);
|
538 |
|
|
return (elf_linker_section_t *)0;
|
539 |
|
|
|
540 |
|
|
case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
|
541 |
|
|
defaults.name = ".sdata";
|
542 |
|
|
defaults.rel_name = ".rela.sdata";
|
543 |
|
|
defaults.bss_name = ".sbss";
|
544 |
|
|
defaults.sym_name = "_SDA_BASE_";
|
545 |
|
|
defaults.sym_offset = 32768;
|
546 |
|
|
break;
|
547 |
|
|
|
548 |
|
|
case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
|
549 |
|
|
defaults.name = ".sdata2";
|
550 |
|
|
defaults.rel_name = ".rela.sdata2";
|
551 |
|
|
defaults.bss_name = ".sbss2";
|
552 |
|
|
defaults.sym_name = "_SDA2_BASE_";
|
553 |
|
|
defaults.sym_offset = 32768;
|
554 |
|
|
defaults.flags |= SEC_READONLY;
|
555 |
|
|
break;
|
556 |
|
|
}
|
557 |
|
|
|
558 |
|
|
lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
|
559 |
|
|
}
|
560 |
|
|
|
561 |
|
|
return lsect;
|
562 |
|
|
}
|
563 |
|
|
#endif
|
564 |
|
|
|
565 |
|
|
/* We have to create .dynsbss and .rela.sbss here so that they get mapped
|
566 |
|
|
to output sections (just like _bfd_elf_create_dynamic_sections has
|
567 |
|
|
to create .dynbss and .rela.bss). */
|
568 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
569 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
570 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
571 |
|
|
*/
|
572 |
|
|
|
573 |
|
|
static boolean
|
574 |
|
|
i370_elf_create_dynamic_sections (abfd, info)
|
575 |
|
|
bfd *abfd;
|
576 |
|
|
struct bfd_link_info *info;
|
577 |
|
|
{
|
578 |
|
|
register asection *s;
|
579 |
|
|
flagword flags;
|
580 |
|
|
|
581 |
|
|
if (!_bfd_elf_create_dynamic_sections(abfd, info))
|
582 |
|
|
return false;
|
583 |
|
|
|
584 |
|
|
flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
|
585 |
|
|
| SEC_LINKER_CREATED);
|
586 |
|
|
|
587 |
|
|
s = bfd_make_section (abfd, ".dynsbss");
|
588 |
|
|
if (s == NULL
|
589 |
|
|
|| ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
|
590 |
|
|
return false;
|
591 |
|
|
|
592 |
|
|
if (! info->shared)
|
593 |
|
|
{
|
594 |
|
|
s = bfd_make_section (abfd, ".rela.sbss");
|
595 |
|
|
if (s == NULL
|
596 |
|
|
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|
597 |
|
|
|| ! bfd_set_section_alignment (abfd, s, 2))
|
598 |
|
|
return false;
|
599 |
|
|
}
|
600 |
|
|
|
601 |
|
|
/* xxx beats me, seem to need a rela.text ... */
|
602 |
|
|
s = bfd_make_section (abfd, ".rela.text");
|
603 |
|
|
if (s == NULL
|
604 |
|
|
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|
605 |
|
|
|| ! bfd_set_section_alignment (abfd, s, 2))
|
606 |
|
|
return false;
|
607 |
|
|
return true;
|
608 |
|
|
}
|
609 |
|
|
|
610 |
|
|
/* Adjust a symbol defined by a dynamic object and referenced by a
|
611 |
|
|
regular object. The current definition is in some section of the
|
612 |
|
|
dynamic object, but we're not including those sections. We have to
|
613 |
|
|
change the definition to something the rest of the link can
|
614 |
|
|
understand. */
|
615 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
616 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
617 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
618 |
|
|
*/
|
619 |
|
|
|
620 |
|
|
static boolean
|
621 |
|
|
i370_elf_adjust_dynamic_symbol (info, h)
|
622 |
|
|
struct bfd_link_info *info;
|
623 |
|
|
struct elf_link_hash_entry *h;
|
624 |
|
|
{
|
625 |
|
|
bfd *dynobj = elf_hash_table (info)->dynobj;
|
626 |
|
|
asection *s;
|
627 |
|
|
unsigned int power_of_two;
|
628 |
|
|
|
629 |
|
|
#ifdef DEBUG
|
630 |
|
|
fprintf (stderr, "i370_elf_adjust_dynamic_symbol called for %s\n",
|
631 |
|
|
h->root.root.string);
|
632 |
|
|
#endif
|
633 |
|
|
|
634 |
|
|
/* Make sure we know what is going on here. */
|
635 |
|
|
BFD_ASSERT (dynobj != NULL
|
636 |
|
|
&& ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
|
637 |
|
|
|| h->weakdef != NULL
|
638 |
|
|
|| ((h->elf_link_hash_flags
|
639 |
|
|
& ELF_LINK_HASH_DEF_DYNAMIC) != 0
|
640 |
|
|
&& (h->elf_link_hash_flags
|
641 |
|
|
& ELF_LINK_HASH_REF_REGULAR) != 0
|
642 |
|
|
&& (h->elf_link_hash_flags
|
643 |
|
|
& ELF_LINK_HASH_DEF_REGULAR) == 0)));
|
644 |
|
|
|
645 |
|
|
s = bfd_get_section_by_name (dynobj, ".rela.text");
|
646 |
|
|
BFD_ASSERT (s != NULL);
|
647 |
|
|
s->_raw_size += sizeof (Elf32_External_Rela);
|
648 |
|
|
|
649 |
|
|
/* If this is a weak symbol, and there is a real definition, the
|
650 |
|
|
processor independent code will have arranged for us to see the
|
651 |
|
|
real definition first, and we can just use the same value. */
|
652 |
|
|
if (h->weakdef != NULL)
|
653 |
|
|
{
|
654 |
|
|
BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
|
655 |
|
|
|| h->weakdef->root.type == bfd_link_hash_defweak);
|
656 |
|
|
h->root.u.def.section = h->weakdef->root.u.def.section;
|
657 |
|
|
h->root.u.def.value = h->weakdef->root.u.def.value;
|
658 |
|
|
return true;
|
659 |
|
|
}
|
660 |
|
|
|
661 |
|
|
/* This is a reference to a symbol defined by a dynamic object which
|
662 |
|
|
is not a function. */
|
663 |
|
|
|
664 |
|
|
/* If we are creating a shared library, we must presume that the
|
665 |
|
|
only references to the symbol are via the global offset table.
|
666 |
|
|
For such cases we need not do anything here; the relocations will
|
667 |
|
|
be handled correctly by relocate_section. */
|
668 |
|
|
if (info->shared)
|
669 |
|
|
return true;
|
670 |
|
|
|
671 |
|
|
/* We must allocate the symbol in our .dynbss section, which will
|
672 |
|
|
become part of the .bss section of the executable. There will be
|
673 |
|
|
an entry for this symbol in the .dynsym section. The dynamic
|
674 |
|
|
object will contain position independent code, so all references
|
675 |
|
|
from the dynamic object to this symbol will go through the global
|
676 |
|
|
offset table. The dynamic linker will use the .dynsym entry to
|
677 |
|
|
determine the address it must put in the global offset table, so
|
678 |
|
|
both the dynamic object and the regular object will refer to the
|
679 |
|
|
same memory location for the variable.
|
680 |
|
|
|
681 |
|
|
Of course, if the symbol is sufficiently small, we must instead
|
682 |
|
|
allocate it in .sbss. FIXME: It would be better to do this if and
|
683 |
|
|
only if there were actually SDAREL relocs for that symbol. */
|
684 |
|
|
|
685 |
|
|
if (h->size <= elf_gp_size (dynobj))
|
686 |
|
|
s = bfd_get_section_by_name (dynobj, ".dynsbss");
|
687 |
|
|
else
|
688 |
|
|
s = bfd_get_section_by_name (dynobj, ".dynbss");
|
689 |
|
|
BFD_ASSERT (s != NULL);
|
690 |
|
|
|
691 |
|
|
/* We must generate a R_I370_COPY reloc to tell the dynamic linker to
|
692 |
|
|
copy the initial value out of the dynamic object and into the
|
693 |
|
|
runtime process image. We need to remember the offset into the
|
694 |
|
|
.rela.bss section we are going to use. */
|
695 |
|
|
if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
|
696 |
|
|
{
|
697 |
|
|
asection *srel;
|
698 |
|
|
|
699 |
|
|
if (h->size <= elf_gp_size (dynobj))
|
700 |
|
|
srel = bfd_get_section_by_name (dynobj, ".rela.sbss");
|
701 |
|
|
else
|
702 |
|
|
srel = bfd_get_section_by_name (dynobj, ".rela.bss");
|
703 |
|
|
BFD_ASSERT (srel != NULL);
|
704 |
|
|
srel->_raw_size += sizeof (Elf32_External_Rela);
|
705 |
|
|
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
|
706 |
|
|
}
|
707 |
|
|
|
708 |
|
|
/* We need to figure out the alignment required for this symbol. I
|
709 |
|
|
have no idea how ELF linkers handle this. */
|
710 |
|
|
power_of_two = bfd_log2 (h->size);
|
711 |
|
|
if (power_of_two > 4)
|
712 |
|
|
power_of_two = 4;
|
713 |
|
|
|
714 |
|
|
/* Apply the required alignment. */
|
715 |
|
|
s->_raw_size = BFD_ALIGN (s->_raw_size,
|
716 |
|
|
(bfd_size_type) (1 << power_of_two));
|
717 |
|
|
if (power_of_two > bfd_get_section_alignment (dynobj, s))
|
718 |
|
|
{
|
719 |
|
|
if (! bfd_set_section_alignment (dynobj, s, power_of_two))
|
720 |
|
|
return false;
|
721 |
|
|
}
|
722 |
|
|
|
723 |
|
|
/* Define the symbol as being at this point in the section. */
|
724 |
|
|
h->root.u.def.section = s;
|
725 |
|
|
h->root.u.def.value = s->_raw_size;
|
726 |
|
|
|
727 |
|
|
/* Increment the section size to make room for the symbol. */
|
728 |
|
|
s->_raw_size += h->size;
|
729 |
|
|
|
730 |
|
|
return true;
|
731 |
|
|
}
|
732 |
|
|
|
733 |
|
|
/* Increment the index of a dynamic symbol by a given amount. Called
|
734 |
|
|
via elf_link_hash_traverse. */
|
735 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
736 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
737 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
738 |
|
|
*/
|
739 |
|
|
|
740 |
|
|
static boolean
|
741 |
|
|
i370_elf_adjust_dynindx (h, cparg)
|
742 |
|
|
struct elf_link_hash_entry *h;
|
743 |
|
|
PTR cparg;
|
744 |
|
|
{
|
745 |
|
|
int *cp = (int *) cparg;
|
746 |
|
|
|
747 |
|
|
#ifdef DEBUG
|
748 |
|
|
fprintf (stderr,
|
749 |
|
|
"i370_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n",
|
750 |
|
|
h->dynindx, *cp);
|
751 |
|
|
#endif
|
752 |
|
|
|
753 |
|
|
if (h->dynindx != -1)
|
754 |
|
|
h->dynindx += *cp;
|
755 |
|
|
|
756 |
|
|
return true;
|
757 |
|
|
}
|
758 |
|
|
|
759 |
|
|
/* Set the sizes of the dynamic sections. */
|
760 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
761 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
762 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
763 |
|
|
*/
|
764 |
|
|
|
765 |
|
|
static boolean
|
766 |
|
|
i370_elf_size_dynamic_sections (output_bfd, info)
|
767 |
|
|
bfd *output_bfd;
|
768 |
|
|
struct bfd_link_info *info;
|
769 |
|
|
{
|
770 |
|
|
bfd *dynobj;
|
771 |
|
|
asection *s;
|
772 |
|
|
boolean plt;
|
773 |
|
|
boolean relocs;
|
774 |
|
|
boolean reltext;
|
775 |
|
|
|
776 |
|
|
#ifdef DEBUG
|
777 |
|
|
fprintf (stderr, "i370_elf_size_dynamic_sections called\n");
|
778 |
|
|
#endif
|
779 |
|
|
|
780 |
|
|
dynobj = elf_hash_table (info)->dynobj;
|
781 |
|
|
BFD_ASSERT (dynobj != NULL);
|
782 |
|
|
|
783 |
|
|
if (elf_hash_table (info)->dynamic_sections_created)
|
784 |
|
|
{
|
785 |
|
|
/* Set the contents of the .interp section to the interpreter. */
|
786 |
|
|
if (! info->shared)
|
787 |
|
|
{
|
788 |
|
|
s = bfd_get_section_by_name (dynobj, ".interp");
|
789 |
|
|
BFD_ASSERT (s != NULL);
|
790 |
|
|
s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
|
791 |
|
|
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
|
792 |
|
|
}
|
793 |
|
|
}
|
794 |
|
|
else
|
795 |
|
|
{
|
796 |
|
|
/* We may have created entries in the .rela.got, .rela.sdata, and
|
797 |
|
|
.rela.sdata2 sections. However, if we are not creating the
|
798 |
|
|
dynamic sections, we will not actually use these entries. Reset
|
799 |
|
|
the size of .rela.got, et al, which will cause it to get
|
800 |
|
|
stripped from the output file below. */
|
801 |
|
|
static char *rela_sections[] = { ".rela.got", ".rela.sdata",
|
802 |
|
|
".rela.sdata2", ".rela.sbss",
|
803 |
|
|
(char *)0 };
|
804 |
|
|
char **p;
|
805 |
|
|
|
806 |
|
|
for (p = rela_sections; *p != (char *)0; p++)
|
807 |
|
|
{
|
808 |
|
|
s = bfd_get_section_by_name (dynobj, *p);
|
809 |
|
|
if (s != NULL)
|
810 |
|
|
s->_raw_size = 0;
|
811 |
|
|
}
|
812 |
|
|
}
|
813 |
|
|
|
814 |
|
|
/* The check_relocs and adjust_dynamic_symbol entry points have
|
815 |
|
|
determined the sizes of the various dynamic sections. Allocate
|
816 |
|
|
memory for them. */
|
817 |
|
|
plt = false;
|
818 |
|
|
relocs = false;
|
819 |
|
|
reltext = false;
|
820 |
|
|
for (s = dynobj->sections; s != NULL; s = s->next)
|
821 |
|
|
{
|
822 |
|
|
const char *name;
|
823 |
|
|
boolean strip;
|
824 |
|
|
|
825 |
|
|
if ((s->flags & SEC_LINKER_CREATED) == 0)
|
826 |
|
|
continue;
|
827 |
|
|
|
828 |
|
|
/* It's OK to base decisions on the section name, because none
|
829 |
|
|
of the dynobj section names depend upon the input files. */
|
830 |
|
|
name = bfd_get_section_name (dynobj, s);
|
831 |
|
|
strip = false;
|
832 |
|
|
|
833 |
|
|
if (strcmp (name, ".plt") == 0)
|
834 |
|
|
{
|
835 |
|
|
if (s->_raw_size == 0)
|
836 |
|
|
{
|
837 |
|
|
/* Strip this section if we don't need it; see the
|
838 |
|
|
comment below. */
|
839 |
|
|
strip = true;
|
840 |
|
|
}
|
841 |
|
|
else
|
842 |
|
|
{
|
843 |
|
|
/* Remember whether there is a PLT. */
|
844 |
|
|
plt = true;
|
845 |
|
|
}
|
846 |
|
|
}
|
847 |
|
|
else if (strncmp (name, ".rela", 5) == 0)
|
848 |
|
|
{
|
849 |
|
|
if (s->_raw_size == 0)
|
850 |
|
|
{
|
851 |
|
|
/* If we don't need this section, strip it from the
|
852 |
|
|
output file. This is mostly to handle .rela.bss and
|
853 |
|
|
.rela.plt. We must create both sections in
|
854 |
|
|
create_dynamic_sections, because they must be created
|
855 |
|
|
before the linker maps input sections to output
|
856 |
|
|
sections. The linker does that before
|
857 |
|
|
adjust_dynamic_symbol is called, and it is that
|
858 |
|
|
function which decides whether anything needs to go
|
859 |
|
|
into these sections. */
|
860 |
|
|
strip = true;
|
861 |
|
|
}
|
862 |
|
|
else
|
863 |
|
|
{
|
864 |
|
|
asection *target;
|
865 |
|
|
const char *outname;
|
866 |
|
|
|
867 |
|
|
/* Remember whether there are any relocation sections. */
|
868 |
|
|
relocs = true;
|
869 |
|
|
|
870 |
|
|
/* If this relocation section applies to a read only
|
871 |
|
|
section, then we probably need a DT_TEXTREL entry. */
|
872 |
|
|
outname = bfd_get_section_name (output_bfd,
|
873 |
|
|
s->output_section);
|
874 |
|
|
target = bfd_get_section_by_name (output_bfd, outname + 5);
|
875 |
|
|
if (target != NULL
|
876 |
|
|
&& (target->flags & SEC_READONLY) != 0
|
877 |
|
|
&& (target->flags & SEC_ALLOC) != 0)
|
878 |
|
|
reltext = true;
|
879 |
|
|
|
880 |
|
|
/* We use the reloc_count field as a counter if we need
|
881 |
|
|
to copy relocs into the output file. */
|
882 |
|
|
s->reloc_count = 0;
|
883 |
|
|
}
|
884 |
|
|
}
|
885 |
|
|
else if (strcmp (name, ".got") != 0
|
886 |
|
|
&& strcmp (name, ".sdata") != 0
|
887 |
|
|
&& strcmp (name, ".sdata2") != 0)
|
888 |
|
|
{
|
889 |
|
|
/* It's not one of our sections, so don't allocate space. */
|
890 |
|
|
continue;
|
891 |
|
|
}
|
892 |
|
|
|
893 |
|
|
if (strip)
|
894 |
|
|
{
|
895 |
|
|
asection **spp;
|
896 |
|
|
|
897 |
|
|
for (spp = &s->output_section->owner->sections;
|
898 |
|
|
*spp != s->output_section;
|
899 |
|
|
spp = &(*spp)->next)
|
900 |
|
|
;
|
901 |
|
|
*spp = s->output_section->next;
|
902 |
|
|
--s->output_section->owner->section_count;
|
903 |
|
|
|
904 |
|
|
continue;
|
905 |
|
|
}
|
906 |
|
|
/* Allocate memory for the section contents. */
|
907 |
|
|
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
|
908 |
|
|
if (s->contents == NULL && s->_raw_size != 0)
|
909 |
|
|
return false;
|
910 |
|
|
}
|
911 |
|
|
|
912 |
|
|
if (elf_hash_table (info)->dynamic_sections_created)
|
913 |
|
|
{
|
914 |
|
|
/* Add some entries to the .dynamic section. We fill in the
|
915 |
|
|
values later, in i370_elf_finish_dynamic_sections, but we
|
916 |
|
|
must add the entries now so that we get the correct size for
|
917 |
|
|
the .dynamic section. The DT_DEBUG entry is filled in by the
|
918 |
|
|
dynamic linker and used by the debugger. */
|
919 |
|
|
if (! info->shared)
|
920 |
|
|
{
|
921 |
|
|
if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
|
922 |
|
|
return false;
|
923 |
|
|
}
|
924 |
|
|
|
925 |
|
|
if (plt)
|
926 |
|
|
{
|
927 |
|
|
if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
|
928 |
|
|
|| ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
|
929 |
|
|
|| ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
|
930 |
|
|
|| ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
|
931 |
|
|
return false;
|
932 |
|
|
}
|
933 |
|
|
|
934 |
|
|
if (relocs)
|
935 |
|
|
{
|
936 |
|
|
if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
|
937 |
|
|
|| ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
|
938 |
|
|
|| ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
|
939 |
|
|
sizeof (Elf32_External_Rela)))
|
940 |
|
|
return false;
|
941 |
|
|
}
|
942 |
|
|
|
943 |
|
|
if (reltext)
|
944 |
|
|
{
|
945 |
|
|
if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
|
946 |
|
|
return false;
|
947 |
|
|
info->flags |= DF_TEXTREL;
|
948 |
|
|
}
|
949 |
|
|
}
|
950 |
|
|
|
951 |
|
|
/* If we are generating a shared library, we generate a section
|
952 |
|
|
symbol for each output section. These are local symbols, which
|
953 |
|
|
means that they must come first in the dynamic symbol table.
|
954 |
|
|
That means we must increment the dynamic symbol index of every
|
955 |
|
|
other dynamic symbol.
|
956 |
|
|
|
957 |
|
|
FIXME: We assume that there will never be relocations to
|
958 |
|
|
locations in linker-created sections that do not have
|
959 |
|
|
externally-visible names. Instead, we should work out precisely
|
960 |
|
|
which sections relocations are targetted at. */
|
961 |
|
|
if (info->shared)
|
962 |
|
|
{
|
963 |
|
|
int c;
|
964 |
|
|
|
965 |
|
|
for (c = 0, s = output_bfd->sections; s != NULL; s = s->next)
|
966 |
|
|
{
|
967 |
|
|
if ((s->flags & SEC_LINKER_CREATED) != 0
|
968 |
|
|
|| (s->flags & SEC_ALLOC) == 0)
|
969 |
|
|
{
|
970 |
|
|
elf_section_data (s)->dynindx = -1;
|
971 |
|
|
continue;
|
972 |
|
|
}
|
973 |
|
|
|
974 |
|
|
/* These symbols will have no names, so we don't need to
|
975 |
|
|
fiddle with dynstr_index. */
|
976 |
|
|
|
977 |
|
|
elf_section_data (s)->dynindx = c + 1;
|
978 |
|
|
|
979 |
|
|
c++;
|
980 |
|
|
}
|
981 |
|
|
|
982 |
|
|
elf_link_hash_traverse (elf_hash_table (info),
|
983 |
|
|
i370_elf_adjust_dynindx,
|
984 |
|
|
(PTR) &c);
|
985 |
|
|
elf_hash_table (info)->dynsymcount += c;
|
986 |
|
|
}
|
987 |
|
|
|
988 |
|
|
return true;
|
989 |
|
|
}
|
990 |
|
|
|
991 |
|
|
/* Look through the relocs for a section during the first phase, and
|
992 |
|
|
allocate space in the global offset table or procedure linkage
|
993 |
|
|
table. */
|
994 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
995 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
996 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
997 |
|
|
*/
|
998 |
|
|
|
999 |
|
|
static boolean
|
1000 |
|
|
i370_elf_check_relocs (abfd, info, sec, relocs)
|
1001 |
|
|
bfd *abfd;
|
1002 |
|
|
struct bfd_link_info *info;
|
1003 |
|
|
asection *sec;
|
1004 |
|
|
const Elf_Internal_Rela *relocs;
|
1005 |
|
|
{
|
1006 |
|
|
bfd *dynobj;
|
1007 |
|
|
Elf_Internal_Shdr *symtab_hdr;
|
1008 |
|
|
struct elf_link_hash_entry **sym_hashes;
|
1009 |
|
|
const Elf_Internal_Rela *rel;
|
1010 |
|
|
const Elf_Internal_Rela *rel_end;
|
1011 |
|
|
bfd_vma *local_got_offsets;
|
1012 |
|
|
asection *sreloc;
|
1013 |
|
|
|
1014 |
|
|
if (info->relocateable)
|
1015 |
|
|
return true;
|
1016 |
|
|
|
1017 |
|
|
#ifdef DEBUG
|
1018 |
|
|
fprintf (stderr, "i370_elf_check_relocs called for section %s in %s\n",
|
1019 |
|
|
bfd_get_section_name (abfd, sec),
|
1020 |
|
|
bfd_get_filename (abfd));
|
1021 |
|
|
#endif
|
1022 |
|
|
|
1023 |
|
|
dynobj = elf_hash_table (info)->dynobj;
|
1024 |
|
|
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
1025 |
|
|
sym_hashes = elf_sym_hashes (abfd);
|
1026 |
|
|
local_got_offsets = elf_local_got_offsets (abfd);
|
1027 |
|
|
|
1028 |
|
|
sreloc = NULL;
|
1029 |
|
|
|
1030 |
|
|
rel_end = relocs + sec->reloc_count;
|
1031 |
|
|
for (rel = relocs; rel < rel_end; rel++)
|
1032 |
|
|
{
|
1033 |
|
|
unsigned long r_symndx;
|
1034 |
|
|
struct elf_link_hash_entry *h;
|
1035 |
|
|
|
1036 |
|
|
r_symndx = ELF32_R_SYM (rel->r_info);
|
1037 |
|
|
if (r_symndx < symtab_hdr->sh_info)
|
1038 |
|
|
h = NULL;
|
1039 |
|
|
else
|
1040 |
|
|
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
1041 |
|
|
|
1042 |
|
|
if (info->shared)
|
1043 |
|
|
{
|
1044 |
|
|
#ifdef DEBUG
|
1045 |
|
|
fprintf (stderr,
|
1046 |
|
|
"i370_elf_check_relocs needs to create relocation for %s\n",
|
1047 |
|
|
(h && h->root.root.string)
|
1048 |
|
|
? h->root.root.string : "<unknown>");
|
1049 |
|
|
#endif
|
1050 |
|
|
if (sreloc == NULL)
|
1051 |
|
|
{
|
1052 |
|
|
const char *name;
|
1053 |
|
|
|
1054 |
|
|
name = (bfd_elf_string_from_elf_section
|
1055 |
|
|
(abfd,
|
1056 |
|
|
elf_elfheader (abfd)->e_shstrndx,
|
1057 |
|
|
elf_section_data (sec)->rel_hdr.sh_name));
|
1058 |
|
|
if (name == NULL)
|
1059 |
|
|
return false;
|
1060 |
|
|
|
1061 |
|
|
BFD_ASSERT (strncmp (name, ".rela", 5) == 0
|
1062 |
|
|
&& strcmp (bfd_get_section_name (abfd, sec), name + 5) == 0);
|
1063 |
|
|
|
1064 |
|
|
sreloc = bfd_get_section_by_name (dynobj, name);
|
1065 |
|
|
if (sreloc == NULL)
|
1066 |
|
|
{
|
1067 |
|
|
flagword flags;
|
1068 |
|
|
|
1069 |
|
|
sreloc = bfd_make_section (dynobj, name);
|
1070 |
|
|
flags = (SEC_HAS_CONTENTS | SEC_READONLY
|
1071 |
|
|
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
|
1072 |
|
|
if ((sec->flags & SEC_ALLOC) != 0)
|
1073 |
|
|
flags |= SEC_ALLOC | SEC_LOAD;
|
1074 |
|
|
if (sreloc == NULL
|
1075 |
|
|
|| ! bfd_set_section_flags (dynobj, sreloc, flags)
|
1076 |
|
|
|| ! bfd_set_section_alignment (dynobj, sreloc, 2))
|
1077 |
|
|
return false;
|
1078 |
|
|
}
|
1079 |
|
|
}
|
1080 |
|
|
|
1081 |
|
|
sreloc->_raw_size += sizeof (Elf32_External_Rela);
|
1082 |
|
|
|
1083 |
|
|
/* FIXME: We should here do what the m68k and i386
|
1084 |
|
|
backends do: if the reloc is pc-relative, record it
|
1085 |
|
|
in case it turns out that the reloc is unnecessary
|
1086 |
|
|
because the symbol is forced local by versioning or
|
1087 |
|
|
we are linking with -Bdynamic. Fortunately this
|
1088 |
|
|
case is not frequent. */
|
1089 |
|
|
}
|
1090 |
|
|
}
|
1091 |
|
|
|
1092 |
|
|
return true;
|
1093 |
|
|
}
|
1094 |
|
|
|
1095 |
|
|
/* Finish up the dynamic sections. */
|
1096 |
|
|
/* XXX hack alert bogus This routine is mostly all junk and almost
|
1097 |
|
|
* certainly does the wrong thing. Its here simply because it does
|
1098 |
|
|
* just enough to allow glibc-2.1 ld.so to compile & link.
|
1099 |
|
|
*/
|
1100 |
|
|
|
1101 |
|
|
static boolean
|
1102 |
|
|
i370_elf_finish_dynamic_sections (output_bfd, info)
|
1103 |
|
|
bfd *output_bfd;
|
1104 |
|
|
struct bfd_link_info *info;
|
1105 |
|
|
{
|
1106 |
|
|
asection *sdyn;
|
1107 |
|
|
bfd *dynobj = elf_hash_table (info)->dynobj;
|
1108 |
|
|
asection *sgot = bfd_get_section_by_name (dynobj, ".got");
|
1109 |
|
|
|
1110 |
|
|
#ifdef DEBUG
|
1111 |
|
|
fprintf (stderr, "i370_elf_finish_dynamic_sections called\n");
|
1112 |
|
|
#endif
|
1113 |
|
|
|
1114 |
|
|
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
|
1115 |
|
|
|
1116 |
|
|
if (elf_hash_table (info)->dynamic_sections_created)
|
1117 |
|
|
{
|
1118 |
|
|
asection *splt;
|
1119 |
|
|
Elf32_External_Dyn *dyncon, *dynconend;
|
1120 |
|
|
|
1121 |
|
|
splt = bfd_get_section_by_name (dynobj, ".plt");
|
1122 |
|
|
BFD_ASSERT (splt != NULL && sdyn != NULL);
|
1123 |
|
|
|
1124 |
|
|
dyncon = (Elf32_External_Dyn *) sdyn->contents;
|
1125 |
|
|
dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
|
1126 |
|
|
for (; dyncon < dynconend; dyncon++)
|
1127 |
|
|
{
|
1128 |
|
|
Elf_Internal_Dyn dyn;
|
1129 |
|
|
const char *name;
|
1130 |
|
|
boolean size;
|
1131 |
|
|
|
1132 |
|
|
bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
|
1133 |
|
|
|
1134 |
|
|
switch (dyn.d_tag)
|
1135 |
|
|
{
|
1136 |
|
|
case DT_PLTGOT: name = ".plt"; size = false; break;
|
1137 |
|
|
case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
|
1138 |
|
|
case DT_JMPREL: name = ".rela.plt"; size = false; break;
|
1139 |
|
|
default: name = NULL; size = false; break;
|
1140 |
|
|
}
|
1141 |
|
|
|
1142 |
|
|
if (name != NULL)
|
1143 |
|
|
{
|
1144 |
|
|
asection *s;
|
1145 |
|
|
|
1146 |
|
|
s = bfd_get_section_by_name (output_bfd, name);
|
1147 |
|
|
if (s == NULL)
|
1148 |
|
|
dyn.d_un.d_val = 0;
|
1149 |
|
|
else
|
1150 |
|
|
{
|
1151 |
|
|
if (! size)
|
1152 |
|
|
dyn.d_un.d_ptr = s->vma;
|
1153 |
|
|
else
|
1154 |
|
|
{
|
1155 |
|
|
if (s->_cooked_size != 0)
|
1156 |
|
|
dyn.d_un.d_val = s->_cooked_size;
|
1157 |
|
|
else
|
1158 |
|
|
dyn.d_un.d_val = s->_raw_size;
|
1159 |
|
|
}
|
1160 |
|
|
}
|
1161 |
|
|
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
|
1162 |
|
|
}
|
1163 |
|
|
}
|
1164 |
|
|
}
|
1165 |
|
|
|
1166 |
|
|
/* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
|
1167 |
|
|
easily find the address of the _GLOBAL_OFFSET_TABLE_. */
|
1168 |
|
|
/* XXX this is clearly very wrong for the 370 arch */
|
1169 |
|
|
if (sgot)
|
1170 |
|
|
{
|
1171 |
|
|
unsigned char *contents = sgot->contents;
|
1172 |
|
|
bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
|
1173 |
|
|
|
1174 |
|
|
if (sdyn == NULL)
|
1175 |
|
|
bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4);
|
1176 |
|
|
else
|
1177 |
|
|
bfd_put_32 (output_bfd,
|
1178 |
|
|
sdyn->output_section->vma + sdyn->output_offset,
|
1179 |
|
|
contents+4);
|
1180 |
|
|
|
1181 |
|
|
elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
|
1182 |
|
|
}
|
1183 |
|
|
|
1184 |
|
|
if (info->shared)
|
1185 |
|
|
{
|
1186 |
|
|
asection *sdynsym;
|
1187 |
|
|
asection *s;
|
1188 |
|
|
Elf_Internal_Sym sym;
|
1189 |
|
|
int maxdindx = 0;
|
1190 |
|
|
|
1191 |
|
|
/* Set up the section symbols for the output sections. */
|
1192 |
|
|
|
1193 |
|
|
sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
|
1194 |
|
|
BFD_ASSERT (sdynsym != NULL);
|
1195 |
|
|
|
1196 |
|
|
sym.st_size = 0;
|
1197 |
|
|
sym.st_name = 0;
|
1198 |
|
|
sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
|
1199 |
|
|
sym.st_other = 0;
|
1200 |
|
|
|
1201 |
|
|
for (s = output_bfd->sections; s != NULL; s = s->next)
|
1202 |
|
|
{
|
1203 |
|
|
int indx, dindx;
|
1204 |
|
|
|
1205 |
|
|
sym.st_value = s->vma;
|
1206 |
|
|
|
1207 |
|
|
indx = elf_section_data (s)->this_idx;
|
1208 |
|
|
dindx = elf_section_data (s)->dynindx;
|
1209 |
|
|
if (dindx != -1)
|
1210 |
|
|
{
|
1211 |
|
|
BFD_ASSERT(indx > 0);
|
1212 |
|
|
BFD_ASSERT(dindx > 0);
|
1213 |
|
|
|
1214 |
|
|
if (dindx > maxdindx)
|
1215 |
|
|
maxdindx = dindx;
|
1216 |
|
|
|
1217 |
|
|
sym.st_shndx = indx;
|
1218 |
|
|
|
1219 |
|
|
bfd_elf32_swap_symbol_out (output_bfd, &sym,
|
1220 |
|
|
(PTR) (((Elf32_External_Sym *)
|
1221 |
|
|
sdynsym->contents)
|
1222 |
|
|
+ dindx));
|
1223 |
|
|
}
|
1224 |
|
|
}
|
1225 |
|
|
|
1226 |
|
|
/* Set the sh_info field of the output .dynsym section to the
|
1227 |
|
|
index of the first global symbol. */
|
1228 |
|
|
elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
|
1229 |
|
|
maxdindx + 1;
|
1230 |
|
|
}
|
1231 |
|
|
|
1232 |
|
|
return true;
|
1233 |
|
|
}
|
1234 |
|
|
|
1235 |
|
|
/* The RELOCATE_SECTION function is called by the ELF backend linker
|
1236 |
|
|
to handle the relocations for a section.
|
1237 |
|
|
|
1238 |
|
|
The relocs are always passed as Rela structures; if the section
|
1239 |
|
|
actually uses Rel structures, the r_addend field will always be
|
1240 |
|
|
zero.
|
1241 |
|
|
|
1242 |
|
|
This function is responsible for adjust the section contents as
|
1243 |
|
|
necessary, and (if using Rela relocs and generating a
|
1244 |
|
|
relocateable output file) adjusting the reloc addend as
|
1245 |
|
|
necessary.
|
1246 |
|
|
|
1247 |
|
|
This function does not have to worry about setting the reloc
|
1248 |
|
|
address or the reloc symbol index.
|
1249 |
|
|
|
1250 |
|
|
LOCAL_SYMS is a pointer to the swapped in local symbols.
|
1251 |
|
|
|
1252 |
|
|
LOCAL_SECTIONS is an array giving the section in the input file
|
1253 |
|
|
corresponding to the st_shndx field of each local symbol.
|
1254 |
|
|
|
1255 |
|
|
The global hash table entry for the global symbols can be found
|
1256 |
|
|
via elf_sym_hashes (input_bfd).
|
1257 |
|
|
|
1258 |
|
|
When generating relocateable output, this function must handle
|
1259 |
|
|
STB_LOCAL/STT_SECTION symbols specially. The output symbol is
|
1260 |
|
|
going to be the section symbol corresponding to the output
|
1261 |
|
|
section, which means that the addend must be adjusted
|
1262 |
|
|
accordingly. */
|
1263 |
|
|
|
1264 |
|
|
static boolean
|
1265 |
|
|
i370_elf_relocate_section (output_bfd, info, input_bfd, input_section,
|
1266 |
|
|
contents, relocs, local_syms, local_sections)
|
1267 |
|
|
bfd *output_bfd;
|
1268 |
|
|
struct bfd_link_info *info;
|
1269 |
|
|
bfd *input_bfd;
|
1270 |
|
|
asection *input_section;
|
1271 |
|
|
bfd_byte *contents;
|
1272 |
|
|
Elf_Internal_Rela *relocs;
|
1273 |
|
|
Elf_Internal_Sym *local_syms;
|
1274 |
|
|
asection **local_sections;
|
1275 |
|
|
{
|
1276 |
|
|
Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
|
1277 |
|
|
struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
|
1278 |
|
|
bfd *dynobj = elf_hash_table (info)->dynobj;
|
1279 |
|
|
Elf_Internal_Rela *rel = relocs;
|
1280 |
|
|
Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
|
1281 |
|
|
asection *sreloc = NULL;
|
1282 |
|
|
bfd_vma *local_got_offsets;
|
1283 |
|
|
boolean ret = true;
|
1284 |
|
|
|
1285 |
|
|
#ifdef DEBUG
|
1286 |
|
|
fprintf (stderr, "i370_elf_relocate_section called for %s section %s, %ld relocations%s\n",
|
1287 |
|
|
bfd_get_filename (input_bfd),
|
1288 |
|
|
bfd_section_name(input_bfd, input_section),
|
1289 |
|
|
(long)input_section->reloc_count,
|
1290 |
|
|
(info->relocateable) ? " (relocatable)" : "");
|
1291 |
|
|
#endif
|
1292 |
|
|
|
1293 |
|
|
if (!i370_elf_howto_table[ R_I370_ADDR31 ]) /* Initialize howto table if needed */
|
1294 |
|
|
i370_elf_howto_init ();
|
1295 |
|
|
|
1296 |
|
|
local_got_offsets = elf_local_got_offsets (input_bfd);
|
1297 |
|
|
|
1298 |
|
|
for (; rel < relend; rel++)
|
1299 |
|
|
{
|
1300 |
|
|
enum i370_reloc_type r_type = (enum i370_reloc_type)ELF32_R_TYPE (rel->r_info);
|
1301 |
|
|
bfd_vma offset = rel->r_offset;
|
1302 |
|
|
bfd_vma addend = rel->r_addend;
|
1303 |
|
|
bfd_reloc_status_type r = bfd_reloc_other;
|
1304 |
|
|
Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
|
1305 |
|
|
asection *sec = (asection *)0;
|
1306 |
|
|
struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
|
1307 |
|
|
const char *sym_name = (const char *)0;
|
1308 |
|
|
reloc_howto_type *howto;
|
1309 |
|
|
unsigned long r_symndx;
|
1310 |
|
|
bfd_vma relocation;
|
1311 |
|
|
|
1312 |
|
|
/* Unknown relocation handling */
|
1313 |
|
|
if ((unsigned)r_type >= (unsigned)R_I370_max
|
1314 |
|
|
|| !i370_elf_howto_table[(int)r_type])
|
1315 |
|
|
{
|
1316 |
|
|
(*_bfd_error_handler) ("%s: unknown relocation type %d",
|
1317 |
|
|
bfd_get_filename (input_bfd),
|
1318 |
|
|
(int)r_type);
|
1319 |
|
|
|
1320 |
|
|
bfd_set_error (bfd_error_bad_value);
|
1321 |
|
|
ret = false;
|
1322 |
|
|
continue;
|
1323 |
|
|
}
|
1324 |
|
|
|
1325 |
|
|
howto = i370_elf_howto_table[(int)r_type];
|
1326 |
|
|
r_symndx = ELF32_R_SYM (rel->r_info);
|
1327 |
|
|
|
1328 |
|
|
if (info->relocateable)
|
1329 |
|
|
{
|
1330 |
|
|
/* This is a relocateable link. We don't have to change
|
1331 |
|
|
anything, unless the reloc is against a section symbol,
|
1332 |
|
|
in which case we have to adjust according to where the
|
1333 |
|
|
section symbol winds up in the output section. */
|
1334 |
|
|
if (r_symndx < symtab_hdr->sh_info)
|
1335 |
|
|
{
|
1336 |
|
|
sym = local_syms + r_symndx;
|
1337 |
|
|
if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
|
1338 |
|
|
{
|
1339 |
|
|
sec = local_sections[r_symndx];
|
1340 |
|
|
addend = rel->r_addend += sec->output_offset + sym->st_value;
|
1341 |
|
|
}
|
1342 |
|
|
}
|
1343 |
|
|
|
1344 |
|
|
#ifdef DEBUG
|
1345 |
|
|
fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
|
1346 |
|
|
howto->name,
|
1347 |
|
|
(int)r_type,
|
1348 |
|
|
r_symndx,
|
1349 |
|
|
(long)offset,
|
1350 |
|
|
(long)addend);
|
1351 |
|
|
#endif
|
1352 |
|
|
continue;
|
1353 |
|
|
}
|
1354 |
|
|
|
1355 |
|
|
/* This is a final link. */
|
1356 |
|
|
if (r_symndx < symtab_hdr->sh_info)
|
1357 |
|
|
{
|
1358 |
|
|
sym = local_syms + r_symndx;
|
1359 |
|
|
sec = local_sections[r_symndx];
|
1360 |
|
|
sym_name = "<local symbol>";
|
1361 |
|
|
|
1362 |
|
|
relocation = (sec->output_section->vma
|
1363 |
|
|
+ sec->output_offset
|
1364 |
|
|
+ sym->st_value);
|
1365 |
|
|
}
|
1366 |
|
|
else
|
1367 |
|
|
{
|
1368 |
|
|
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
1369 |
|
|
while (h->root.type == bfd_link_hash_indirect
|
1370 |
|
|
|| h->root.type == bfd_link_hash_warning)
|
1371 |
|
|
h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
1372 |
|
|
sym_name = h->root.root.string;
|
1373 |
|
|
if (h->root.type == bfd_link_hash_defined
|
1374 |
|
|
|| h->root.type == bfd_link_hash_defweak)
|
1375 |
|
|
{
|
1376 |
|
|
sec = h->root.u.def.section;
|
1377 |
|
|
if (info->shared
|
1378 |
|
|
&& ((! info->symbolic && h->dynindx != -1)
|
1379 |
|
|
|| (h->elf_link_hash_flags
|
1380 |
|
|
& ELF_LINK_HASH_DEF_REGULAR) == 0)
|
1381 |
|
|
&& (input_section->flags & SEC_ALLOC) != 0
|
1382 |
|
|
&& (r_type == R_I370_ADDR31
|
1383 |
|
|
|| r_type == R_I370_COPY
|
1384 |
|
|
|| r_type == R_I370_ADDR16
|
1385 |
|
|
|| r_type == R_I370_RELATIVE))
|
1386 |
|
|
{
|
1387 |
|
|
/* In these cases, we don't need the relocation
|
1388 |
|
|
value. We check specially because in some
|
1389 |
|
|
obscure cases sec->output_section will be NULL. */
|
1390 |
|
|
relocation = 0;
|
1391 |
|
|
}
|
1392 |
|
|
else
|
1393 |
|
|
relocation = (h->root.u.def.value
|
1394 |
|
|
+ sec->output_section->vma
|
1395 |
|
|
+ sec->output_offset);
|
1396 |
|
|
}
|
1397 |
|
|
else if (h->root.type == bfd_link_hash_undefweak)
|
1398 |
|
|
relocation = 0;
|
1399 |
|
|
else if (info->shared
|
1400 |
|
|
&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
|
1401 |
|
|
relocation = 0;
|
1402 |
|
|
else
|
1403 |
|
|
{
|
1404 |
|
|
(*info->callbacks->undefined_symbol) (info,
|
1405 |
|
|
h->root.root.string,
|
1406 |
|
|
input_bfd,
|
1407 |
|
|
input_section,
|
1408 |
|
|
rel->r_offset,
|
1409 |
|
|
true);
|
1410 |
|
|
ret = false;
|
1411 |
|
|
continue;
|
1412 |
|
|
}
|
1413 |
|
|
}
|
1414 |
|
|
|
1415 |
|
|
switch ((int)r_type)
|
1416 |
|
|
{
|
1417 |
|
|
default:
|
1418 |
|
|
(*_bfd_error_handler) ("%s: unknown relocation type %d for symbol %s",
|
1419 |
|
|
bfd_get_filename (input_bfd),
|
1420 |
|
|
(int)r_type, sym_name);
|
1421 |
|
|
|
1422 |
|
|
bfd_set_error (bfd_error_bad_value);
|
1423 |
|
|
ret = false;
|
1424 |
|
|
continue;
|
1425 |
|
|
|
1426 |
|
|
/* Relocations that may need to be propagated if this is a shared
|
1427 |
|
|
object. */
|
1428 |
|
|
case (int)R_I370_REL31:
|
1429 |
|
|
/* If these relocations are not to a named symbol, they can be
|
1430 |
|
|
handled right here, no need to bother the dynamic linker. */
|
1431 |
|
|
if (h == NULL
|
1432 |
|
|
|| strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
|
1433 |
|
|
break;
|
1434 |
|
|
/* fall through */
|
1435 |
|
|
|
1436 |
|
|
/* Relocations that always need to be propagated if this is a shared
|
1437 |
|
|
object. */
|
1438 |
|
|
case (int)R_I370_NONE:
|
1439 |
|
|
case (int)R_I370_ADDR31:
|
1440 |
|
|
case (int)R_I370_ADDR16:
|
1441 |
|
|
if (info->shared)
|
1442 |
|
|
{
|
1443 |
|
|
Elf_Internal_Rela outrel;
|
1444 |
|
|
boolean skip;
|
1445 |
|
|
|
1446 |
|
|
#ifdef DEBUG
|
1447 |
|
|
fprintf (stderr,
|
1448 |
|
|
"i370_elf_relocate_section needs to create relocation for %s\n",
|
1449 |
|
|
(h && h->root.root.string) ? h->root.root.string : "<unknown>");
|
1450 |
|
|
#endif
|
1451 |
|
|
|
1452 |
|
|
/* When generating a shared object, these relocations
|
1453 |
|
|
are copied into the output file to be resolved at run
|
1454 |
|
|
time. */
|
1455 |
|
|
|
1456 |
|
|
if (sreloc == NULL)
|
1457 |
|
|
{
|
1458 |
|
|
const char *name;
|
1459 |
|
|
|
1460 |
|
|
name = (bfd_elf_string_from_elf_section
|
1461 |
|
|
(input_bfd,
|
1462 |
|
|
elf_elfheader (input_bfd)->e_shstrndx,
|
1463 |
|
|
elf_section_data (input_section)->rel_hdr.sh_name));
|
1464 |
|
|
if (name == NULL)
|
1465 |
|
|
return false;
|
1466 |
|
|
|
1467 |
|
|
BFD_ASSERT (strncmp (name, ".rela", 5) == 0
|
1468 |
|
|
&& strcmp (bfd_get_section_name (input_bfd,
|
1469 |
|
|
input_section),
|
1470 |
|
|
name + 5) == 0);
|
1471 |
|
|
|
1472 |
|
|
sreloc = bfd_get_section_by_name (dynobj, name);
|
1473 |
|
|
BFD_ASSERT (sreloc != NULL);
|
1474 |
|
|
}
|
1475 |
|
|
|
1476 |
|
|
skip = false;
|
1477 |
|
|
|
1478 |
|
|
if (elf_section_data (input_section)->stab_info == NULL)
|
1479 |
|
|
outrel.r_offset = rel->r_offset;
|
1480 |
|
|
else
|
1481 |
|
|
{
|
1482 |
|
|
bfd_vma off;
|
1483 |
|
|
|
1484 |
|
|
off = (_bfd_stab_section_offset
|
1485 |
|
|
(output_bfd, &elf_hash_table (info)->stab_info,
|
1486 |
|
|
input_section,
|
1487 |
|
|
&elf_section_data (input_section)->stab_info,
|
1488 |
|
|
rel->r_offset));
|
1489 |
|
|
if (off == (bfd_vma) -1)
|
1490 |
|
|
skip = true;
|
1491 |
|
|
outrel.r_offset = off;
|
1492 |
|
|
}
|
1493 |
|
|
|
1494 |
|
|
outrel.r_offset += (input_section->output_section->vma
|
1495 |
|
|
+ input_section->output_offset);
|
1496 |
|
|
|
1497 |
|
|
if (skip)
|
1498 |
|
|
memset (&outrel, 0, sizeof outrel);
|
1499 |
|
|
/* h->dynindx may be -1 if this symbol was marked to
|
1500 |
|
|
become local. */
|
1501 |
|
|
else if (h != NULL
|
1502 |
|
|
&& ((! info->symbolic && h->dynindx != -1)
|
1503 |
|
|
|| (h->elf_link_hash_flags
|
1504 |
|
|
& ELF_LINK_HASH_DEF_REGULAR) == 0))
|
1505 |
|
|
{
|
1506 |
|
|
BFD_ASSERT (h->dynindx != -1);
|
1507 |
|
|
outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
|
1508 |
|
|
outrel.r_addend = rel->r_addend;
|
1509 |
|
|
}
|
1510 |
|
|
else
|
1511 |
|
|
{
|
1512 |
|
|
if (r_type == R_I370_ADDR31)
|
1513 |
|
|
{
|
1514 |
|
|
outrel.r_info = ELF32_R_INFO (0, R_I370_RELATIVE);
|
1515 |
|
|
outrel.r_addend = relocation + rel->r_addend;
|
1516 |
|
|
}
|
1517 |
|
|
else
|
1518 |
|
|
{
|
1519 |
|
|
long indx;
|
1520 |
|
|
|
1521 |
|
|
if (h == NULL)
|
1522 |
|
|
sec = local_sections[r_symndx];
|
1523 |
|
|
else
|
1524 |
|
|
{
|
1525 |
|
|
BFD_ASSERT (h->root.type == bfd_link_hash_defined
|
1526 |
|
|
|| (h->root.type
|
1527 |
|
|
== bfd_link_hash_defweak));
|
1528 |
|
|
sec = h->root.u.def.section;
|
1529 |
|
|
}
|
1530 |
|
|
if (sec != NULL && bfd_is_abs_section (sec))
|
1531 |
|
|
indx = 0;
|
1532 |
|
|
else if (sec == NULL || sec->owner == NULL)
|
1533 |
|
|
{
|
1534 |
|
|
bfd_set_error (bfd_error_bad_value);
|
1535 |
|
|
return false;
|
1536 |
|
|
}
|
1537 |
|
|
else
|
1538 |
|
|
{
|
1539 |
|
|
asection *osec;
|
1540 |
|
|
|
1541 |
|
|
osec = sec->output_section;
|
1542 |
|
|
indx = elf_section_data (osec)->dynindx;
|
1543 |
|
|
BFD_ASSERT(indx > 0);
|
1544 |
|
|
#ifdef DEBUG
|
1545 |
|
|
if (indx <= 0)
|
1546 |
|
|
{
|
1547 |
|
|
printf ("indx=%d section=%s flags=%08x name=%s\n",
|
1548 |
|
|
indx, osec->name, osec->flags,
|
1549 |
|
|
h->root.root.string);
|
1550 |
|
|
}
|
1551 |
|
|
#endif
|
1552 |
|
|
}
|
1553 |
|
|
|
1554 |
|
|
outrel.r_info = ELF32_R_INFO (indx, r_type);
|
1555 |
|
|
outrel.r_addend = relocation + rel->r_addend;
|
1556 |
|
|
}
|
1557 |
|
|
}
|
1558 |
|
|
|
1559 |
|
|
bfd_elf32_swap_reloca_out (output_bfd, &outrel,
|
1560 |
|
|
(((Elf32_External_Rela *)
|
1561 |
|
|
sreloc->contents)
|
1562 |
|
|
+ sreloc->reloc_count));
|
1563 |
|
|
++sreloc->reloc_count;
|
1564 |
|
|
|
1565 |
|
|
/* This reloc will be computed at runtime, so there's no
|
1566 |
|
|
need to do anything now, unless this is a RELATIVE
|
1567 |
|
|
reloc in an unallocated section. */
|
1568 |
|
|
if (skip
|
1569 |
|
|
|| (input_section->flags & SEC_ALLOC) != 0
|
1570 |
|
|
|| ELF32_R_TYPE (outrel.r_info) != R_I370_RELATIVE)
|
1571 |
|
|
continue;
|
1572 |
|
|
}
|
1573 |
|
|
break;
|
1574 |
|
|
|
1575 |
|
|
case (int)R_I370_COPY:
|
1576 |
|
|
case (int)R_I370_RELATIVE:
|
1577 |
|
|
(*_bfd_error_handler) ("%s: Relocation %s is not yet supported for symbol %s.",
|
1578 |
|
|
bfd_get_filename (input_bfd),
|
1579 |
|
|
i370_elf_howto_table[ (int)r_type ]->name,
|
1580 |
|
|
sym_name);
|
1581 |
|
|
|
1582 |
|
|
bfd_set_error (bfd_error_invalid_operation);
|
1583 |
|
|
ret = false;
|
1584 |
|
|
continue;
|
1585 |
|
|
}
|
1586 |
|
|
|
1587 |
|
|
#ifdef DEBUG
|
1588 |
|
|
fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
|
1589 |
|
|
howto->name,
|
1590 |
|
|
(int)r_type,
|
1591 |
|
|
sym_name,
|
1592 |
|
|
r_symndx,
|
1593 |
|
|
(long)offset,
|
1594 |
|
|
(long)addend);
|
1595 |
|
|
#endif
|
1596 |
|
|
|
1597 |
|
|
r = _bfd_final_link_relocate (howto,
|
1598 |
|
|
input_bfd,
|
1599 |
|
|
input_section,
|
1600 |
|
|
contents,
|
1601 |
|
|
offset,
|
1602 |
|
|
relocation,
|
1603 |
|
|
addend);
|
1604 |
|
|
|
1605 |
|
|
if (r != bfd_reloc_ok)
|
1606 |
|
|
{
|
1607 |
|
|
ret = false;
|
1608 |
|
|
switch (r)
|
1609 |
|
|
{
|
1610 |
|
|
default:
|
1611 |
|
|
break;
|
1612 |
|
|
|
1613 |
|
|
case bfd_reloc_overflow:
|
1614 |
|
|
{
|
1615 |
|
|
const char *name;
|
1616 |
|
|
|
1617 |
|
|
if (h != NULL)
|
1618 |
|
|
name = h->root.root.string;
|
1619 |
|
|
else
|
1620 |
|
|
{
|
1621 |
|
|
name = bfd_elf_string_from_elf_section (input_bfd,
|
1622 |
|
|
symtab_hdr->sh_link,
|
1623 |
|
|
sym->st_name);
|
1624 |
|
|
if (name == NULL)
|
1625 |
|
|
break;
|
1626 |
|
|
|
1627 |
|
|
if (*name == '\0')
|
1628 |
|
|
name = bfd_section_name (input_bfd, sec);
|
1629 |
|
|
}
|
1630 |
|
|
|
1631 |
|
|
(*info->callbacks->reloc_overflow) (info,
|
1632 |
|
|
name,
|
1633 |
|
|
howto->name,
|
1634 |
|
|
(bfd_vma) 0,
|
1635 |
|
|
input_bfd,
|
1636 |
|
|
input_section,
|
1637 |
|
|
offset);
|
1638 |
|
|
}
|
1639 |
|
|
break;
|
1640 |
|
|
|
1641 |
|
|
}
|
1642 |
|
|
}
|
1643 |
|
|
}
|
1644 |
|
|
|
1645 |
|
|
#ifdef DEBUG
|
1646 |
|
|
fprintf (stderr, "\n");
|
1647 |
|
|
#endif
|
1648 |
|
|
|
1649 |
|
|
return ret;
|
1650 |
|
|
}
|
1651 |
|
|
|
1652 |
|
|
static void
|
1653 |
|
|
i370_elf_post_process_headers (abfd, link_info)
|
1654 |
|
|
bfd * abfd;
|
1655 |
|
|
struct bfd_link_info * link_info ATTRIBUTE_UNUSED;
|
1656 |
|
|
{
|
1657 |
|
|
Elf_Internal_Ehdr * i_ehdrp; /* Elf file header, internal form */
|
1658 |
|
|
|
1659 |
|
|
i_ehdrp = elf_elfheader (abfd);
|
1660 |
|
|
i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_LINUX;
|
1661 |
|
|
}
|
1662 |
|
|
|
1663 |
|
|
#define TARGET_BIG_SYM bfd_elf32_i370_vec
|
1664 |
|
|
#define TARGET_BIG_NAME "elf32-i370"
|
1665 |
|
|
#define ELF_ARCH bfd_arch_i370
|
1666 |
|
|
#define ELF_MACHINE_CODE EM_S370
|
1667 |
|
|
#ifdef EM_I370_OLD
|
1668 |
|
|
#define ELF_MACHINE_ALT1 EM_I370_OLD
|
1669 |
|
|
#endif
|
1670 |
|
|
#define ELF_MAXPAGESIZE 0x1000
|
1671 |
|
|
#define elf_info_to_howto i370_elf_info_to_howto
|
1672 |
|
|
|
1673 |
|
|
#define elf_backend_plt_not_loaded 1
|
1674 |
|
|
#define elf_backend_got_symbol_offset 4
|
1675 |
|
|
|
1676 |
|
|
#define bfd_elf32_bfd_reloc_type_lookup i370_elf_reloc_type_lookup
|
1677 |
|
|
#define bfd_elf32_bfd_set_private_flags i370_elf_set_private_flags
|
1678 |
|
|
#define bfd_elf32_bfd_copy_private_bfd_data i370_elf_copy_private_bfd_data
|
1679 |
|
|
#define bfd_elf32_bfd_merge_private_bfd_data i370_elf_merge_private_bfd_data
|
1680 |
|
|
#define elf_backend_relocate_section i370_elf_relocate_section
|
1681 |
|
|
|
1682 |
|
|
/* dynamic loader support is mostly broken; just enough here to be able to
|
1683 |
|
|
* link glibc's ld.so without errors.
|
1684 |
|
|
*/
|
1685 |
|
|
#define elf_backend_create_dynamic_sections i370_elf_create_dynamic_sections
|
1686 |
|
|
#define elf_backend_size_dynamic_sections i370_elf_size_dynamic_sections
|
1687 |
|
|
#define elf_backend_finish_dynamic_sections i370_elf_finish_dynamic_sections
|
1688 |
|
|
#define elf_backend_fake_sections i370_elf_fake_sections
|
1689 |
|
|
#define elf_backend_section_from_shdr i370_elf_section_from_shdr
|
1690 |
|
|
#define elf_backend_adjust_dynamic_symbol i370_elf_adjust_dynamic_symbol
|
1691 |
|
|
#define elf_backend_check_relocs i370_elf_check_relocs
|
1692 |
|
|
|
1693 |
|
|
/*
|
1694 |
|
|
#define elf_backend_add_symbol_hook i370_elf_add_symbol_hook
|
1695 |
|
|
#define elf_backend_finish_dynamic_symbol i370_elf_finish_dynamic_symbol
|
1696 |
|
|
#define elf_backend_additional_program_headers i370_elf_additional_program_headers
|
1697 |
|
|
#define elf_backend_modify_segment_map i370_elf_modify_segment_map
|
1698 |
|
|
*/
|
1699 |
|
|
|
1700 |
|
|
#define elf_backend_post_process_headers i370_elf_post_process_headers
|
1701 |
|
|
|
1702 |
|
|
int i370_noop()
|
1703 |
|
|
{
|
1704 |
|
|
return 1;
|
1705 |
|
|
}
|
1706 |
|
|
|
1707 |
|
|
/* we need to define these at least as no-ops to link glibc ld.so */
|
1708 |
|
|
|
1709 |
|
|
#define elf_backend_add_symbol_hook \
|
1710 |
|
|
(boolean (*) PARAMS ((bfd *, struct bfd_link_info *, \
|
1711 |
|
|
const Elf_Internal_Sym *, const char **, flagword *, \
|
1712 |
|
|
asection **, bfd_vma *))) i370_noop
|
1713 |
|
|
#define elf_backend_finish_dynamic_symbol \
|
1714 |
|
|
(boolean (*) PARAMS ((bfd *, struct bfd_link_info *, \
|
1715 |
|
|
struct elf_link_hash_entry *, \
|
1716 |
|
|
Elf_Internal_Sym *))) i370_noop
|
1717 |
|
|
#define elf_backend_additional_program_headers \
|
1718 |
|
|
(int (*) PARAMS ((bfd *))) i370_noop
|
1719 |
|
|
#define elf_backend_modify_segment_map \
|
1720 |
|
|
(boolean (*) PARAMS ((bfd *))) i370_noop
|
1721 |
|
|
|
1722 |
|
|
#include "elf32-target.h"
|