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