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