| 1 | /* IBM S/390-specific support for 32-bit ELF |
| 2 | Copyright 2000, 2001 Free Software Foundation, Inc. |
| 3 | Contributed by Carl B. Pedersen and Martin Schwidefsky. |
| 4 | |
| 5 | This file is part of BFD, the Binary File Descriptor library. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 | 02111-1307, USA. */ |
| 21 | |
| 22 | #include "bfd.h" |
| 23 | #include "sysdep.h" |
| 24 | #include "bfdlink.h" |
| 25 | #include "libbfd.h" |
| 26 | #include "elf-bfd.h" |
| 27 | |
| 28 | static reloc_howto_type *elf_s390_reloc_type_lookup |
| 29 | PARAMS ((bfd *, bfd_reloc_code_real_type)); |
| 30 | static void elf_s390_info_to_howto |
| 31 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); |
| 32 | static boolean elf_s390_is_local_label_name PARAMS ((bfd *, const char *)); |
| 33 | static struct bfd_hash_entry *elf_s390_link_hash_newfunc |
| 34 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); |
| 35 | static struct bfd_link_hash_table *elf_s390_link_hash_table_create |
| 36 | PARAMS ((bfd *)); |
| 37 | static boolean elf_s390_check_relocs |
| 38 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
| 39 | const Elf_Internal_Rela *)); |
| 40 | static asection *elf_s390_gc_mark_hook |
| 41 | PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *, |
| 42 | struct elf_link_hash_entry *, Elf_Internal_Sym *sym)); |
| 43 | static boolean elf_s390_gc_sweep_hook |
| 44 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
| 45 | const Elf_Internal_Rela *)); |
| 46 | static boolean elf_s390_adjust_dynamic_symbol |
| 47 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); |
| 48 | static boolean elf_s390_size_dynamic_sections |
| 49 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 50 | static boolean elf_s390_relocate_section |
| 51 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
| 52 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); |
| 53 | static boolean elf_s390_finish_dynamic_symbol |
| 54 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, |
| 55 | Elf_Internal_Sym *)); |
| 56 | static boolean elf_s390_finish_dynamic_sections |
| 57 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 58 | static boolean elf_s390_object_p PARAMS ((bfd *)); |
| 59 | static enum elf_reloc_type_class elf_s390_reloc_type_class PARAMS ((int)); |
| 60 | |
| 61 | #define USE_RELA 1 /* We want RELA relocations, not REL. */ |
| 62 | |
| 63 | #include "elf/s390.h" |
| 64 | |
| 65 | /* The relocation "howto" table. */ |
| 66 | |
| 67 | static reloc_howto_type elf_howto_table[] = |
| 68 | { |
| 69 | HOWTO (R_390_NONE, /* type */ |
| 70 | 0, /* rightshift */ |
| 71 | 0, /* size (0 = byte, 1 = short, 2 = long) */ |
| 72 | 0, /* bitsize */ |
| 73 | false, /* pc_relative */ |
| 74 | 0, /* bitpos */ |
| 75 | complain_overflow_dont, /* complain_on_overflow */ |
| 76 | bfd_elf_generic_reloc, /* special_function */ |
| 77 | "R_390_NONE", /* name */ |
| 78 | false, /* partial_inplace */ |
| 79 | 0, /* src_mask */ |
| 80 | 0, /* dst_mask */ |
| 81 | false), /* pcrel_offset */ |
| 82 | |
| 83 | HOWTO(R_390_8, 0, 0, 8, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_8", false, 0,0x000000ff, false), |
| 84 | HOWTO(R_390_12, 0, 1, 12, false, 0, complain_overflow_dont, bfd_elf_generic_reloc, "R_390_12", false, 0,0x00000fff, false), |
| 85 | HOWTO(R_390_16, 0, 1, 16, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_16", false, 0,0x0000ffff, false), |
| 86 | HOWTO(R_390_32, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_32", false, 0,0xffffffff, false), |
| 87 | HOWTO(R_390_PC32, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC32", false, 0,0xffffffff, true), |
| 88 | HOWTO(R_390_GOT12, 0, 1, 12, false, 0, complain_overflow_dont, bfd_elf_generic_reloc, "R_390_GOT12", false, 0,0x00000fff, false), |
| 89 | HOWTO(R_390_GOT32, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOT32", false, 0,0xffffffff, false), |
| 90 | HOWTO(R_390_PLT32, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT32", false, 0,0xffffffff, true), |
| 91 | HOWTO(R_390_COPY, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_COPY", false, 0,0xffffffff, false), |
| 92 | HOWTO(R_390_GLOB_DAT, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GLOB_DAT",false, 0,0xffffffff, false), |
| 93 | HOWTO(R_390_JMP_SLOT, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_JMP_SLOT",false, 0,0xffffffff, false), |
| 94 | HOWTO(R_390_RELATIVE, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_RELATIVE",false, 0,0xffffffff, false), |
| 95 | HOWTO(R_390_GOTOFF, 0, 2, 32, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTOFF", false, 0,0xffffffff, false), |
| 96 | HOWTO(R_390_GOTPC, 0, 2, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOTPC", false, 0,0xffffffff, true), |
| 97 | HOWTO(R_390_GOT16, 0, 1, 16, false, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_GOT16", false, 0,0x0000ffff, false), |
| 98 | HOWTO(R_390_PC16, 0, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC16", false, 0,0x0000ffff, true), |
| 99 | HOWTO(R_390_PC16DBL, 1, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PC16DBL", false, 0,0x0000ffff, true), |
| 100 | HOWTO(R_390_PLT16DBL, 1, 1, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_390_PLT16DBL", false, 0,0x0000ffff, true), |
| 101 | }; |
| 102 | |
| 103 | /* GNU extension to record C++ vtable hierarchy. */ |
| 104 | static reloc_howto_type elf32_s390_vtinherit_howto = |
| 105 | HOWTO (R_390_GNU_VTINHERIT, 0,2,0,false,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", false,0, 0, false); |
| 106 | static reloc_howto_type elf32_s390_vtentry_howto = |
| 107 | HOWTO (R_390_GNU_VTENTRY, 0,2,0,false,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", false,0,0, false); |
| 108 | |
| 109 | static reloc_howto_type * |
| 110 | elf_s390_reloc_type_lookup (abfd, code) |
| 111 | bfd *abfd ATTRIBUTE_UNUSED; |
| 112 | bfd_reloc_code_real_type code; |
| 113 | { |
| 114 | switch (code) { |
| 115 | case BFD_RELOC_NONE: |
| 116 | return &elf_howto_table[(int) R_390_NONE]; |
| 117 | case BFD_RELOC_8: |
| 118 | return &elf_howto_table[(int) R_390_8]; |
| 119 | case BFD_RELOC_390_12: |
| 120 | return &elf_howto_table[(int) R_390_12]; |
| 121 | case BFD_RELOC_16: |
| 122 | return &elf_howto_table[(int) R_390_16]; |
| 123 | case BFD_RELOC_32: |
| 124 | return &elf_howto_table[(int) R_390_32]; |
| 125 | case BFD_RELOC_CTOR: |
| 126 | return &elf_howto_table[(int) R_390_32]; |
| 127 | case BFD_RELOC_32_PCREL: |
| 128 | return &elf_howto_table[(int) R_390_PC32]; |
| 129 | case BFD_RELOC_390_GOT12: |
| 130 | return &elf_howto_table[(int) R_390_GOT12]; |
| 131 | case BFD_RELOC_32_GOT_PCREL: |
| 132 | return &elf_howto_table[(int) R_390_GOT32]; |
| 133 | case BFD_RELOC_390_PLT32: |
| 134 | return &elf_howto_table[(int) R_390_PLT32]; |
| 135 | case BFD_RELOC_390_COPY: |
| 136 | return &elf_howto_table[(int) R_390_COPY]; |
| 137 | case BFD_RELOC_390_GLOB_DAT: |
| 138 | return &elf_howto_table[(int) R_390_GLOB_DAT]; |
| 139 | case BFD_RELOC_390_JMP_SLOT: |
| 140 | return &elf_howto_table[(int) R_390_JMP_SLOT]; |
| 141 | case BFD_RELOC_390_RELATIVE: |
| 142 | return &elf_howto_table[(int) R_390_RELATIVE]; |
| 143 | case BFD_RELOC_32_GOTOFF: |
| 144 | return &elf_howto_table[(int) R_390_GOTOFF]; |
| 145 | case BFD_RELOC_390_GOTPC: |
| 146 | return &elf_howto_table[(int) R_390_GOTPC]; |
| 147 | case BFD_RELOC_390_GOT16: |
| 148 | return &elf_howto_table[(int) R_390_GOT16]; |
| 149 | case BFD_RELOC_16_PCREL: |
| 150 | return &elf_howto_table[(int) R_390_PC16]; |
| 151 | case BFD_RELOC_390_PC16DBL: |
| 152 | return &elf_howto_table[(int) R_390_PC16DBL]; |
| 153 | case BFD_RELOC_390_PLT16DBL: |
| 154 | return &elf_howto_table[(int) R_390_PLT16DBL]; |
| 155 | case BFD_RELOC_VTABLE_INHERIT: |
| 156 | return &elf32_s390_vtinherit_howto; |
| 157 | case BFD_RELOC_VTABLE_ENTRY: |
| 158 | return &elf32_s390_vtentry_howto; |
| 159 | default: |
| 160 | break; |
| 161 | } |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | /* We need to use ELF32_R_TYPE so we have our own copy of this function, |
| 166 | and elf32-s390.c has its own copy. */ |
| 167 | |
| 168 | static void |
| 169 | elf_s390_info_to_howto (abfd, cache_ptr, dst) |
| 170 | bfd *abfd ATTRIBUTE_UNUSED; |
| 171 | arelent *cache_ptr; |
| 172 | Elf_Internal_Rela *dst; |
| 173 | { |
| 174 | switch (ELF32_R_TYPE(dst->r_info)) |
| 175 | { |
| 176 | case R_390_GNU_VTINHERIT: |
| 177 | cache_ptr->howto = &elf32_s390_vtinherit_howto; |
| 178 | break; |
| 179 | |
| 180 | case R_390_GNU_VTENTRY: |
| 181 | cache_ptr->howto = &elf32_s390_vtentry_howto; |
| 182 | break; |
| 183 | |
| 184 | default: |
| 185 | BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_390_max); |
| 186 | cache_ptr->howto = &elf_howto_table[ELF32_R_TYPE(dst->r_info)]; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | static boolean |
| 191 | elf_s390_is_local_label_name (abfd, name) |
| 192 | bfd *abfd; |
| 193 | const char *name; |
| 194 | { |
| 195 | if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L')) |
| 196 | return true; |
| 197 | |
| 198 | return _bfd_elf_is_local_label_name (abfd, name); |
| 199 | } |
| 200 | |
| 201 | /* Functions for the 390 ELF linker. */ |
| 202 | |
| 203 | /* The name of the dynamic interpreter. This is put in the .interp |
| 204 | section. */ |
| 205 | |
| 206 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
| 207 | |
| 208 | /* The nop opcode we use. */ |
| 209 | |
| 210 | #define s390_NOP 0x07070707 |
| 211 | |
| 212 | |
| 213 | /* The size in bytes of the first entry in the procedure linkage table. */ |
| 214 | #define PLT_FIRST_ENTRY_SIZE 32 |
| 215 | /* The size in bytes of an entry in the procedure linkage table. */ |
| 216 | #define PLT_ENTRY_SIZE 32 |
| 217 | |
| 218 | #define GOT_ENTRY_SIZE 4 |
| 219 | |
| 220 | /* The first three entries in a procedure linkage table are reserved, |
| 221 | and the initial contents are unimportant (we zero them out). |
| 222 | Subsequent entries look like this. See the SVR4 ABI 386 |
| 223 | supplement to see how this works. */ |
| 224 | |
| 225 | /* For the s390, simple addr offset can only be 0 - 4096. |
| 226 | To use the full 2 GB address space, several instructions |
| 227 | are needed to load an address in a register and execute |
| 228 | a branch( or just saving the address) |
| 229 | |
| 230 | Furthermore, only r 0 and 1 are free to use!!! */ |
| 231 | |
| 232 | /* The first 3 words in the GOT are then reserved. |
| 233 | Word 0 is the address of the dynamic table. |
| 234 | Word 1 is a pointer to a structure describing the object |
| 235 | Word 2 is used to point to the loader entry address. |
| 236 | |
| 237 | The code for position independand PLT entries looks like this: |
| 238 | |
| 239 | r12 holds addr of the current GOT at entry to the PLT |
| 240 | |
| 241 | The GOT holds the address in the PLT to be executed. |
| 242 | The loader then gets: |
| 243 | 24(15) = Pointer to the structure describing the object. |
| 244 | 28(15) = Offset in symbol table |
| 245 | |
| 246 | The loader must then find the module where the function is |
| 247 | and insert the address in the GOT. |
| 248 | |
| 249 | Note: 390 can only address +- 64 K relative. |
| 250 | We check if offset > 65536, then make a relative branch -64xxx |
| 251 | back to a previous defined branch |
| 252 | |
| 253 | PLT1: BASR 1,0 # 2 bytes |
| 254 | L 1,22(1) # 4 bytes Load offset in GOT in r 1 |
| 255 | L 1,(1,12) # 4 bytes Load address from GOT in r1 |
| 256 | BCR 15,1 # 2 bytes Jump to address |
| 257 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time |
| 258 | L 1,14(1) # 4 bytes Load offset in symol table in r1 |
| 259 | BRC 15,-x # 4 bytes Jump to start of PLT |
| 260 | .word 0 # 2 bytes filler |
| 261 | .long ? # 4 bytes offset in GOT |
| 262 | .long ? # 4 bytes offset into symbol table |
| 263 | |
| 264 | This was the general case. There are two additional, optimizes PLT |
| 265 | definitions. One for GOT offsets < 4096 and one for GOT offsets < 32768. |
| 266 | First the one for GOT offsets < 4096: |
| 267 | |
| 268 | PLT1: L 1,<offset>(12) # 4 bytes Load address from GOT in R1 |
| 269 | BCR 15,1 # 2 bytes Jump to address |
| 270 | .word 0,0,0 # 6 bytes filler |
| 271 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time |
| 272 | L 1,14(1) # 4 bytes Load offset in symbol table in r1 |
| 273 | BRC 15,-x # 4 bytes Jump to start of PLT |
| 274 | .word 0,0,0 # 6 bytes filler |
| 275 | .long ? # 4 bytes offset into symbol table |
| 276 | |
| 277 | Second the one for GOT offsets < 32768: |
| 278 | |
| 279 | PLT1: LHI 1,<offset> # 4 bytes Load offset in GOT to r1 |
| 280 | L 1,(1,12) # 4 bytes Load address from GOT to r1 |
| 281 | BCR 15,1 # 2 bytes Jump to address |
| 282 | .word 0 # 2 bytes filler |
| 283 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time |
| 284 | L 1,14(1) # 4 bytes Load offset in symbol table in r1 |
| 285 | BRC 15,-x # 4 bytes Jump to start of PLT |
| 286 | .word 0,0,0 # 6 bytes filler |
| 287 | .long ? # 4 bytes offset into symbol table |
| 288 | |
| 289 | Total = 32 bytes per PLT entry |
| 290 | |
| 291 | The code for static build PLT entries looks like this: |
| 292 | |
| 293 | PLT1: BASR 1,0 # 2 bytes |
| 294 | L 1,22(1) # 4 bytes Load address of GOT entry |
| 295 | L 1,0(0,1) # 4 bytes Load address from GOT in r1 |
| 296 | BCR 15,1 # 2 bytes Jump to address |
| 297 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time |
| 298 | L 1,14(1) # 4 bytes Load offset in symbol table in r1 |
| 299 | BRC 15,-x # 4 bytes Jump to start of PLT |
| 300 | .word 0 # 2 bytes filler |
| 301 | .long ? # 4 bytes address of GOT entry |
| 302 | .long ? # 4 bytes offset into symbol table */ |
| 303 | |
| 304 | #define PLT_PIC_ENTRY_WORD0 0x0d105810 |
| 305 | #define PLT_PIC_ENTRY_WORD1 0x10165811 |
| 306 | #define PLT_PIC_ENTRY_WORD2 0xc00007f1 |
| 307 | #define PLT_PIC_ENTRY_WORD3 0x0d105810 |
| 308 | #define PLT_PIC_ENTRY_WORD4 0x100ea7f4 |
| 309 | |
| 310 | #define PLT_PIC12_ENTRY_WORD0 0x5810c000 |
| 311 | #define PLT_PIC12_ENTRY_WORD1 0x07f10000 |
| 312 | #define PLT_PIC12_ENTRY_WORD2 0x00000000 |
| 313 | #define PLT_PIC12_ENTRY_WORD3 0x0d105810 |
| 314 | #define PLT_PIC12_ENTRY_WORD4 0x100ea7f4 |
| 315 | |
| 316 | #define PLT_PIC16_ENTRY_WORD0 0xa7180000 |
| 317 | #define PLT_PIC16_ENTRY_WORD1 0x5811c000 |
| 318 | #define PLT_PIC16_ENTRY_WORD2 0x07f10000 |
| 319 | #define PLT_PIC16_ENTRY_WORD3 0x0d105810 |
| 320 | #define PLT_PIC16_ENTRY_WORD4 0x100ea7f4 |
| 321 | |
| 322 | #define PLT_ENTRY_WORD0 0x0d105810 |
| 323 | #define PLT_ENTRY_WORD1 0x10165810 |
| 324 | #define PLT_ENTRY_WORD2 0x100007f1 |
| 325 | #define PLT_ENTRY_WORD3 0x0d105810 |
| 326 | #define PLT_ENTRY_WORD4 0x100ea7f4 |
| 327 | |
| 328 | /* The first PLT entry pushes the offset into the symbol table |
| 329 | from R1 onto the stack at 8(15) and the loader object info |
| 330 | at 12(15), loads the loader address in R1 and jumps to it. */ |
| 331 | |
| 332 | /* The first entry in the PLT for PIC code: |
| 333 | |
| 334 | PLT0: |
| 335 | ST 1,28(15) # R1 has offset into symbol table |
| 336 | L 1,4(12) # Get loader ino(object struct address) |
| 337 | ST 1,24(15) # Store address |
| 338 | L 1,8(12) # Entry address of loader in R1 |
| 339 | BR 1 # Jump to loader |
| 340 | |
| 341 | The first entry in the PLT for static code: |
| 342 | |
| 343 | PLT0: |
| 344 | ST 1,28(15) # R1 has offset into symbol table |
| 345 | BASR 1,0 |
| 346 | L 1,18(0,1) # Get address of GOT |
| 347 | MVC 24(4,15),4(1) # Move loader ino to stack |
| 348 | L 1,8(1) # Get address of loader |
| 349 | BR 1 # Jump to loader |
| 350 | .word 0 # filler |
| 351 | .long got # address of GOT */ |
| 352 | |
| 353 | #define PLT_PIC_FIRST_ENTRY_WORD0 0x5010f01c |
| 354 | #define PLT_PIC_FIRST_ENTRY_WORD1 0x5810c004 |
| 355 | #define PLT_PIC_FIRST_ENTRY_WORD2 0x5010f018 |
| 356 | #define PLT_PIC_FIRST_ENTRY_WORD3 0x5810c008 |
| 357 | #define PLT_PIC_FIRST_ENTRY_WORD4 0x07f10000 |
| 358 | |
| 359 | #define PLT_FIRST_ENTRY_WORD0 0x5010f01c |
| 360 | #define PLT_FIRST_ENTRY_WORD1 0x0d105810 |
| 361 | #define PLT_FIRST_ENTRY_WORD2 0x1012D203 |
| 362 | #define PLT_FIRST_ENTRY_WORD3 0xf0181004 |
| 363 | #define PLT_FIRST_ENTRY_WORD4 0x58101008 |
| 364 | #define PLT_FIRST_ENTRY_WORD5 0x07f10000 |
| 365 | |
| 366 | /* The s390 linker needs to keep track of the number of relocs that it |
| 367 | decides to copy in check_relocs for each symbol. This is so that |
| 368 | it can discard PC relative relocs if it doesn't need them when |
| 369 | linking with -Bsymbolic. We store the information in a field |
| 370 | extending the regular ELF linker hash table. */ |
| 371 | |
| 372 | /* This structure keeps track of the number of PC relative relocs we |
| 373 | have copied for a given symbol. */ |
| 374 | |
| 375 | struct elf_s390_pcrel_relocs_copied |
| 376 | { |
| 377 | /* Next section. */ |
| 378 | struct elf_s390_pcrel_relocs_copied *next; |
| 379 | /* A section in dynobj. */ |
| 380 | asection *section; |
| 381 | /* Number of relocs copied in this section. */ |
| 382 | bfd_size_type count; |
| 383 | }; |
| 384 | |
| 385 | /* s390 ELF linker hash entry. */ |
| 386 | |
| 387 | struct elf_s390_link_hash_entry |
| 388 | { |
| 389 | struct elf_link_hash_entry root; |
| 390 | |
| 391 | /* Number of PC relative relocs copied for this symbol. */ |
| 392 | struct elf_s390_pcrel_relocs_copied *pcrel_relocs_copied; |
| 393 | }; |
| 394 | |
| 395 | /* s390 ELF linker hash table. */ |
| 396 | |
| 397 | struct elf_s390_link_hash_table |
| 398 | { |
| 399 | struct elf_link_hash_table root; |
| 400 | }; |
| 401 | |
| 402 | /* Declare this now that the above structures are defined. */ |
| 403 | |
| 404 | static boolean elf_s390_discard_copies |
| 405 | PARAMS ((struct elf_s390_link_hash_entry *, PTR)); |
| 406 | |
| 407 | /* Traverse an s390 ELF linker hash table. */ |
| 408 | |
| 409 | #define elf_s390_link_hash_traverse(table, func, info) \ |
| 410 | (elf_link_hash_traverse \ |
| 411 | (&(table)->root, \ |
| 412 | (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \ |
| 413 | (info))) |
| 414 | |
| 415 | /* Get the s390 ELF linker hash table from a link_info structure. */ |
| 416 | |
| 417 | #define elf_s390_hash_table(p) \ |
| 418 | ((struct elf_s390_link_hash_table *) ((p)->hash)) |
| 419 | |
| 420 | /* Create an entry in an s390 ELF linker hash table. */ |
| 421 | |
| 422 | static struct bfd_hash_entry * |
| 423 | elf_s390_link_hash_newfunc (entry, table, string) |
| 424 | struct bfd_hash_entry *entry; |
| 425 | struct bfd_hash_table *table; |
| 426 | const char *string; |
| 427 | { |
| 428 | struct elf_s390_link_hash_entry *ret = |
| 429 | (struct elf_s390_link_hash_entry *) entry; |
| 430 | |
| 431 | /* Allocate the structure if it has not already been allocated by a |
| 432 | subclass. */ |
| 433 | if (ret == (struct elf_s390_link_hash_entry *) NULL) |
| 434 | ret = ((struct elf_s390_link_hash_entry *) |
| 435 | bfd_hash_allocate (table, |
| 436 | sizeof (struct elf_s390_link_hash_entry))); |
| 437 | if (ret == (struct elf_s390_link_hash_entry *) NULL) |
| 438 | return (struct bfd_hash_entry *) ret; |
| 439 | |
| 440 | /* Call the allocation method of the superclass. */ |
| 441 | ret = ((struct elf_s390_link_hash_entry *) |
| 442 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
| 443 | table, string)); |
| 444 | if (ret != (struct elf_s390_link_hash_entry *) NULL) |
| 445 | { |
| 446 | ret->pcrel_relocs_copied = NULL; |
| 447 | } |
| 448 | |
| 449 | return (struct bfd_hash_entry *) ret; |
| 450 | } |
| 451 | |
| 452 | /* Create an s390 ELF linker hash table. */ |
| 453 | |
| 454 | static struct bfd_link_hash_table * |
| 455 | elf_s390_link_hash_table_create (abfd) |
| 456 | bfd *abfd; |
| 457 | { |
| 458 | struct elf_s390_link_hash_table *ret; |
| 459 | bfd_size_type amt = sizeof (struct elf_s390_link_hash_table); |
| 460 | |
| 461 | ret = (struct elf_s390_link_hash_table *) bfd_alloc (abfd, amt); |
| 462 | if (ret == (struct elf_s390_link_hash_table *) NULL) |
| 463 | return NULL; |
| 464 | |
| 465 | if (! _bfd_elf_link_hash_table_init (&ret->root, abfd, |
| 466 | elf_s390_link_hash_newfunc)) |
| 467 | { |
| 468 | bfd_release (abfd, ret); |
| 469 | return NULL; |
| 470 | } |
| 471 | |
| 472 | return &ret->root.root; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | /* Look through the relocs for a section during the first phase, and |
| 477 | allocate space in the global offset table or procedure linkage |
| 478 | table. */ |
| 479 | |
| 480 | static boolean |
| 481 | elf_s390_check_relocs (abfd, info, sec, relocs) |
| 482 | bfd *abfd; |
| 483 | struct bfd_link_info *info; |
| 484 | asection *sec; |
| 485 | const Elf_Internal_Rela *relocs; |
| 486 | { |
| 487 | bfd *dynobj; |
| 488 | Elf_Internal_Shdr *symtab_hdr; |
| 489 | struct elf_link_hash_entry **sym_hashes; |
| 490 | bfd_signed_vma *local_got_refcounts; |
| 491 | const Elf_Internal_Rela *rel; |
| 492 | const Elf_Internal_Rela *rel_end; |
| 493 | asection *sgot; |
| 494 | asection *srelgot; |
| 495 | asection *sreloc; |
| 496 | |
| 497 | if (info->relocateable) |
| 498 | return true; |
| 499 | |
| 500 | dynobj = elf_hash_table (info)->dynobj; |
| 501 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 502 | sym_hashes = elf_sym_hashes (abfd); |
| 503 | local_got_refcounts = elf_local_got_offsets (abfd); |
| 504 | |
| 505 | sgot = NULL; |
| 506 | srelgot = NULL; |
| 507 | sreloc = NULL; |
| 508 | |
| 509 | rel_end = relocs + sec->reloc_count; |
| 510 | for (rel = relocs; rel < rel_end; rel++) |
| 511 | { |
| 512 | unsigned long r_symndx; |
| 513 | struct elf_link_hash_entry *h; |
| 514 | |
| 515 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 516 | |
| 517 | if (r_symndx < symtab_hdr->sh_info) |
| 518 | h = NULL; |
| 519 | else |
| 520 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 521 | |
| 522 | /* Some relocs require a global offset table. */ |
| 523 | if (dynobj == NULL) |
| 524 | { |
| 525 | switch (ELF32_R_TYPE (rel->r_info)) |
| 526 | { |
| 527 | case R_390_GOT12: |
| 528 | case R_390_GOT16: |
| 529 | case R_390_GOT32: |
| 530 | case R_390_GOTOFF: |
| 531 | case R_390_GOTPC: |
| 532 | elf_hash_table (info)->dynobj = dynobj = abfd; |
| 533 | if (! _bfd_elf_create_got_section (dynobj, info)) |
| 534 | return false; |
| 535 | break; |
| 536 | |
| 537 | default: |
| 538 | break; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | |
| 543 | switch (ELF32_R_TYPE (rel->r_info)) |
| 544 | { |
| 545 | case R_390_GOT12: |
| 546 | case R_390_GOT16: |
| 547 | case R_390_GOT32: |
| 548 | /* This symbol requires a global offset table entry. */ |
| 549 | |
| 550 | if (sgot == NULL) |
| 551 | { |
| 552 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 553 | BFD_ASSERT (sgot != NULL); |
| 554 | } |
| 555 | |
| 556 | |
| 557 | if (srelgot == NULL |
| 558 | && (h != NULL || info->shared)) |
| 559 | { |
| 560 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 561 | if (srelgot == NULL) |
| 562 | { |
| 563 | srelgot = bfd_make_section (dynobj, ".rela.got"); |
| 564 | if (srelgot == NULL |
| 565 | || ! bfd_set_section_flags (dynobj, srelgot, |
| 566 | (SEC_ALLOC |
| 567 | | SEC_LOAD |
| 568 | | SEC_HAS_CONTENTS |
| 569 | | SEC_IN_MEMORY |
| 570 | | SEC_LINKER_CREATED |
| 571 | | SEC_READONLY)) |
| 572 | || ! bfd_set_section_alignment (dynobj, srelgot, 2)) |
| 573 | return false; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | if (h != NULL) |
| 578 | { |
| 579 | if (h->got.refcount == -1) |
| 580 | { |
| 581 | h->got.refcount = 1; |
| 582 | |
| 583 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 584 | if (h->dynindx == -1) |
| 585 | { |
| 586 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | sgot->_raw_size += 4; |
| 591 | srelgot->_raw_size += sizeof (Elf32_External_Rela); |
| 592 | } |
| 593 | else |
| 594 | h->got.refcount += 1; |
| 595 | } |
| 596 | else |
| 597 | { |
| 598 | /* This is a global offset table entry for a local symbol. */ |
| 599 | if (local_got_refcounts == NULL) |
| 600 | { |
| 601 | bfd_size_type size; |
| 602 | |
| 603 | size = symtab_hdr->sh_info; |
| 604 | size *= sizeof (bfd_signed_vma); |
| 605 | local_got_refcounts = (bfd_signed_vma *) |
| 606 | bfd_alloc (abfd, size); |
| 607 | if (local_got_refcounts == NULL) |
| 608 | return false; |
| 609 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
| 610 | memset (local_got_refcounts, -1, (size_t) size); |
| 611 | } |
| 612 | if (local_got_refcounts[r_symndx] == -1) |
| 613 | { |
| 614 | local_got_refcounts[r_symndx] = 1; |
| 615 | |
| 616 | sgot->_raw_size += 4; |
| 617 | if (info->shared) |
| 618 | { |
| 619 | /* If we are generating a shared object, we need to |
| 620 | output a R_390_RELATIVE reloc so that the dynamic |
| 621 | linker can adjust this GOT entry. */ |
| 622 | srelgot->_raw_size += sizeof (Elf32_External_Rela); |
| 623 | } |
| 624 | } |
| 625 | else |
| 626 | local_got_refcounts[r_symndx] += 1; |
| 627 | } |
| 628 | break; |
| 629 | |
| 630 | case R_390_PLT16DBL: |
| 631 | case R_390_PLT32: |
| 632 | /* This symbol requires a procedure linkage table entry. We |
| 633 | actually build the entry in adjust_dynamic_symbol, |
| 634 | because this might be a case of linking PIC code which is |
| 635 | never referenced by a dynamic object, in which case we |
| 636 | don't need to generate a procedure linkage table entry |
| 637 | after all. */ |
| 638 | |
| 639 | /* If this is a local symbol, we resolve it directly without |
| 640 | creating a procedure linkage table entry. */ |
| 641 | if (h == NULL) |
| 642 | continue; |
| 643 | |
| 644 | if (h->plt.refcount == -1) |
| 645 | { |
| 646 | h->plt.refcount = 1; |
| 647 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
| 648 | } |
| 649 | else |
| 650 | h->plt.refcount += 1; |
| 651 | break; |
| 652 | |
| 653 | case R_390_8: |
| 654 | case R_390_16: |
| 655 | case R_390_32: |
| 656 | case R_390_PC16: |
| 657 | case R_390_PC16DBL: |
| 658 | case R_390_PC32: |
| 659 | if (h != NULL) |
| 660 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; |
| 661 | |
| 662 | /* If we are creating a shared library, and this is a reloc |
| 663 | against a global symbol, or a non PC relative reloc |
| 664 | against a local symbol, then we need to copy the reloc |
| 665 | into the shared library. However, if we are linking with |
| 666 | -Bsymbolic, we do not need to copy a reloc against a |
| 667 | global symbol which is defined in an object we are |
| 668 | including in the link (i.e., DEF_REGULAR is set). At |
| 669 | this point we have not seen all the input files, so it is |
| 670 | possible that DEF_REGULAR is not set now but will be set |
| 671 | later (it is never cleared). We account for that |
| 672 | possibility below by storing information in the |
| 673 | pcrel_relocs_copied field of the hash table entry. */ |
| 674 | if (info->shared |
| 675 | && (sec->flags & SEC_ALLOC) != 0 |
| 676 | && ((ELF32_R_TYPE (rel->r_info) != R_390_PC16 && |
| 677 | ELF32_R_TYPE (rel->r_info) != R_390_PC16DBL && |
| 678 | ELF32_R_TYPE (rel->r_info) != R_390_PC32) |
| 679 | || (h != NULL |
| 680 | && (! info->symbolic |
| 681 | || (h->elf_link_hash_flags |
| 682 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) |
| 683 | { |
| 684 | /* When creating a shared object, we must copy these |
| 685 | reloc types into the output file. We create a reloc |
| 686 | section in dynobj and make room for this reloc. */ |
| 687 | if (sreloc == NULL) |
| 688 | { |
| 689 | const char *name; |
| 690 | |
| 691 | name = (bfd_elf_string_from_elf_section |
| 692 | (abfd, |
| 693 | elf_elfheader (abfd)->e_shstrndx, |
| 694 | elf_section_data (sec)->rel_hdr.sh_name)); |
| 695 | if (name == NULL) |
| 696 | return false; |
| 697 | |
| 698 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 |
| 699 | && strcmp (bfd_get_section_name (abfd, sec), |
| 700 | name + 5) == 0); |
| 701 | |
| 702 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 703 | if (sreloc == NULL) |
| 704 | { |
| 705 | flagword flags; |
| 706 | |
| 707 | sreloc = bfd_make_section (dynobj, name); |
| 708 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
| 709 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); |
| 710 | if ((sec->flags & SEC_ALLOC) != 0) |
| 711 | flags |= SEC_ALLOC | SEC_LOAD; |
| 712 | if (sreloc == NULL |
| 713 | || ! bfd_set_section_flags (dynobj, sreloc, flags) |
| 714 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) |
| 715 | return false; |
| 716 | } |
| 717 | if (sec->flags & SEC_READONLY) |
| 718 | info->flags |= DF_TEXTREL; |
| 719 | } |
| 720 | |
| 721 | sreloc->_raw_size += sizeof (Elf32_External_Rela); |
| 722 | |
| 723 | /* If we are linking with -Bsymbolic, and this is a |
| 724 | global symbol, we count the number of PC relative |
| 725 | relocations we have entered for this symbol, so that |
| 726 | we can discard them again if the symbol is later |
| 727 | defined by a regular object. Note that this function |
| 728 | is only called if we are using an elf_s390 linker |
| 729 | hash table, which means that h is really a pointer to |
| 730 | an elf_s390_link_hash_entry. */ |
| 731 | if (h != NULL |
| 732 | && (ELF32_R_TYPE (rel->r_info) == R_390_PC16 || |
| 733 | ELF32_R_TYPE (rel->r_info) == R_390_PC16DBL || |
| 734 | ELF32_R_TYPE (rel->r_info) == R_390_PC32)) |
| 735 | { |
| 736 | struct elf_s390_link_hash_entry *eh; |
| 737 | struct elf_s390_pcrel_relocs_copied *p; |
| 738 | |
| 739 | eh = (struct elf_s390_link_hash_entry *) h; |
| 740 | |
| 741 | for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next) |
| 742 | if (p->section == sreloc) |
| 743 | break; |
| 744 | |
| 745 | if (p == NULL) |
| 746 | { |
| 747 | p = ((struct elf_s390_pcrel_relocs_copied *) |
| 748 | bfd_alloc (dynobj, (bfd_size_type) sizeof *p)); |
| 749 | if (p == NULL) |
| 750 | return false; |
| 751 | p->next = eh->pcrel_relocs_copied; |
| 752 | eh->pcrel_relocs_copied = p; |
| 753 | p->section = sreloc; |
| 754 | p->count = 0; |
| 755 | } |
| 756 | |
| 757 | ++p->count; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | break; |
| 762 | |
| 763 | /* This relocation describes the C++ object vtable hierarchy. |
| 764 | Reconstruct it for later use during GC. */ |
| 765 | case R_390_GNU_VTINHERIT: |
| 766 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
| 767 | return false; |
| 768 | break; |
| 769 | |
| 770 | /* This relocation describes which C++ vtable entries are actually |
| 771 | used. Record for later use during GC. */ |
| 772 | case R_390_GNU_VTENTRY: |
| 773 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
| 774 | return false; |
| 775 | break; |
| 776 | |
| 777 | default: |
| 778 | break; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | return true; |
| 783 | } |
| 784 | |
| 785 | /* Return the section that should be marked against GC for a given |
| 786 | relocation. */ |
| 787 | |
| 788 | static asection * |
| 789 | elf_s390_gc_mark_hook (abfd, info, rel, h, sym) |
| 790 | bfd *abfd; |
| 791 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 792 | Elf_Internal_Rela *rel; |
| 793 | struct elf_link_hash_entry *h; |
| 794 | Elf_Internal_Sym *sym; |
| 795 | { |
| 796 | if (h != NULL) |
| 797 | { |
| 798 | switch (ELF32_R_TYPE (rel->r_info)) |
| 799 | { |
| 800 | case R_390_GNU_VTINHERIT: |
| 801 | case R_390_GNU_VTENTRY: |
| 802 | break; |
| 803 | |
| 804 | default: |
| 805 | switch (h->root.type) |
| 806 | { |
| 807 | case bfd_link_hash_defined: |
| 808 | case bfd_link_hash_defweak: |
| 809 | return h->root.u.def.section; |
| 810 | |
| 811 | case bfd_link_hash_common: |
| 812 | return h->root.u.c.p->section; |
| 813 | |
| 814 | default: |
| 815 | break; |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | else |
| 820 | { |
| 821 | if (!(elf_bad_symtab (abfd) |
| 822 | && ELF_ST_BIND (sym->st_info) != STB_LOCAL) |
| 823 | && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) |
| 824 | && sym->st_shndx != SHN_COMMON)) |
| 825 | { |
| 826 | return bfd_section_from_elf_index (abfd, sym->st_shndx); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | return NULL; |
| 831 | } |
| 832 | |
| 833 | /* Update the got entry reference counts for the section being removed. */ |
| 834 | |
| 835 | static boolean |
| 836 | elf_s390_gc_sweep_hook (abfd, info, sec, relocs) |
| 837 | bfd *abfd ATTRIBUTE_UNUSED; |
| 838 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
| 839 | asection *sec ATTRIBUTE_UNUSED; |
| 840 | const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED; |
| 841 | { |
| 842 | Elf_Internal_Shdr *symtab_hdr; |
| 843 | struct elf_link_hash_entry **sym_hashes; |
| 844 | bfd_signed_vma *local_got_refcounts; |
| 845 | const Elf_Internal_Rela *rel, *relend; |
| 846 | unsigned long r_symndx; |
| 847 | struct elf_link_hash_entry *h; |
| 848 | bfd *dynobj; |
| 849 | asection *sgot; |
| 850 | asection *srelgot; |
| 851 | |
| 852 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 853 | sym_hashes = elf_sym_hashes (abfd); |
| 854 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 855 | |
| 856 | dynobj = elf_hash_table (info)->dynobj; |
| 857 | if (dynobj == NULL) |
| 858 | return true; |
| 859 | |
| 860 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 861 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 862 | |
| 863 | relend = relocs + sec->reloc_count; |
| 864 | for (rel = relocs; rel < relend; rel++) |
| 865 | switch (ELF32_R_TYPE (rel->r_info)) |
| 866 | { |
| 867 | case R_390_GOT12: |
| 868 | case R_390_GOT16: |
| 869 | case R_390_GOT32: |
| 870 | case R_390_GOTOFF: |
| 871 | case R_390_GOTPC: |
| 872 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 873 | if (r_symndx >= symtab_hdr->sh_info) |
| 874 | { |
| 875 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 876 | if (h->got.refcount > 0) |
| 877 | { |
| 878 | h->got.refcount -= 1; |
| 879 | if (h->got.refcount == 0) |
| 880 | { |
| 881 | sgot->_raw_size -= 4; |
| 882 | srelgot->_raw_size -= sizeof (Elf32_External_Rela); |
| 883 | } |
| 884 | } |
| 885 | } |
| 886 | else if (local_got_refcounts != NULL) |
| 887 | { |
| 888 | if (local_got_refcounts[r_symndx] > 0) |
| 889 | { |
| 890 | local_got_refcounts[r_symndx] -= 1; |
| 891 | if (local_got_refcounts[r_symndx] == 0) |
| 892 | { |
| 893 | sgot->_raw_size -= 4; |
| 894 | if (info->shared) |
| 895 | srelgot->_raw_size -= sizeof (Elf32_External_Rela); |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | break; |
| 900 | |
| 901 | case R_390_PLT16DBL: |
| 902 | case R_390_PLT32: |
| 903 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 904 | if (r_symndx >= symtab_hdr->sh_info) |
| 905 | { |
| 906 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 907 | if (h->plt.refcount > 0) |
| 908 | h->plt.refcount -= 1; |
| 909 | } |
| 910 | break; |
| 911 | |
| 912 | default: |
| 913 | break; |
| 914 | } |
| 915 | |
| 916 | return true; |
| 917 | } |
| 918 | |
| 919 | /* Adjust a symbol defined by a dynamic object and referenced by a |
| 920 | regular object. The current definition is in some section of the |
| 921 | dynamic object, but we're not including those sections. We have to |
| 922 | change the definition to something the rest of the link can |
| 923 | understand. */ |
| 924 | |
| 925 | static boolean |
| 926 | elf_s390_adjust_dynamic_symbol (info, h) |
| 927 | struct bfd_link_info *info; |
| 928 | struct elf_link_hash_entry *h; |
| 929 | { |
| 930 | bfd *dynobj; |
| 931 | asection *s; |
| 932 | unsigned int power_of_two; |
| 933 | |
| 934 | dynobj = elf_hash_table (info)->dynobj; |
| 935 | |
| 936 | /* Make sure we know what is going on here. */ |
| 937 | BFD_ASSERT (dynobj != NULL |
| 938 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) |
| 939 | || h->weakdef != NULL |
| 940 | || ((h->elf_link_hash_flags |
| 941 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 |
| 942 | && (h->elf_link_hash_flags |
| 943 | & ELF_LINK_HASH_REF_REGULAR) != 0 |
| 944 | && (h->elf_link_hash_flags |
| 945 | & ELF_LINK_HASH_DEF_REGULAR) == 0))); |
| 946 | |
| 947 | /* If this is a function, put it in the procedure linkage table. We |
| 948 | will fill in the contents of the procedure linkage table later |
| 949 | (although we could actually do it here). */ |
| 950 | if (h->type == STT_FUNC |
| 951 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) |
| 952 | { |
| 953 | if ((! info->shared |
| 954 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 |
| 955 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0) |
| 956 | || (info->shared && h->plt.refcount <= 0)) |
| 957 | { |
| 958 | /* This case can occur if we saw a PLT32 reloc in an input |
| 959 | file, but the symbol was never referred to by a dynamic |
| 960 | object, or if all references were garbage collected. In |
| 961 | such a case, we don't actually need to build a procedure |
| 962 | linkage table, and we can just do a PC32 reloc instead. */ |
| 963 | h->plt.offset = (bfd_vma) -1; |
| 964 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
| 965 | return true; |
| 966 | } |
| 967 | |
| 968 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 969 | if (h->dynindx == -1) |
| 970 | { |
| 971 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) |
| 972 | return false; |
| 973 | } |
| 974 | |
| 975 | s = bfd_get_section_by_name (dynobj, ".plt"); |
| 976 | BFD_ASSERT (s != NULL); |
| 977 | |
| 978 | /* The first entry in .plt is reserved. */ |
| 979 | if (s->_raw_size == 0) |
| 980 | s->_raw_size = PLT_FIRST_ENTRY_SIZE; |
| 981 | |
| 982 | /* If this symbol is not defined in a regular file, and we are |
| 983 | not generating a shared library, then set the symbol to this |
| 984 | location in the .plt. This is required to make function |
| 985 | pointers compare as equal between the normal executable and |
| 986 | the shared library. */ |
| 987 | if (! info->shared |
| 988 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 989 | { |
| 990 | h->root.u.def.section = s; |
| 991 | h->root.u.def.value = s->_raw_size; |
| 992 | } |
| 993 | |
| 994 | h->plt.offset = s->_raw_size; |
| 995 | |
| 996 | /* Make room for this entry. */ |
| 997 | s->_raw_size += PLT_ENTRY_SIZE; |
| 998 | |
| 999 | /* We also need to make an entry in the .got.plt section, which |
| 1000 | will be placed in the .got section by the linker script. */ |
| 1001 | s = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 1002 | BFD_ASSERT (s != NULL); |
| 1003 | s->_raw_size += GOT_ENTRY_SIZE; |
| 1004 | |
| 1005 | /* We also need to make an entry in the .rela.plt section. */ |
| 1006 | s = bfd_get_section_by_name (dynobj, ".rela.plt"); |
| 1007 | BFD_ASSERT (s != NULL); |
| 1008 | s->_raw_size += sizeof (Elf32_External_Rela); |
| 1009 | |
| 1010 | return true; |
| 1011 | } |
| 1012 | |
| 1013 | /* If this is a weak symbol, and there is a real definition, the |
| 1014 | processor independent code will have arranged for us to see the |
| 1015 | real definition first, and we can just use the same value. */ |
| 1016 | if (h->weakdef != NULL) |
| 1017 | { |
| 1018 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined |
| 1019 | || h->weakdef->root.type == bfd_link_hash_defweak); |
| 1020 | h->root.u.def.section = h->weakdef->root.u.def.section; |
| 1021 | h->root.u.def.value = h->weakdef->root.u.def.value; |
| 1022 | return true; |
| 1023 | } |
| 1024 | |
| 1025 | /* This is a reference to a symbol defined by a dynamic object which |
| 1026 | is not a function. */ |
| 1027 | |
| 1028 | /* If we are creating a shared library, we must presume that the |
| 1029 | only references to the symbol are via the global offset table. |
| 1030 | For such cases we need not do anything here; the relocations will |
| 1031 | be handled correctly by relocate_section. */ |
| 1032 | if (info->shared) |
| 1033 | return true; |
| 1034 | |
| 1035 | /* If there are no references to this symbol that do not use the |
| 1036 | GOT, we don't need to generate a copy reloc. */ |
| 1037 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) |
| 1038 | return true; |
| 1039 | |
| 1040 | /* We must allocate the symbol in our .dynbss section, which will |
| 1041 | become part of the .bss section of the executable. There will be |
| 1042 | an entry for this symbol in the .dynsym section. The dynamic |
| 1043 | object will contain position independent code, so all references |
| 1044 | from the dynamic object to this symbol will go through the global |
| 1045 | offset table. The dynamic linker will use the .dynsym entry to |
| 1046 | determine the address it must put in the global offset table, so |
| 1047 | both the dynamic object and the regular object will refer to the |
| 1048 | same memory location for the variable. */ |
| 1049 | |
| 1050 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
| 1051 | BFD_ASSERT (s != NULL); |
| 1052 | |
| 1053 | /* We must generate a R_390_COPY reloc to tell the dynamic linker |
| 1054 | to copy the initial value out of the dynamic object and into the |
| 1055 | runtime process image. We need to remember the offset into the |
| 1056 | .rel.bss section we are going to use. */ |
| 1057 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
| 1058 | { |
| 1059 | asection *srel; |
| 1060 | |
| 1061 | srel = bfd_get_section_by_name (dynobj, ".rela.bss"); |
| 1062 | BFD_ASSERT (srel != NULL); |
| 1063 | srel->_raw_size += sizeof (Elf32_External_Rela); |
| 1064 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
| 1065 | } |
| 1066 | |
| 1067 | /* We need to figure out the alignment required for this symbol. I |
| 1068 | have no idea how ELF linkers handle this. */ |
| 1069 | power_of_two = bfd_log2 (h->size); |
| 1070 | if (power_of_two > 3) |
| 1071 | power_of_two = 3; |
| 1072 | |
| 1073 | /* Apply the required alignment. */ |
| 1074 | s->_raw_size = BFD_ALIGN (s->_raw_size, |
| 1075 | (bfd_size_type) (1 << power_of_two)); |
| 1076 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
| 1077 | { |
| 1078 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) |
| 1079 | return false; |
| 1080 | } |
| 1081 | |
| 1082 | /* Define the symbol as being at this point in the section. */ |
| 1083 | h->root.u.def.section = s; |
| 1084 | h->root.u.def.value = s->_raw_size; |
| 1085 | |
| 1086 | /* Increment the section size to make room for the symbol. */ |
| 1087 | s->_raw_size += h->size; |
| 1088 | |
| 1089 | return true; |
| 1090 | } |
| 1091 | |
| 1092 | /* Set the sizes of the dynamic sections. */ |
| 1093 | |
| 1094 | static boolean |
| 1095 | elf_s390_size_dynamic_sections (output_bfd, info) |
| 1096 | bfd *output_bfd ATTRIBUTE_UNUSED; |
| 1097 | struct bfd_link_info *info; |
| 1098 | { |
| 1099 | bfd *dynobj; |
| 1100 | asection *s; |
| 1101 | boolean relocs; |
| 1102 | boolean plt; |
| 1103 | |
| 1104 | dynobj = elf_hash_table (info)->dynobj; |
| 1105 | BFD_ASSERT (dynobj != NULL); |
| 1106 | |
| 1107 | if (elf_hash_table (info)->dynamic_sections_created) |
| 1108 | { |
| 1109 | /* Set the contents of the .interp section to the interpreter. */ |
| 1110 | if (! info->shared) |
| 1111 | { |
| 1112 | s = bfd_get_section_by_name (dynobj, ".interp"); |
| 1113 | BFD_ASSERT (s != NULL); |
| 1114 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; |
| 1115 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
| 1116 | } |
| 1117 | } |
| 1118 | else |
| 1119 | { |
| 1120 | /* We may have created entries in the .rela.got section. |
| 1121 | However, if we are not creating the dynamic sections, we will |
| 1122 | not actually use these entries. Reset the size of .rela.got, |
| 1123 | which will cause it to get stripped from the output file |
| 1124 | below. */ |
| 1125 | s = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 1126 | if (s != NULL) |
| 1127 | s->_raw_size = 0; |
| 1128 | } |
| 1129 | |
| 1130 | /* If this is a -Bsymbolic shared link, then we need to discard all |
| 1131 | PC relative relocs against symbols defined in a regular object. |
| 1132 | We allocated space for them in the check_relocs routine, but we |
| 1133 | will not fill them in in the relocate_section routine. */ |
| 1134 | if (info->shared) |
| 1135 | elf_s390_link_hash_traverse (elf_s390_hash_table (info), |
| 1136 | elf_s390_discard_copies, |
| 1137 | (PTR) info); |
| 1138 | |
| 1139 | /* The check_relocs and adjust_dynamic_symbol entry points have |
| 1140 | determined the sizes of the various dynamic sections. Allocate |
| 1141 | memory for them. */ |
| 1142 | plt = false; |
| 1143 | relocs = false; |
| 1144 | for (s = dynobj->sections; s != NULL; s = s->next) |
| 1145 | { |
| 1146 | const char *name; |
| 1147 | boolean strip; |
| 1148 | |
| 1149 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
| 1150 | continue; |
| 1151 | |
| 1152 | /* It's OK to base decisions on the section name, because none |
| 1153 | of the dynobj section names depend upon the input files. */ |
| 1154 | name = bfd_get_section_name (dynobj, s); |
| 1155 | |
| 1156 | strip = false; |
| 1157 | |
| 1158 | if (strcmp (name, ".plt") == 0) |
| 1159 | { |
| 1160 | if (s->_raw_size == 0) |
| 1161 | { |
| 1162 | /* Strip this section if we don't need it; see the |
| 1163 | comment below. */ |
| 1164 | strip = true; |
| 1165 | } |
| 1166 | else |
| 1167 | { |
| 1168 | /* Remember whether there is a PLT. */ |
| 1169 | plt = true; |
| 1170 | } |
| 1171 | } |
| 1172 | else if (strncmp (name, ".rela", 5) == 0) |
| 1173 | { |
| 1174 | if (s->_raw_size == 0) |
| 1175 | { |
| 1176 | /* If we don't need this section, strip it from the |
| 1177 | output file. This is to handle .rela.bss and |
| 1178 | .rel.plt. We must create it in |
| 1179 | create_dynamic_sections, because it must be created |
| 1180 | before the linker maps input sections to output |
| 1181 | sections. The linker does that before |
| 1182 | adjust_dynamic_symbol is called, and it is that |
| 1183 | function which decides whether anything needs to go |
| 1184 | into these sections. */ |
| 1185 | strip = true; |
| 1186 | } |
| 1187 | else |
| 1188 | { |
| 1189 | /* Remember whether there are any reloc sections other |
| 1190 | than .rela.plt. */ |
| 1191 | if (strcmp (name, ".rela.plt") != 0) |
| 1192 | relocs = true; |
| 1193 | |
| 1194 | /* We use the reloc_count field as a counter if we need |
| 1195 | to copy relocs into the output file. */ |
| 1196 | s->reloc_count = 0; |
| 1197 | } |
| 1198 | } |
| 1199 | else if (strncmp (name, ".got", 4) != 0) |
| 1200 | { |
| 1201 | /* It's not one of our sections, so don't allocate space. */ |
| 1202 | continue; |
| 1203 | } |
| 1204 | |
| 1205 | if (strip) |
| 1206 | { |
| 1207 | _bfd_strip_section_from_output (info, s); |
| 1208 | continue; |
| 1209 | } |
| 1210 | |
| 1211 | /* Allocate memory for the section contents. */ |
| 1212 | s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size); |
| 1213 | if (s->contents == NULL && s->_raw_size != 0) |
| 1214 | return false; |
| 1215 | } |
| 1216 | |
| 1217 | if (elf_hash_table (info)->dynamic_sections_created) |
| 1218 | { |
| 1219 | /* Add some entries to the .dynamic section. We fill in the |
| 1220 | values later, in elf_s390_finish_dynamic_sections, but we |
| 1221 | must add the entries now so that we get the correct size for |
| 1222 | the .dynamic section. The DT_DEBUG entry is filled in by the |
| 1223 | dynamic linker and used by the debugger. */ |
| 1224 | #define add_dynamic_entry(TAG, VAL) \ |
| 1225 | bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) |
| 1226 | |
| 1227 | if (! info->shared) |
| 1228 | { |
| 1229 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
| 1230 | return false; |
| 1231 | } |
| 1232 | |
| 1233 | if (plt) |
| 1234 | { |
| 1235 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
| 1236 | || !add_dynamic_entry (DT_PLTRELSZ, 0) |
| 1237 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) |
| 1238 | || !add_dynamic_entry (DT_JMPREL, 0)) |
| 1239 | return false; |
| 1240 | } |
| 1241 | |
| 1242 | if (relocs) |
| 1243 | { |
| 1244 | if (!add_dynamic_entry (DT_RELA, 0) |
| 1245 | || !add_dynamic_entry (DT_RELASZ, 0) |
| 1246 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) |
| 1247 | return false; |
| 1248 | } |
| 1249 | |
| 1250 | if ((info->flags & DF_TEXTREL) != 0) |
| 1251 | { |
| 1252 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
| 1253 | return false; |
| 1254 | info->flags |= DF_TEXTREL; |
| 1255 | } |
| 1256 | } |
| 1257 | #undef add_dynamic_entry |
| 1258 | |
| 1259 | return true; |
| 1260 | } |
| 1261 | |
| 1262 | /* This function is called via elf_s390_link_hash_traverse if we are |
| 1263 | creating a shared object with -Bsymbolic. It discards the space |
| 1264 | allocated to copy PC relative relocs against symbols which are |
| 1265 | defined in regular objects. We allocated space for them in the |
| 1266 | check_relocs routine, but we won't fill them in in the |
| 1267 | relocate_section routine. */ |
| 1268 | |
| 1269 | /*ARGSUSED*/ |
| 1270 | static boolean |
| 1271 | elf_s390_discard_copies (h, inf) |
| 1272 | struct elf_s390_link_hash_entry *h; |
| 1273 | PTR inf; |
| 1274 | { |
| 1275 | struct elf_s390_pcrel_relocs_copied *s; |
| 1276 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
| 1277 | |
| 1278 | /* If a symbol has been forced local or we have found a regular |
| 1279 | definition for the symbolic link case, then we won't be needing |
| 1280 | any relocs. */ |
| 1281 | if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 |
| 1282 | && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 |
| 1283 | || info->symbolic)) |
| 1284 | { |
| 1285 | for (s = h->pcrel_relocs_copied; s != NULL; s = s->next) |
| 1286 | s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela); |
| 1287 | } |
| 1288 | return true; |
| 1289 | } |
| 1290 | /* Relocate a 390 ELF section. */ |
| 1291 | |
| 1292 | static boolean |
| 1293 | elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, |
| 1294 | contents, relocs, local_syms, local_sections) |
| 1295 | bfd *output_bfd; |
| 1296 | struct bfd_link_info *info; |
| 1297 | bfd *input_bfd; |
| 1298 | asection *input_section; |
| 1299 | bfd_byte *contents; |
| 1300 | Elf_Internal_Rela *relocs; |
| 1301 | Elf_Internal_Sym *local_syms; |
| 1302 | asection **local_sections; |
| 1303 | { |
| 1304 | bfd *dynobj; |
| 1305 | Elf_Internal_Shdr *symtab_hdr; |
| 1306 | struct elf_link_hash_entry **sym_hashes; |
| 1307 | bfd_vma *local_got_offsets; |
| 1308 | asection *sgot; |
| 1309 | asection *splt; |
| 1310 | asection *sreloc; |
| 1311 | Elf_Internal_Rela *rel; |
| 1312 | Elf_Internal_Rela *relend; |
| 1313 | |
| 1314 | dynobj = elf_hash_table (info)->dynobj; |
| 1315 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 1316 | sym_hashes = elf_sym_hashes (input_bfd); |
| 1317 | local_got_offsets = elf_local_got_offsets (input_bfd); |
| 1318 | |
| 1319 | sgot = NULL; |
| 1320 | splt = NULL; |
| 1321 | sreloc = NULL; |
| 1322 | if (dynobj != NULL) |
| 1323 | { |
| 1324 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 1325 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 1326 | } |
| 1327 | |
| 1328 | rel = relocs; |
| 1329 | relend = relocs + input_section->reloc_count; |
| 1330 | for (; rel < relend; rel++) |
| 1331 | { |
| 1332 | int r_type; |
| 1333 | reloc_howto_type *howto; |
| 1334 | unsigned long r_symndx; |
| 1335 | struct elf_link_hash_entry *h; |
| 1336 | Elf_Internal_Sym *sym; |
| 1337 | asection *sec; |
| 1338 | bfd_vma relocation; |
| 1339 | bfd_reloc_status_type r; |
| 1340 | |
| 1341 | r_type = ELF32_R_TYPE (rel->r_info); |
| 1342 | if (r_type == (int) R_390_GNU_VTINHERIT |
| 1343 | || r_type == (int) R_390_GNU_VTENTRY) |
| 1344 | continue; |
| 1345 | if (r_type < 0 || r_type >= (int) R_390_max) |
| 1346 | { |
| 1347 | bfd_set_error (bfd_error_bad_value); |
| 1348 | return false; |
| 1349 | } |
| 1350 | howto = elf_howto_table + r_type; |
| 1351 | |
| 1352 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 1353 | |
| 1354 | if (info->relocateable) |
| 1355 | { |
| 1356 | /* This is a relocateable link. We don't have to change |
| 1357 | anything, unless the reloc is against a section symbol, |
| 1358 | in which case we have to adjust according to where the |
| 1359 | section symbol winds up in the output section. */ |
| 1360 | if (r_symndx < symtab_hdr->sh_info) |
| 1361 | { |
| 1362 | sym = local_syms + r_symndx; |
| 1363 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) |
| 1364 | { |
| 1365 | sec = local_sections[r_symndx]; |
| 1366 | rel->r_addend += sec->output_offset + sym->st_value; |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | continue; |
| 1371 | } |
| 1372 | |
| 1373 | /* This is a final link. */ |
| 1374 | h = NULL; |
| 1375 | sym = NULL; |
| 1376 | sec = NULL; |
| 1377 | if (r_symndx < symtab_hdr->sh_info) |
| 1378 | { |
| 1379 | sym = local_syms + r_symndx; |
| 1380 | sec = local_sections[r_symndx]; |
| 1381 | relocation = (sec->output_section->vma |
| 1382 | + sec->output_offset |
| 1383 | + sym->st_value); |
| 1384 | } |
| 1385 | else |
| 1386 | { |
| 1387 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 1388 | while (h->root.type == bfd_link_hash_indirect |
| 1389 | || h->root.type == bfd_link_hash_warning) |
| 1390 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 1391 | if (h->root.type == bfd_link_hash_defined |
| 1392 | || h->root.type == bfd_link_hash_defweak) |
| 1393 | { |
| 1394 | sec = h->root.u.def.section; |
| 1395 | if (r_type == R_390_GOTPC |
| 1396 | || ((r_type == R_390_PLT16DBL || |
| 1397 | r_type == R_390_PLT32) |
| 1398 | && splt != NULL |
| 1399 | && h->plt.offset != (bfd_vma) -1) |
| 1400 | || ((r_type == R_390_GOT12 || |
| 1401 | r_type == R_390_GOT16 || |
| 1402 | r_type == R_390_GOT32) |
| 1403 | && elf_hash_table (info)->dynamic_sections_created |
| 1404 | && (! info->shared |
| 1405 | || (! info->symbolic && h->dynindx != -1) |
| 1406 | || (h->elf_link_hash_flags |
| 1407 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) |
| 1408 | || (info->shared |
| 1409 | && ((! info->symbolic && h->dynindx != -1) |
| 1410 | || (h->elf_link_hash_flags |
| 1411 | & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 1412 | && ( r_type == R_390_8 || |
| 1413 | r_type == R_390_16 || |
| 1414 | r_type == R_390_32 || |
| 1415 | r_type == R_390_PC16 || |
| 1416 | r_type == R_390_PC16DBL || |
| 1417 | r_type == R_390_PC32) |
| 1418 | && ((input_section->flags & SEC_ALLOC) != 0 |
| 1419 | /* DWARF will emit R_386_32 relocations in its |
| 1420 | sections against symbols defined externally |
| 1421 | in shared libraries. We can't do anything |
| 1422 | with them here. */ |
| 1423 | || ((input_section->flags & SEC_DEBUGGING) != 0 |
| 1424 | && (h->elf_link_hash_flags |
| 1425 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))) |
| 1426 | { |
| 1427 | /* In these cases, we don't need the relocation |
| 1428 | value. We check specially because in some |
| 1429 | obscure cases sec->output_section will be NULL. */ |
| 1430 | relocation = 0; |
| 1431 | } |
| 1432 | else if (sec->output_section == NULL) |
| 1433 | { |
| 1434 | (*_bfd_error_handler) |
| 1435 | (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"), |
| 1436 | bfd_get_filename (input_bfd), h->root.root.string, |
| 1437 | bfd_get_section_name (input_bfd, input_section)); |
| 1438 | relocation = 0; |
| 1439 | } |
| 1440 | else |
| 1441 | relocation = (h->root.u.def.value |
| 1442 | + sec->output_section->vma |
| 1443 | + sec->output_offset); |
| 1444 | } |
| 1445 | else if (h->root.type == bfd_link_hash_undefweak) |
| 1446 | relocation = 0; |
| 1447 | else if (info->shared && !info->symbolic |
| 1448 | && !info->no_undefined |
| 1449 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
| 1450 | relocation = 0; |
| 1451 | else |
| 1452 | { |
| 1453 | if (! ((*info->callbacks->undefined_symbol) |
| 1454 | (info, h->root.root.string, input_bfd, |
| 1455 | input_section, rel->r_offset, |
| 1456 | (!info->shared || info->no_undefined |
| 1457 | || ELF_ST_VISIBILITY (h->other))))) |
| 1458 | return false; |
| 1459 | relocation = 0; |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | switch (r_type) |
| 1464 | { |
| 1465 | case R_390_GOT12: |
| 1466 | case R_390_GOT16: |
| 1467 | case R_390_GOT32: |
| 1468 | /* Relocation is to the entry for this symbol in the global |
| 1469 | offset table. */ |
| 1470 | BFD_ASSERT (sgot != NULL); |
| 1471 | |
| 1472 | if (h != NULL) |
| 1473 | { |
| 1474 | bfd_vma off; |
| 1475 | |
| 1476 | off = h->got.offset; |
| 1477 | BFD_ASSERT (off != (bfd_vma) -1); |
| 1478 | |
| 1479 | if (! elf_hash_table (info)->dynamic_sections_created |
| 1480 | || (info->shared |
| 1481 | && (info->symbolic || h->dynindx == -1) |
| 1482 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) |
| 1483 | { |
| 1484 | /* This is actually a static link, or it is a |
| 1485 | -Bsymbolic link and the symbol is defined |
| 1486 | locally, or the symbol was forced to be local |
| 1487 | because of a version file. We must initialize |
| 1488 | this entry in the global offset table. Since the |
| 1489 | offset must always be a multiple of 2, we use the |
| 1490 | least significant bit to record whether we have |
| 1491 | initialized it already. |
| 1492 | |
| 1493 | When doing a dynamic link, we create a .rel.got |
| 1494 | relocation entry to initialize the value. This |
| 1495 | is done in the finish_dynamic_symbol routine. */ |
| 1496 | if ((off & 1) != 0) |
| 1497 | off &= ~1; |
| 1498 | else |
| 1499 | { |
| 1500 | bfd_put_32 (output_bfd, relocation, |
| 1501 | sgot->contents + off); |
| 1502 | h->got.offset |= 1; |
| 1503 | } |
| 1504 | } |
| 1505 | relocation = sgot->output_offset + off; |
| 1506 | } |
| 1507 | else |
| 1508 | { |
| 1509 | bfd_vma off; |
| 1510 | |
| 1511 | BFD_ASSERT (local_got_offsets != NULL |
| 1512 | && local_got_offsets[r_symndx] != (bfd_vma) -1); |
| 1513 | |
| 1514 | off = local_got_offsets[r_symndx]; |
| 1515 | |
| 1516 | /* The offset must always be a multiple of 4. We use |
| 1517 | the least significant bit to record whether we have |
| 1518 | already generated the necessary reloc. */ |
| 1519 | if ((off & 1) != 0) |
| 1520 | off &= ~1; |
| 1521 | else |
| 1522 | { |
| 1523 | bfd_put_32 (output_bfd, relocation, sgot->contents + off); |
| 1524 | |
| 1525 | if (info->shared) |
| 1526 | { |
| 1527 | asection *srelgot; |
| 1528 | Elf_Internal_Rela outrel; |
| 1529 | |
| 1530 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 1531 | BFD_ASSERT (srelgot != NULL); |
| 1532 | |
| 1533 | outrel.r_offset = (sgot->output_section->vma |
| 1534 | + sgot->output_offset |
| 1535 | + off); |
| 1536 | outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE); |
| 1537 | outrel.r_addend = relocation; |
| 1538 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, |
| 1539 | (((Elf32_External_Rela *) |
| 1540 | srelgot->contents) |
| 1541 | + srelgot->reloc_count)); |
| 1542 | ++srelgot->reloc_count; |
| 1543 | } |
| 1544 | |
| 1545 | local_got_offsets[r_symndx] |= 1; |
| 1546 | } |
| 1547 | |
| 1548 | relocation = sgot->output_offset + off; |
| 1549 | } |
| 1550 | |
| 1551 | |
| 1552 | break; |
| 1553 | |
| 1554 | case R_390_GOTOFF: |
| 1555 | /* Relocation is relative to the start of the global offset |
| 1556 | table. */ |
| 1557 | |
| 1558 | if (sgot == NULL) |
| 1559 | { |
| 1560 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 1561 | BFD_ASSERT (sgot != NULL); |
| 1562 | } |
| 1563 | |
| 1564 | /* Note that sgot->output_offset is not involved in this |
| 1565 | calculation. We always want the start of .got. If we |
| 1566 | defined _GLOBAL_OFFSET_TABLE in a different way, as is |
| 1567 | permitted by the ABI, we might have to change this |
| 1568 | calculation. */ |
| 1569 | relocation -= sgot->output_section->vma; |
| 1570 | |
| 1571 | break; |
| 1572 | |
| 1573 | case R_390_GOTPC: |
| 1574 | /* Use global offset table as symbol value. */ |
| 1575 | |
| 1576 | if (sgot == NULL) |
| 1577 | { |
| 1578 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 1579 | BFD_ASSERT (sgot != NULL); |
| 1580 | } |
| 1581 | |
| 1582 | relocation = sgot->output_section->vma; |
| 1583 | |
| 1584 | break; |
| 1585 | |
| 1586 | case R_390_PLT16DBL: |
| 1587 | case R_390_PLT32: |
| 1588 | /* Relocation is to the entry for this symbol in the |
| 1589 | procedure linkage table. */ |
| 1590 | |
| 1591 | /* Resolve a PLT32 reloc against a local symbol directly, |
| 1592 | without using the procedure linkage table. */ |
| 1593 | if (h == NULL) |
| 1594 | break; |
| 1595 | |
| 1596 | if (h->plt.offset == (bfd_vma) -1 || splt == NULL) |
| 1597 | { |
| 1598 | /* We didn't make a PLT entry for this symbol. This |
| 1599 | happens when statically linking PIC code, or when |
| 1600 | using -Bsymbolic. */ |
| 1601 | break; |
| 1602 | } |
| 1603 | |
| 1604 | relocation = (splt->output_section->vma |
| 1605 | + splt->output_offset |
| 1606 | + h->plt.offset); |
| 1607 | |
| 1608 | break; |
| 1609 | |
| 1610 | case R_390_8: |
| 1611 | case R_390_16: |
| 1612 | case R_390_32: |
| 1613 | case R_390_PC16: |
| 1614 | case R_390_PC16DBL: |
| 1615 | case R_390_PC32: |
| 1616 | if (info->shared |
| 1617 | && (input_section->flags & SEC_ALLOC) != 0 |
| 1618 | && ((r_type != R_390_PC16 && |
| 1619 | r_type != R_390_PC16DBL && |
| 1620 | r_type != R_390_PC32) |
| 1621 | || (h != NULL |
| 1622 | && h->dynindx != -1 |
| 1623 | && (! info->symbolic |
| 1624 | || (h->elf_link_hash_flags |
| 1625 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) |
| 1626 | { |
| 1627 | Elf_Internal_Rela outrel; |
| 1628 | boolean skip, relocate; |
| 1629 | |
| 1630 | /* When generating a shared object, these relocations |
| 1631 | are copied into the output file to be resolved at run |
| 1632 | time. */ |
| 1633 | |
| 1634 | if (sreloc == NULL) |
| 1635 | { |
| 1636 | const char *name; |
| 1637 | |
| 1638 | name = (bfd_elf_string_from_elf_section |
| 1639 | (input_bfd, |
| 1640 | elf_elfheader (input_bfd)->e_shstrndx, |
| 1641 | elf_section_data (input_section)->rel_hdr.sh_name)); |
| 1642 | if (name == NULL) |
| 1643 | return false; |
| 1644 | |
| 1645 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 |
| 1646 | && strcmp (bfd_get_section_name (input_bfd, |
| 1647 | input_section), |
| 1648 | name + 5) == 0); |
| 1649 | |
| 1650 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 1651 | BFD_ASSERT (sreloc != NULL); |
| 1652 | } |
| 1653 | |
| 1654 | skip = false; |
| 1655 | |
| 1656 | if (elf_section_data (input_section)->stab_info == NULL) |
| 1657 | outrel.r_offset = rel->r_offset; |
| 1658 | else |
| 1659 | { |
| 1660 | bfd_vma off; |
| 1661 | |
| 1662 | off = (_bfd_stab_section_offset |
| 1663 | (output_bfd, &elf_hash_table (info)->stab_info, |
| 1664 | input_section, |
| 1665 | &elf_section_data (input_section)->stab_info, |
| 1666 | rel->r_offset)); |
| 1667 | if (off == (bfd_vma) -1) |
| 1668 | skip = true; |
| 1669 | outrel.r_offset = off; |
| 1670 | } |
| 1671 | |
| 1672 | outrel.r_offset += (input_section->output_section->vma |
| 1673 | + input_section->output_offset); |
| 1674 | |
| 1675 | if (skip) |
| 1676 | { |
| 1677 | memset (&outrel, 0, sizeof outrel); |
| 1678 | relocate = false; |
| 1679 | } |
| 1680 | else if (r_type == R_390_PC16 || |
| 1681 | r_type == R_390_PC16DBL || |
| 1682 | r_type == R_390_PC32) |
| 1683 | { |
| 1684 | BFD_ASSERT (h != NULL && h->dynindx != -1); |
| 1685 | relocate = false; |
| 1686 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
| 1687 | outrel.r_addend = relocation + rel->r_addend; |
| 1688 | } |
| 1689 | else |
| 1690 | { |
| 1691 | /* h->dynindx may be -1 if this symbol was marked to |
| 1692 | become local. */ |
| 1693 | if (h == NULL |
| 1694 | || ((info->symbolic || h->dynindx == -1) |
| 1695 | && (h->elf_link_hash_flags |
| 1696 | & ELF_LINK_HASH_DEF_REGULAR) != 0)) |
| 1697 | { |
| 1698 | relocate = true; |
| 1699 | outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE); |
| 1700 | outrel.r_addend = relocation + rel->r_addend; |
| 1701 | } |
| 1702 | else |
| 1703 | { |
| 1704 | BFD_ASSERT (h->dynindx != -1); |
| 1705 | relocate = false; |
| 1706 | outrel.r_info = ELF32_R_INFO (h->dynindx, R_390_32); |
| 1707 | outrel.r_addend = relocation + rel->r_addend; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, |
| 1712 | (((Elf32_External_Rela *) |
| 1713 | sreloc->contents) |
| 1714 | + sreloc->reloc_count)); |
| 1715 | ++sreloc->reloc_count; |
| 1716 | |
| 1717 | /* If this reloc is against an external symbol, we do |
| 1718 | not want to fiddle with the addend. Otherwise, we |
| 1719 | need to include the symbol value so that it becomes |
| 1720 | an addend for the dynamic reloc. */ |
| 1721 | if (! relocate) |
| 1722 | continue; |
| 1723 | } |
| 1724 | |
| 1725 | break; |
| 1726 | |
| 1727 | default: |
| 1728 | break; |
| 1729 | } |
| 1730 | |
| 1731 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 1732 | contents, rel->r_offset, |
| 1733 | relocation, rel->r_addend); |
| 1734 | |
| 1735 | if (r != bfd_reloc_ok) |
| 1736 | { |
| 1737 | switch (r) |
| 1738 | { |
| 1739 | default: |
| 1740 | case bfd_reloc_outofrange: |
| 1741 | abort (); |
| 1742 | case bfd_reloc_overflow: |
| 1743 | { |
| 1744 | const char *name; |
| 1745 | |
| 1746 | if (h != NULL) |
| 1747 | name = h->root.root.string; |
| 1748 | else |
| 1749 | { |
| 1750 | name = bfd_elf_string_from_elf_section (input_bfd, |
| 1751 | symtab_hdr->sh_link, |
| 1752 | sym->st_name); |
| 1753 | if (name == NULL) |
| 1754 | return false; |
| 1755 | if (*name == '\0') |
| 1756 | name = bfd_section_name (input_bfd, sec); |
| 1757 | } |
| 1758 | if (! ((*info->callbacks->reloc_overflow) |
| 1759 | (info, name, howto->name, (bfd_vma) 0, |
| 1760 | input_bfd, input_section, rel->r_offset))) |
| 1761 | return false; |
| 1762 | } |
| 1763 | break; |
| 1764 | } |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | return true; |
| 1769 | } |
| 1770 | |
| 1771 | /* Finish up dynamic symbol handling. We set the contents of various |
| 1772 | dynamic sections here. */ |
| 1773 | |
| 1774 | static boolean |
| 1775 | elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym) |
| 1776 | bfd *output_bfd; |
| 1777 | struct bfd_link_info *info; |
| 1778 | struct elf_link_hash_entry *h; |
| 1779 | Elf_Internal_Sym *sym; |
| 1780 | { |
| 1781 | bfd *dynobj; |
| 1782 | |
| 1783 | dynobj = elf_hash_table (info)->dynobj; |
| 1784 | |
| 1785 | if (h->plt.offset != (bfd_vma) -1) |
| 1786 | { |
| 1787 | asection *splt; |
| 1788 | asection *srela; |
| 1789 | Elf_Internal_Rela rela; |
| 1790 | bfd_vma relative_offset; |
| 1791 | bfd_vma got_offset; |
| 1792 | bfd_vma plt_index; |
| 1793 | asection *sgot; |
| 1794 | |
| 1795 | /* This symbol has an entry in the procedure linkage table. Set |
| 1796 | it up. */ |
| 1797 | |
| 1798 | BFD_ASSERT (h->dynindx != -1); |
| 1799 | |
| 1800 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 1801 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 1802 | srela = bfd_get_section_by_name (dynobj, ".rela.plt"); |
| 1803 | BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); |
| 1804 | |
| 1805 | /* Calc. index no. |
| 1806 | Current offset - size first entry / entry size. */ |
| 1807 | plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE; |
| 1808 | |
| 1809 | /* Offset in GOT is PLT index plus GOT headers(3) times 4, |
| 1810 | addr & GOT addr. */ |
| 1811 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; |
| 1812 | |
| 1813 | /* S390 uses halfwords for relative branch calc! */ |
| 1814 | relative_offset = - ((PLT_FIRST_ENTRY_SIZE + |
| 1815 | (PLT_ENTRY_SIZE * plt_index) + 18) / 2); |
| 1816 | /* If offset is > 32768, branch to a previous branch |
| 1817 | 390 can only handle +-64 K jumps. */ |
| 1818 | if ( -32768 > (int) relative_offset ) |
| 1819 | relative_offset = |
| 1820 | -(unsigned) (((65536 / PLT_ENTRY_SIZE - 1) * PLT_ENTRY_SIZE) / 2); |
| 1821 | |
| 1822 | /* Fill in the entry in the procedure linkage table. */ |
| 1823 | if (!info->shared) |
| 1824 | { |
| 1825 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0, |
| 1826 | splt->contents + h->plt.offset); |
| 1827 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1, |
| 1828 | splt->contents + h->plt.offset + 4); |
| 1829 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2, |
| 1830 | splt->contents + h->plt.offset + 8); |
| 1831 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3, |
| 1832 | splt->contents + h->plt.offset + 12); |
| 1833 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4, |
| 1834 | splt->contents + h->plt.offset + 16); |
| 1835 | bfd_put_32 (output_bfd, (bfd_vma) 0 + (relative_offset << 16), |
| 1836 | splt->contents + h->plt.offset + 20); |
| 1837 | bfd_put_32 (output_bfd, |
| 1838 | (sgot->output_section->vma |
| 1839 | + sgot->output_offset |
| 1840 | + got_offset), |
| 1841 | splt->contents + h->plt.offset + 24); |
| 1842 | } |
| 1843 | else if (got_offset < 4096) |
| 1844 | { |
| 1845 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD0 + got_offset, |
| 1846 | splt->contents + h->plt.offset); |
| 1847 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD1, |
| 1848 | splt->contents + h->plt.offset + 4); |
| 1849 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD2, |
| 1850 | splt->contents + h->plt.offset + 8); |
| 1851 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD3, |
| 1852 | splt->contents + h->plt.offset + 12); |
| 1853 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD4, |
| 1854 | splt->contents + h->plt.offset + 16); |
| 1855 | bfd_put_32 (output_bfd, (bfd_vma) 0 + (relative_offset << 16), |
| 1856 | splt->contents + h->plt.offset + 20); |
| 1857 | bfd_put_32 (output_bfd, (bfd_vma) 0, |
| 1858 | splt->contents + h->plt.offset + 24); |
| 1859 | } |
| 1860 | else if (got_offset < 32768) |
| 1861 | { |
| 1862 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD0 + got_offset, |
| 1863 | splt->contents + h->plt.offset); |
| 1864 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD1, |
| 1865 | splt->contents + h->plt.offset + 4); |
| 1866 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD2, |
| 1867 | splt->contents + h->plt.offset + 8); |
| 1868 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD3, |
| 1869 | splt->contents + h->plt.offset + 12); |
| 1870 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD4, |
| 1871 | splt->contents + h->plt.offset + 16); |
| 1872 | bfd_put_32 (output_bfd, (bfd_vma) 0 + (relative_offset << 16), |
| 1873 | splt->contents + h->plt.offset + 20); |
| 1874 | bfd_put_32 (output_bfd, (bfd_vma) 0, |
| 1875 | splt->contents + h->plt.offset + 24); |
| 1876 | } |
| 1877 | else |
| 1878 | { |
| 1879 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD0, |
| 1880 | splt->contents + h->plt.offset); |
| 1881 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD1, |
| 1882 | splt->contents + h->plt.offset + 4); |
| 1883 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD2, |
| 1884 | splt->contents + h->plt.offset + 8); |
| 1885 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD3, |
| 1886 | splt->contents + h->plt.offset + 12); |
| 1887 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD4, |
| 1888 | splt->contents + h->plt.offset + 16); |
| 1889 | bfd_put_32 (output_bfd, (bfd_vma) 0 + (relative_offset << 16), |
| 1890 | splt->contents + h->plt.offset + 20); |
| 1891 | bfd_put_32 (output_bfd, got_offset, |
| 1892 | splt->contents + h->plt.offset + 24); |
| 1893 | } |
| 1894 | /* Insert offset into reloc. table here. */ |
| 1895 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), |
| 1896 | splt->contents + h->plt.offset + 28); |
| 1897 | /* Fill in the entry in the .rela.plt section. */ |
| 1898 | rela.r_offset = (sgot->output_section->vma |
| 1899 | + sgot->output_offset |
| 1900 | + got_offset); |
| 1901 | rela.r_info = ELF32_R_INFO (h->dynindx, R_390_JMP_SLOT); |
| 1902 | rela.r_addend = 0; |
| 1903 | bfd_elf32_swap_reloca_out (output_bfd, &rela, |
| 1904 | ((Elf32_External_Rela *) srela->contents |
| 1905 | + plt_index )); |
| 1906 | |
| 1907 | /* Fill in the entry in the global offset table. |
| 1908 | Points to instruction after GOT offset. */ |
| 1909 | bfd_put_32 (output_bfd, |
| 1910 | (splt->output_section->vma |
| 1911 | + splt->output_offset |
| 1912 | + h->plt.offset |
| 1913 | + 12), |
| 1914 | sgot->contents + got_offset); |
| 1915 | |
| 1916 | |
| 1917 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) |
| 1918 | { |
| 1919 | /* Mark the symbol as undefined, rather than as defined in |
| 1920 | the .plt section. Leave the value alone. */ |
| 1921 | sym->st_shndx = SHN_UNDEF; |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | if (h->got.offset != (bfd_vma) -1) |
| 1926 | { |
| 1927 | asection *sgot; |
| 1928 | asection *srela; |
| 1929 | Elf_Internal_Rela rela; |
| 1930 | |
| 1931 | /* This symbol has an entry in the global offset table. Set it |
| 1932 | up. */ |
| 1933 | |
| 1934 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 1935 | srela = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 1936 | BFD_ASSERT (sgot != NULL && srela != NULL); |
| 1937 | |
| 1938 | rela.r_offset = (sgot->output_section->vma |
| 1939 | + sgot->output_offset |
| 1940 | + (h->got.offset &~ (bfd_vma) 1)); |
| 1941 | |
| 1942 | /* If this is a static link, or it is a -Bsymbolic link and the |
| 1943 | symbol is defined locally or was forced to be local because |
| 1944 | of a version file, we just want to emit a RELATIVE reloc. |
| 1945 | The entry in the global offset table will already have been |
| 1946 | initialized in the relocate_section function. */ |
| 1947 | if (! elf_hash_table (info)->dynamic_sections_created |
| 1948 | || (info->shared |
| 1949 | && (info->symbolic || h->dynindx == -1) |
| 1950 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) |
| 1951 | { |
| 1952 | rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE); |
| 1953 | rela.r_addend = (h->root.u.def.value |
| 1954 | + h->root.u.def.section->output_section->vma |
| 1955 | + h->root.u.def.section->output_offset); |
| 1956 | } |
| 1957 | else |
| 1958 | { |
| 1959 | BFD_ASSERT((h->got.offset & 1) == 0); |
| 1960 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); |
| 1961 | rela.r_info = ELF32_R_INFO (h->dynindx, R_390_GLOB_DAT); |
| 1962 | rela.r_addend = 0; |
| 1963 | } |
| 1964 | |
| 1965 | bfd_elf32_swap_reloca_out (output_bfd, &rela, |
| 1966 | ((Elf32_External_Rela *) srela->contents |
| 1967 | + srela->reloc_count)); |
| 1968 | ++srela->reloc_count; |
| 1969 | } |
| 1970 | |
| 1971 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) |
| 1972 | { |
| 1973 | asection *s; |
| 1974 | Elf_Internal_Rela rela; |
| 1975 | |
| 1976 | /* This symbols needs a copy reloc. Set it up. */ |
| 1977 | |
| 1978 | BFD_ASSERT (h->dynindx != -1 |
| 1979 | && (h->root.type == bfd_link_hash_defined |
| 1980 | || h->root.type == bfd_link_hash_defweak)); |
| 1981 | |
| 1982 | |
| 1983 | s = bfd_get_section_by_name (h->root.u.def.section->owner, |
| 1984 | ".rela.bss"); |
| 1985 | BFD_ASSERT (s != NULL); |
| 1986 | |
| 1987 | rela.r_offset = (h->root.u.def.value |
| 1988 | + h->root.u.def.section->output_section->vma |
| 1989 | + h->root.u.def.section->output_offset); |
| 1990 | rela.r_info = ELF32_R_INFO (h->dynindx, R_390_COPY); |
| 1991 | rela.r_addend = 0; |
| 1992 | bfd_elf32_swap_reloca_out (output_bfd, &rela, |
| 1993 | ((Elf32_External_Rela *) s->contents |
| 1994 | + s->reloc_count)); |
| 1995 | ++s->reloc_count; |
| 1996 | } |
| 1997 | |
| 1998 | /* Mark some specially defined symbols as absolute. */ |
| 1999 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
| 2000 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 |
| 2001 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) |
| 2002 | sym->st_shndx = SHN_ABS; |
| 2003 | |
| 2004 | return true; |
| 2005 | } |
| 2006 | |
| 2007 | /* Finish up the dynamic sections. */ |
| 2008 | |
| 2009 | static boolean |
| 2010 | elf_s390_finish_dynamic_sections (output_bfd, info) |
| 2011 | bfd *output_bfd; |
| 2012 | struct bfd_link_info *info; |
| 2013 | { |
| 2014 | bfd *dynobj; |
| 2015 | asection *sdyn; |
| 2016 | asection *sgot; |
| 2017 | |
| 2018 | dynobj = elf_hash_table (info)->dynobj; |
| 2019 | |
| 2020 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 2021 | BFD_ASSERT (sgot != NULL); |
| 2022 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
| 2023 | |
| 2024 | if (elf_hash_table (info)->dynamic_sections_created) |
| 2025 | { |
| 2026 | asection *splt; |
| 2027 | Elf32_External_Dyn *dyncon, *dynconend; |
| 2028 | |
| 2029 | BFD_ASSERT (sdyn != NULL); |
| 2030 | |
| 2031 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
| 2032 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); |
| 2033 | for (; dyncon < dynconend; dyncon++) |
| 2034 | { |
| 2035 | Elf_Internal_Dyn dyn; |
| 2036 | const char *name; |
| 2037 | asection *s; |
| 2038 | |
| 2039 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
| 2040 | |
| 2041 | switch (dyn.d_tag) |
| 2042 | { |
| 2043 | default: |
| 2044 | break; |
| 2045 | |
| 2046 | case DT_PLTGOT: |
| 2047 | name = ".got"; |
| 2048 | goto get_vma; |
| 2049 | case DT_JMPREL: |
| 2050 | name = ".rela.plt"; |
| 2051 | get_vma: |
| 2052 | s = bfd_get_section_by_name(output_bfd, name); |
| 2053 | BFD_ASSERT (s != NULL); |
| 2054 | dyn.d_un.d_ptr = s->vma; |
| 2055 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 2056 | break; |
| 2057 | |
| 2058 | case DT_PLTRELSZ: |
| 2059 | s = bfd_get_section_by_name (output_bfd, ".rela.plt"); |
| 2060 | BFD_ASSERT (s != NULL); |
| 2061 | if (s->_cooked_size != 0) |
| 2062 | dyn.d_un.d_val = s->_cooked_size; |
| 2063 | else |
| 2064 | dyn.d_un.d_val = s->_raw_size; |
| 2065 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 2066 | break; |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | /* Fill in the special first entry in the procedure linkage table. */ |
| 2071 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 2072 | if (splt && splt->_raw_size > 0) |
| 2073 | { |
| 2074 | memset (splt->contents, 0, PLT_FIRST_ENTRY_SIZE); |
| 2075 | if (info->shared) |
| 2076 | { |
| 2077 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD0, |
| 2078 | splt->contents ); |
| 2079 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD1, |
| 2080 | splt->contents + 4 ); |
| 2081 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD2, |
| 2082 | splt->contents + 8 ); |
| 2083 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD3, |
| 2084 | splt->contents + 12 ); |
| 2085 | bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD4, |
| 2086 | splt->contents + 16 ); |
| 2087 | } |
| 2088 | else |
| 2089 | { |
| 2090 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD0, |
| 2091 | splt->contents ); |
| 2092 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1, |
| 2093 | splt->contents + 4 ); |
| 2094 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD2, |
| 2095 | splt->contents + 8 ); |
| 2096 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3, |
| 2097 | splt->contents + 12 ); |
| 2098 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4, |
| 2099 | splt->contents + 16 ); |
| 2100 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5, |
| 2101 | splt->contents + 20 ); |
| 2102 | bfd_put_32 (output_bfd, |
| 2103 | sgot->output_section->vma + sgot->output_offset, |
| 2104 | splt->contents + 24); |
| 2105 | } |
| 2106 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; |
| 2107 | } |
| 2108 | |
| 2109 | } |
| 2110 | |
| 2111 | /* Set the first entry in the global offset table to the address of |
| 2112 | the dynamic section. */ |
| 2113 | if (sgot->_raw_size > 0) |
| 2114 | { |
| 2115 | if (sdyn == NULL) |
| 2116 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); |
| 2117 | else |
| 2118 | bfd_put_32 (output_bfd, |
| 2119 | sdyn->output_section->vma + sdyn->output_offset, |
| 2120 | sgot->contents); |
| 2121 | |
| 2122 | /* One entry for shared object struct ptr. */ |
| 2123 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); |
| 2124 | /* One entry for _dl_runtime_resolve. */ |
| 2125 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); |
| 2126 | } |
| 2127 | |
| 2128 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
| 2129 | |
| 2130 | return true; |
| 2131 | } |
| 2132 | |
| 2133 | static boolean |
| 2134 | elf_s390_object_p (abfd) |
| 2135 | bfd *abfd; |
| 2136 | { |
| 2137 | return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_esa); |
| 2138 | } |
| 2139 | |
| 2140 | static enum elf_reloc_type_class |
| 2141 | elf_s390_reloc_type_class (type) |
| 2142 | int type; |
| 2143 | { |
| 2144 | switch (type) |
| 2145 | { |
| 2146 | case R_390_RELATIVE: |
| 2147 | return reloc_class_relative; |
| 2148 | case R_390_JMP_SLOT: |
| 2149 | return reloc_class_plt; |
| 2150 | case R_390_COPY: |
| 2151 | return reloc_class_copy; |
| 2152 | default: |
| 2153 | return reloc_class_normal; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | #define TARGET_BIG_SYM bfd_elf32_s390_vec |
| 2158 | #define TARGET_BIG_NAME "elf32-s390" |
| 2159 | #define ELF_ARCH bfd_arch_s390 |
| 2160 | #define ELF_MACHINE_CODE EM_S390 |
| 2161 | #define ELF_MACHINE_ALT1 EM_S390_OLD |
| 2162 | #define ELF_MAXPAGESIZE 0x1000 |
| 2163 | |
| 2164 | #define elf_backend_can_gc_sections 1 |
| 2165 | #define elf_backend_want_got_plt 1 |
| 2166 | #define elf_backend_plt_readonly 1 |
| 2167 | #define elf_backend_want_plt_sym 0 |
| 2168 | #define elf_backend_got_header_size 12 |
| 2169 | #define elf_backend_plt_header_size PLT_ENTRY_SIZE |
| 2170 | |
| 2171 | #define elf_info_to_howto elf_s390_info_to_howto |
| 2172 | |
| 2173 | #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link |
| 2174 | #define bfd_elf32_bfd_is_local_label_name elf_s390_is_local_label_name |
| 2175 | #define bfd_elf32_bfd_link_hash_table_create elf_s390_link_hash_table_create |
| 2176 | #define bfd_elf32_bfd_reloc_type_lookup elf_s390_reloc_type_lookup |
| 2177 | |
| 2178 | #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol |
| 2179 | #define elf_backend_check_relocs elf_s390_check_relocs |
| 2180 | #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections |
| 2181 | #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections |
| 2182 | #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol |
| 2183 | #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook |
| 2184 | #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook |
| 2185 | #define elf_backend_relocate_section elf_s390_relocate_section |
| 2186 | #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections |
| 2187 | #define elf_backend_reloc_type_class elf_s390_reloc_type_class |
| 2188 | |
| 2189 | #define elf_backend_object_p elf_s390_object_p |
| 2190 | |
| 2191 | #include "elf32-target.h" |