| 1 | /* Alpha specific support for 64-bit ELF
|
|---|
| 2 | Copyright 1996, 1997, 1998, 1999, 2000, 2001
|
|---|
| 3 | Free Software Foundation, Inc.
|
|---|
| 4 | Contributed by Richard Henderson <rth@tamu.edu>.
|
|---|
| 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 | /* We need a published ABI spec for this. Until one comes out, don't
|
|---|
| 23 | assume this'll remain unchanged forever. */
|
|---|
| 24 |
|
|---|
| 25 | #include "bfd.h"
|
|---|
| 26 | #include "sysdep.h"
|
|---|
| 27 | #include "libbfd.h"
|
|---|
| 28 | #include "elf-bfd.h"
|
|---|
| 29 |
|
|---|
| 30 | #include "elf/alpha.h"
|
|---|
| 31 |
|
|---|
| 32 | #define ALPHAECOFF
|
|---|
| 33 |
|
|---|
| 34 | #define NO_COFF_RELOCS
|
|---|
| 35 | #define NO_COFF_SYMBOLS
|
|---|
| 36 | #define NO_COFF_LINENOS
|
|---|
| 37 |
|
|---|
| 38 | /* Get the ECOFF swapping routines. Needed for the debug information. */
|
|---|
| 39 | #include "coff/internal.h"
|
|---|
| 40 | #include "coff/sym.h"
|
|---|
| 41 | #include "coff/symconst.h"
|
|---|
| 42 | #include "coff/ecoff.h"
|
|---|
| 43 | #include "coff/alpha.h"
|
|---|
| 44 | #include "aout/ar.h"
|
|---|
| 45 | #include "libcoff.h"
|
|---|
| 46 | #include "libecoff.h"
|
|---|
| 47 | #define ECOFF_64
|
|---|
| 48 | #include "ecoffswap.h"
|
|---|
| 49 |
|
|---|
| 50 | static int alpha_elf_dynamic_symbol_p
|
|---|
| 51 | PARAMS((struct elf_link_hash_entry *, struct bfd_link_info *));
|
|---|
| 52 | static struct bfd_hash_entry * elf64_alpha_link_hash_newfunc
|
|---|
| 53 | PARAMS((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
|
|---|
| 54 | static struct bfd_link_hash_table * elf64_alpha_bfd_link_hash_table_create
|
|---|
| 55 | PARAMS((bfd *));
|
|---|
| 56 |
|
|---|
| 57 | static bfd_reloc_status_type elf64_alpha_reloc_nil
|
|---|
| 58 | PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 59 | static bfd_reloc_status_type elf64_alpha_reloc_bad
|
|---|
| 60 | PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 61 | static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
|
|---|
| 62 | PARAMS((bfd *, bfd_vma, bfd_byte *, bfd_byte *));
|
|---|
| 63 | static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
|
|---|
| 64 | PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 65 |
|
|---|
| 66 | static reloc_howto_type * elf64_alpha_bfd_reloc_type_lookup
|
|---|
| 67 | PARAMS((bfd *, bfd_reloc_code_real_type));
|
|---|
| 68 | static void elf64_alpha_info_to_howto
|
|---|
| 69 | PARAMS((bfd *, arelent *, Elf64_Internal_Rela *));
|
|---|
| 70 |
|
|---|
| 71 | static boolean elf64_alpha_mkobject
|
|---|
| 72 | PARAMS((bfd *));
|
|---|
| 73 | static boolean elf64_alpha_object_p
|
|---|
| 74 | PARAMS((bfd *));
|
|---|
| 75 | static boolean elf64_alpha_section_from_shdr
|
|---|
| 76 | PARAMS((bfd *, Elf64_Internal_Shdr *, char *));
|
|---|
| 77 | static boolean elf64_alpha_fake_sections
|
|---|
| 78 | PARAMS((bfd *, Elf64_Internal_Shdr *, asection *));
|
|---|
| 79 | static boolean elf64_alpha_create_got_section
|
|---|
| 80 | PARAMS((bfd *, struct bfd_link_info *));
|
|---|
| 81 | static boolean elf64_alpha_create_dynamic_sections
|
|---|
| 82 | PARAMS((bfd *, struct bfd_link_info *));
|
|---|
| 83 |
|
|---|
| 84 | static boolean elf64_alpha_read_ecoff_info
|
|---|
| 85 | PARAMS((bfd *, asection *, struct ecoff_debug_info *));
|
|---|
| 86 | static boolean elf64_alpha_is_local_label_name
|
|---|
| 87 | PARAMS((bfd *, const char *));
|
|---|
| 88 | static boolean elf64_alpha_find_nearest_line
|
|---|
| 89 | PARAMS((bfd *, asection *, asymbol **, bfd_vma, const char **,
|
|---|
| 90 | const char **, unsigned int *));
|
|---|
| 91 |
|
|---|
| 92 | #if defined(__STDC__) || defined(ALMOST_STDC)
|
|---|
| 93 | struct alpha_elf_link_hash_entry;
|
|---|
| 94 | #endif
|
|---|
| 95 |
|
|---|
| 96 | static boolean elf64_alpha_output_extsym
|
|---|
| 97 | PARAMS((struct alpha_elf_link_hash_entry *, PTR));
|
|---|
| 98 |
|
|---|
| 99 | static boolean elf64_alpha_can_merge_gots
|
|---|
| 100 | PARAMS((bfd *, bfd *));
|
|---|
| 101 | static void elf64_alpha_merge_gots
|
|---|
| 102 | PARAMS((bfd *, bfd *));
|
|---|
| 103 | static boolean elf64_alpha_calc_got_offsets_for_symbol
|
|---|
| 104 | PARAMS ((struct alpha_elf_link_hash_entry *, PTR));
|
|---|
| 105 | static void elf64_alpha_calc_got_offsets PARAMS ((struct bfd_link_info *));
|
|---|
| 106 | static boolean elf64_alpha_size_got_sections
|
|---|
| 107 | PARAMS ((bfd *, struct bfd_link_info *));
|
|---|
| 108 | static boolean elf64_alpha_always_size_sections
|
|---|
| 109 | PARAMS ((bfd *, struct bfd_link_info *));
|
|---|
| 110 | static boolean elf64_alpha_calc_dynrel_sizes
|
|---|
| 111 | PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *));
|
|---|
| 112 | static boolean elf64_alpha_add_symbol_hook
|
|---|
| 113 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
|
|---|
| 114 | const char **, flagword *, asection **, bfd_vma *));
|
|---|
| 115 | static boolean elf64_alpha_check_relocs
|
|---|
| 116 | PARAMS((bfd *, struct bfd_link_info *, asection *sec,
|
|---|
| 117 | const Elf_Internal_Rela *));
|
|---|
| 118 | static boolean elf64_alpha_adjust_dynamic_symbol
|
|---|
| 119 | PARAMS((struct bfd_link_info *, struct elf_link_hash_entry *));
|
|---|
| 120 | static boolean elf64_alpha_size_dynamic_sections
|
|---|
| 121 | PARAMS((bfd *, struct bfd_link_info *));
|
|---|
| 122 | static boolean elf64_alpha_relocate_section
|
|---|
| 123 | PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
|
|---|
| 124 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
|
|---|
| 125 | static boolean elf64_alpha_finish_dynamic_symbol
|
|---|
| 126 | PARAMS((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
|
|---|
| 127 | Elf_Internal_Sym *));
|
|---|
| 128 | static boolean elf64_alpha_finish_dynamic_sections
|
|---|
| 129 | PARAMS((bfd *, struct bfd_link_info *));
|
|---|
| 130 | static boolean elf64_alpha_final_link
|
|---|
| 131 | PARAMS((bfd *, struct bfd_link_info *));
|
|---|
| 132 | static boolean elf64_alpha_merge_ind_symbols
|
|---|
| 133 | PARAMS((struct alpha_elf_link_hash_entry *, PTR));
|
|---|
| 134 | static Elf_Internal_Rela * elf64_alpha_find_reloc_at_ofs
|
|---|
| 135 | PARAMS ((Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_vma, int));
|
|---|
| 136 | |
|---|
| 137 |
|
|---|
| 138 | struct alpha_elf_link_hash_entry
|
|---|
| 139 | {
|
|---|
| 140 | struct elf_link_hash_entry root;
|
|---|
| 141 |
|
|---|
| 142 | /* External symbol information. */
|
|---|
| 143 | EXTR esym;
|
|---|
| 144 |
|
|---|
| 145 | /* Cumulative flags for all the .got entries. */
|
|---|
| 146 | int flags;
|
|---|
| 147 |
|
|---|
| 148 | /* Contexts (LITUSE) in which a literal was referenced. */
|
|---|
| 149 | #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
|
|---|
| 150 | #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
|
|---|
| 151 | #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
|
|---|
| 152 | #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x08
|
|---|
| 153 |
|
|---|
| 154 | /* Used to implement multiple .got subsections. */
|
|---|
| 155 | struct alpha_elf_got_entry
|
|---|
| 156 | {
|
|---|
| 157 | struct alpha_elf_got_entry *next;
|
|---|
| 158 |
|
|---|
| 159 | /* which .got subsection? */
|
|---|
| 160 | bfd *gotobj;
|
|---|
| 161 |
|
|---|
| 162 | /* the addend in effect for this entry. */
|
|---|
| 163 | bfd_vma addend;
|
|---|
| 164 |
|
|---|
| 165 | /* the .got offset for this entry. */
|
|---|
| 166 | int got_offset;
|
|---|
| 167 |
|
|---|
| 168 | int flags;
|
|---|
| 169 |
|
|---|
| 170 | /* An additional flag. */
|
|---|
| 171 | #define ALPHA_ELF_GOT_ENTRY_RELOCS_DONE 0x10
|
|---|
| 172 |
|
|---|
| 173 | int use_count;
|
|---|
| 174 | } *got_entries;
|
|---|
| 175 |
|
|---|
| 176 | /* used to count non-got, non-plt relocations for delayed sizing
|
|---|
| 177 | of relocation sections. */
|
|---|
| 178 | struct alpha_elf_reloc_entry
|
|---|
| 179 | {
|
|---|
| 180 | struct alpha_elf_reloc_entry *next;
|
|---|
| 181 |
|
|---|
| 182 | /* which .reloc section? */
|
|---|
| 183 | asection *srel;
|
|---|
| 184 |
|
|---|
| 185 | /* what kind of relocation? */
|
|---|
| 186 | unsigned long rtype;
|
|---|
| 187 |
|
|---|
| 188 | /* how many did we find? */
|
|---|
| 189 | unsigned long count;
|
|---|
| 190 | } *reloc_entries;
|
|---|
| 191 | };
|
|---|
| 192 |
|
|---|
| 193 | /* Alpha ELF linker hash table. */
|
|---|
| 194 |
|
|---|
| 195 | struct alpha_elf_link_hash_table
|
|---|
| 196 | {
|
|---|
| 197 | struct elf_link_hash_table root;
|
|---|
| 198 |
|
|---|
| 199 | /* The head of a list of .got subsections linked through
|
|---|
| 200 | alpha_elf_tdata(abfd)->got_link_next. */
|
|---|
| 201 | bfd *got_list;
|
|---|
| 202 | };
|
|---|
| 203 |
|
|---|
| 204 | /* Look up an entry in a Alpha ELF linker hash table. */
|
|---|
| 205 |
|
|---|
| 206 | #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
|
|---|
| 207 | ((struct alpha_elf_link_hash_entry *) \
|
|---|
| 208 | elf_link_hash_lookup (&(table)->root, (string), (create), \
|
|---|
| 209 | (copy), (follow)))
|
|---|
| 210 |
|
|---|
| 211 | /* Traverse a Alpha ELF linker hash table. */
|
|---|
| 212 |
|
|---|
| 213 | #define alpha_elf_link_hash_traverse(table, func, info) \
|
|---|
| 214 | (elf_link_hash_traverse \
|
|---|
| 215 | (&(table)->root, \
|
|---|
| 216 | (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
|
|---|
| 217 | (info)))
|
|---|
| 218 |
|
|---|
| 219 | /* Get the Alpha ELF linker hash table from a link_info structure. */
|
|---|
| 220 |
|
|---|
| 221 | #define alpha_elf_hash_table(p) \
|
|---|
| 222 | ((struct alpha_elf_link_hash_table *) ((p)->hash))
|
|---|
| 223 |
|
|---|
| 224 | /* Get the object's symbols as our own entry type. */
|
|---|
| 225 |
|
|---|
| 226 | #define alpha_elf_sym_hashes(abfd) \
|
|---|
| 227 | ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
|
|---|
| 228 |
|
|---|
| 229 | /* Should we do dynamic things to this symbol? */
|
|---|
| 230 |
|
|---|
| 231 | static int
|
|---|
| 232 | alpha_elf_dynamic_symbol_p (h, info)
|
|---|
| 233 | struct elf_link_hash_entry *h;
|
|---|
| 234 | struct bfd_link_info *info;
|
|---|
| 235 | {
|
|---|
| 236 | if (h == NULL)
|
|---|
| 237 | return false;
|
|---|
| 238 |
|
|---|
| 239 | while (h->root.type == bfd_link_hash_indirect
|
|---|
| 240 | || h->root.type == bfd_link_hash_warning)
|
|---|
| 241 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
|---|
| 242 |
|
|---|
| 243 | if (h->dynindx == -1)
|
|---|
| 244 | return false;
|
|---|
| 245 |
|
|---|
| 246 | if (h->root.type == bfd_link_hash_undefweak
|
|---|
| 247 | || h->root.type == bfd_link_hash_defweak)
|
|---|
| 248 | return true;
|
|---|
| 249 |
|
|---|
| 250 | switch (ELF_ST_VISIBILITY (h->other))
|
|---|
| 251 | {
|
|---|
| 252 | case STV_DEFAULT:
|
|---|
| 253 | break;
|
|---|
| 254 | case STV_HIDDEN:
|
|---|
| 255 | case STV_INTERNAL:
|
|---|
| 256 | return false;
|
|---|
| 257 | case STV_PROTECTED:
|
|---|
| 258 | if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
|
|---|
| 259 | return false;
|
|---|
| 260 | break;
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | if ((info->shared && !info->symbolic)
|
|---|
| 264 | || ((h->elf_link_hash_flags
|
|---|
| 265 | & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))
|
|---|
| 266 | == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
|
|---|
| 267 | return true;
|
|---|
| 268 |
|
|---|
| 269 | return false;
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | /* Create an entry in a Alpha ELF linker hash table. */
|
|---|
| 273 |
|
|---|
| 274 | static struct bfd_hash_entry *
|
|---|
| 275 | elf64_alpha_link_hash_newfunc (entry, table, string)
|
|---|
| 276 | struct bfd_hash_entry *entry;
|
|---|
| 277 | struct bfd_hash_table *table;
|
|---|
| 278 | const char *string;
|
|---|
| 279 | {
|
|---|
| 280 | struct alpha_elf_link_hash_entry *ret =
|
|---|
| 281 | (struct alpha_elf_link_hash_entry *) entry;
|
|---|
| 282 |
|
|---|
| 283 | /* Allocate the structure if it has not already been allocated by a
|
|---|
| 284 | subclass. */
|
|---|
| 285 | if (ret == (struct alpha_elf_link_hash_entry *) NULL)
|
|---|
| 286 | ret = ((struct alpha_elf_link_hash_entry *)
|
|---|
| 287 | bfd_hash_allocate (table,
|
|---|
| 288 | sizeof (struct alpha_elf_link_hash_entry)));
|
|---|
| 289 | if (ret == (struct alpha_elf_link_hash_entry *) NULL)
|
|---|
| 290 | return (struct bfd_hash_entry *) ret;
|
|---|
| 291 |
|
|---|
| 292 | /* Call the allocation method of the superclass. */
|
|---|
| 293 | ret = ((struct alpha_elf_link_hash_entry *)
|
|---|
| 294 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
|
|---|
| 295 | table, string));
|
|---|
| 296 | if (ret != (struct alpha_elf_link_hash_entry *) NULL)
|
|---|
| 297 | {
|
|---|
| 298 | /* Set local fields. */
|
|---|
| 299 | memset (&ret->esym, 0, sizeof (EXTR));
|
|---|
| 300 | /* We use -2 as a marker to indicate that the information has
|
|---|
| 301 | not been set. -1 means there is no associated ifd. */
|
|---|
| 302 | ret->esym.ifd = -2;
|
|---|
| 303 | ret->flags = 0;
|
|---|
| 304 | ret->got_entries = NULL;
|
|---|
| 305 | ret->reloc_entries = NULL;
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | return (struct bfd_hash_entry *) ret;
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | /* Create a Alpha ELF linker hash table. */
|
|---|
| 312 |
|
|---|
| 313 | static struct bfd_link_hash_table *
|
|---|
| 314 | elf64_alpha_bfd_link_hash_table_create (abfd)
|
|---|
| 315 | bfd *abfd;
|
|---|
| 316 | {
|
|---|
| 317 | struct alpha_elf_link_hash_table *ret;
|
|---|
| 318 |
|
|---|
| 319 | ret = ((struct alpha_elf_link_hash_table *)
|
|---|
| 320 | bfd_zalloc (abfd, sizeof (struct alpha_elf_link_hash_table)));
|
|---|
| 321 | if (ret == (struct alpha_elf_link_hash_table *) NULL)
|
|---|
| 322 | return NULL;
|
|---|
| 323 |
|
|---|
| 324 | if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
|
|---|
| 325 | elf64_alpha_link_hash_newfunc))
|
|---|
| 326 | {
|
|---|
| 327 | bfd_release (abfd, ret);
|
|---|
| 328 | return NULL;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | return &ret->root.root;
|
|---|
| 332 | }
|
|---|
| 333 | |
|---|
| 334 |
|
|---|
| 335 | /* We have some private fields hanging off of the elf_tdata structure. */
|
|---|
| 336 |
|
|---|
| 337 | struct alpha_elf_obj_tdata
|
|---|
| 338 | {
|
|---|
| 339 | struct elf_obj_tdata root;
|
|---|
| 340 |
|
|---|
| 341 | /* For every input file, these are the got entries for that object's
|
|---|
| 342 | local symbols. */
|
|---|
| 343 | struct alpha_elf_got_entry ** local_got_entries;
|
|---|
| 344 |
|
|---|
| 345 | /* For every input file, this is the object that owns the got that
|
|---|
| 346 | this input file uses. */
|
|---|
| 347 | bfd *gotobj;
|
|---|
| 348 |
|
|---|
| 349 | /* For every got, this is a linked list through the objects using this got */
|
|---|
| 350 | bfd *in_got_link_next;
|
|---|
| 351 |
|
|---|
| 352 | /* For every got, this is a link to the next got subsegment. */
|
|---|
| 353 | bfd *got_link_next;
|
|---|
| 354 |
|
|---|
| 355 | /* For every got, this is the section. */
|
|---|
| 356 | asection *got;
|
|---|
| 357 |
|
|---|
| 358 | /* For every got, this is it's total number of *entries*. */
|
|---|
| 359 | int total_got_entries;
|
|---|
| 360 |
|
|---|
| 361 | /* For every got, this is the sum of the number of *entries* required
|
|---|
| 362 | to hold all of the member object's local got. */
|
|---|
| 363 | int n_local_got_entries;
|
|---|
| 364 | };
|
|---|
| 365 |
|
|---|
| 366 | #define alpha_elf_tdata(abfd) \
|
|---|
| 367 | ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
|
|---|
| 368 |
|
|---|
| 369 | static boolean
|
|---|
| 370 | elf64_alpha_mkobject (abfd)
|
|---|
| 371 | bfd *abfd;
|
|---|
| 372 | {
|
|---|
| 373 | abfd->tdata.any = bfd_zalloc (abfd, sizeof (struct alpha_elf_obj_tdata));
|
|---|
| 374 | if (abfd->tdata.any == NULL)
|
|---|
| 375 | return false;
|
|---|
| 376 | return true;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | static boolean
|
|---|
| 380 | elf64_alpha_object_p (abfd)
|
|---|
| 381 | bfd *abfd;
|
|---|
| 382 | {
|
|---|
| 383 | /* Allocate our special target data. */
|
|---|
| 384 | struct alpha_elf_obj_tdata *new_tdata;
|
|---|
| 385 | new_tdata = bfd_zalloc (abfd, sizeof (struct alpha_elf_obj_tdata));
|
|---|
| 386 | if (new_tdata == NULL)
|
|---|
| 387 | return false;
|
|---|
| 388 | new_tdata->root = *abfd->tdata.elf_obj_data;
|
|---|
| 389 | abfd->tdata.any = new_tdata;
|
|---|
| 390 |
|
|---|
| 391 | /* Set the right machine number for an Alpha ELF file. */
|
|---|
| 392 | return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
|
|---|
| 393 | }
|
|---|
| 394 | |
|---|
| 395 |
|
|---|
| 396 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
|
|---|
| 397 | from smaller values. Start with zero, widen, *then* decrement. */
|
|---|
| 398 | #define MINUS_ONE (((bfd_vma)0) - 1)
|
|---|
| 399 |
|
|---|
| 400 | static reloc_howto_type elf64_alpha_howto_table[] =
|
|---|
| 401 | {
|
|---|
| 402 | HOWTO (R_ALPHA_NONE, /* type */
|
|---|
| 403 | 0, /* rightshift */
|
|---|
| 404 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 405 | 8, /* bitsize */
|
|---|
| 406 | true, /* pc_relative */
|
|---|
| 407 | 0, /* bitpos */
|
|---|
| 408 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 409 | elf64_alpha_reloc_nil, /* special_function */
|
|---|
| 410 | "NONE", /* name */
|
|---|
| 411 | false, /* partial_inplace */
|
|---|
| 412 | 0, /* src_mask */
|
|---|
| 413 | 0, /* dst_mask */
|
|---|
| 414 | true), /* pcrel_offset */
|
|---|
| 415 |
|
|---|
| 416 | /* A 32 bit reference to a symbol. */
|
|---|
| 417 | HOWTO (R_ALPHA_REFLONG, /* type */
|
|---|
| 418 | 0, /* rightshift */
|
|---|
| 419 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 420 | 32, /* bitsize */
|
|---|
| 421 | false, /* pc_relative */
|
|---|
| 422 | 0, /* bitpos */
|
|---|
| 423 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 424 | 0, /* special_function */
|
|---|
| 425 | "REFLONG", /* name */
|
|---|
| 426 | false, /* partial_inplace */
|
|---|
| 427 | 0xffffffff, /* src_mask */
|
|---|
| 428 | 0xffffffff, /* dst_mask */
|
|---|
| 429 | false), /* pcrel_offset */
|
|---|
| 430 |
|
|---|
| 431 | /* A 64 bit reference to a symbol. */
|
|---|
| 432 | HOWTO (R_ALPHA_REFQUAD, /* type */
|
|---|
| 433 | 0, /* rightshift */
|
|---|
| 434 | 4, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 435 | 64, /* bitsize */
|
|---|
| 436 | false, /* pc_relative */
|
|---|
| 437 | 0, /* bitpos */
|
|---|
| 438 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 439 | 0, /* special_function */
|
|---|
| 440 | "REFQUAD", /* name */
|
|---|
| 441 | false, /* partial_inplace */
|
|---|
| 442 | MINUS_ONE, /* src_mask */
|
|---|
| 443 | MINUS_ONE, /* dst_mask */
|
|---|
| 444 | false), /* pcrel_offset */
|
|---|
| 445 |
|
|---|
| 446 | /* A 32 bit GP relative offset. This is just like REFLONG except
|
|---|
| 447 | that when the value is used the value of the gp register will be
|
|---|
| 448 | added in. */
|
|---|
| 449 | HOWTO (R_ALPHA_GPREL32, /* type */
|
|---|
| 450 | 0, /* rightshift */
|
|---|
| 451 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 452 | 32, /* bitsize */
|
|---|
| 453 | false, /* pc_relative */
|
|---|
| 454 | 0, /* bitpos */
|
|---|
| 455 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 456 | 0, /* special_function */
|
|---|
| 457 | "GPREL32", /* name */
|
|---|
| 458 | false, /* partial_inplace */
|
|---|
| 459 | 0xffffffff, /* src_mask */
|
|---|
| 460 | 0xffffffff, /* dst_mask */
|
|---|
| 461 | false), /* pcrel_offset */
|
|---|
| 462 |
|
|---|
| 463 | /* Used for an instruction that refers to memory off the GP register. */
|
|---|
| 464 | HOWTO (R_ALPHA_LITERAL, /* type */
|
|---|
| 465 | 0, /* rightshift */
|
|---|
| 466 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 467 | 16, /* bitsize */
|
|---|
| 468 | false, /* pc_relative */
|
|---|
| 469 | 0, /* bitpos */
|
|---|
| 470 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 471 | 0, /* special_function */
|
|---|
| 472 | "ELF_LITERAL", /* name */
|
|---|
| 473 | false, /* partial_inplace */
|
|---|
| 474 | 0xffff, /* src_mask */
|
|---|
| 475 | 0xffff, /* dst_mask */
|
|---|
| 476 | false), /* pcrel_offset */
|
|---|
| 477 |
|
|---|
| 478 | /* This reloc only appears immediately following an ELF_LITERAL reloc.
|
|---|
| 479 | It identifies a use of the literal. The symbol index is special:
|
|---|
| 480 | 1 means the literal address is in the base register of a memory
|
|---|
| 481 | format instruction; 2 means the literal address is in the byte
|
|---|
| 482 | offset register of a byte-manipulation instruction; 3 means the
|
|---|
| 483 | literal address is in the target register of a jsr instruction.
|
|---|
| 484 | This does not actually do any relocation. */
|
|---|
| 485 | HOWTO (R_ALPHA_LITUSE, /* type */
|
|---|
| 486 | 0, /* rightshift */
|
|---|
| 487 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 488 | 32, /* bitsize */
|
|---|
| 489 | false, /* pc_relative */
|
|---|
| 490 | 0, /* bitpos */
|
|---|
| 491 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 492 | elf64_alpha_reloc_nil, /* special_function */
|
|---|
| 493 | "LITUSE", /* name */
|
|---|
| 494 | false, /* partial_inplace */
|
|---|
| 495 | 0, /* src_mask */
|
|---|
| 496 | 0, /* dst_mask */
|
|---|
| 497 | false), /* pcrel_offset */
|
|---|
| 498 |
|
|---|
| 499 | /* Load the gp register. This is always used for a ldah instruction
|
|---|
| 500 | which loads the upper 16 bits of the gp register. The symbol
|
|---|
| 501 | index of the GPDISP instruction is an offset in bytes to the lda
|
|---|
| 502 | instruction that loads the lower 16 bits. The value to use for
|
|---|
| 503 | the relocation is the difference between the GP value and the
|
|---|
| 504 | current location; the load will always be done against a register
|
|---|
| 505 | holding the current address.
|
|---|
| 506 |
|
|---|
| 507 | NOTE: Unlike ECOFF, partial in-place relocation is not done. If
|
|---|
| 508 | any offset is present in the instructions, it is an offset from
|
|---|
| 509 | the register to the ldah instruction. This lets us avoid any
|
|---|
| 510 | stupid hackery like inventing a gp value to do partial relocation
|
|---|
| 511 | against. Also unlike ECOFF, we do the whole relocation off of
|
|---|
| 512 | the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
|
|---|
| 513 | space consuming bit, that, since all the information was present
|
|---|
| 514 | in the GPDISP_HI16 reloc. */
|
|---|
| 515 | HOWTO (R_ALPHA_GPDISP, /* type */
|
|---|
| 516 | 16, /* rightshift */
|
|---|
| 517 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 518 | 16, /* bitsize */
|
|---|
| 519 | false, /* pc_relative */
|
|---|
| 520 | 0, /* bitpos */
|
|---|
| 521 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 522 | elf64_alpha_reloc_gpdisp, /* special_function */
|
|---|
| 523 | "GPDISP", /* name */
|
|---|
| 524 | false, /* partial_inplace */
|
|---|
| 525 | 0xffff, /* src_mask */
|
|---|
| 526 | 0xffff, /* dst_mask */
|
|---|
| 527 | true), /* pcrel_offset */
|
|---|
| 528 |
|
|---|
| 529 | /* A 21 bit branch. */
|
|---|
| 530 | HOWTO (R_ALPHA_BRADDR, /* type */
|
|---|
| 531 | 2, /* rightshift */
|
|---|
| 532 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 533 | 21, /* bitsize */
|
|---|
| 534 | true, /* pc_relative */
|
|---|
| 535 | 0, /* bitpos */
|
|---|
| 536 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 537 | 0, /* special_function */
|
|---|
| 538 | "BRADDR", /* name */
|
|---|
| 539 | false, /* partial_inplace */
|
|---|
| 540 | 0x1fffff, /* src_mask */
|
|---|
| 541 | 0x1fffff, /* dst_mask */
|
|---|
| 542 | true), /* pcrel_offset */
|
|---|
| 543 |
|
|---|
| 544 | /* A hint for a jump to a register. */
|
|---|
| 545 | HOWTO (R_ALPHA_HINT, /* type */
|
|---|
| 546 | 2, /* rightshift */
|
|---|
| 547 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 548 | 14, /* bitsize */
|
|---|
| 549 | true, /* pc_relative */
|
|---|
| 550 | 0, /* bitpos */
|
|---|
| 551 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 552 | 0, /* special_function */
|
|---|
| 553 | "HINT", /* name */
|
|---|
| 554 | false, /* partial_inplace */
|
|---|
| 555 | 0x3fff, /* src_mask */
|
|---|
| 556 | 0x3fff, /* dst_mask */
|
|---|
| 557 | true), /* pcrel_offset */
|
|---|
| 558 |
|
|---|
| 559 | /* 16 bit PC relative offset. */
|
|---|
| 560 | HOWTO (R_ALPHA_SREL16, /* type */
|
|---|
| 561 | 0, /* rightshift */
|
|---|
| 562 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 563 | 16, /* bitsize */
|
|---|
| 564 | true, /* pc_relative */
|
|---|
| 565 | 0, /* bitpos */
|
|---|
| 566 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 567 | 0, /* special_function */
|
|---|
| 568 | "SREL16", /* name */
|
|---|
| 569 | false, /* partial_inplace */
|
|---|
| 570 | 0xffff, /* src_mask */
|
|---|
| 571 | 0xffff, /* dst_mask */
|
|---|
| 572 | true), /* pcrel_offset */
|
|---|
| 573 |
|
|---|
| 574 | /* 32 bit PC relative offset. */
|
|---|
| 575 | HOWTO (R_ALPHA_SREL32, /* type */
|
|---|
| 576 | 0, /* rightshift */
|
|---|
| 577 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 578 | 32, /* bitsize */
|
|---|
| 579 | true, /* pc_relative */
|
|---|
| 580 | 0, /* bitpos */
|
|---|
| 581 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 582 | 0, /* special_function */
|
|---|
| 583 | "SREL32", /* name */
|
|---|
| 584 | false, /* partial_inplace */
|
|---|
| 585 | 0xffffffff, /* src_mask */
|
|---|
| 586 | 0xffffffff, /* dst_mask */
|
|---|
| 587 | true), /* pcrel_offset */
|
|---|
| 588 |
|
|---|
| 589 | /* A 64 bit PC relative offset. */
|
|---|
| 590 | HOWTO (R_ALPHA_SREL64, /* type */
|
|---|
| 591 | 0, /* rightshift */
|
|---|
| 592 | 4, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 593 | 64, /* bitsize */
|
|---|
| 594 | true, /* pc_relative */
|
|---|
| 595 | 0, /* bitpos */
|
|---|
| 596 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 597 | 0, /* special_function */
|
|---|
| 598 | "SREL64", /* name */
|
|---|
| 599 | false, /* partial_inplace */
|
|---|
| 600 | MINUS_ONE, /* src_mask */
|
|---|
| 601 | MINUS_ONE, /* dst_mask */
|
|---|
| 602 | true), /* pcrel_offset */
|
|---|
| 603 |
|
|---|
| 604 | /* Push a value on the reloc evaluation stack. */
|
|---|
| 605 | /* Not implemented -- it's dumb. */
|
|---|
| 606 | HOWTO (R_ALPHA_OP_PUSH, /* type */
|
|---|
| 607 | 0, /* rightshift */
|
|---|
| 608 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 609 | 0, /* bitsize */
|
|---|
| 610 | false, /* pc_relative */
|
|---|
| 611 | 0, /* bitpos */
|
|---|
| 612 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 613 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 614 | "OP_PUSH", /* name */
|
|---|
| 615 | false, /* partial_inplace */
|
|---|
| 616 | 0, /* src_mask */
|
|---|
| 617 | 0, /* dst_mask */
|
|---|
| 618 | false), /* pcrel_offset */
|
|---|
| 619 |
|
|---|
| 620 | /* Store the value from the stack at the given address. Store it in
|
|---|
| 621 | a bitfield of size r_size starting at bit position r_offset. */
|
|---|
| 622 | /* Not implemented -- it's dumb. */
|
|---|
| 623 | HOWTO (R_ALPHA_OP_STORE, /* type */
|
|---|
| 624 | 0, /* rightshift */
|
|---|
| 625 | 4, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 626 | 64, /* bitsize */
|
|---|
| 627 | false, /* pc_relative */
|
|---|
| 628 | 0, /* bitpos */
|
|---|
| 629 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 630 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 631 | "OP_STORE", /* name */
|
|---|
| 632 | false, /* partial_inplace */
|
|---|
| 633 | 0, /* src_mask */
|
|---|
| 634 | MINUS_ONE, /* dst_mask */
|
|---|
| 635 | false), /* pcrel_offset */
|
|---|
| 636 |
|
|---|
| 637 | /* Subtract the reloc address from the value on the top of the
|
|---|
| 638 | relocation stack. */
|
|---|
| 639 | /* Not implemented -- it's dumb. */
|
|---|
| 640 | HOWTO (R_ALPHA_OP_PSUB, /* type */
|
|---|
| 641 | 0, /* rightshift */
|
|---|
| 642 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 643 | 0, /* bitsize */
|
|---|
| 644 | false, /* pc_relative */
|
|---|
| 645 | 0, /* bitpos */
|
|---|
| 646 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 647 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 648 | "OP_PSUB", /* name */
|
|---|
| 649 | false, /* partial_inplace */
|
|---|
| 650 | 0, /* src_mask */
|
|---|
| 651 | 0, /* dst_mask */
|
|---|
| 652 | false), /* pcrel_offset */
|
|---|
| 653 |
|
|---|
| 654 | /* Shift the value on the top of the relocation stack right by the
|
|---|
| 655 | given value. */
|
|---|
| 656 | /* Not implemented -- it's dumb. */
|
|---|
| 657 | HOWTO (R_ALPHA_OP_PRSHIFT, /* type */
|
|---|
| 658 | 0, /* rightshift */
|
|---|
| 659 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 660 | 0, /* bitsize */
|
|---|
| 661 | false, /* pc_relative */
|
|---|
| 662 | 0, /* bitpos */
|
|---|
| 663 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 664 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 665 | "OP_PRSHIFT", /* name */
|
|---|
| 666 | false, /* partial_inplace */
|
|---|
| 667 | 0, /* src_mask */
|
|---|
| 668 | 0, /* dst_mask */
|
|---|
| 669 | false), /* pcrel_offset */
|
|---|
| 670 |
|
|---|
| 671 | /* Change the value of GP used by +r_addend until the next GPVALUE or the
|
|---|
| 672 | end of the input bfd. */
|
|---|
| 673 | /* Not implemented -- it's dumb. */
|
|---|
| 674 | HOWTO (R_ALPHA_GPVALUE,
|
|---|
| 675 | 0, /* rightshift */
|
|---|
| 676 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 677 | 0, /* bitsize */
|
|---|
| 678 | false, /* pc_relative */
|
|---|
| 679 | 0, /* bitpos */
|
|---|
| 680 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 681 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 682 | "GPVALUE", /* name */
|
|---|
| 683 | false, /* partial_inplace */
|
|---|
| 684 | 0, /* src_mask */
|
|---|
| 685 | 0, /* dst_mask */
|
|---|
| 686 | false), /* pcrel_offset */
|
|---|
| 687 |
|
|---|
| 688 | /* The high 16 bits of the displacement from GP to the target. */
|
|---|
| 689 | HOWTO (R_ALPHA_GPRELHIGH,
|
|---|
| 690 | 0, /* rightshift */
|
|---|
| 691 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 692 | 16, /* bitsize */
|
|---|
| 693 | false, /* pc_relative */
|
|---|
| 694 | 0, /* bitpos */
|
|---|
| 695 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 696 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 697 | "GPRELHIGH", /* name */
|
|---|
| 698 | false, /* partial_inplace */
|
|---|
| 699 | 0xffff, /* src_mask */
|
|---|
| 700 | 0xffff, /* dst_mask */
|
|---|
| 701 | false), /* pcrel_offset */
|
|---|
| 702 |
|
|---|
| 703 | /* The low 16 bits of the displacement from GP to the target. */
|
|---|
| 704 | HOWTO (R_ALPHA_GPRELLOW,
|
|---|
| 705 | 0, /* rightshift */
|
|---|
| 706 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 707 | 16, /* bitsize */
|
|---|
| 708 | false, /* pc_relative */
|
|---|
| 709 | 0, /* bitpos */
|
|---|
| 710 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 711 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 712 | "GPRELLOW", /* name */
|
|---|
| 713 | false, /* partial_inplace */
|
|---|
| 714 | 0xffff, /* src_mask */
|
|---|
| 715 | 0xffff, /* dst_mask */
|
|---|
| 716 | false), /* pcrel_offset */
|
|---|
| 717 |
|
|---|
| 718 | /* A 16-bit displacement from the GP to the target. */
|
|---|
| 719 | /* XXX: Not implemented. */
|
|---|
| 720 | HOWTO (R_ALPHA_IMMED_GP_16,
|
|---|
| 721 | 0, /* rightshift */
|
|---|
| 722 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 723 | 16, /* bitsize */
|
|---|
| 724 | false, /* pc_relative */
|
|---|
| 725 | 0, /* bitpos */
|
|---|
| 726 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 727 | 0, /* special_function */
|
|---|
| 728 | "IMMED_GP_16", /* name */
|
|---|
| 729 | false, /* partial_inplace */
|
|---|
| 730 | 0xffff, /* src_mask */
|
|---|
| 731 | 0xffff, /* dst_mask */
|
|---|
| 732 | false), /* pcrel_offset */
|
|---|
| 733 |
|
|---|
| 734 | /* The high bits of a 32-bit displacement from the GP to the target; the
|
|---|
| 735 | low bits are supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
|
|---|
| 736 | /* XXX: Not implemented. */
|
|---|
| 737 | HOWTO (R_ALPHA_IMMED_GP_HI32,
|
|---|
| 738 | 0, /* rightshift */
|
|---|
| 739 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 740 | 0, /* bitsize */
|
|---|
| 741 | false, /* pc_relative */
|
|---|
| 742 | 0, /* bitpos */
|
|---|
| 743 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 744 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 745 | "IMMED_GP_HI32", /* name */
|
|---|
| 746 | false, /* partial_inplace */
|
|---|
| 747 | 0, /* src_mask */
|
|---|
| 748 | 0, /* dst_mask */
|
|---|
| 749 | false), /* pcrel_offset */
|
|---|
| 750 |
|
|---|
| 751 | /* The high bits of a 32-bit displacement to the starting address of the
|
|---|
| 752 | current section (the relocation target is ignored); the low bits are
|
|---|
| 753 | supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
|
|---|
| 754 | /* XXX: Not implemented. */
|
|---|
| 755 | HOWTO (R_ALPHA_IMMED_SCN_HI32,
|
|---|
| 756 | 0, /* rightshift */
|
|---|
| 757 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 758 | 0, /* bitsize */
|
|---|
| 759 | false, /* pc_relative */
|
|---|
| 760 | 0, /* bitpos */
|
|---|
| 761 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 762 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 763 | "IMMED_SCN_HI32", /* name */
|
|---|
| 764 | false, /* partial_inplace */
|
|---|
| 765 | 0, /* src_mask */
|
|---|
| 766 | 0, /* dst_mask */
|
|---|
| 767 | false), /* pcrel_offset */
|
|---|
| 768 |
|
|---|
| 769 | /* The high bits of a 32-bit displacement from the previous br, bsr, jsr
|
|---|
| 770 | or jmp insn (as tagged by a BRADDR or HINT reloc) to the target; the
|
|---|
| 771 | low bits are supplied by subsequent R_ALPHA_IMMED_LO32 relocs. */
|
|---|
| 772 | /* XXX: Not implemented. */
|
|---|
| 773 | HOWTO (R_ALPHA_IMMED_BR_HI32,
|
|---|
| 774 | 0, /* rightshift */
|
|---|
| 775 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 776 | 0, /* bitsize */
|
|---|
| 777 | false, /* pc_relative */
|
|---|
| 778 | 0, /* bitpos */
|
|---|
| 779 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 780 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 781 | "IMMED_BR_HI32", /* name */
|
|---|
| 782 | false, /* partial_inplace */
|
|---|
| 783 | 0, /* src_mask */
|
|---|
| 784 | 0, /* dst_mask */
|
|---|
| 785 | false), /* pcrel_offset */
|
|---|
| 786 |
|
|---|
| 787 | /* The low 16 bits of a displacement calculated in a previous HI32 reloc. */
|
|---|
| 788 | /* XXX: Not implemented. */
|
|---|
| 789 | HOWTO (R_ALPHA_IMMED_LO32,
|
|---|
| 790 | 0, /* rightshift */
|
|---|
| 791 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 792 | 0, /* bitsize */
|
|---|
| 793 | false, /* pc_relative */
|
|---|
| 794 | 0, /* bitpos */
|
|---|
| 795 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 796 | elf64_alpha_reloc_bad, /* special_function */
|
|---|
| 797 | "IMMED_LO32", /* name */
|
|---|
| 798 | false, /* partial_inplace */
|
|---|
| 799 | 0, /* src_mask */
|
|---|
| 800 | 0, /* dst_mask */
|
|---|
| 801 | false), /* pcrel_offset */
|
|---|
| 802 |
|
|---|
| 803 | /* Misc ELF relocations. */
|
|---|
| 804 |
|
|---|
| 805 | /* A dynamic relocation to copy the target into our .dynbss section. */
|
|---|
| 806 | /* Not generated, as all Alpha objects use PIC, so it is not needed. It
|
|---|
| 807 | is present because every other ELF has one, but should not be used
|
|---|
| 808 | because .dynbss is an ugly thing. */
|
|---|
| 809 | HOWTO (R_ALPHA_COPY,
|
|---|
| 810 | 0,
|
|---|
| 811 | 0,
|
|---|
| 812 | 0,
|
|---|
| 813 | false,
|
|---|
| 814 | 0,
|
|---|
| 815 | complain_overflow_dont,
|
|---|
| 816 | bfd_elf_generic_reloc,
|
|---|
| 817 | "COPY",
|
|---|
| 818 | false,
|
|---|
| 819 | 0,
|
|---|
| 820 | 0,
|
|---|
| 821 | true),
|
|---|
| 822 |
|
|---|
| 823 | /* A dynamic relocation for a .got entry. */
|
|---|
| 824 | HOWTO (R_ALPHA_GLOB_DAT,
|
|---|
| 825 | 0,
|
|---|
| 826 | 0,
|
|---|
| 827 | 0,
|
|---|
| 828 | false,
|
|---|
| 829 | 0,
|
|---|
| 830 | complain_overflow_dont,
|
|---|
| 831 | bfd_elf_generic_reloc,
|
|---|
| 832 | "GLOB_DAT",
|
|---|
| 833 | false,
|
|---|
| 834 | 0,
|
|---|
| 835 | 0,
|
|---|
| 836 | true),
|
|---|
| 837 |
|
|---|
| 838 | /* A dynamic relocation for a .plt entry. */
|
|---|
| 839 | HOWTO (R_ALPHA_JMP_SLOT,
|
|---|
| 840 | 0,
|
|---|
| 841 | 0,
|
|---|
| 842 | 0,
|
|---|
| 843 | false,
|
|---|
| 844 | 0,
|
|---|
| 845 | complain_overflow_dont,
|
|---|
| 846 | bfd_elf_generic_reloc,
|
|---|
| 847 | "JMP_SLOT",
|
|---|
| 848 | false,
|
|---|
| 849 | 0,
|
|---|
| 850 | 0,
|
|---|
| 851 | true),
|
|---|
| 852 |
|
|---|
| 853 | /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
|
|---|
| 854 | HOWTO (R_ALPHA_RELATIVE,
|
|---|
| 855 | 0,
|
|---|
| 856 | 0,
|
|---|
| 857 | 0,
|
|---|
| 858 | false,
|
|---|
| 859 | 0,
|
|---|
| 860 | complain_overflow_dont,
|
|---|
| 861 | bfd_elf_generic_reloc,
|
|---|
| 862 | "RELATIVE",
|
|---|
| 863 | false,
|
|---|
| 864 | 0,
|
|---|
| 865 | 0,
|
|---|
| 866 | true)
|
|---|
| 867 | };
|
|---|
| 868 |
|
|---|
| 869 | /* A relocation function which doesn't do anything. */
|
|---|
| 870 |
|
|---|
| 871 | static bfd_reloc_status_type
|
|---|
| 872 | elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
|
|---|
| 873 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 874 | arelent *reloc;
|
|---|
| 875 | asymbol *sym ATTRIBUTE_UNUSED;
|
|---|
| 876 | PTR data ATTRIBUTE_UNUSED;
|
|---|
| 877 | asection *sec;
|
|---|
| 878 | bfd *output_bfd;
|
|---|
| 879 | char **error_message ATTRIBUTE_UNUSED;
|
|---|
| 880 | {
|
|---|
| 881 | if (output_bfd)
|
|---|
| 882 | reloc->address += sec->output_offset;
|
|---|
| 883 | return bfd_reloc_ok;
|
|---|
| 884 | }
|
|---|
| 885 |
|
|---|
| 886 | /* A relocation function used for an unsupported reloc. */
|
|---|
| 887 |
|
|---|
| 888 | static bfd_reloc_status_type
|
|---|
| 889 | elf64_alpha_reloc_bad (abfd, reloc, sym, data, sec, output_bfd, error_message)
|
|---|
| 890 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 891 | arelent *reloc;
|
|---|
| 892 | asymbol *sym ATTRIBUTE_UNUSED;
|
|---|
| 893 | PTR data ATTRIBUTE_UNUSED;
|
|---|
| 894 | asection *sec;
|
|---|
| 895 | bfd *output_bfd;
|
|---|
| 896 | char **error_message ATTRIBUTE_UNUSED;
|
|---|
| 897 | {
|
|---|
| 898 | if (output_bfd)
|
|---|
| 899 | reloc->address += sec->output_offset;
|
|---|
| 900 | return bfd_reloc_notsupported;
|
|---|
| 901 | }
|
|---|
| 902 |
|
|---|
| 903 | /* Do the work of the GPDISP relocation. */
|
|---|
| 904 |
|
|---|
| 905 | static bfd_reloc_status_type
|
|---|
| 906 | elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda)
|
|---|
| 907 | bfd *abfd;
|
|---|
| 908 | bfd_vma gpdisp;
|
|---|
| 909 | bfd_byte *p_ldah;
|
|---|
| 910 | bfd_byte *p_lda;
|
|---|
| 911 | {
|
|---|
| 912 | bfd_reloc_status_type ret = bfd_reloc_ok;
|
|---|
| 913 | bfd_vma addend;
|
|---|
| 914 | unsigned long i_ldah, i_lda;
|
|---|
| 915 |
|
|---|
| 916 | i_ldah = bfd_get_32 (abfd, p_ldah);
|
|---|
| 917 | i_lda = bfd_get_32 (abfd, p_lda);
|
|---|
| 918 |
|
|---|
| 919 | /* Complain if the instructions are not correct. */
|
|---|
| 920 | if (((i_ldah >> 26) & 0x3f) != 0x09
|
|---|
| 921 | || ((i_lda >> 26) & 0x3f) != 0x08)
|
|---|
| 922 | ret = bfd_reloc_dangerous;
|
|---|
| 923 |
|
|---|
| 924 | /* Extract the user-supplied offset, mirroring the sign extensions
|
|---|
| 925 | that the instructions perform. */
|
|---|
| 926 | addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff);
|
|---|
| 927 | addend = (addend ^ 0x80008000) - 0x80008000;
|
|---|
| 928 |
|
|---|
| 929 | gpdisp += addend;
|
|---|
| 930 |
|
|---|
| 931 | if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma) 0x80000000
|
|---|
| 932 | || (bfd_signed_vma) gpdisp >= (bfd_signed_vma) 0x7fff8000)
|
|---|
| 933 | ret = bfd_reloc_overflow;
|
|---|
| 934 |
|
|---|
| 935 | /* compensate for the sign extension again. */
|
|---|
| 936 | i_ldah = ((i_ldah & 0xffff0000)
|
|---|
| 937 | | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff));
|
|---|
| 938 | i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff);
|
|---|
| 939 |
|
|---|
| 940 | bfd_put_32 (abfd, i_ldah, p_ldah);
|
|---|
| 941 | bfd_put_32 (abfd, i_lda, p_lda);
|
|---|
| 942 |
|
|---|
| 943 | return ret;
|
|---|
| 944 | }
|
|---|
| 945 |
|
|---|
| 946 | /* The special function for the GPDISP reloc. */
|
|---|
| 947 |
|
|---|
| 948 | static bfd_reloc_status_type
|
|---|
| 949 | elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section,
|
|---|
| 950 | output_bfd, err_msg)
|
|---|
| 951 | bfd *abfd;
|
|---|
| 952 | arelent *reloc_entry;
|
|---|
| 953 | asymbol *sym ATTRIBUTE_UNUSED;
|
|---|
| 954 | PTR data;
|
|---|
| 955 | asection *input_section;
|
|---|
| 956 | bfd *output_bfd;
|
|---|
| 957 | char **err_msg;
|
|---|
| 958 | {
|
|---|
| 959 | bfd_reloc_status_type ret;
|
|---|
| 960 | bfd_vma gp, relocation;
|
|---|
| 961 | bfd_byte *p_ldah, *p_lda;
|
|---|
| 962 |
|
|---|
| 963 | /* Don't do anything if we're not doing a final link. */
|
|---|
| 964 | if (output_bfd)
|
|---|
| 965 | {
|
|---|
| 966 | reloc_entry->address += input_section->output_offset;
|
|---|
| 967 | return bfd_reloc_ok;
|
|---|
| 968 | }
|
|---|
| 969 |
|
|---|
| 970 | if (reloc_entry->address > input_section->_cooked_size ||
|
|---|
| 971 | reloc_entry->address + reloc_entry->addend > input_section->_cooked_size)
|
|---|
| 972 | return bfd_reloc_outofrange;
|
|---|
| 973 |
|
|---|
| 974 | /* The gp used in the portion of the output object to which this
|
|---|
| 975 | input object belongs is cached on the input bfd. */
|
|---|
| 976 | gp = _bfd_get_gp_value (abfd);
|
|---|
| 977 |
|
|---|
| 978 | relocation = (input_section->output_section->vma
|
|---|
| 979 | + input_section->output_offset
|
|---|
| 980 | + reloc_entry->address);
|
|---|
| 981 |
|
|---|
| 982 | p_ldah = (bfd_byte *) data + reloc_entry->address;
|
|---|
| 983 | p_lda = p_ldah + reloc_entry->addend;
|
|---|
| 984 |
|
|---|
| 985 | ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda);
|
|---|
| 986 |
|
|---|
| 987 | /* Complain if the instructions are not correct. */
|
|---|
| 988 | if (ret == bfd_reloc_dangerous)
|
|---|
| 989 | *err_msg = _("GPDISP relocation did not find ldah and lda instructions");
|
|---|
| 990 |
|
|---|
| 991 | return ret;
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | /* A mapping from BFD reloc types to Alpha ELF reloc types. */
|
|---|
| 995 |
|
|---|
| 996 | struct elf_reloc_map
|
|---|
| 997 | {
|
|---|
| 998 | bfd_reloc_code_real_type bfd_reloc_val;
|
|---|
| 999 | int elf_reloc_val;
|
|---|
| 1000 | };
|
|---|
| 1001 |
|
|---|
| 1002 | static const struct elf_reloc_map elf64_alpha_reloc_map[] =
|
|---|
| 1003 | {
|
|---|
| 1004 | {BFD_RELOC_NONE, R_ALPHA_NONE},
|
|---|
| 1005 | {BFD_RELOC_32, R_ALPHA_REFLONG},
|
|---|
| 1006 | {BFD_RELOC_64, R_ALPHA_REFQUAD},
|
|---|
| 1007 | {BFD_RELOC_CTOR, R_ALPHA_REFQUAD},
|
|---|
| 1008 | {BFD_RELOC_GPREL32, R_ALPHA_GPREL32},
|
|---|
| 1009 | {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL},
|
|---|
| 1010 | {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE},
|
|---|
| 1011 | {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP},
|
|---|
| 1012 | {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR},
|
|---|
| 1013 | {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT},
|
|---|
| 1014 | {BFD_RELOC_16_PCREL, R_ALPHA_SREL16},
|
|---|
| 1015 | {BFD_RELOC_32_PCREL, R_ALPHA_SREL32},
|
|---|
| 1016 | {BFD_RELOC_64_PCREL, R_ALPHA_SREL64},
|
|---|
| 1017 |
|
|---|
| 1018 | /* The BFD_RELOC_ALPHA_USER_* relocations are used by the assembler to process
|
|---|
| 1019 | the explicit !<reloc>!sequence relocations, and are mapped into the normal
|
|---|
| 1020 | relocations at the end of processing. */
|
|---|
| 1021 | {BFD_RELOC_ALPHA_USER_LITERAL, R_ALPHA_LITERAL},
|
|---|
| 1022 | {BFD_RELOC_ALPHA_USER_LITUSE_BASE, R_ALPHA_LITUSE},
|
|---|
| 1023 | {BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF, R_ALPHA_LITUSE},
|
|---|
| 1024 | {BFD_RELOC_ALPHA_USER_LITUSE_JSR, R_ALPHA_LITUSE},
|
|---|
| 1025 | {BFD_RELOC_ALPHA_USER_GPDISP, R_ALPHA_GPDISP},
|
|---|
| 1026 | {BFD_RELOC_ALPHA_USER_GPRELHIGH, R_ALPHA_GPRELHIGH},
|
|---|
| 1027 | {BFD_RELOC_ALPHA_USER_GPRELLOW, R_ALPHA_GPRELLOW},
|
|---|
| 1028 | };
|
|---|
| 1029 |
|
|---|
| 1030 | /* Given a BFD reloc type, return a HOWTO structure. */
|
|---|
| 1031 |
|
|---|
| 1032 | static reloc_howto_type *
|
|---|
| 1033 | elf64_alpha_bfd_reloc_type_lookup (abfd, code)
|
|---|
| 1034 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 1035 | bfd_reloc_code_real_type code;
|
|---|
| 1036 | {
|
|---|
| 1037 | const struct elf_reloc_map *i, *e;
|
|---|
| 1038 | i = e = elf64_alpha_reloc_map;
|
|---|
| 1039 | e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map);
|
|---|
| 1040 | for (; i != e; ++i)
|
|---|
| 1041 | {
|
|---|
| 1042 | if (i->bfd_reloc_val == code)
|
|---|
| 1043 | return &elf64_alpha_howto_table[i->elf_reloc_val];
|
|---|
| 1044 | }
|
|---|
| 1045 | return 0;
|
|---|
| 1046 | }
|
|---|
| 1047 |
|
|---|
| 1048 | /* Given an Alpha ELF reloc type, fill in an arelent structure. */
|
|---|
| 1049 |
|
|---|
| 1050 | static void
|
|---|
| 1051 | elf64_alpha_info_to_howto (abfd, cache_ptr, dst)
|
|---|
| 1052 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 1053 | arelent *cache_ptr;
|
|---|
| 1054 | Elf64_Internal_Rela *dst;
|
|---|
| 1055 | {
|
|---|
| 1056 | unsigned r_type;
|
|---|
| 1057 |
|
|---|
| 1058 | r_type = ELF64_R_TYPE(dst->r_info);
|
|---|
| 1059 | BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
|
|---|
| 1060 | cache_ptr->howto = &elf64_alpha_howto_table[r_type];
|
|---|
| 1061 | }
|
|---|
| 1062 | |
|---|
| 1063 |
|
|---|
| 1064 | /* These functions do relaxation for Alpha ELF.
|
|---|
| 1065 |
|
|---|
| 1066 | Currently I'm only handling what I can do with existing compiler
|
|---|
| 1067 | and assembler support, which means no instructions are removed,
|
|---|
| 1068 | though some may be nopped. At this time GCC does not emit enough
|
|---|
| 1069 | information to do all of the relaxing that is possible. It will
|
|---|
| 1070 | take some not small amount of work for that to happen.
|
|---|
| 1071 |
|
|---|
| 1072 | There are a couple of interesting papers that I once read on this
|
|---|
| 1073 | subject, that I cannot find references to at the moment, that
|
|---|
| 1074 | related to Alpha in particular. They are by David Wall, then of
|
|---|
| 1075 | DEC WRL. */
|
|---|
| 1076 |
|
|---|
| 1077 | #define OP_LDA 0x08
|
|---|
| 1078 | #define OP_LDAH 0x09
|
|---|
| 1079 | #define INSN_JSR 0x68004000
|
|---|
| 1080 | #define INSN_JSR_MASK 0xfc00c000
|
|---|
| 1081 | #define OP_LDQ 0x29
|
|---|
| 1082 | #define OP_BR 0x30
|
|---|
| 1083 | #define OP_BSR 0x34
|
|---|
| 1084 | #define INSN_UNOP 0x2fe00000
|
|---|
| 1085 |
|
|---|
| 1086 | struct alpha_relax_info
|
|---|
| 1087 | {
|
|---|
| 1088 | bfd *abfd;
|
|---|
| 1089 | asection *sec;
|
|---|
| 1090 | bfd_byte *contents;
|
|---|
| 1091 | Elf_Internal_Rela *relocs, *relend;
|
|---|
| 1092 | struct bfd_link_info *link_info;
|
|---|
| 1093 | boolean changed_contents;
|
|---|
| 1094 | boolean changed_relocs;
|
|---|
| 1095 | bfd_vma gp;
|
|---|
| 1096 | bfd *gotobj;
|
|---|
| 1097 | asection *tsec;
|
|---|
| 1098 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 1099 | struct alpha_elf_got_entry *gotent;
|
|---|
| 1100 | unsigned char other;
|
|---|
| 1101 | };
|
|---|
| 1102 |
|
|---|
| 1103 | static Elf_Internal_Rela * elf64_alpha_relax_with_lituse
|
|---|
| 1104 | PARAMS((struct alpha_relax_info *info, bfd_vma symval,
|
|---|
| 1105 | Elf_Internal_Rela *irel, Elf_Internal_Rela *irelend));
|
|---|
| 1106 |
|
|---|
| 1107 | static boolean elf64_alpha_relax_without_lituse
|
|---|
| 1108 | PARAMS((struct alpha_relax_info *info, bfd_vma symval,
|
|---|
| 1109 | Elf_Internal_Rela *irel));
|
|---|
| 1110 |
|
|---|
| 1111 | static bfd_vma elf64_alpha_relax_opt_call
|
|---|
| 1112 | PARAMS((struct alpha_relax_info *info, bfd_vma symval));
|
|---|
| 1113 |
|
|---|
| 1114 | static boolean elf64_alpha_relax_section
|
|---|
| 1115 | PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
|
|---|
| 1116 | boolean *again));
|
|---|
| 1117 |
|
|---|
| 1118 | static Elf_Internal_Rela *
|
|---|
| 1119 | elf64_alpha_find_reloc_at_ofs (rel, relend, offset, type)
|
|---|
| 1120 | Elf_Internal_Rela *rel, *relend;
|
|---|
| 1121 | bfd_vma offset;
|
|---|
| 1122 | int type;
|
|---|
| 1123 | {
|
|---|
| 1124 | while (rel < relend)
|
|---|
| 1125 | {
|
|---|
| 1126 | if (rel->r_offset == offset && ELF64_R_TYPE (rel->r_info) == type)
|
|---|
| 1127 | return rel;
|
|---|
| 1128 | ++rel;
|
|---|
| 1129 | }
|
|---|
| 1130 | return NULL;
|
|---|
| 1131 | }
|
|---|
| 1132 |
|
|---|
| 1133 | static Elf_Internal_Rela *
|
|---|
| 1134 | elf64_alpha_relax_with_lituse (info, symval, irel, irelend)
|
|---|
| 1135 | struct alpha_relax_info *info;
|
|---|
| 1136 | bfd_vma symval;
|
|---|
| 1137 | Elf_Internal_Rela *irel, *irelend;
|
|---|
| 1138 | {
|
|---|
| 1139 | Elf_Internal_Rela *urel;
|
|---|
| 1140 | int flags, count, i;
|
|---|
| 1141 | bfd_signed_vma disp;
|
|---|
| 1142 | boolean fits16;
|
|---|
| 1143 | boolean fits32;
|
|---|
| 1144 | boolean lit_reused = false;
|
|---|
| 1145 | boolean all_optimized = true;
|
|---|
| 1146 | unsigned int lit_insn;
|
|---|
| 1147 |
|
|---|
| 1148 | lit_insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
|
|---|
| 1149 | if (lit_insn >> 26 != OP_LDQ)
|
|---|
| 1150 | {
|
|---|
| 1151 | ((*_bfd_error_handler)
|
|---|
| 1152 | ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
|
|---|
| 1153 | bfd_get_filename (info->abfd), info->sec->name,
|
|---|
| 1154 | (unsigned long)irel->r_offset));
|
|---|
| 1155 | return irel;
|
|---|
| 1156 | }
|
|---|
| 1157 |
|
|---|
| 1158 | /* Summarize how this particular LITERAL is used. */
|
|---|
| 1159 | for (urel = irel+1, flags = count = 0; urel < irelend; ++urel, ++count)
|
|---|
| 1160 | {
|
|---|
| 1161 | if (ELF64_R_TYPE (urel->r_info) != R_ALPHA_LITUSE)
|
|---|
| 1162 | break;
|
|---|
| 1163 | if (urel->r_addend >= 0 && urel->r_addend <= 3)
|
|---|
| 1164 | flags |= 1 << urel->r_addend;
|
|---|
| 1165 | }
|
|---|
| 1166 |
|
|---|
| 1167 | /* A little preparation for the loop... */
|
|---|
| 1168 | disp = symval - info->gp;
|
|---|
| 1169 |
|
|---|
| 1170 | for (urel = irel+1, i = 0; i < count; ++i, ++urel)
|
|---|
| 1171 | {
|
|---|
| 1172 | unsigned int insn;
|
|---|
| 1173 | int insn_disp;
|
|---|
| 1174 | bfd_signed_vma xdisp;
|
|---|
| 1175 |
|
|---|
| 1176 | insn = bfd_get_32 (info->abfd, info->contents + urel->r_offset);
|
|---|
| 1177 |
|
|---|
| 1178 | switch (urel->r_addend)
|
|---|
| 1179 | {
|
|---|
| 1180 | default: /* 0 = ADDRESS FORMAT */
|
|---|
| 1181 | /* This type is really just a placeholder to note that all
|
|---|
| 1182 | uses cannot be optimized, but to still allow some. */
|
|---|
| 1183 | all_optimized = false;
|
|---|
| 1184 | break;
|
|---|
| 1185 |
|
|---|
| 1186 | case 1: /* MEM FORMAT */
|
|---|
| 1187 | /* We can always optimize 16-bit displacements. */
|
|---|
| 1188 |
|
|---|
| 1189 | /* Extract the displacement from the instruction, sign-extending
|
|---|
| 1190 | it if necessary, then test whether it is within 16 or 32 bits
|
|---|
| 1191 | displacement from GP. */
|
|---|
| 1192 | insn_disp = insn & 0x0000ffff;
|
|---|
| 1193 | if (insn_disp & 0x00008000)
|
|---|
| 1194 | insn_disp |= 0xffff0000; /* Negative: sign-extend. */
|
|---|
| 1195 |
|
|---|
| 1196 | xdisp = disp + insn_disp;
|
|---|
| 1197 | fits16 = (xdisp >= - (bfd_signed_vma) 0x00008000 && xdisp < 0x00008000);
|
|---|
| 1198 | fits32 = (xdisp >= - (bfd_signed_vma) 0x80000000 && xdisp < 0x7fff8000);
|
|---|
| 1199 |
|
|---|
| 1200 | if (fits16)
|
|---|
| 1201 | {
|
|---|
| 1202 | /* Take the op code and dest from this insn, take the base
|
|---|
| 1203 | register from the literal insn. Leave the offset alone. */
|
|---|
| 1204 | insn = (insn & 0xffe0ffff) | (lit_insn & 0x001f0000);
|
|---|
| 1205 | urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
|
|---|
| 1206 | R_ALPHA_GPRELLOW);
|
|---|
| 1207 | urel->r_addend = irel->r_addend;
|
|---|
| 1208 | info->changed_relocs = true;
|
|---|
| 1209 |
|
|---|
| 1210 | bfd_put_32 (info->abfd, insn, info->contents + urel->r_offset);
|
|---|
| 1211 | info->changed_contents = true;
|
|---|
| 1212 | }
|
|---|
| 1213 |
|
|---|
| 1214 | /* If all mem+byte, we can optimize 32-bit mem displacements. */
|
|---|
| 1215 | else if (fits32 && !(flags & ~6))
|
|---|
| 1216 | {
|
|---|
| 1217 | /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
|
|---|
| 1218 |
|
|---|
| 1219 | irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
|
|---|
| 1220 | R_ALPHA_GPRELHIGH);
|
|---|
| 1221 | lit_insn = (OP_LDAH << 26) | (lit_insn & 0x03ff0000);
|
|---|
| 1222 | bfd_put_32 (info->abfd, lit_insn,
|
|---|
| 1223 | info->contents + irel->r_offset);
|
|---|
| 1224 | lit_reused = true;
|
|---|
| 1225 | info->changed_contents = true;
|
|---|
| 1226 |
|
|---|
| 1227 | urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
|
|---|
| 1228 | R_ALPHA_GPRELLOW);
|
|---|
| 1229 | urel->r_addend = irel->r_addend;
|
|---|
| 1230 | info->changed_relocs = true;
|
|---|
| 1231 | }
|
|---|
| 1232 | else
|
|---|
| 1233 | all_optimized = false;
|
|---|
| 1234 | break;
|
|---|
| 1235 |
|
|---|
| 1236 | case 2: /* BYTE OFFSET FORMAT */
|
|---|
| 1237 | /* We can always optimize byte instructions. */
|
|---|
| 1238 |
|
|---|
| 1239 | /* FIXME: sanity check the insn for byte op. Check that the
|
|---|
| 1240 | literal dest reg is indeed Rb in the byte insn. */
|
|---|
| 1241 |
|
|---|
| 1242 | insn = (insn & ~0x001ff000) | ((symval & 7) << 13) | 0x1000;
|
|---|
| 1243 |
|
|---|
| 1244 | urel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
|
|---|
| 1245 | urel->r_addend = 0;
|
|---|
| 1246 | info->changed_relocs = true;
|
|---|
| 1247 |
|
|---|
| 1248 | bfd_put_32 (info->abfd, insn, info->contents + urel->r_offset);
|
|---|
| 1249 | info->changed_contents = true;
|
|---|
| 1250 | break;
|
|---|
| 1251 |
|
|---|
| 1252 | case 3: /* CALL FORMAT */
|
|---|
| 1253 | {
|
|---|
| 1254 | /* If not zero, place to jump without needing pv. */
|
|---|
| 1255 | bfd_vma optdest = elf64_alpha_relax_opt_call (info, symval);
|
|---|
| 1256 | bfd_vma org = (info->sec->output_section->vma
|
|---|
| 1257 | + info->sec->output_offset
|
|---|
| 1258 | + urel->r_offset + 4);
|
|---|
| 1259 | bfd_signed_vma odisp;
|
|---|
| 1260 |
|
|---|
| 1261 | odisp = (optdest ? optdest : symval) - org;
|
|---|
| 1262 | if (odisp >= -0x400000 && odisp < 0x400000)
|
|---|
| 1263 | {
|
|---|
| 1264 | Elf_Internal_Rela *xrel;
|
|---|
| 1265 |
|
|---|
| 1266 | /* Preserve branch prediction call stack when possible. */
|
|---|
| 1267 | if ((insn & INSN_JSR_MASK) == INSN_JSR)
|
|---|
| 1268 | insn = (OP_BSR << 26) | (insn & 0x03e00000);
|
|---|
| 1269 | else
|
|---|
| 1270 | insn = (OP_BR << 26) | (insn & 0x03e00000);
|
|---|
| 1271 |
|
|---|
| 1272 | urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
|
|---|
| 1273 | R_ALPHA_BRADDR);
|
|---|
| 1274 | urel->r_addend = irel->r_addend;
|
|---|
| 1275 |
|
|---|
| 1276 | if (optdest)
|
|---|
| 1277 | urel->r_addend += optdest - symval;
|
|---|
| 1278 | else
|
|---|
| 1279 | all_optimized = false;
|
|---|
| 1280 |
|
|---|
| 1281 | bfd_put_32 (info->abfd, insn, info->contents + urel->r_offset);
|
|---|
| 1282 |
|
|---|
| 1283 | /* Kill any HINT reloc that might exist for this insn. */
|
|---|
| 1284 | xrel = (elf64_alpha_find_reloc_at_ofs
|
|---|
| 1285 | (info->relocs, info->relend, urel->r_offset,
|
|---|
| 1286 | R_ALPHA_HINT));
|
|---|
| 1287 | if (xrel)
|
|---|
| 1288 | xrel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
|
|---|
| 1289 |
|
|---|
| 1290 | info->changed_contents = true;
|
|---|
| 1291 | info->changed_relocs = true;
|
|---|
| 1292 | }
|
|---|
| 1293 | else
|
|---|
| 1294 | all_optimized = false;
|
|---|
| 1295 |
|
|---|
| 1296 | /* ??? If target gp == current gp we can eliminate the gp reload.
|
|---|
| 1297 | This does depend on every place a gp could be reloaded will
|
|---|
| 1298 | be, which currently happens for all code produced by gcc, but
|
|---|
| 1299 | not necessarily by hand-coded assembly, or if sibling calls
|
|---|
| 1300 | are enabled in gcc.
|
|---|
| 1301 |
|
|---|
| 1302 | Perhaps conditionalize this on a flag being set in the target
|
|---|
| 1303 | object file's header, and have gcc set it? */
|
|---|
| 1304 | }
|
|---|
| 1305 | break;
|
|---|
| 1306 | }
|
|---|
| 1307 | }
|
|---|
| 1308 |
|
|---|
| 1309 | /* If all cases were optimized, we can reduce the use count on this
|
|---|
| 1310 | got entry by one, possibly eliminating it. */
|
|---|
| 1311 | if (all_optimized)
|
|---|
| 1312 | {
|
|---|
| 1313 | info->gotent->use_count -= 1;
|
|---|
| 1314 | alpha_elf_tdata (info->gotent->gotobj)->total_got_entries -= 1;
|
|---|
| 1315 | if (!info->h)
|
|---|
| 1316 | alpha_elf_tdata (info->gotent->gotobj)->n_local_got_entries -= 1;
|
|---|
| 1317 |
|
|---|
| 1318 | /* If the literal instruction is no longer needed (it may have been
|
|---|
| 1319 | reused. We can eliminate it.
|
|---|
| 1320 | ??? For now, I don't want to deal with compacting the section,
|
|---|
| 1321 | so just nop it out. */
|
|---|
| 1322 | if (!lit_reused)
|
|---|
| 1323 | {
|
|---|
| 1324 | irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
|
|---|
| 1325 | info->changed_relocs = true;
|
|---|
| 1326 |
|
|---|
| 1327 | bfd_put_32 (info->abfd, INSN_UNOP, info->contents + irel->r_offset);
|
|---|
| 1328 | info->changed_contents = true;
|
|---|
| 1329 | }
|
|---|
| 1330 | }
|
|---|
| 1331 |
|
|---|
| 1332 | return irel + count;
|
|---|
| 1333 | }
|
|---|
| 1334 |
|
|---|
| 1335 | static bfd_vma
|
|---|
| 1336 | elf64_alpha_relax_opt_call (info, symval)
|
|---|
| 1337 | struct alpha_relax_info *info;
|
|---|
| 1338 | bfd_vma symval;
|
|---|
| 1339 | {
|
|---|
| 1340 | /* If the function has the same gp, and we can identify that the
|
|---|
| 1341 | function does not use its function pointer, we can eliminate the
|
|---|
| 1342 | address load. */
|
|---|
| 1343 |
|
|---|
| 1344 | /* If the symbol is marked NOPV, we are being told the function never
|
|---|
| 1345 | needs its procedure value. */
|
|---|
| 1346 | if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_NOPV)
|
|---|
| 1347 | return symval;
|
|---|
| 1348 |
|
|---|
| 1349 | /* If the symbol is marked STD_GP, we are being told the function does
|
|---|
| 1350 | a normal ldgp in the first two words. */
|
|---|
| 1351 | else if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_STD_GPLOAD)
|
|---|
| 1352 | ;
|
|---|
| 1353 |
|
|---|
| 1354 | /* Otherwise, we may be able to identify a GP load in the first two
|
|---|
| 1355 | words, which we can then skip. */
|
|---|
| 1356 | else
|
|---|
| 1357 | {
|
|---|
| 1358 | Elf_Internal_Rela *tsec_relocs, *tsec_relend, *tsec_free, *gpdisp;
|
|---|
| 1359 | bfd_vma ofs;
|
|---|
| 1360 |
|
|---|
| 1361 | /* Load the relocations from the section that the target symbol is in. */
|
|---|
| 1362 | if (info->sec == info->tsec)
|
|---|
| 1363 | {
|
|---|
| 1364 | tsec_relocs = info->relocs;
|
|---|
| 1365 | tsec_relend = info->relend;
|
|---|
| 1366 | tsec_free = NULL;
|
|---|
| 1367 | }
|
|---|
| 1368 | else
|
|---|
| 1369 | {
|
|---|
| 1370 | tsec_relocs = (_bfd_elf64_link_read_relocs
|
|---|
| 1371 | (info->abfd, info->tsec, (PTR) NULL,
|
|---|
| 1372 | (Elf_Internal_Rela *) NULL,
|
|---|
| 1373 | info->link_info->keep_memory));
|
|---|
| 1374 | if (tsec_relocs == NULL)
|
|---|
| 1375 | return 0;
|
|---|
| 1376 | tsec_relend = tsec_relocs + info->tsec->reloc_count;
|
|---|
| 1377 | tsec_free = (info->link_info->keep_memory ? NULL : tsec_relocs);
|
|---|
| 1378 | }
|
|---|
| 1379 |
|
|---|
| 1380 | /* Recover the symbol's offset within the section. */
|
|---|
| 1381 | ofs = (symval - info->tsec->output_section->vma
|
|---|
| 1382 | - info->tsec->output_offset);
|
|---|
| 1383 |
|
|---|
| 1384 | /* Look for a GPDISP reloc. */
|
|---|
| 1385 | gpdisp = (elf64_alpha_find_reloc_at_ofs
|
|---|
| 1386 | (tsec_relocs, tsec_relend, ofs, R_ALPHA_GPDISP));
|
|---|
| 1387 |
|
|---|
| 1388 | if (!gpdisp || gpdisp->r_addend != 4)
|
|---|
| 1389 | {
|
|---|
| 1390 | if (tsec_free)
|
|---|
| 1391 | free (tsec_free);
|
|---|
| 1392 | return 0;
|
|---|
| 1393 | }
|
|---|
| 1394 | if (tsec_free)
|
|---|
| 1395 | free (tsec_free);
|
|---|
| 1396 | }
|
|---|
| 1397 |
|
|---|
| 1398 | /* We've now determined that we can skip an initial gp load. Verify
|
|---|
| 1399 | that the call and the target use the same gp. */
|
|---|
| 1400 | if (info->link_info->hash->creator != info->tsec->owner->xvec
|
|---|
| 1401 | || info->gotobj != alpha_elf_tdata (info->tsec->owner)->gotobj)
|
|---|
| 1402 | return 0;
|
|---|
| 1403 |
|
|---|
| 1404 | return symval + 8;
|
|---|
| 1405 | }
|
|---|
| 1406 |
|
|---|
| 1407 | static boolean
|
|---|
| 1408 | elf64_alpha_relax_without_lituse (info, symval, irel)
|
|---|
| 1409 | struct alpha_relax_info *info;
|
|---|
| 1410 | bfd_vma symval;
|
|---|
| 1411 | Elf_Internal_Rela *irel;
|
|---|
| 1412 | {
|
|---|
| 1413 | unsigned int insn;
|
|---|
| 1414 | bfd_signed_vma disp;
|
|---|
| 1415 |
|
|---|
| 1416 | /* Get the instruction. */
|
|---|
| 1417 | insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
|
|---|
| 1418 |
|
|---|
| 1419 | if (insn >> 26 != OP_LDQ)
|
|---|
| 1420 | {
|
|---|
| 1421 | ((*_bfd_error_handler)
|
|---|
| 1422 | ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
|
|---|
| 1423 | bfd_get_filename (info->abfd), info->sec->name,
|
|---|
| 1424 | (unsigned long) irel->r_offset));
|
|---|
| 1425 | return true;
|
|---|
| 1426 | }
|
|---|
| 1427 |
|
|---|
| 1428 | /* So we aren't told much. Do what we can with the address load and
|
|---|
| 1429 | fake the rest. All of the optimizations here require that the
|
|---|
| 1430 | offset from the GP fit in 16 bits. */
|
|---|
| 1431 |
|
|---|
| 1432 | disp = symval - info->gp;
|
|---|
| 1433 | if (disp < -0x8000 || disp >= 0x8000)
|
|---|
| 1434 | return true;
|
|---|
| 1435 |
|
|---|
| 1436 | /* On the LITERAL instruction itself, consider exchanging
|
|---|
| 1437 | `ldq R,X(gp)' for `lda R,Y(gp)'. */
|
|---|
| 1438 |
|
|---|
| 1439 | insn = (OP_LDA << 26) | (insn & 0x03ff0000);
|
|---|
| 1440 | bfd_put_32 (info->abfd, insn, info->contents + irel->r_offset);
|
|---|
| 1441 | info->changed_contents = true;
|
|---|
| 1442 |
|
|---|
| 1443 | irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), R_ALPHA_GPRELLOW);
|
|---|
| 1444 | info->changed_relocs = true;
|
|---|
| 1445 |
|
|---|
| 1446 | /* Reduce the use count on this got entry by one, possibly
|
|---|
| 1447 | eliminating it. */
|
|---|
| 1448 | info->gotent->use_count -= 1;
|
|---|
| 1449 | alpha_elf_tdata (info->gotent->gotobj)->total_got_entries -= 1;
|
|---|
| 1450 | if (!info->h)
|
|---|
| 1451 | alpha_elf_tdata (info->gotent->gotobj)->n_local_got_entries -= 1;
|
|---|
| 1452 |
|
|---|
| 1453 | /* ??? Search forward through this basic block looking for insns
|
|---|
| 1454 | that use the target register. Stop after an insn modifying the
|
|---|
| 1455 | register is seen, or after a branch or call.
|
|---|
| 1456 |
|
|---|
| 1457 | Any such memory load insn may be substituted by a load directly
|
|---|
| 1458 | off the GP. This allows the memory load insn to be issued before
|
|---|
| 1459 | the calculated GP register would otherwise be ready.
|
|---|
| 1460 |
|
|---|
| 1461 | Any such jsr insn can be replaced by a bsr if it is in range.
|
|---|
| 1462 |
|
|---|
| 1463 | This would mean that we'd have to _add_ relocations, the pain of
|
|---|
| 1464 | which gives one pause. */
|
|---|
| 1465 |
|
|---|
| 1466 | return true;
|
|---|
| 1467 | }
|
|---|
| 1468 |
|
|---|
| 1469 | static boolean
|
|---|
| 1470 | elf64_alpha_relax_section (abfd, sec, link_info, again)
|
|---|
| 1471 | bfd *abfd;
|
|---|
| 1472 | asection *sec;
|
|---|
| 1473 | struct bfd_link_info *link_info;
|
|---|
| 1474 | boolean *again;
|
|---|
| 1475 | {
|
|---|
| 1476 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 1477 | Elf_Internal_Rela *internal_relocs;
|
|---|
| 1478 | Elf_Internal_Rela *free_relocs = NULL;
|
|---|
| 1479 | Elf_Internal_Rela *irel, *irelend;
|
|---|
| 1480 | bfd_byte *free_contents = NULL;
|
|---|
| 1481 | Elf64_External_Sym *extsyms = NULL;
|
|---|
| 1482 | Elf64_External_Sym *free_extsyms = NULL;
|
|---|
| 1483 | struct alpha_elf_got_entry **local_got_entries;
|
|---|
| 1484 | struct alpha_relax_info info;
|
|---|
| 1485 |
|
|---|
| 1486 | /* We are not currently changing any sizes, so only one pass. */
|
|---|
| 1487 | *again = false;
|
|---|
| 1488 |
|
|---|
| 1489 | if (link_info->relocateable
|
|---|
| 1490 | || (sec->flags & SEC_RELOC) == 0
|
|---|
| 1491 | || sec->reloc_count == 0)
|
|---|
| 1492 | return true;
|
|---|
| 1493 |
|
|---|
| 1494 | /* If this is the first time we have been called for this section,
|
|---|
| 1495 | initialize the cooked size. */
|
|---|
| 1496 | if (sec->_cooked_size == 0)
|
|---|
| 1497 | sec->_cooked_size = sec->_raw_size;
|
|---|
| 1498 |
|
|---|
| 1499 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
|---|
| 1500 | local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
|
|---|
| 1501 |
|
|---|
| 1502 | /* Load the relocations for this section. */
|
|---|
| 1503 | internal_relocs = (_bfd_elf64_link_read_relocs
|
|---|
| 1504 | (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
|
|---|
| 1505 | link_info->keep_memory));
|
|---|
| 1506 | if (internal_relocs == NULL)
|
|---|
| 1507 | goto error_return;
|
|---|
| 1508 | if (! link_info->keep_memory)
|
|---|
| 1509 | free_relocs = internal_relocs;
|
|---|
| 1510 |
|
|---|
| 1511 | memset(&info, 0, sizeof (info));
|
|---|
| 1512 | info.abfd = abfd;
|
|---|
| 1513 | info.sec = sec;
|
|---|
| 1514 | info.link_info = link_info;
|
|---|
| 1515 | info.relocs = internal_relocs;
|
|---|
| 1516 | info.relend = irelend = internal_relocs + sec->reloc_count;
|
|---|
| 1517 |
|
|---|
| 1518 | /* Find the GP for this object. */
|
|---|
| 1519 | info.gotobj = alpha_elf_tdata (abfd)->gotobj;
|
|---|
| 1520 | if (info.gotobj)
|
|---|
| 1521 | {
|
|---|
| 1522 | asection *sgot = alpha_elf_tdata (info.gotobj)->got;
|
|---|
| 1523 | info.gp = _bfd_get_gp_value (info.gotobj);
|
|---|
| 1524 | if (info.gp == 0)
|
|---|
| 1525 | {
|
|---|
| 1526 | info.gp = (sgot->output_section->vma
|
|---|
| 1527 | + sgot->output_offset
|
|---|
| 1528 | + 0x8000);
|
|---|
| 1529 | _bfd_set_gp_value (info.gotobj, info.gp);
|
|---|
| 1530 | }
|
|---|
| 1531 | }
|
|---|
| 1532 |
|
|---|
| 1533 | for (irel = internal_relocs; irel < irelend; irel++)
|
|---|
| 1534 | {
|
|---|
| 1535 | bfd_vma symval;
|
|---|
| 1536 | Elf_Internal_Sym isym;
|
|---|
| 1537 | struct alpha_elf_got_entry *gotent;
|
|---|
| 1538 |
|
|---|
| 1539 | if (ELF64_R_TYPE (irel->r_info) != (int) R_ALPHA_LITERAL)
|
|---|
| 1540 | continue;
|
|---|
| 1541 |
|
|---|
| 1542 | /* Get the section contents. */
|
|---|
| 1543 | if (info.contents == NULL)
|
|---|
| 1544 | {
|
|---|
| 1545 | if (elf_section_data (sec)->this_hdr.contents != NULL)
|
|---|
| 1546 | info.contents = elf_section_data (sec)->this_hdr.contents;
|
|---|
| 1547 | else
|
|---|
| 1548 | {
|
|---|
| 1549 | info.contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
|
|---|
| 1550 | if (info.contents == NULL)
|
|---|
| 1551 | goto error_return;
|
|---|
| 1552 | free_contents = info.contents;
|
|---|
| 1553 |
|
|---|
| 1554 | if (! bfd_get_section_contents (abfd, sec, info.contents,
|
|---|
| 1555 | (file_ptr) 0, sec->_raw_size))
|
|---|
| 1556 | goto error_return;
|
|---|
| 1557 | }
|
|---|
| 1558 | }
|
|---|
| 1559 |
|
|---|
| 1560 | /* Read this BFD's symbols if we haven't done so already. */
|
|---|
| 1561 | if (extsyms == NULL)
|
|---|
| 1562 | {
|
|---|
| 1563 | if (symtab_hdr->contents != NULL)
|
|---|
| 1564 | extsyms = (Elf64_External_Sym *) symtab_hdr->contents;
|
|---|
| 1565 | else
|
|---|
| 1566 | {
|
|---|
| 1567 | extsyms = ((Elf64_External_Sym *)
|
|---|
| 1568 | bfd_malloc (symtab_hdr->sh_size));
|
|---|
| 1569 | if (extsyms == NULL)
|
|---|
| 1570 | goto error_return;
|
|---|
| 1571 | free_extsyms = extsyms;
|
|---|
| 1572 | if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
|
|---|
| 1573 | || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd)
|
|---|
| 1574 | != symtab_hdr->sh_size))
|
|---|
| 1575 | goto error_return;
|
|---|
| 1576 | }
|
|---|
| 1577 | }
|
|---|
| 1578 |
|
|---|
| 1579 | /* Get the value of the symbol referred to by the reloc. */
|
|---|
| 1580 | if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
|
|---|
| 1581 | {
|
|---|
| 1582 | /* A local symbol. */
|
|---|
| 1583 | bfd_elf64_swap_symbol_in (abfd,
|
|---|
| 1584 | extsyms + ELF64_R_SYM (irel->r_info),
|
|---|
| 1585 | &isym);
|
|---|
| 1586 | if (isym.st_shndx == SHN_UNDEF)
|
|---|
| 1587 | info.tsec = bfd_und_section_ptr;
|
|---|
| 1588 | else if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE)
|
|---|
| 1589 | info.tsec = bfd_section_from_elf_index (abfd, isym.st_shndx);
|
|---|
| 1590 | else if (isym.st_shndx == SHN_ABS)
|
|---|
| 1591 | info.tsec = bfd_abs_section_ptr;
|
|---|
| 1592 | else if (isym.st_shndx == SHN_COMMON)
|
|---|
| 1593 | info.tsec = bfd_com_section_ptr;
|
|---|
| 1594 | else
|
|---|
| 1595 | continue; /* who knows. */
|
|---|
| 1596 |
|
|---|
| 1597 | info.h = NULL;
|
|---|
| 1598 | info.other = isym.st_other;
|
|---|
| 1599 | gotent = local_got_entries[ELF64_R_SYM(irel->r_info)];
|
|---|
| 1600 | symval = isym.st_value;
|
|---|
| 1601 | }
|
|---|
| 1602 | else
|
|---|
| 1603 | {
|
|---|
| 1604 | unsigned long indx;
|
|---|
| 1605 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 1606 |
|
|---|
| 1607 | indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
|
|---|
| 1608 | h = alpha_elf_sym_hashes (abfd)[indx];
|
|---|
| 1609 | BFD_ASSERT (h != NULL);
|
|---|
| 1610 |
|
|---|
| 1611 | while (h->root.root.type == bfd_link_hash_indirect
|
|---|
| 1612 | || h->root.root.type == bfd_link_hash_warning)
|
|---|
| 1613 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
|
|---|
| 1614 |
|
|---|
| 1615 | /* We can't do anthing with undefined or dynamic symbols. */
|
|---|
| 1616 | if (h->root.root.type == bfd_link_hash_undefined
|
|---|
| 1617 | || h->root.root.type == bfd_link_hash_undefweak
|
|---|
| 1618 | || alpha_elf_dynamic_symbol_p (&h->root, link_info))
|
|---|
| 1619 | continue;
|
|---|
| 1620 |
|
|---|
| 1621 | info.h = h;
|
|---|
| 1622 | info.gotent = gotent;
|
|---|
| 1623 | info.tsec = h->root.root.u.def.section;
|
|---|
| 1624 | info.other = h->root.other;
|
|---|
| 1625 | gotent = h->got_entries;
|
|---|
| 1626 | symval = h->root.root.u.def.value;
|
|---|
| 1627 | }
|
|---|
| 1628 |
|
|---|
| 1629 | /* Search for the got entry to be used by this relocation. */
|
|---|
| 1630 | while (gotent->gotobj != info.gotobj || gotent->addend != irel->r_addend)
|
|---|
| 1631 | gotent = gotent->next;
|
|---|
| 1632 | info.gotent = gotent;
|
|---|
| 1633 |
|
|---|
| 1634 | symval += info.tsec->output_section->vma + info.tsec->output_offset;
|
|---|
| 1635 | symval += irel->r_addend;
|
|---|
| 1636 |
|
|---|
| 1637 | BFD_ASSERT(info.gotent != NULL);
|
|---|
| 1638 |
|
|---|
| 1639 | /* If there exist LITUSE relocations immediately following, this
|
|---|
| 1640 | opens up all sorts of interesting optimizations, because we
|
|---|
| 1641 | now know every location that this address load is used. */
|
|---|
| 1642 |
|
|---|
| 1643 | if (irel+1 < irelend && ELF64_R_TYPE (irel[1].r_info) == R_ALPHA_LITUSE)
|
|---|
| 1644 | {
|
|---|
| 1645 | irel = elf64_alpha_relax_with_lituse (&info, symval, irel, irelend);
|
|---|
| 1646 | if (irel == NULL)
|
|---|
| 1647 | goto error_return;
|
|---|
| 1648 | }
|
|---|
| 1649 | else
|
|---|
| 1650 | {
|
|---|
| 1651 | if (!elf64_alpha_relax_without_lituse (&info, symval, irel))
|
|---|
| 1652 | goto error_return;
|
|---|
| 1653 | }
|
|---|
| 1654 | }
|
|---|
| 1655 |
|
|---|
| 1656 | if (!elf64_alpha_size_got_sections (abfd, link_info))
|
|---|
| 1657 | return false;
|
|---|
| 1658 |
|
|---|
| 1659 | if (info.changed_relocs)
|
|---|
| 1660 | {
|
|---|
| 1661 | elf_section_data (sec)->relocs = internal_relocs;
|
|---|
| 1662 | }
|
|---|
| 1663 | else if (free_relocs != NULL)
|
|---|
| 1664 | {
|
|---|
| 1665 | free (free_relocs);
|
|---|
| 1666 | }
|
|---|
| 1667 |
|
|---|
| 1668 | if (info.changed_contents)
|
|---|
| 1669 | {
|
|---|
| 1670 | elf_section_data (sec)->this_hdr.contents = info.contents;
|
|---|
| 1671 | }
|
|---|
| 1672 | else if (free_contents != NULL)
|
|---|
| 1673 | {
|
|---|
| 1674 | if (! link_info->keep_memory)
|
|---|
| 1675 | free (free_contents);
|
|---|
| 1676 | else
|
|---|
| 1677 | {
|
|---|
| 1678 | /* Cache the section contents for elf_link_input_bfd. */
|
|---|
| 1679 | elf_section_data (sec)->this_hdr.contents = info.contents;
|
|---|
| 1680 | }
|
|---|
| 1681 | }
|
|---|
| 1682 |
|
|---|
| 1683 | if (free_extsyms != NULL)
|
|---|
| 1684 | {
|
|---|
| 1685 | if (! link_info->keep_memory)
|
|---|
| 1686 | free (free_extsyms);
|
|---|
| 1687 | else
|
|---|
| 1688 | {
|
|---|
| 1689 | /* Cache the symbols for elf_link_input_bfd. */
|
|---|
| 1690 | symtab_hdr->contents = extsyms;
|
|---|
| 1691 | }
|
|---|
| 1692 | }
|
|---|
| 1693 |
|
|---|
| 1694 | *again = info.changed_contents || info.changed_relocs;
|
|---|
| 1695 |
|
|---|
| 1696 | return true;
|
|---|
| 1697 |
|
|---|
| 1698 | error_return:
|
|---|
| 1699 | if (free_relocs != NULL)
|
|---|
| 1700 | free (free_relocs);
|
|---|
| 1701 | if (free_contents != NULL)
|
|---|
| 1702 | free (free_contents);
|
|---|
| 1703 | if (free_extsyms != NULL)
|
|---|
| 1704 | free (free_extsyms);
|
|---|
| 1705 | return false;
|
|---|
| 1706 | }
|
|---|
| 1707 | |
|---|
| 1708 |
|
|---|
| 1709 | /* PLT/GOT Stuff */
|
|---|
| 1710 | #define PLT_HEADER_SIZE 32
|
|---|
| 1711 | #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
|
|---|
| 1712 | #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
|
|---|
| 1713 | #define PLT_HEADER_WORD3 0x47ff041f /* nop */
|
|---|
| 1714 | #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
|
|---|
| 1715 |
|
|---|
| 1716 | #define PLT_ENTRY_SIZE 12
|
|---|
| 1717 | #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
|
|---|
| 1718 | #define PLT_ENTRY_WORD2 0
|
|---|
| 1719 | #define PLT_ENTRY_WORD3 0
|
|---|
| 1720 |
|
|---|
| 1721 | #define MAX_GOT_ENTRIES (64*1024 / 8)
|
|---|
| 1722 |
|
|---|
| 1723 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
|
|---|
| 1724 | |
|---|
| 1725 |
|
|---|
| 1726 | /* Handle an Alpha specific section when reading an object file. This
|
|---|
| 1727 | is called when elfcode.h finds a section with an unknown type.
|
|---|
| 1728 | FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
|
|---|
| 1729 | how to. */
|
|---|
| 1730 |
|
|---|
| 1731 | static boolean
|
|---|
| 1732 | elf64_alpha_section_from_shdr (abfd, hdr, name)
|
|---|
| 1733 | bfd *abfd;
|
|---|
| 1734 | Elf64_Internal_Shdr *hdr;
|
|---|
| 1735 | char *name;
|
|---|
| 1736 | {
|
|---|
| 1737 | asection *newsect;
|
|---|
| 1738 |
|
|---|
| 1739 | /* There ought to be a place to keep ELF backend specific flags, but
|
|---|
| 1740 | at the moment there isn't one. We just keep track of the
|
|---|
| 1741 | sections by their name, instead. Fortunately, the ABI gives
|
|---|
| 1742 | suggested names for all the MIPS specific sections, so we will
|
|---|
| 1743 | probably get away with this. */
|
|---|
| 1744 | switch (hdr->sh_type)
|
|---|
| 1745 | {
|
|---|
| 1746 | case SHT_ALPHA_DEBUG:
|
|---|
| 1747 | if (strcmp (name, ".mdebug") != 0)
|
|---|
| 1748 | return false;
|
|---|
| 1749 | break;
|
|---|
| 1750 | #ifdef ERIC_neverdef
|
|---|
| 1751 | case SHT_ALPHA_REGINFO:
|
|---|
| 1752 | if (strcmp (name, ".reginfo") != 0
|
|---|
| 1753 | || hdr->sh_size != sizeof (Elf64_External_RegInfo))
|
|---|
| 1754 | return false;
|
|---|
| 1755 | break;
|
|---|
| 1756 | #endif
|
|---|
| 1757 | default:
|
|---|
| 1758 | return false;
|
|---|
| 1759 | }
|
|---|
| 1760 |
|
|---|
| 1761 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
|
|---|
| 1762 | return false;
|
|---|
| 1763 | newsect = hdr->bfd_section;
|
|---|
| 1764 |
|
|---|
| 1765 | if (hdr->sh_type == SHT_ALPHA_DEBUG)
|
|---|
| 1766 | {
|
|---|
| 1767 | if (! bfd_set_section_flags (abfd, newsect,
|
|---|
| 1768 | (bfd_get_section_flags (abfd, newsect)
|
|---|
| 1769 | | SEC_DEBUGGING)))
|
|---|
| 1770 | return false;
|
|---|
| 1771 | }
|
|---|
| 1772 |
|
|---|
| 1773 | #ifdef ERIC_neverdef
|
|---|
| 1774 | /* For a .reginfo section, set the gp value in the tdata information
|
|---|
| 1775 | from the contents of this section. We need the gp value while
|
|---|
| 1776 | processing relocs, so we just get it now. */
|
|---|
| 1777 | if (hdr->sh_type == SHT_ALPHA_REGINFO)
|
|---|
| 1778 | {
|
|---|
| 1779 | Elf64_External_RegInfo ext;
|
|---|
| 1780 | Elf64_RegInfo s;
|
|---|
| 1781 |
|
|---|
| 1782 | if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
|
|---|
| 1783 | (file_ptr) 0, sizeof ext))
|
|---|
| 1784 | return false;
|
|---|
| 1785 | bfd_alpha_elf64_swap_reginfo_in (abfd, &ext, &s);
|
|---|
| 1786 | elf_gp (abfd) = s.ri_gp_value;
|
|---|
| 1787 | }
|
|---|
| 1788 | #endif
|
|---|
| 1789 |
|
|---|
| 1790 | return true;
|
|---|
| 1791 | }
|
|---|
| 1792 |
|
|---|
| 1793 | /* Set the correct type for an Alpha ELF section. We do this by the
|
|---|
| 1794 | section name, which is a hack, but ought to work. */
|
|---|
| 1795 |
|
|---|
| 1796 | static boolean
|
|---|
| 1797 | elf64_alpha_fake_sections (abfd, hdr, sec)
|
|---|
| 1798 | bfd *abfd;
|
|---|
| 1799 | Elf64_Internal_Shdr *hdr;
|
|---|
| 1800 | asection *sec;
|
|---|
| 1801 | {
|
|---|
| 1802 | register const char *name;
|
|---|
| 1803 |
|
|---|
| 1804 | name = bfd_get_section_name (abfd, sec);
|
|---|
| 1805 |
|
|---|
| 1806 | if (strcmp (name, ".mdebug") == 0)
|
|---|
| 1807 | {
|
|---|
| 1808 | hdr->sh_type = SHT_ALPHA_DEBUG;
|
|---|
| 1809 | /* In a shared object on Irix 5.3, the .mdebug section has an
|
|---|
| 1810 | entsize of 0. FIXME: Does this matter? */
|
|---|
| 1811 | if ((abfd->flags & DYNAMIC) != 0 )
|
|---|
| 1812 | hdr->sh_entsize = 0;
|
|---|
| 1813 | else
|
|---|
| 1814 | hdr->sh_entsize = 1;
|
|---|
| 1815 | }
|
|---|
| 1816 | #ifdef ERIC_neverdef
|
|---|
| 1817 | else if (strcmp (name, ".reginfo") == 0)
|
|---|
| 1818 | {
|
|---|
| 1819 | hdr->sh_type = SHT_ALPHA_REGINFO;
|
|---|
| 1820 | /* In a shared object on Irix 5.3, the .reginfo section has an
|
|---|
| 1821 | entsize of 0x18. FIXME: Does this matter? */
|
|---|
| 1822 | if ((abfd->flags & DYNAMIC) != 0)
|
|---|
| 1823 | hdr->sh_entsize = sizeof (Elf64_External_RegInfo);
|
|---|
| 1824 | else
|
|---|
| 1825 | hdr->sh_entsize = 1;
|
|---|
| 1826 |
|
|---|
| 1827 | /* Force the section size to the correct value, even if the
|
|---|
| 1828 | linker thinks it is larger. The link routine below will only
|
|---|
| 1829 | write out this much data for .reginfo. */
|
|---|
| 1830 | hdr->sh_size = sec->_raw_size = sizeof (Elf64_External_RegInfo);
|
|---|
| 1831 | }
|
|---|
| 1832 | else if (strcmp (name, ".hash") == 0
|
|---|
| 1833 | || strcmp (name, ".dynamic") == 0
|
|---|
| 1834 | || strcmp (name, ".dynstr") == 0)
|
|---|
| 1835 | {
|
|---|
| 1836 | hdr->sh_entsize = 0;
|
|---|
| 1837 | hdr->sh_info = SIZEOF_ALPHA_DYNSYM_SECNAMES;
|
|---|
| 1838 | }
|
|---|
| 1839 | #endif
|
|---|
| 1840 | else if (strcmp (name, ".sdata") == 0
|
|---|
| 1841 | || strcmp (name, ".sbss") == 0
|
|---|
| 1842 | || strcmp (name, ".lit4") == 0
|
|---|
| 1843 | || strcmp (name, ".lit8") == 0)
|
|---|
| 1844 | hdr->sh_flags |= SHF_ALPHA_GPREL;
|
|---|
| 1845 |
|
|---|
| 1846 | return true;
|
|---|
| 1847 | }
|
|---|
| 1848 |
|
|---|
| 1849 | /* Hook called by the linker routine which adds symbols from an object
|
|---|
| 1850 | file. We use it to put .comm items in .sbss, and not .bss. */
|
|---|
| 1851 |
|
|---|
| 1852 | static boolean
|
|---|
| 1853 | elf64_alpha_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
|
|---|
| 1854 | bfd *abfd;
|
|---|
| 1855 | struct bfd_link_info *info;
|
|---|
| 1856 | const Elf_Internal_Sym *sym;
|
|---|
| 1857 | const char **namep ATTRIBUTE_UNUSED;
|
|---|
| 1858 | flagword *flagsp ATTRIBUTE_UNUSED;
|
|---|
| 1859 | asection **secp;
|
|---|
| 1860 | bfd_vma *valp;
|
|---|
| 1861 | {
|
|---|
| 1862 | if (sym->st_shndx == SHN_COMMON
|
|---|
| 1863 | && !info->relocateable
|
|---|
| 1864 | && sym->st_size <= bfd_get_gp_size (abfd))
|
|---|
| 1865 | {
|
|---|
| 1866 | /* Common symbols less than or equal to -G nn bytes are
|
|---|
| 1867 | automatically put into .sbss. */
|
|---|
| 1868 |
|
|---|
| 1869 | asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
|
|---|
| 1870 |
|
|---|
| 1871 | if (scomm == NULL)
|
|---|
| 1872 | {
|
|---|
| 1873 | scomm = bfd_make_section (abfd, ".scommon");
|
|---|
| 1874 | if (scomm == NULL
|
|---|
| 1875 | || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
|
|---|
| 1876 | | SEC_IS_COMMON
|
|---|
| 1877 | | SEC_LINKER_CREATED)))
|
|---|
| 1878 | return false;
|
|---|
| 1879 | }
|
|---|
| 1880 |
|
|---|
| 1881 | *secp = scomm;
|
|---|
| 1882 | *valp = sym->st_size;
|
|---|
| 1883 | }
|
|---|
| 1884 |
|
|---|
| 1885 | return true;
|
|---|
| 1886 | }
|
|---|
| 1887 |
|
|---|
| 1888 | /* Create the .got section. */
|
|---|
| 1889 |
|
|---|
| 1890 | static boolean
|
|---|
| 1891 | elf64_alpha_create_got_section(abfd, info)
|
|---|
| 1892 | bfd *abfd;
|
|---|
| 1893 | struct bfd_link_info *info ATTRIBUTE_UNUSED;
|
|---|
| 1894 | {
|
|---|
| 1895 | asection *s;
|
|---|
| 1896 |
|
|---|
| 1897 | if (bfd_get_section_by_name (abfd, ".got"))
|
|---|
| 1898 | return true;
|
|---|
| 1899 |
|
|---|
| 1900 | s = bfd_make_section (abfd, ".got");
|
|---|
| 1901 | if (s == NULL
|
|---|
| 1902 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
|
|---|
| 1903 | | SEC_HAS_CONTENTS
|
|---|
| 1904 | | SEC_IN_MEMORY
|
|---|
| 1905 | | SEC_LINKER_CREATED))
|
|---|
| 1906 | || !bfd_set_section_alignment (abfd, s, 3))
|
|---|
| 1907 | return false;
|
|---|
| 1908 |
|
|---|
| 1909 | alpha_elf_tdata (abfd)->got = s;
|
|---|
| 1910 |
|
|---|
| 1911 | return true;
|
|---|
| 1912 | }
|
|---|
| 1913 |
|
|---|
| 1914 | /* Create all the dynamic sections. */
|
|---|
| 1915 |
|
|---|
| 1916 | static boolean
|
|---|
| 1917 | elf64_alpha_create_dynamic_sections (abfd, info)
|
|---|
| 1918 | bfd *abfd;
|
|---|
| 1919 | struct bfd_link_info *info;
|
|---|
| 1920 | {
|
|---|
| 1921 | asection *s;
|
|---|
| 1922 | struct elf_link_hash_entry *h;
|
|---|
| 1923 |
|
|---|
| 1924 | /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
|
|---|
| 1925 |
|
|---|
| 1926 | s = bfd_make_section (abfd, ".plt");
|
|---|
| 1927 | if (s == NULL
|
|---|
| 1928 | || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
|
|---|
| 1929 | | SEC_HAS_CONTENTS
|
|---|
| 1930 | | SEC_IN_MEMORY
|
|---|
| 1931 | | SEC_LINKER_CREATED
|
|---|
| 1932 | | SEC_CODE))
|
|---|
| 1933 | || ! bfd_set_section_alignment (abfd, s, 3))
|
|---|
| 1934 | return false;
|
|---|
| 1935 |
|
|---|
| 1936 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
|
|---|
| 1937 | .plt section. */
|
|---|
| 1938 | h = NULL;
|
|---|
| 1939 | if (! (_bfd_generic_link_add_one_symbol
|
|---|
| 1940 | (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
|
|---|
| 1941 | (bfd_vma) 0, (const char *) NULL, false,
|
|---|
| 1942 | get_elf_backend_data (abfd)->collect,
|
|---|
| 1943 | (struct bfd_link_hash_entry **) &h)))
|
|---|
| 1944 | return false;
|
|---|
| 1945 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
|
|---|
| 1946 | h->type = STT_OBJECT;
|
|---|
| 1947 |
|
|---|
| 1948 | if (info->shared
|
|---|
| 1949 | && ! _bfd_elf_link_record_dynamic_symbol (info, h))
|
|---|
| 1950 | return false;
|
|---|
| 1951 |
|
|---|
| 1952 | s = bfd_make_section (abfd, ".rela.plt");
|
|---|
| 1953 | if (s == NULL
|
|---|
| 1954 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
|
|---|
| 1955 | | SEC_HAS_CONTENTS
|
|---|
| 1956 | | SEC_IN_MEMORY
|
|---|
| 1957 | | SEC_LINKER_CREATED
|
|---|
| 1958 | | SEC_READONLY))
|
|---|
| 1959 | || ! bfd_set_section_alignment (abfd, s, 3))
|
|---|
| 1960 | return false;
|
|---|
| 1961 |
|
|---|
| 1962 | /* We may or may not have created a .got section for this object, but
|
|---|
| 1963 | we definitely havn't done the rest of the work. */
|
|---|
| 1964 |
|
|---|
| 1965 | if (!elf64_alpha_create_got_section (abfd, info))
|
|---|
| 1966 | return false;
|
|---|
| 1967 |
|
|---|
| 1968 | s = bfd_make_section(abfd, ".rela.got");
|
|---|
| 1969 | if (s == NULL
|
|---|
| 1970 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
|
|---|
| 1971 | | SEC_HAS_CONTENTS
|
|---|
| 1972 | | SEC_IN_MEMORY
|
|---|
| 1973 | | SEC_LINKER_CREATED
|
|---|
| 1974 | | SEC_READONLY))
|
|---|
| 1975 | || !bfd_set_section_alignment (abfd, s, 3))
|
|---|
| 1976 | return false;
|
|---|
| 1977 |
|
|---|
| 1978 | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
|
|---|
| 1979 | dynobj's .got section. We don't do this in the linker script
|
|---|
| 1980 | because we don't want to define the symbol if we are not creating
|
|---|
| 1981 | a global offset table. */
|
|---|
| 1982 | h = NULL;
|
|---|
| 1983 | if (!(_bfd_generic_link_add_one_symbol
|
|---|
| 1984 | (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL,
|
|---|
| 1985 | alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL,
|
|---|
| 1986 | false, get_elf_backend_data (abfd)->collect,
|
|---|
| 1987 | (struct bfd_link_hash_entry **) &h)))
|
|---|
| 1988 | return false;
|
|---|
| 1989 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
|
|---|
| 1990 | h->type = STT_OBJECT;
|
|---|
| 1991 |
|
|---|
| 1992 | if (info->shared
|
|---|
| 1993 | && ! _bfd_elf_link_record_dynamic_symbol (info, h))
|
|---|
| 1994 | return false;
|
|---|
| 1995 |
|
|---|
| 1996 | elf_hash_table (info)->hgot = h;
|
|---|
| 1997 |
|
|---|
| 1998 | return true;
|
|---|
| 1999 | }
|
|---|
| 2000 | |
|---|
| 2001 |
|
|---|
| 2002 | /* Read ECOFF debugging information from a .mdebug section into a
|
|---|
| 2003 | ecoff_debug_info structure. */
|
|---|
| 2004 |
|
|---|
| 2005 | static boolean
|
|---|
| 2006 | elf64_alpha_read_ecoff_info (abfd, section, debug)
|
|---|
| 2007 | bfd *abfd;
|
|---|
| 2008 | asection *section;
|
|---|
| 2009 | struct ecoff_debug_info *debug;
|
|---|
| 2010 | {
|
|---|
| 2011 | HDRR *symhdr;
|
|---|
| 2012 | const struct ecoff_debug_swap *swap;
|
|---|
| 2013 | char *ext_hdr = NULL;
|
|---|
| 2014 |
|
|---|
| 2015 | swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
|
|---|
| 2016 | memset (debug, 0, sizeof (*debug));
|
|---|
| 2017 |
|
|---|
| 2018 | ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
|
|---|
| 2019 | if (ext_hdr == NULL && swap->external_hdr_size != 0)
|
|---|
| 2020 | goto error_return;
|
|---|
| 2021 |
|
|---|
| 2022 | if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
|
|---|
| 2023 | swap->external_hdr_size)
|
|---|
| 2024 | == false)
|
|---|
| 2025 | goto error_return;
|
|---|
| 2026 |
|
|---|
| 2027 | symhdr = &debug->symbolic_header;
|
|---|
| 2028 | (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
|
|---|
| 2029 |
|
|---|
| 2030 | /* The symbolic header contains absolute file offsets and sizes to
|
|---|
| 2031 | read. */
|
|---|
| 2032 | #define READ(ptr, offset, count, size, type) \
|
|---|
| 2033 | if (symhdr->count == 0) \
|
|---|
| 2034 | debug->ptr = NULL; \
|
|---|
| 2035 | else \
|
|---|
| 2036 | { \
|
|---|
| 2037 | debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
|
|---|
| 2038 | if (debug->ptr == NULL) \
|
|---|
| 2039 | goto error_return; \
|
|---|
| 2040 | if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
|
|---|
| 2041 | || (bfd_read (debug->ptr, size, symhdr->count, \
|
|---|
| 2042 | abfd) != size * symhdr->count)) \
|
|---|
| 2043 | goto error_return; \
|
|---|
| 2044 | }
|
|---|
| 2045 |
|
|---|
| 2046 | READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
|
|---|
| 2047 | READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
|
|---|
| 2048 | READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
|
|---|
| 2049 | READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
|
|---|
| 2050 | READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
|
|---|
| 2051 | READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
|
|---|
| 2052 | union aux_ext *);
|
|---|
| 2053 | READ (ss, cbSsOffset, issMax, sizeof (char), char *);
|
|---|
| 2054 | READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
|
|---|
| 2055 | READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
|
|---|
| 2056 | READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
|
|---|
| 2057 | READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
|
|---|
| 2058 | #undef READ
|
|---|
| 2059 |
|
|---|
| 2060 | debug->fdr = NULL;
|
|---|
| 2061 | debug->adjust = NULL;
|
|---|
| 2062 |
|
|---|
| 2063 | return true;
|
|---|
| 2064 |
|
|---|
| 2065 | error_return:
|
|---|
| 2066 | if (ext_hdr != NULL)
|
|---|
| 2067 | free (ext_hdr);
|
|---|
| 2068 | if (debug->line != NULL)
|
|---|
| 2069 | free (debug->line);
|
|---|
| 2070 | if (debug->external_dnr != NULL)
|
|---|
| 2071 | free (debug->external_dnr);
|
|---|
| 2072 | if (debug->external_pdr != NULL)
|
|---|
| 2073 | free (debug->external_pdr);
|
|---|
| 2074 | if (debug->external_sym != NULL)
|
|---|
| 2075 | free (debug->external_sym);
|
|---|
| 2076 | if (debug->external_opt != NULL)
|
|---|
| 2077 | free (debug->external_opt);
|
|---|
| 2078 | if (debug->external_aux != NULL)
|
|---|
| 2079 | free (debug->external_aux);
|
|---|
| 2080 | if (debug->ss != NULL)
|
|---|
| 2081 | free (debug->ss);
|
|---|
| 2082 | if (debug->ssext != NULL)
|
|---|
| 2083 | free (debug->ssext);
|
|---|
| 2084 | if (debug->external_fdr != NULL)
|
|---|
| 2085 | free (debug->external_fdr);
|
|---|
| 2086 | if (debug->external_rfd != NULL)
|
|---|
| 2087 | free (debug->external_rfd);
|
|---|
| 2088 | if (debug->external_ext != NULL)
|
|---|
| 2089 | free (debug->external_ext);
|
|---|
| 2090 | return false;
|
|---|
| 2091 | }
|
|---|
| 2092 |
|
|---|
| 2093 | /* Alpha ELF local labels start with '$'. */
|
|---|
| 2094 |
|
|---|
| 2095 | static boolean
|
|---|
| 2096 | elf64_alpha_is_local_label_name (abfd, name)
|
|---|
| 2097 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 2098 | const char *name;
|
|---|
| 2099 | {
|
|---|
| 2100 | return name[0] == '$';
|
|---|
| 2101 | }
|
|---|
| 2102 |
|
|---|
| 2103 | /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
|
|---|
| 2104 | routine in order to handle the ECOFF debugging information. We
|
|---|
| 2105 | still call this mips_elf_find_line because of the slot
|
|---|
| 2106 | find_line_info in elf_obj_tdata is declared that way. */
|
|---|
| 2107 |
|
|---|
| 2108 | struct mips_elf_find_line
|
|---|
| 2109 | {
|
|---|
| 2110 | struct ecoff_debug_info d;
|
|---|
| 2111 | struct ecoff_find_line i;
|
|---|
| 2112 | };
|
|---|
| 2113 |
|
|---|
| 2114 | static boolean
|
|---|
| 2115 | elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
|
|---|
| 2116 | functionname_ptr, line_ptr)
|
|---|
| 2117 | bfd *abfd;
|
|---|
| 2118 | asection *section;
|
|---|
| 2119 | asymbol **symbols;
|
|---|
| 2120 | bfd_vma offset;
|
|---|
| 2121 | const char **filename_ptr;
|
|---|
| 2122 | const char **functionname_ptr;
|
|---|
| 2123 | unsigned int *line_ptr;
|
|---|
| 2124 | {
|
|---|
| 2125 | asection *msec;
|
|---|
| 2126 |
|
|---|
| 2127 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
|
|---|
| 2128 | filename_ptr, functionname_ptr,
|
|---|
| 2129 | line_ptr, 0,
|
|---|
| 2130 | &elf_tdata (abfd)->dwarf2_find_line_info))
|
|---|
| 2131 | return true;
|
|---|
| 2132 |
|
|---|
| 2133 | msec = bfd_get_section_by_name (abfd, ".mdebug");
|
|---|
| 2134 | if (msec != NULL)
|
|---|
| 2135 | {
|
|---|
| 2136 | flagword origflags;
|
|---|
| 2137 | struct mips_elf_find_line *fi;
|
|---|
| 2138 | const struct ecoff_debug_swap * const swap =
|
|---|
| 2139 | get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
|
|---|
| 2140 |
|
|---|
| 2141 | /* If we are called during a link, alpha_elf_final_link may have
|
|---|
| 2142 | cleared the SEC_HAS_CONTENTS field. We force it back on here
|
|---|
| 2143 | if appropriate (which it normally will be). */
|
|---|
| 2144 | origflags = msec->flags;
|
|---|
| 2145 | if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
|
|---|
| 2146 | msec->flags |= SEC_HAS_CONTENTS;
|
|---|
| 2147 |
|
|---|
| 2148 | fi = elf_tdata (abfd)->find_line_info;
|
|---|
| 2149 | if (fi == NULL)
|
|---|
| 2150 | {
|
|---|
| 2151 | bfd_size_type external_fdr_size;
|
|---|
| 2152 | char *fraw_src;
|
|---|
| 2153 | char *fraw_end;
|
|---|
| 2154 | struct fdr *fdr_ptr;
|
|---|
| 2155 |
|
|---|
| 2156 | fi = ((struct mips_elf_find_line *)
|
|---|
| 2157 | bfd_zalloc (abfd, sizeof (struct mips_elf_find_line)));
|
|---|
| 2158 | if (fi == NULL)
|
|---|
| 2159 | {
|
|---|
| 2160 | msec->flags = origflags;
|
|---|
| 2161 | return false;
|
|---|
| 2162 | }
|
|---|
| 2163 |
|
|---|
| 2164 | if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d))
|
|---|
| 2165 | {
|
|---|
| 2166 | msec->flags = origflags;
|
|---|
| 2167 | return false;
|
|---|
| 2168 | }
|
|---|
| 2169 |
|
|---|
| 2170 | /* Swap in the FDR information. */
|
|---|
| 2171 | fi->d.fdr = ((struct fdr *)
|
|---|
| 2172 | bfd_alloc (abfd,
|
|---|
| 2173 | (fi->d.symbolic_header.ifdMax *
|
|---|
| 2174 | sizeof (struct fdr))));
|
|---|
| 2175 | if (fi->d.fdr == NULL)
|
|---|
| 2176 | {
|
|---|
| 2177 | msec->flags = origflags;
|
|---|
| 2178 | return false;
|
|---|
| 2179 | }
|
|---|
| 2180 | external_fdr_size = swap->external_fdr_size;
|
|---|
| 2181 | fdr_ptr = fi->d.fdr;
|
|---|
| 2182 | fraw_src = (char *) fi->d.external_fdr;
|
|---|
| 2183 | fraw_end = (fraw_src
|
|---|
| 2184 | + fi->d.symbolic_header.ifdMax * external_fdr_size);
|
|---|
| 2185 | for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
|
|---|
| 2186 | (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
|
|---|
| 2187 |
|
|---|
| 2188 | elf_tdata (abfd)->find_line_info = fi;
|
|---|
| 2189 |
|
|---|
| 2190 | /* Note that we don't bother to ever free this information.
|
|---|
| 2191 | find_nearest_line is either called all the time, as in
|
|---|
| 2192 | objdump -l, so the information should be saved, or it is
|
|---|
| 2193 | rarely called, as in ld error messages, so the memory
|
|---|
| 2194 | wasted is unimportant. Still, it would probably be a
|
|---|
| 2195 | good idea for free_cached_info to throw it away. */
|
|---|
| 2196 | }
|
|---|
| 2197 |
|
|---|
| 2198 | if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
|
|---|
| 2199 | &fi->i, filename_ptr, functionname_ptr,
|
|---|
| 2200 | line_ptr))
|
|---|
| 2201 | {
|
|---|
| 2202 | msec->flags = origflags;
|
|---|
| 2203 | return true;
|
|---|
| 2204 | }
|
|---|
| 2205 |
|
|---|
| 2206 | msec->flags = origflags;
|
|---|
| 2207 | }
|
|---|
| 2208 |
|
|---|
| 2209 | /* Fall back on the generic ELF find_nearest_line routine. */
|
|---|
| 2210 |
|
|---|
| 2211 | return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
|
|---|
| 2212 | filename_ptr, functionname_ptr,
|
|---|
| 2213 | line_ptr);
|
|---|
| 2214 | }
|
|---|
| 2215 | |
|---|
| 2216 |
|
|---|
| 2217 | /* Structure used to pass information to alpha_elf_output_extsym. */
|
|---|
| 2218 |
|
|---|
| 2219 | struct extsym_info
|
|---|
| 2220 | {
|
|---|
| 2221 | bfd *abfd;
|
|---|
| 2222 | struct bfd_link_info *info;
|
|---|
| 2223 | struct ecoff_debug_info *debug;
|
|---|
| 2224 | const struct ecoff_debug_swap *swap;
|
|---|
| 2225 | boolean failed;
|
|---|
| 2226 | };
|
|---|
| 2227 |
|
|---|
| 2228 | static boolean
|
|---|
| 2229 | elf64_alpha_output_extsym (h, data)
|
|---|
| 2230 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 2231 | PTR data;
|
|---|
| 2232 | {
|
|---|
| 2233 | struct extsym_info *einfo = (struct extsym_info *) data;
|
|---|
| 2234 | boolean strip;
|
|---|
| 2235 | asection *sec, *output_section;
|
|---|
| 2236 |
|
|---|
| 2237 | if (h->root.indx == -2)
|
|---|
| 2238 | strip = false;
|
|---|
| 2239 | else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
|
|---|
| 2240 | || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
|
|---|
| 2241 | && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
|
|---|
| 2242 | && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
|
|---|
| 2243 | strip = true;
|
|---|
| 2244 | else if (einfo->info->strip == strip_all
|
|---|
| 2245 | || (einfo->info->strip == strip_some
|
|---|
| 2246 | && bfd_hash_lookup (einfo->info->keep_hash,
|
|---|
| 2247 | h->root.root.root.string,
|
|---|
| 2248 | false, false) == NULL))
|
|---|
| 2249 | strip = true;
|
|---|
| 2250 | else
|
|---|
| 2251 | strip = false;
|
|---|
| 2252 |
|
|---|
| 2253 | if (strip)
|
|---|
| 2254 | return true;
|
|---|
| 2255 |
|
|---|
| 2256 | if (h->esym.ifd == -2)
|
|---|
| 2257 | {
|
|---|
| 2258 | h->esym.jmptbl = 0;
|
|---|
| 2259 | h->esym.cobol_main = 0;
|
|---|
| 2260 | h->esym.weakext = 0;
|
|---|
| 2261 | h->esym.reserved = 0;
|
|---|
| 2262 | h->esym.ifd = ifdNil;
|
|---|
| 2263 | h->esym.asym.value = 0;
|
|---|
| 2264 | h->esym.asym.st = stGlobal;
|
|---|
| 2265 |
|
|---|
| 2266 | if (h->root.root.type != bfd_link_hash_defined
|
|---|
| 2267 | && h->root.root.type != bfd_link_hash_defweak)
|
|---|
| 2268 | h->esym.asym.sc = scAbs;
|
|---|
| 2269 | else
|
|---|
| 2270 | {
|
|---|
| 2271 | const char *name;
|
|---|
| 2272 |
|
|---|
| 2273 | sec = h->root.root.u.def.section;
|
|---|
| 2274 | output_section = sec->output_section;
|
|---|
| 2275 |
|
|---|
| 2276 | /* When making a shared library and symbol h is the one from
|
|---|
| 2277 | the another shared library, OUTPUT_SECTION may be null. */
|
|---|
| 2278 | if (output_section == NULL)
|
|---|
| 2279 | h->esym.asym.sc = scUndefined;
|
|---|
| 2280 | else
|
|---|
| 2281 | {
|
|---|
| 2282 | name = bfd_section_name (output_section->owner, output_section);
|
|---|
| 2283 |
|
|---|
| 2284 | if (strcmp (name, ".text") == 0)
|
|---|
| 2285 | h->esym.asym.sc = scText;
|
|---|
| 2286 | else if (strcmp (name, ".data") == 0)
|
|---|
| 2287 | h->esym.asym.sc = scData;
|
|---|
| 2288 | else if (strcmp (name, ".sdata") == 0)
|
|---|
| 2289 | h->esym.asym.sc = scSData;
|
|---|
| 2290 | else if (strcmp (name, ".rodata") == 0
|
|---|
| 2291 | || strcmp (name, ".rdata") == 0)
|
|---|
| 2292 | h->esym.asym.sc = scRData;
|
|---|
| 2293 | else if (strcmp (name, ".bss") == 0)
|
|---|
| 2294 | h->esym.asym.sc = scBss;
|
|---|
| 2295 | else if (strcmp (name, ".sbss") == 0)
|
|---|
| 2296 | h->esym.asym.sc = scSBss;
|
|---|
| 2297 | else if (strcmp (name, ".init") == 0)
|
|---|
| 2298 | h->esym.asym.sc = scInit;
|
|---|
| 2299 | else if (strcmp (name, ".fini") == 0)
|
|---|
| 2300 | h->esym.asym.sc = scFini;
|
|---|
| 2301 | else
|
|---|
| 2302 | h->esym.asym.sc = scAbs;
|
|---|
| 2303 | }
|
|---|
| 2304 | }
|
|---|
| 2305 |
|
|---|
| 2306 | h->esym.asym.reserved = 0;
|
|---|
| 2307 | h->esym.asym.index = indexNil;
|
|---|
| 2308 | }
|
|---|
| 2309 |
|
|---|
| 2310 | if (h->root.root.type == bfd_link_hash_common)
|
|---|
| 2311 | h->esym.asym.value = h->root.root.u.c.size;
|
|---|
| 2312 | else if (h->root.root.type == bfd_link_hash_defined
|
|---|
| 2313 | || h->root.root.type == bfd_link_hash_defweak)
|
|---|
| 2314 | {
|
|---|
| 2315 | if (h->esym.asym.sc == scCommon)
|
|---|
| 2316 | h->esym.asym.sc = scBss;
|
|---|
| 2317 | else if (h->esym.asym.sc == scSCommon)
|
|---|
| 2318 | h->esym.asym.sc = scSBss;
|
|---|
| 2319 |
|
|---|
| 2320 | sec = h->root.root.u.def.section;
|
|---|
| 2321 | output_section = sec->output_section;
|
|---|
| 2322 | if (output_section != NULL)
|
|---|
| 2323 | h->esym.asym.value = (h->root.root.u.def.value
|
|---|
| 2324 | + sec->output_offset
|
|---|
| 2325 | + output_section->vma);
|
|---|
| 2326 | else
|
|---|
| 2327 | h->esym.asym.value = 0;
|
|---|
| 2328 | }
|
|---|
| 2329 | else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
|
|---|
| 2330 | {
|
|---|
| 2331 | /* Set type and value for a symbol with a function stub. */
|
|---|
| 2332 | h->esym.asym.st = stProc;
|
|---|
| 2333 | sec = bfd_get_section_by_name (einfo->abfd, ".plt");
|
|---|
| 2334 | if (sec == NULL)
|
|---|
| 2335 | h->esym.asym.value = 0;
|
|---|
| 2336 | else
|
|---|
| 2337 | {
|
|---|
| 2338 | output_section = sec->output_section;
|
|---|
| 2339 | if (output_section != NULL)
|
|---|
| 2340 | h->esym.asym.value = (h->root.plt.offset
|
|---|
| 2341 | + sec->output_offset
|
|---|
| 2342 | + output_section->vma);
|
|---|
| 2343 | else
|
|---|
| 2344 | h->esym.asym.value = 0;
|
|---|
| 2345 | }
|
|---|
| 2346 | #if 0 /* FIXME? */
|
|---|
| 2347 | h->esym.ifd = 0;
|
|---|
| 2348 | #endif
|
|---|
| 2349 | }
|
|---|
| 2350 |
|
|---|
| 2351 | if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
|
|---|
| 2352 | h->root.root.root.string,
|
|---|
| 2353 | &h->esym))
|
|---|
| 2354 | {
|
|---|
| 2355 | einfo->failed = true;
|
|---|
| 2356 | return false;
|
|---|
| 2357 | }
|
|---|
| 2358 |
|
|---|
| 2359 | return true;
|
|---|
| 2360 | }
|
|---|
| 2361 |
|
|---|
| 2362 | /* FIXME: Create a runtime procedure table from the .mdebug section.
|
|---|
| 2363 |
|
|---|
| 2364 | static boolean
|
|---|
| 2365 | mips_elf_create_procedure_table (handle, abfd, info, s, debug)
|
|---|
| 2366 | PTR handle;
|
|---|
| 2367 | bfd *abfd;
|
|---|
| 2368 | struct bfd_link_info *info;
|
|---|
| 2369 | asection *s;
|
|---|
| 2370 | struct ecoff_debug_info *debug;
|
|---|
| 2371 | */
|
|---|
| 2372 | |
|---|
| 2373 |
|
|---|
| 2374 | /* Handle dynamic relocations when doing an Alpha ELF link. */
|
|---|
| 2375 |
|
|---|
| 2376 | static boolean
|
|---|
| 2377 | elf64_alpha_check_relocs (abfd, info, sec, relocs)
|
|---|
| 2378 | bfd *abfd;
|
|---|
| 2379 | struct bfd_link_info *info;
|
|---|
| 2380 | asection *sec;
|
|---|
| 2381 | const Elf_Internal_Rela *relocs;
|
|---|
| 2382 | {
|
|---|
| 2383 | bfd *dynobj;
|
|---|
| 2384 | asection *sreloc;
|
|---|
| 2385 | const char *rel_sec_name;
|
|---|
| 2386 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 2387 | struct alpha_elf_link_hash_entry **sym_hashes;
|
|---|
| 2388 | struct alpha_elf_got_entry **local_got_entries;
|
|---|
| 2389 | const Elf_Internal_Rela *rel, *relend;
|
|---|
| 2390 | int got_created;
|
|---|
| 2391 |
|
|---|
| 2392 | if (info->relocateable)
|
|---|
| 2393 | return true;
|
|---|
| 2394 |
|
|---|
| 2395 | dynobj = elf_hash_table(info)->dynobj;
|
|---|
| 2396 | if (dynobj == NULL)
|
|---|
| 2397 | elf_hash_table(info)->dynobj = dynobj = abfd;
|
|---|
| 2398 |
|
|---|
| 2399 | sreloc = NULL;
|
|---|
| 2400 | rel_sec_name = NULL;
|
|---|
| 2401 | symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
|
|---|
| 2402 | sym_hashes = alpha_elf_sym_hashes(abfd);
|
|---|
| 2403 | local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
|
|---|
| 2404 | got_created = 0;
|
|---|
| 2405 |
|
|---|
| 2406 | relend = relocs + sec->reloc_count;
|
|---|
| 2407 | for (rel = relocs; rel < relend; ++rel)
|
|---|
| 2408 | {
|
|---|
| 2409 | unsigned long r_symndx, r_type;
|
|---|
| 2410 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 2411 |
|
|---|
| 2412 | r_symndx = ELF64_R_SYM (rel->r_info);
|
|---|
| 2413 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 2414 | h = NULL;
|
|---|
| 2415 | else
|
|---|
| 2416 | {
|
|---|
| 2417 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
|---|
| 2418 |
|
|---|
| 2419 | while (h->root.root.type == bfd_link_hash_indirect
|
|---|
| 2420 | || h->root.root.type == bfd_link_hash_warning)
|
|---|
| 2421 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
|
|---|
| 2422 |
|
|---|
| 2423 | h->root.elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
|
|---|
| 2424 | }
|
|---|
| 2425 | r_type = ELF64_R_TYPE (rel->r_info);
|
|---|
| 2426 |
|
|---|
| 2427 | switch (r_type)
|
|---|
| 2428 | {
|
|---|
| 2429 | case R_ALPHA_LITERAL:
|
|---|
| 2430 | {
|
|---|
| 2431 | struct alpha_elf_got_entry *gotent;
|
|---|
| 2432 | int flags = 0;
|
|---|
| 2433 |
|
|---|
| 2434 | if (h)
|
|---|
| 2435 | {
|
|---|
| 2436 | /* Search for and possibly create a got entry. */
|
|---|
| 2437 | for (gotent = h->got_entries; gotent ; gotent = gotent->next)
|
|---|
| 2438 | if (gotent->gotobj == abfd &&
|
|---|
| 2439 | gotent->addend == rel->r_addend)
|
|---|
| 2440 | break;
|
|---|
| 2441 |
|
|---|
| 2442 | if (!gotent)
|
|---|
| 2443 | {
|
|---|
| 2444 | gotent = ((struct alpha_elf_got_entry *)
|
|---|
| 2445 | bfd_alloc (abfd,
|
|---|
| 2446 | sizeof (struct alpha_elf_got_entry)));
|
|---|
| 2447 | if (!gotent)
|
|---|
| 2448 | return false;
|
|---|
| 2449 |
|
|---|
| 2450 | gotent->gotobj = abfd;
|
|---|
| 2451 | gotent->addend = rel->r_addend;
|
|---|
| 2452 | gotent->got_offset = -1;
|
|---|
| 2453 | gotent->flags = 0;
|
|---|
| 2454 | gotent->use_count = 1;
|
|---|
| 2455 |
|
|---|
| 2456 | gotent->next = h->got_entries;
|
|---|
| 2457 | h->got_entries = gotent;
|
|---|
| 2458 |
|
|---|
| 2459 | alpha_elf_tdata (abfd)->total_got_entries++;
|
|---|
| 2460 | }
|
|---|
| 2461 | else
|
|---|
| 2462 | gotent->use_count += 1;
|
|---|
| 2463 | }
|
|---|
| 2464 | else
|
|---|
| 2465 | {
|
|---|
| 2466 | /* This is a local .got entry -- record for merge. */
|
|---|
| 2467 | if (!local_got_entries)
|
|---|
| 2468 | {
|
|---|
| 2469 | size_t size;
|
|---|
| 2470 | size = (symtab_hdr->sh_info
|
|---|
| 2471 | * sizeof (struct alpha_elf_got_entry *));
|
|---|
| 2472 |
|
|---|
| 2473 | local_got_entries = ((struct alpha_elf_got_entry **)
|
|---|
| 2474 | bfd_alloc (abfd, size));
|
|---|
| 2475 | if (!local_got_entries)
|
|---|
| 2476 | return false;
|
|---|
| 2477 |
|
|---|
| 2478 | memset (local_got_entries, 0, size);
|
|---|
| 2479 | alpha_elf_tdata (abfd)->local_got_entries =
|
|---|
| 2480 | local_got_entries;
|
|---|
| 2481 | }
|
|---|
| 2482 |
|
|---|
| 2483 | for (gotent = local_got_entries[ELF64_R_SYM(rel->r_info)];
|
|---|
| 2484 | gotent != NULL && gotent->addend != rel->r_addend;
|
|---|
| 2485 | gotent = gotent->next)
|
|---|
| 2486 | continue;
|
|---|
| 2487 | if (!gotent)
|
|---|
| 2488 | {
|
|---|
| 2489 | gotent = ((struct alpha_elf_got_entry *)
|
|---|
| 2490 | bfd_alloc (abfd,
|
|---|
| 2491 | sizeof (struct alpha_elf_got_entry)));
|
|---|
| 2492 | if (!gotent)
|
|---|
| 2493 | return false;
|
|---|
| 2494 |
|
|---|
| 2495 | gotent->gotobj = abfd;
|
|---|
| 2496 | gotent->addend = rel->r_addend;
|
|---|
| 2497 | gotent->got_offset = -1;
|
|---|
| 2498 | gotent->flags = 0;
|
|---|
| 2499 | gotent->use_count = 1;
|
|---|
| 2500 |
|
|---|
| 2501 | gotent->next = local_got_entries[ELF64_R_SYM(rel->r_info)];
|
|---|
| 2502 | local_got_entries[ELF64_R_SYM(rel->r_info)] = gotent;
|
|---|
| 2503 |
|
|---|
| 2504 | alpha_elf_tdata(abfd)->total_got_entries++;
|
|---|
| 2505 | alpha_elf_tdata(abfd)->n_local_got_entries++;
|
|---|
| 2506 | }
|
|---|
| 2507 | else
|
|---|
| 2508 | gotent->use_count += 1;
|
|---|
| 2509 | }
|
|---|
| 2510 |
|
|---|
| 2511 | /* Remember how this literal is used from its LITUSEs.
|
|---|
| 2512 | This will be important when it comes to decide if we can
|
|---|
| 2513 | create a .plt entry for a function symbol. */
|
|---|
| 2514 | if (rel+1 < relend
|
|---|
| 2515 | && ELF64_R_TYPE (rel[1].r_info) == R_ALPHA_LITUSE)
|
|---|
| 2516 | {
|
|---|
| 2517 | do
|
|---|
| 2518 | {
|
|---|
| 2519 | ++rel;
|
|---|
| 2520 | if (rel->r_addend >= 1 && rel->r_addend <= 3)
|
|---|
| 2521 | flags |= 1 << rel->r_addend;
|
|---|
| 2522 | }
|
|---|
| 2523 | while (rel+1 < relend &&
|
|---|
| 2524 | ELF64_R_TYPE (rel[1].r_info) == R_ALPHA_LITUSE);
|
|---|
| 2525 | }
|
|---|
| 2526 | else
|
|---|
| 2527 | {
|
|---|
| 2528 | /* No LITUSEs -- presumably the address is not being
|
|---|
| 2529 | loaded for nothing. */
|
|---|
| 2530 | flags = ALPHA_ELF_LINK_HASH_LU_ADDR;
|
|---|
| 2531 | }
|
|---|
| 2532 |
|
|---|
| 2533 | gotent->flags |= flags;
|
|---|
| 2534 | if (h)
|
|---|
| 2535 | {
|
|---|
| 2536 | /* Make a guess as to whether a .plt entry will be needed. */
|
|---|
| 2537 | if ((h->flags |= flags) == ALPHA_ELF_LINK_HASH_LU_FUNC)
|
|---|
| 2538 | h->root.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 2539 | else
|
|---|
| 2540 | h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 2541 | }
|
|---|
| 2542 | }
|
|---|
| 2543 | /* FALLTHRU */
|
|---|
| 2544 |
|
|---|
| 2545 | case R_ALPHA_GPDISP:
|
|---|
| 2546 | case R_ALPHA_GPREL32:
|
|---|
| 2547 | case R_ALPHA_GPRELHIGH:
|
|---|
| 2548 | case R_ALPHA_GPRELLOW:
|
|---|
| 2549 | /* We don't actually use the .got here, but the sections must
|
|---|
| 2550 | be created before the linker maps input sections to output
|
|---|
| 2551 | sections. */
|
|---|
| 2552 | if (!got_created)
|
|---|
| 2553 | {
|
|---|
| 2554 | if (!elf64_alpha_create_got_section (abfd, info))
|
|---|
| 2555 | return false;
|
|---|
| 2556 |
|
|---|
| 2557 | /* Make sure the object's gotobj is set to itself so
|
|---|
| 2558 | that we default to every object with its own .got.
|
|---|
| 2559 | We'll merge .gots later once we've collected each
|
|---|
| 2560 | object's info. */
|
|---|
| 2561 | alpha_elf_tdata(abfd)->gotobj = abfd;
|
|---|
| 2562 |
|
|---|
| 2563 | got_created = 1;
|
|---|
| 2564 | }
|
|---|
| 2565 | break;
|
|---|
| 2566 |
|
|---|
| 2567 | case R_ALPHA_SREL16:
|
|---|
| 2568 | case R_ALPHA_SREL32:
|
|---|
| 2569 | case R_ALPHA_SREL64:
|
|---|
| 2570 | if (h == NULL)
|
|---|
| 2571 | break;
|
|---|
| 2572 | /* FALLTHRU */
|
|---|
| 2573 |
|
|---|
| 2574 | case R_ALPHA_REFLONG:
|
|---|
| 2575 | case R_ALPHA_REFQUAD:
|
|---|
| 2576 | if (rel_sec_name == NULL)
|
|---|
| 2577 | {
|
|---|
| 2578 | rel_sec_name = (bfd_elf_string_from_elf_section
|
|---|
| 2579 | (abfd, elf_elfheader(abfd)->e_shstrndx,
|
|---|
| 2580 | elf_section_data(sec)->rel_hdr.sh_name));
|
|---|
| 2581 | if (rel_sec_name == NULL)
|
|---|
| 2582 | return false;
|
|---|
| 2583 |
|
|---|
| 2584 | BFD_ASSERT (strncmp (rel_sec_name, ".rela", 5) == 0
|
|---|
| 2585 | && strcmp (bfd_get_section_name (abfd, sec),
|
|---|
| 2586 | rel_sec_name+5) == 0);
|
|---|
| 2587 | }
|
|---|
| 2588 |
|
|---|
| 2589 | /* We need to create the section here now whether we eventually
|
|---|
| 2590 | use it or not so that it gets mapped to an output section by
|
|---|
| 2591 | the linker. If not used, we'll kill it in
|
|---|
| 2592 | size_dynamic_sections. */
|
|---|
| 2593 | if (sreloc == NULL)
|
|---|
| 2594 | {
|
|---|
| 2595 | sreloc = bfd_get_section_by_name (dynobj, rel_sec_name);
|
|---|
| 2596 | if (sreloc == NULL)
|
|---|
| 2597 | {
|
|---|
| 2598 | sreloc = bfd_make_section (dynobj, rel_sec_name);
|
|---|
| 2599 | if (sreloc == NULL
|
|---|
| 2600 | || !bfd_set_section_flags (dynobj, sreloc,
|
|---|
| 2601 | ((sec->flags & (SEC_ALLOC
|
|---|
| 2602 | | SEC_LOAD))
|
|---|
| 2603 | | SEC_HAS_CONTENTS
|
|---|
| 2604 | | SEC_IN_MEMORY
|
|---|
| 2605 | | SEC_LINKER_CREATED
|
|---|
| 2606 | | SEC_READONLY))
|
|---|
| 2607 | || !bfd_set_section_alignment (dynobj, sreloc, 3))
|
|---|
| 2608 | return false;
|
|---|
| 2609 | }
|
|---|
| 2610 | }
|
|---|
| 2611 |
|
|---|
| 2612 | if (h)
|
|---|
| 2613 | {
|
|---|
| 2614 | /* Since we havn't seen all of the input symbols yet, we
|
|---|
| 2615 | don't know whether we'll actually need a dynamic relocation
|
|---|
| 2616 | entry for this reloc. So make a record of it. Once we
|
|---|
| 2617 | find out if this thing needs dynamic relocation we'll
|
|---|
| 2618 | expand the relocation sections by the appropriate amount. */
|
|---|
| 2619 |
|
|---|
| 2620 | struct alpha_elf_reloc_entry *rent;
|
|---|
| 2621 |
|
|---|
| 2622 | for (rent = h->reloc_entries; rent; rent = rent->next)
|
|---|
| 2623 | if (rent->rtype == r_type && rent->srel == sreloc)
|
|---|
| 2624 | break;
|
|---|
| 2625 |
|
|---|
| 2626 | if (!rent)
|
|---|
| 2627 | {
|
|---|
| 2628 | rent = ((struct alpha_elf_reloc_entry *)
|
|---|
| 2629 | bfd_alloc (abfd,
|
|---|
| 2630 | sizeof (struct alpha_elf_reloc_entry)));
|
|---|
| 2631 | if (!rent)
|
|---|
| 2632 | return false;
|
|---|
| 2633 |
|
|---|
| 2634 | rent->srel = sreloc;
|
|---|
| 2635 | rent->rtype = r_type;
|
|---|
| 2636 | rent->count = 1;
|
|---|
| 2637 |
|
|---|
| 2638 | rent->next = h->reloc_entries;
|
|---|
| 2639 | h->reloc_entries = rent;
|
|---|
| 2640 | }
|
|---|
| 2641 | else
|
|---|
| 2642 | rent->count++;
|
|---|
| 2643 | }
|
|---|
| 2644 | else if (info->shared && (sec->flags & SEC_ALLOC))
|
|---|
| 2645 | {
|
|---|
| 2646 | /* If this is a shared library, and the section is to be
|
|---|
| 2647 | loaded into memory, we need a RELATIVE reloc. */
|
|---|
| 2648 | sreloc->_raw_size += sizeof (Elf64_External_Rela);
|
|---|
| 2649 | }
|
|---|
| 2650 | break;
|
|---|
| 2651 | }
|
|---|
| 2652 | }
|
|---|
| 2653 |
|
|---|
| 2654 | return true;
|
|---|
| 2655 | }
|
|---|
| 2656 |
|
|---|
| 2657 | /* Adjust a symbol defined by a dynamic object and referenced by a
|
|---|
| 2658 | regular object. The current definition is in some section of the
|
|---|
| 2659 | dynamic object, but we're not including those sections. We have to
|
|---|
| 2660 | change the definition to something the rest of the link can
|
|---|
| 2661 | understand. */
|
|---|
| 2662 |
|
|---|
| 2663 | static boolean
|
|---|
| 2664 | elf64_alpha_adjust_dynamic_symbol (info, h)
|
|---|
| 2665 | struct bfd_link_info *info;
|
|---|
| 2666 | struct elf_link_hash_entry *h;
|
|---|
| 2667 | {
|
|---|
| 2668 | bfd *dynobj;
|
|---|
| 2669 | asection *s;
|
|---|
| 2670 | struct alpha_elf_link_hash_entry *ah;
|
|---|
| 2671 |
|
|---|
| 2672 | dynobj = elf_hash_table(info)->dynobj;
|
|---|
| 2673 | ah = (struct alpha_elf_link_hash_entry *)h;
|
|---|
| 2674 |
|
|---|
| 2675 | /* Now that we've seen all of the input symbols, finalize our decision
|
|---|
| 2676 | about whether this symbol should get a .plt entry. */
|
|---|
| 2677 |
|
|---|
| 2678 | if (h->root.type != bfd_link_hash_undefweak
|
|---|
| 2679 | && alpha_elf_dynamic_symbol_p (h, info)
|
|---|
| 2680 | && ((h->type == STT_FUNC
|
|---|
| 2681 | && !(ah->flags & ALPHA_ELF_LINK_HASH_LU_ADDR))
|
|---|
| 2682 | || (h->type == STT_NOTYPE
|
|---|
| 2683 | && ah->flags == ALPHA_ELF_LINK_HASH_LU_FUNC))
|
|---|
| 2684 | /* Don't prevent otherwise valid programs from linking by attempting
|
|---|
| 2685 | to create a new .got entry somewhere. A Correct Solution would be
|
|---|
| 2686 | to add a new .got section to a new object file and let it be merged
|
|---|
| 2687 | somewhere later. But for now don't bother. */
|
|---|
| 2688 | && ah->got_entries)
|
|---|
| 2689 | {
|
|---|
| 2690 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 2691 |
|
|---|
| 2692 | s = bfd_get_section_by_name(dynobj, ".plt");
|
|---|
| 2693 | if (!s && !elf64_alpha_create_dynamic_sections (dynobj, info))
|
|---|
| 2694 | return false;
|
|---|
| 2695 |
|
|---|
| 2696 | /* The first bit of the .plt is reserved. */
|
|---|
| 2697 | if (s->_raw_size == 0)
|
|---|
| 2698 | s->_raw_size = PLT_HEADER_SIZE;
|
|---|
| 2699 |
|
|---|
| 2700 | h->plt.offset = s->_raw_size;
|
|---|
| 2701 | s->_raw_size += PLT_ENTRY_SIZE;
|
|---|
| 2702 |
|
|---|
| 2703 | /* If this symbol is not defined in a regular file, and we are not
|
|---|
| 2704 | generating a shared library, then set the symbol to the location
|
|---|
| 2705 | in the .plt. This is required to make function pointers compare
|
|---|
| 2706 | equal between the normal executable and the shared library. */
|
|---|
| 2707 | if (! info->shared
|
|---|
| 2708 | && h->root.type != bfd_link_hash_defweak)
|
|---|
| 2709 | {
|
|---|
| 2710 | h->root.u.def.section = s;
|
|---|
| 2711 | h->root.u.def.value = h->plt.offset;
|
|---|
| 2712 | }
|
|---|
| 2713 |
|
|---|
| 2714 | /* We also need a JMP_SLOT entry in the .rela.plt section. */
|
|---|
| 2715 | s = bfd_get_section_by_name (dynobj, ".rela.plt");
|
|---|
| 2716 | BFD_ASSERT (s != NULL);
|
|---|
| 2717 | s->_raw_size += sizeof (Elf64_External_Rela);
|
|---|
| 2718 |
|
|---|
| 2719 | return true;
|
|---|
| 2720 | }
|
|---|
| 2721 | else
|
|---|
| 2722 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 2723 |
|
|---|
| 2724 | /* If this is a weak symbol, and there is a real definition, the
|
|---|
| 2725 | processor independent code will have arranged for us to see the
|
|---|
| 2726 | real definition first, and we can just use the same value. */
|
|---|
| 2727 | if (h->weakdef != NULL)
|
|---|
| 2728 | {
|
|---|
| 2729 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
|
|---|
| 2730 | || h->weakdef->root.type == bfd_link_hash_defweak);
|
|---|
| 2731 | h->root.u.def.section = h->weakdef->root.u.def.section;
|
|---|
| 2732 | h->root.u.def.value = h->weakdef->root.u.def.value;
|
|---|
| 2733 | return true;
|
|---|
| 2734 | }
|
|---|
| 2735 |
|
|---|
| 2736 | /* This is a reference to a symbol defined by a dynamic object which
|
|---|
| 2737 | is not a function. The Alpha, since it uses .got entries for all
|
|---|
| 2738 | symbols even in regular objects, does not need the hackery of a
|
|---|
| 2739 | .dynbss section and COPY dynamic relocations. */
|
|---|
| 2740 |
|
|---|
| 2741 | return true;
|
|---|
| 2742 | }
|
|---|
| 2743 |
|
|---|
| 2744 | /* Symbol versioning can create new symbols, and make our old symbols
|
|---|
| 2745 | indirect to the new ones. Consolidate the got and reloc information
|
|---|
| 2746 | in these situations. */
|
|---|
| 2747 |
|
|---|
| 2748 | static boolean
|
|---|
| 2749 | elf64_alpha_merge_ind_symbols (hi, dummy)
|
|---|
| 2750 | struct alpha_elf_link_hash_entry *hi;
|
|---|
| 2751 | PTR dummy ATTRIBUTE_UNUSED;
|
|---|
| 2752 | {
|
|---|
| 2753 | struct alpha_elf_link_hash_entry *hs;
|
|---|
| 2754 |
|
|---|
| 2755 | if (hi->root.root.type != bfd_link_hash_indirect)
|
|---|
| 2756 | return true;
|
|---|
| 2757 | hs = hi;
|
|---|
| 2758 | do {
|
|---|
| 2759 | hs = (struct alpha_elf_link_hash_entry *)hs->root.root.u.i.link;
|
|---|
| 2760 | } while (hs->root.root.type == bfd_link_hash_indirect);
|
|---|
| 2761 |
|
|---|
| 2762 | /* Merge the flags. Whee. */
|
|---|
| 2763 |
|
|---|
| 2764 | hs->flags |= hi->flags;
|
|---|
| 2765 |
|
|---|
| 2766 | /* Merge the .got entries. Cannibalize the old symbol's list in
|
|---|
| 2767 | doing so, since we don't need it anymore. */
|
|---|
| 2768 |
|
|---|
| 2769 | if (hs->got_entries == NULL)
|
|---|
| 2770 | hs->got_entries = hi->got_entries;
|
|---|
| 2771 | else
|
|---|
| 2772 | {
|
|---|
| 2773 | struct alpha_elf_got_entry *gi, *gs, *gin, *gsh;
|
|---|
| 2774 |
|
|---|
| 2775 | gsh = hs->got_entries;
|
|---|
| 2776 | for (gi = hi->got_entries; gi ; gi = gin)
|
|---|
| 2777 | {
|
|---|
| 2778 | gin = gi->next;
|
|---|
| 2779 | for (gs = gsh; gs ; gs = gs->next)
|
|---|
| 2780 | if (gi->gotobj == gs->gotobj && gi->addend == gs->addend)
|
|---|
| 2781 | goto got_found;
|
|---|
| 2782 | gi->next = hs->got_entries;
|
|---|
| 2783 | hs->got_entries = gi;
|
|---|
| 2784 | got_found:;
|
|---|
| 2785 | }
|
|---|
| 2786 | }
|
|---|
| 2787 | hi->got_entries = NULL;
|
|---|
| 2788 |
|
|---|
| 2789 | /* And similar for the reloc entries. */
|
|---|
| 2790 |
|
|---|
| 2791 | if (hs->reloc_entries == NULL)
|
|---|
| 2792 | hs->reloc_entries = hi->reloc_entries;
|
|---|
| 2793 | else
|
|---|
| 2794 | {
|
|---|
| 2795 | struct alpha_elf_reloc_entry *ri, *rs, *rin, *rsh;
|
|---|
| 2796 |
|
|---|
| 2797 | rsh = hs->reloc_entries;
|
|---|
| 2798 | for (ri = hi->reloc_entries; ri ; ri = rin)
|
|---|
| 2799 | {
|
|---|
| 2800 | rin = ri->next;
|
|---|
| 2801 | for (rs = rsh; rs ; rs = rs->next)
|
|---|
| 2802 | if (ri->rtype == rs->rtype)
|
|---|
| 2803 | {
|
|---|
| 2804 | rs->count += ri->count;
|
|---|
| 2805 | goto found_reloc;
|
|---|
| 2806 | }
|
|---|
| 2807 | ri->next = hs->reloc_entries;
|
|---|
| 2808 | hs->reloc_entries = ri;
|
|---|
| 2809 | found_reloc:;
|
|---|
| 2810 | }
|
|---|
| 2811 | }
|
|---|
| 2812 | hi->reloc_entries = NULL;
|
|---|
| 2813 |
|
|---|
| 2814 | return true;
|
|---|
| 2815 | }
|
|---|
| 2816 |
|
|---|
| 2817 | /* Is it possible to merge two object file's .got tables? */
|
|---|
| 2818 |
|
|---|
| 2819 | static boolean
|
|---|
| 2820 | elf64_alpha_can_merge_gots (a, b)
|
|---|
| 2821 | bfd *a, *b;
|
|---|
| 2822 | {
|
|---|
| 2823 | int total = alpha_elf_tdata (a)->total_got_entries;
|
|---|
| 2824 | bfd *bsub;
|
|---|
| 2825 |
|
|---|
| 2826 | /* Trivial quick fallout test. */
|
|---|
| 2827 | if (total + alpha_elf_tdata (b)->total_got_entries <= MAX_GOT_ENTRIES)
|
|---|
| 2828 | return true;
|
|---|
| 2829 |
|
|---|
| 2830 | /* By their nature, local .got entries cannot be merged. */
|
|---|
| 2831 | if ((total += alpha_elf_tdata (b)->n_local_got_entries) > MAX_GOT_ENTRIES)
|
|---|
| 2832 | return false;
|
|---|
| 2833 |
|
|---|
| 2834 | /* Failing the common trivial comparison, we must effectively
|
|---|
| 2835 | perform the merge. Not actually performing the merge means that
|
|---|
| 2836 | we don't have to store undo information in case we fail. */
|
|---|
| 2837 | for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
|
|---|
| 2838 | {
|
|---|
| 2839 | struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes (bsub);
|
|---|
| 2840 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
|
|---|
| 2841 | int i, n;
|
|---|
| 2842 |
|
|---|
| 2843 | n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info;
|
|---|
| 2844 | for (i = 0; i < n; ++i)
|
|---|
| 2845 | {
|
|---|
| 2846 | struct alpha_elf_got_entry *ae, *be;
|
|---|
| 2847 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 2848 |
|
|---|
| 2849 | h = hashes[i];
|
|---|
| 2850 | while (h->root.root.type == bfd_link_hash_indirect
|
|---|
| 2851 | || h->root.root.type == bfd_link_hash_warning)
|
|---|
| 2852 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
|
|---|
| 2853 |
|
|---|
| 2854 | for (be = h->got_entries; be ; be = be->next)
|
|---|
| 2855 | {
|
|---|
| 2856 | if (be->use_count == 0)
|
|---|
| 2857 | continue;
|
|---|
| 2858 | if (be->gotobj != b)
|
|---|
| 2859 | continue;
|
|---|
| 2860 |
|
|---|
| 2861 | for (ae = h->got_entries; ae ; ae = ae->next)
|
|---|
| 2862 | if (ae->gotobj == a && ae->addend == be->addend)
|
|---|
| 2863 | goto global_found;
|
|---|
| 2864 |
|
|---|
| 2865 | if (++total > MAX_GOT_ENTRIES)
|
|---|
| 2866 | return false;
|
|---|
| 2867 | global_found:;
|
|---|
| 2868 | }
|
|---|
| 2869 | }
|
|---|
| 2870 | }
|
|---|
| 2871 |
|
|---|
| 2872 | return true;
|
|---|
| 2873 | }
|
|---|
| 2874 |
|
|---|
| 2875 | /* Actually merge two .got tables. */
|
|---|
| 2876 |
|
|---|
| 2877 | static void
|
|---|
| 2878 | elf64_alpha_merge_gots (a, b)
|
|---|
| 2879 | bfd *a, *b;
|
|---|
| 2880 | {
|
|---|
| 2881 | int total = alpha_elf_tdata (a)->total_got_entries;
|
|---|
| 2882 | bfd *bsub;
|
|---|
| 2883 |
|
|---|
| 2884 | /* Remember local expansion. */
|
|---|
| 2885 | {
|
|---|
| 2886 | int e = alpha_elf_tdata (b)->n_local_got_entries;
|
|---|
| 2887 | total += e;
|
|---|
| 2888 | alpha_elf_tdata (a)->n_local_got_entries += e;
|
|---|
| 2889 | }
|
|---|
| 2890 |
|
|---|
| 2891 | for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
|
|---|
| 2892 | {
|
|---|
| 2893 | struct alpha_elf_got_entry **local_got_entries;
|
|---|
| 2894 | struct alpha_elf_link_hash_entry **hashes;
|
|---|
| 2895 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 2896 | int i, n;
|
|---|
| 2897 |
|
|---|
| 2898 | /* Let the local .got entries know they are part of a new subsegment. */
|
|---|
| 2899 | local_got_entries = alpha_elf_tdata (bsub)->local_got_entries;
|
|---|
| 2900 | if (local_got_entries)
|
|---|
| 2901 | {
|
|---|
| 2902 | n = elf_tdata (bsub)->symtab_hdr.sh_info;
|
|---|
| 2903 | for (i = 0; i < n; ++i)
|
|---|
| 2904 | {
|
|---|
| 2905 | struct alpha_elf_got_entry *ent;
|
|---|
| 2906 | for (ent = local_got_entries[i]; ent; ent = ent->next)
|
|---|
| 2907 | ent->gotobj = a;
|
|---|
| 2908 | }
|
|---|
| 2909 | }
|
|---|
| 2910 |
|
|---|
| 2911 | /* Merge the global .got entries. */
|
|---|
| 2912 | hashes = alpha_elf_sym_hashes (bsub);
|
|---|
| 2913 | symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
|
|---|
| 2914 |
|
|---|
| 2915 | n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info;
|
|---|
| 2916 | for (i = 0; i < n; ++i)
|
|---|
| 2917 | {
|
|---|
| 2918 | struct alpha_elf_got_entry *ae, *be, **pbe, **start;
|
|---|
| 2919 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 2920 |
|
|---|
| 2921 | h = hashes[i];
|
|---|
| 2922 | while (h->root.root.type == bfd_link_hash_indirect
|
|---|
| 2923 | || h->root.root.type == bfd_link_hash_warning)
|
|---|
| 2924 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
|
|---|
| 2925 |
|
|---|
| 2926 | start = &h->got_entries;
|
|---|
| 2927 | for (pbe = start, be = *start; be ; pbe = &be->next, be = be->next)
|
|---|
| 2928 | {
|
|---|
| 2929 | if (be->use_count == 0)
|
|---|
| 2930 | {
|
|---|
| 2931 | *pbe = be->next;
|
|---|
| 2932 | continue;
|
|---|
| 2933 | }
|
|---|
| 2934 | if (be->gotobj != b)
|
|---|
| 2935 | continue;
|
|---|
| 2936 |
|
|---|
| 2937 | for (ae = *start; ae ; ae = ae->next)
|
|---|
| 2938 | if (ae->gotobj == a && ae->addend == be->addend)
|
|---|
| 2939 | {
|
|---|
| 2940 | ae->flags |= be->flags;
|
|---|
| 2941 | ae->use_count += be->use_count;
|
|---|
| 2942 | *pbe = be->next;
|
|---|
| 2943 | goto global_found;
|
|---|
| 2944 | }
|
|---|
| 2945 | be->gotobj = a;
|
|---|
| 2946 | total += 1;
|
|---|
| 2947 |
|
|---|
| 2948 | global_found:;
|
|---|
| 2949 | }
|
|---|
| 2950 | }
|
|---|
| 2951 |
|
|---|
| 2952 | alpha_elf_tdata (bsub)->gotobj = a;
|
|---|
| 2953 | }
|
|---|
| 2954 | alpha_elf_tdata (a)->total_got_entries = total;
|
|---|
| 2955 |
|
|---|
| 2956 | /* Merge the two in_got chains. */
|
|---|
| 2957 | {
|
|---|
| 2958 | bfd *next;
|
|---|
| 2959 |
|
|---|
| 2960 | bsub = a;
|
|---|
| 2961 | while ((next = alpha_elf_tdata (bsub)->in_got_link_next) != NULL)
|
|---|
| 2962 | bsub = next;
|
|---|
| 2963 |
|
|---|
| 2964 | alpha_elf_tdata (bsub)->in_got_link_next = b;
|
|---|
| 2965 | }
|
|---|
| 2966 | }
|
|---|
| 2967 |
|
|---|
| 2968 | /* Calculate the offsets for the got entries. */
|
|---|
| 2969 |
|
|---|
| 2970 | static boolean
|
|---|
| 2971 | elf64_alpha_calc_got_offsets_for_symbol (h, arg)
|
|---|
| 2972 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 2973 | PTR arg;
|
|---|
| 2974 | {
|
|---|
| 2975 | struct alpha_elf_got_entry *gotent;
|
|---|
| 2976 |
|
|---|
| 2977 | for (gotent = h->got_entries; gotent; gotent = gotent->next)
|
|---|
| 2978 | if (gotent->use_count > 0)
|
|---|
| 2979 | {
|
|---|
| 2980 | bfd_size_type *plge
|
|---|
| 2981 | = &alpha_elf_tdata (gotent->gotobj)->got->_raw_size;
|
|---|
| 2982 |
|
|---|
| 2983 | gotent->got_offset = *plge;
|
|---|
| 2984 | *plge += 8;
|
|---|
| 2985 | }
|
|---|
| 2986 |
|
|---|
| 2987 | return true;
|
|---|
| 2988 | }
|
|---|
| 2989 |
|
|---|
| 2990 | static void
|
|---|
| 2991 | elf64_alpha_calc_got_offsets (info)
|
|---|
| 2992 | struct bfd_link_info *info;
|
|---|
| 2993 | {
|
|---|
| 2994 | bfd *i, *got_list = alpha_elf_hash_table(info)->got_list;
|
|---|
| 2995 |
|
|---|
| 2996 | /* First, zero out the .got sizes, as we may be recalculating the
|
|---|
| 2997 | .got after optimizing it. */
|
|---|
| 2998 | for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
|
|---|
| 2999 | alpha_elf_tdata(i)->got->_raw_size = 0;
|
|---|
| 3000 |
|
|---|
| 3001 | /* Next, fill in the offsets for all the global entries. */
|
|---|
| 3002 | alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
|
|---|
| 3003 | elf64_alpha_calc_got_offsets_for_symbol,
|
|---|
| 3004 | NULL);
|
|---|
| 3005 |
|
|---|
| 3006 | /* Finally, fill in the offsets for the local entries. */
|
|---|
| 3007 | for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
|
|---|
| 3008 | {
|
|---|
| 3009 | bfd_size_type got_offset = alpha_elf_tdata(i)->got->_raw_size;
|
|---|
| 3010 | bfd *j;
|
|---|
| 3011 |
|
|---|
| 3012 | for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
|
|---|
| 3013 | {
|
|---|
| 3014 | struct alpha_elf_got_entry **local_got_entries, *gotent;
|
|---|
| 3015 | int k, n;
|
|---|
| 3016 |
|
|---|
| 3017 | local_got_entries = alpha_elf_tdata(j)->local_got_entries;
|
|---|
| 3018 | if (!local_got_entries)
|
|---|
| 3019 | continue;
|
|---|
| 3020 |
|
|---|
| 3021 | for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
|
|---|
| 3022 | for (gotent = local_got_entries[k]; gotent; gotent = gotent->next)
|
|---|
| 3023 | if (gotent->use_count > 0)
|
|---|
| 3024 | {
|
|---|
| 3025 | gotent->got_offset = got_offset;
|
|---|
| 3026 | got_offset += 8;
|
|---|
| 3027 | }
|
|---|
| 3028 | }
|
|---|
| 3029 |
|
|---|
| 3030 | alpha_elf_tdata(i)->got->_raw_size = got_offset;
|
|---|
| 3031 | alpha_elf_tdata(i)->got->_cooked_size = got_offset;
|
|---|
| 3032 | }
|
|---|
| 3033 | }
|
|---|
| 3034 |
|
|---|
| 3035 | /* Constructs the gots. */
|
|---|
| 3036 |
|
|---|
| 3037 | static boolean
|
|---|
| 3038 | elf64_alpha_size_got_sections (output_bfd, info)
|
|---|
| 3039 | bfd *output_bfd;
|
|---|
| 3040 | struct bfd_link_info *info;
|
|---|
| 3041 | {
|
|---|
| 3042 | bfd *i, *got_list, *cur_got_obj;
|
|---|
| 3043 | int something_changed = 0;
|
|---|
| 3044 |
|
|---|
| 3045 | got_list = alpha_elf_hash_table (info)->got_list;
|
|---|
| 3046 |
|
|---|
| 3047 | /* On the first time through, pretend we have an existing got list
|
|---|
| 3048 | consisting of all of the input files. */
|
|---|
| 3049 | if (got_list == NULL)
|
|---|
| 3050 | {
|
|---|
| 3051 | for (i = info->input_bfds; i ; i = i->link_next)
|
|---|
| 3052 | {
|
|---|
| 3053 | bfd *this_got = alpha_elf_tdata (i)->gotobj;
|
|---|
| 3054 | if (this_got == NULL)
|
|---|
| 3055 | continue;
|
|---|
| 3056 |
|
|---|
| 3057 | /* We are assuming no merging has yet ocurred. */
|
|---|
| 3058 | BFD_ASSERT (this_got == i);
|
|---|
| 3059 |
|
|---|
| 3060 | if (alpha_elf_tdata (this_got)->total_got_entries > MAX_GOT_ENTRIES)
|
|---|
| 3061 | {
|
|---|
| 3062 | /* Yikes! A single object file has too many entries. */
|
|---|
| 3063 | (*_bfd_error_handler)
|
|---|
| 3064 | (_("%s: .got subsegment exceeds 64K (size %d)"),
|
|---|
| 3065 | bfd_get_filename (i),
|
|---|
| 3066 | alpha_elf_tdata (this_got)->total_got_entries * 8);
|
|---|
| 3067 | return false;
|
|---|
| 3068 | }
|
|---|
| 3069 |
|
|---|
| 3070 | if (got_list == NULL)
|
|---|
| 3071 | got_list = this_got;
|
|---|
| 3072 | else
|
|---|
| 3073 | alpha_elf_tdata(cur_got_obj)->got_link_next = this_got;
|
|---|
| 3074 | cur_got_obj = this_got;
|
|---|
| 3075 | }
|
|---|
| 3076 |
|
|---|
| 3077 | /* Strange degenerate case of no got references. */
|
|---|
| 3078 | if (got_list == NULL)
|
|---|
| 3079 | return true;
|
|---|
| 3080 |
|
|---|
| 3081 | alpha_elf_hash_table (info)->got_list = got_list;
|
|---|
| 3082 |
|
|---|
| 3083 | /* Force got offsets to be recalculated. */
|
|---|
| 3084 | something_changed = 1;
|
|---|
| 3085 | }
|
|---|
| 3086 |
|
|---|
| 3087 | cur_got_obj = got_list;
|
|---|
| 3088 | i = alpha_elf_tdata(cur_got_obj)->got_link_next;
|
|---|
| 3089 | while (i != NULL)
|
|---|
| 3090 | {
|
|---|
| 3091 | if (elf64_alpha_can_merge_gots (cur_got_obj, i))
|
|---|
| 3092 | {
|
|---|
| 3093 | elf64_alpha_merge_gots (cur_got_obj, i);
|
|---|
| 3094 | i = alpha_elf_tdata(i)->got_link_next;
|
|---|
| 3095 | alpha_elf_tdata(cur_got_obj)->got_link_next = i;
|
|---|
| 3096 | something_changed = 1;
|
|---|
| 3097 | }
|
|---|
| 3098 | else
|
|---|
| 3099 | {
|
|---|
| 3100 | cur_got_obj = i;
|
|---|
| 3101 | i = alpha_elf_tdata(i)->got_link_next;
|
|---|
| 3102 | }
|
|---|
| 3103 | }
|
|---|
| 3104 |
|
|---|
| 3105 | /* Once the gots have been merged, fill in the got offsets for
|
|---|
| 3106 | everything therein. */
|
|---|
| 3107 | if (1 || something_changed)
|
|---|
| 3108 | elf64_alpha_calc_got_offsets (info);
|
|---|
| 3109 |
|
|---|
| 3110 | return true;
|
|---|
| 3111 | }
|
|---|
| 3112 |
|
|---|
| 3113 | static boolean
|
|---|
| 3114 | elf64_alpha_always_size_sections (output_bfd, info)
|
|---|
| 3115 | bfd *output_bfd;
|
|---|
| 3116 | struct bfd_link_info *info;
|
|---|
| 3117 | {
|
|---|
| 3118 | bfd *i;
|
|---|
| 3119 |
|
|---|
| 3120 | if (info->relocateable)
|
|---|
| 3121 | return true;
|
|---|
| 3122 |
|
|---|
| 3123 | /* First, take care of the indirect symbols created by versioning. */
|
|---|
| 3124 | alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
|
|---|
| 3125 | elf64_alpha_merge_ind_symbols,
|
|---|
| 3126 | NULL);
|
|---|
| 3127 |
|
|---|
| 3128 | if (!elf64_alpha_size_got_sections (output_bfd, info))
|
|---|
| 3129 | return false;
|
|---|
| 3130 |
|
|---|
| 3131 | /* Allocate space for all of the .got subsections. */
|
|---|
| 3132 | i = alpha_elf_hash_table (info)->got_list;
|
|---|
| 3133 | for ( ; i ; i = alpha_elf_tdata(i)->got_link_next)
|
|---|
| 3134 | {
|
|---|
| 3135 | asection *s = alpha_elf_tdata(i)->got;
|
|---|
| 3136 | if (s->_raw_size > 0)
|
|---|
| 3137 | {
|
|---|
| 3138 | s->contents = (bfd_byte *) bfd_zalloc (i, s->_raw_size);
|
|---|
| 3139 | if (s->contents == NULL)
|
|---|
| 3140 | return false;
|
|---|
| 3141 | }
|
|---|
| 3142 | }
|
|---|
| 3143 |
|
|---|
| 3144 | return true;
|
|---|
| 3145 | }
|
|---|
| 3146 |
|
|---|
| 3147 | /* Work out the sizes of the dynamic relocation entries. */
|
|---|
| 3148 |
|
|---|
| 3149 | static boolean
|
|---|
| 3150 | elf64_alpha_calc_dynrel_sizes (h, info)
|
|---|
| 3151 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 3152 | struct bfd_link_info *info;
|
|---|
| 3153 | {
|
|---|
| 3154 | /* If the symbol was defined as a common symbol in a regular object
|
|---|
| 3155 | file, and there was no definition in any dynamic object, then the
|
|---|
| 3156 | linker will have allocated space for the symbol in a common
|
|---|
| 3157 | section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
|
|---|
| 3158 | set. This is done for dynamic symbols in
|
|---|
| 3159 | elf_adjust_dynamic_symbol but this is not done for non-dynamic
|
|---|
| 3160 | symbols, somehow. */
|
|---|
| 3161 | if (((h->root.elf_link_hash_flags
|
|---|
| 3162 | & (ELF_LINK_HASH_DEF_REGULAR
|
|---|
| 3163 | | ELF_LINK_HASH_REF_REGULAR
|
|---|
| 3164 | | ELF_LINK_HASH_DEF_DYNAMIC))
|
|---|
| 3165 | == ELF_LINK_HASH_REF_REGULAR)
|
|---|
| 3166 | && (h->root.root.type == bfd_link_hash_defined
|
|---|
| 3167 | || h->root.root.type == bfd_link_hash_defweak)
|
|---|
| 3168 | && !(h->root.root.u.def.section->owner->flags & DYNAMIC))
|
|---|
| 3169 | {
|
|---|
| 3170 | h->root.elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
|
|---|
| 3171 | }
|
|---|
| 3172 |
|
|---|
| 3173 | /* If the symbol is dynamic, we'll need all the relocations in their
|
|---|
| 3174 | natural form. If this is a shared object, and it has been forced
|
|---|
| 3175 | local, we'll need the same number of RELATIVE relocations. */
|
|---|
| 3176 |
|
|---|
| 3177 | if (alpha_elf_dynamic_symbol_p (&h->root, info) || info->shared)
|
|---|
| 3178 | {
|
|---|
| 3179 | struct alpha_elf_reloc_entry *relent;
|
|---|
| 3180 | bfd *dynobj;
|
|---|
| 3181 | struct alpha_elf_got_entry *gotent;
|
|---|
| 3182 | bfd_size_type count;
|
|---|
| 3183 | asection *srel;
|
|---|
| 3184 |
|
|---|
| 3185 | for (relent = h->reloc_entries; relent; relent = relent->next)
|
|---|
| 3186 | if (relent->rtype == R_ALPHA_REFLONG
|
|---|
| 3187 | || relent->rtype == R_ALPHA_REFQUAD)
|
|---|
| 3188 | {
|
|---|
| 3189 | relent->srel->_raw_size +=
|
|---|
| 3190 | sizeof (Elf64_External_Rela) * relent->count;
|
|---|
| 3191 | }
|
|---|
| 3192 |
|
|---|
| 3193 | dynobj = elf_hash_table(info)->dynobj;
|
|---|
| 3194 | count = 0;
|
|---|
| 3195 |
|
|---|
| 3196 | for (gotent = h->got_entries; gotent ; gotent = gotent->next)
|
|---|
| 3197 | count++;
|
|---|
| 3198 |
|
|---|
| 3199 | /* If we are using a .plt entry, subtract one, as the first
|
|---|
| 3200 | reference uses a .rela.plt entry instead. */
|
|---|
| 3201 | if (h->root.plt.offset != MINUS_ONE)
|
|---|
| 3202 | count--;
|
|---|
| 3203 |
|
|---|
| 3204 | if (count > 0)
|
|---|
| 3205 | {
|
|---|
| 3206 | srel = bfd_get_section_by_name (dynobj, ".rela.got");
|
|---|
| 3207 | BFD_ASSERT (srel != NULL);
|
|---|
| 3208 | srel->_raw_size += sizeof (Elf64_External_Rela) * count;
|
|---|
| 3209 | }
|
|---|
| 3210 | }
|
|---|
| 3211 |
|
|---|
| 3212 | return true;
|
|---|
| 3213 | }
|
|---|
| 3214 |
|
|---|
| 3215 | /* Set the sizes of the dynamic sections. */
|
|---|
| 3216 |
|
|---|
| 3217 | static boolean
|
|---|
| 3218 | elf64_alpha_size_dynamic_sections (output_bfd, info)
|
|---|
| 3219 | bfd *output_bfd;
|
|---|
| 3220 | struct bfd_link_info *info;
|
|---|
| 3221 | {
|
|---|
| 3222 | bfd *dynobj;
|
|---|
| 3223 | asection *s;
|
|---|
| 3224 | boolean reltext;
|
|---|
| 3225 | boolean relplt;
|
|---|
| 3226 |
|
|---|
| 3227 | dynobj = elf_hash_table(info)->dynobj;
|
|---|
| 3228 | BFD_ASSERT(dynobj != NULL);
|
|---|
| 3229 |
|
|---|
| 3230 | if (elf_hash_table (info)->dynamic_sections_created)
|
|---|
| 3231 | {
|
|---|
| 3232 | /* Set the contents of the .interp section to the interpreter. */
|
|---|
| 3233 | if (!info->shared)
|
|---|
| 3234 | {
|
|---|
| 3235 | s = bfd_get_section_by_name (dynobj, ".interp");
|
|---|
| 3236 | BFD_ASSERT (s != NULL);
|
|---|
| 3237 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
|
|---|
| 3238 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
|
|---|
| 3239 | }
|
|---|
| 3240 |
|
|---|
| 3241 | /* Now that we've seen all of the input files, we can decide which
|
|---|
| 3242 | symbols need dynamic relocation entries and which don't. We've
|
|---|
| 3243 | collected information in check_relocs that we can now apply to
|
|---|
| 3244 | size the dynamic relocation sections. */
|
|---|
| 3245 | alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
|
|---|
| 3246 | elf64_alpha_calc_dynrel_sizes,
|
|---|
| 3247 | info);
|
|---|
| 3248 |
|
|---|
| 3249 | /* When building shared libraries, each local .got entry needs a
|
|---|
| 3250 | RELATIVE reloc. */
|
|---|
| 3251 | if (info->shared)
|
|---|
| 3252 | {
|
|---|
| 3253 | bfd *i;
|
|---|
| 3254 | asection *srel;
|
|---|
| 3255 | bfd_size_type count;
|
|---|
| 3256 |
|
|---|
| 3257 | srel = bfd_get_section_by_name (dynobj, ".rela.got");
|
|---|
| 3258 | BFD_ASSERT (srel != NULL);
|
|---|
| 3259 |
|
|---|
| 3260 | for (i = alpha_elf_hash_table(info)->got_list, count = 0;
|
|---|
| 3261 | i != NULL;
|
|---|
| 3262 | i = alpha_elf_tdata(i)->got_link_next)
|
|---|
| 3263 | count += alpha_elf_tdata(i)->n_local_got_entries;
|
|---|
| 3264 |
|
|---|
| 3265 | srel->_raw_size += count * sizeof (Elf64_External_Rela);
|
|---|
| 3266 | }
|
|---|
| 3267 | }
|
|---|
| 3268 | /* else we're not dynamic and by definition we don't need such things. */
|
|---|
| 3269 |
|
|---|
| 3270 | /* The check_relocs and adjust_dynamic_symbol entry points have
|
|---|
| 3271 | determined the sizes of the various dynamic sections. Allocate
|
|---|
| 3272 | memory for them. */
|
|---|
| 3273 | reltext = false;
|
|---|
| 3274 | relplt = false;
|
|---|
| 3275 | for (s = dynobj->sections; s != NULL; s = s->next)
|
|---|
| 3276 | {
|
|---|
| 3277 | const char *name;
|
|---|
| 3278 | boolean strip;
|
|---|
| 3279 |
|
|---|
| 3280 | if (!(s->flags & SEC_LINKER_CREATED))
|
|---|
| 3281 | continue;
|
|---|
| 3282 |
|
|---|
| 3283 | /* It's OK to base decisions on the section name, because none
|
|---|
| 3284 | of the dynobj section names depend upon the input files. */
|
|---|
| 3285 | name = bfd_get_section_name (dynobj, s);
|
|---|
| 3286 |
|
|---|
| 3287 | /* If we don't need this section, strip it from the output file.
|
|---|
| 3288 | This is to handle .rela.bss and .rela.plt. We must create it
|
|---|
| 3289 | in create_dynamic_sections, because it must be created before
|
|---|
| 3290 | the linker maps input sections to output sections. The
|
|---|
| 3291 | linker does that before adjust_dynamic_symbol is called, and
|
|---|
| 3292 | it is that function which decides whether anything needs to
|
|---|
| 3293 | go into these sections. */
|
|---|
| 3294 |
|
|---|
| 3295 | strip = false;
|
|---|
| 3296 |
|
|---|
| 3297 | if (strncmp (name, ".rela", 5) == 0)
|
|---|
| 3298 | {
|
|---|
| 3299 | strip = (s->_raw_size == 0);
|
|---|
| 3300 |
|
|---|
| 3301 | if (!strip)
|
|---|
| 3302 | {
|
|---|
| 3303 | const char *outname;
|
|---|
| 3304 | asection *target;
|
|---|
| 3305 |
|
|---|
| 3306 | /* If this relocation section applies to a read only
|
|---|
| 3307 | section, then we probably need a DT_TEXTREL entry. */
|
|---|
| 3308 | outname = bfd_get_section_name (output_bfd,
|
|---|
| 3309 | s->output_section);
|
|---|
| 3310 | target = bfd_get_section_by_name (output_bfd, outname + 5);
|
|---|
| 3311 | if (target != NULL
|
|---|
| 3312 | && (target->flags & SEC_READONLY) != 0
|
|---|
| 3313 | && (target->flags & SEC_ALLOC) != 0)
|
|---|
| 3314 | reltext = true;
|
|---|
| 3315 |
|
|---|
| 3316 | if (strcmp(name, ".rela.plt") == 0)
|
|---|
| 3317 | relplt = true;
|
|---|
| 3318 |
|
|---|
| 3319 | /* We use the reloc_count field as a counter if we need
|
|---|
| 3320 | to copy relocs into the output file. */
|
|---|
| 3321 | s->reloc_count = 0;
|
|---|
| 3322 | }
|
|---|
| 3323 | }
|
|---|
| 3324 | else if (strcmp (name, ".plt") != 0)
|
|---|
| 3325 | {
|
|---|
| 3326 | /* It's not one of our dynamic sections, so don't allocate space. */
|
|---|
| 3327 | continue;
|
|---|
| 3328 | }
|
|---|
| 3329 |
|
|---|
| 3330 | if (strip)
|
|---|
| 3331 | _bfd_strip_section_from_output (info, s);
|
|---|
| 3332 | else
|
|---|
| 3333 | {
|
|---|
| 3334 | /* Allocate memory for the section contents. */
|
|---|
| 3335 | s->contents = (bfd_byte *) bfd_zalloc(dynobj, s->_raw_size);
|
|---|
| 3336 | if (s->contents == NULL && s->_raw_size != 0)
|
|---|
| 3337 | return false;
|
|---|
| 3338 | }
|
|---|
| 3339 | }
|
|---|
| 3340 |
|
|---|
| 3341 | if (elf_hash_table (info)->dynamic_sections_created)
|
|---|
| 3342 | {
|
|---|
| 3343 | /* Add some entries to the .dynamic section. We fill in the
|
|---|
| 3344 | values later, in elf64_alpha_finish_dynamic_sections, but we
|
|---|
| 3345 | must add the entries now so that we get the correct size for
|
|---|
| 3346 | the .dynamic section. The DT_DEBUG entry is filled in by the
|
|---|
| 3347 | dynamic linker and used by the debugger. */
|
|---|
| 3348 | if (!info->shared)
|
|---|
| 3349 | {
|
|---|
| 3350 | if (!bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
|
|---|
| 3351 | return false;
|
|---|
| 3352 | }
|
|---|
| 3353 |
|
|---|
| 3354 | if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0))
|
|---|
| 3355 | return false;
|
|---|
| 3356 |
|
|---|
| 3357 | if (relplt)
|
|---|
| 3358 | {
|
|---|
| 3359 | if (! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
|
|---|
| 3360 | || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
|
|---|
| 3361 | || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
|
|---|
| 3362 | return false;
|
|---|
| 3363 | }
|
|---|
| 3364 |
|
|---|
| 3365 | if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
|
|---|
| 3366 | || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
|
|---|
| 3367 | || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
|
|---|
| 3368 | sizeof (Elf64_External_Rela)))
|
|---|
| 3369 | return false;
|
|---|
| 3370 |
|
|---|
| 3371 | if (reltext)
|
|---|
| 3372 | {
|
|---|
| 3373 | if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
|
|---|
| 3374 | return false;
|
|---|
| 3375 | info->flags |= DF_TEXTREL;
|
|---|
| 3376 | }
|
|---|
| 3377 | }
|
|---|
| 3378 |
|
|---|
| 3379 | return true;
|
|---|
| 3380 | }
|
|---|
| 3381 |
|
|---|
| 3382 | /* Relocate an Alpha ELF section. */
|
|---|
| 3383 |
|
|---|
| 3384 | static boolean
|
|---|
| 3385 | elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section,
|
|---|
| 3386 | contents, relocs, local_syms, local_sections)
|
|---|
| 3387 | bfd *output_bfd;
|
|---|
| 3388 | struct bfd_link_info *info;
|
|---|
| 3389 | bfd *input_bfd;
|
|---|
| 3390 | asection *input_section;
|
|---|
| 3391 | bfd_byte *contents;
|
|---|
| 3392 | Elf_Internal_Rela *relocs;
|
|---|
| 3393 | Elf_Internal_Sym *local_syms;
|
|---|
| 3394 | asection **local_sections;
|
|---|
| 3395 | {
|
|---|
| 3396 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 3397 | Elf_Internal_Rela *rel;
|
|---|
| 3398 | Elf_Internal_Rela *relend;
|
|---|
| 3399 | asection *sec, *sgot, *srel, *srelgot;
|
|---|
| 3400 | bfd *dynobj, *gotobj;
|
|---|
| 3401 | bfd_vma gp;
|
|---|
| 3402 |
|
|---|
| 3403 | srelgot = srel = NULL;
|
|---|
| 3404 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
|
|---|
| 3405 | dynobj = elf_hash_table (info)->dynobj;
|
|---|
| 3406 | if (dynobj)
|
|---|
| 3407 | {
|
|---|
| 3408 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
|
|---|
| 3409 | }
|
|---|
| 3410 |
|
|---|
| 3411 | /* Find the gp value for this input bfd. */
|
|---|
| 3412 | sgot = NULL;
|
|---|
| 3413 | gp = 0;
|
|---|
| 3414 | gotobj = alpha_elf_tdata (input_bfd)->gotobj;
|
|---|
| 3415 | if (gotobj)
|
|---|
| 3416 | {
|
|---|
| 3417 | sgot = alpha_elf_tdata (gotobj)->got;
|
|---|
| 3418 | gp = _bfd_get_gp_value (gotobj);
|
|---|
| 3419 | if (gp == 0)
|
|---|
| 3420 | {
|
|---|
| 3421 | gp = (sgot->output_section->vma
|
|---|
| 3422 | + sgot->output_offset
|
|---|
| 3423 | + 0x8000);
|
|---|
| 3424 | _bfd_set_gp_value (gotobj, gp);
|
|---|
| 3425 | }
|
|---|
| 3426 | }
|
|---|
| 3427 |
|
|---|
| 3428 | rel = relocs;
|
|---|
| 3429 | relend = relocs + input_section->reloc_count;
|
|---|
| 3430 | for (; rel < relend; rel++)
|
|---|
| 3431 | {
|
|---|
| 3432 | int r_type;
|
|---|
| 3433 | reloc_howto_type *howto;
|
|---|
| 3434 | unsigned long r_symndx;
|
|---|
| 3435 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 3436 | Elf_Internal_Sym *sym;
|
|---|
| 3437 | bfd_vma relocation;
|
|---|
| 3438 | bfd_vma addend;
|
|---|
| 3439 | bfd_reloc_status_type r;
|
|---|
| 3440 |
|
|---|
| 3441 | r_type = ELF64_R_TYPE(rel->r_info);
|
|---|
| 3442 | if (r_type < 0 || r_type >= (int) R_ALPHA_max)
|
|---|
| 3443 | {
|
|---|
| 3444 | bfd_set_error (bfd_error_bad_value);
|
|---|
| 3445 | return false;
|
|---|
| 3446 | }
|
|---|
| 3447 | howto = elf64_alpha_howto_table + r_type;
|
|---|
| 3448 |
|
|---|
| 3449 | r_symndx = ELF64_R_SYM(rel->r_info);
|
|---|
| 3450 |
|
|---|
| 3451 | if (info->relocateable)
|
|---|
| 3452 | {
|
|---|
| 3453 | /* This is a relocateable link. We don't have to change
|
|---|
| 3454 | anything, unless the reloc is against a section symbol,
|
|---|
| 3455 | in which case we have to adjust according to where the
|
|---|
| 3456 | section symbol winds up in the output section. */
|
|---|
| 3457 |
|
|---|
| 3458 | /* The symbol associated with GPDISP and LITUSE is
|
|---|
| 3459 | immaterial. Only the addend is significant. */
|
|---|
| 3460 | if (r_type == R_ALPHA_GPDISP || r_type == R_ALPHA_LITUSE)
|
|---|
| 3461 | continue;
|
|---|
| 3462 |
|
|---|
| 3463 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 3464 | {
|
|---|
| 3465 | sym = local_syms + r_symndx;
|
|---|
| 3466 | if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
|
|---|
| 3467 | {
|
|---|
| 3468 | sec = local_sections[r_symndx];
|
|---|
| 3469 | rel->r_addend += sec->output_offset + sym->st_value;
|
|---|
| 3470 | }
|
|---|
| 3471 | }
|
|---|
| 3472 |
|
|---|
| 3473 | continue;
|
|---|
| 3474 | }
|
|---|
| 3475 |
|
|---|
| 3476 | /* This is a final link. */
|
|---|
| 3477 |
|
|---|
| 3478 | h = NULL;
|
|---|
| 3479 | sym = NULL;
|
|---|
| 3480 | sec = NULL;
|
|---|
| 3481 |
|
|---|
| 3482 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 3483 | {
|
|---|
| 3484 | sym = local_syms + r_symndx;
|
|---|
| 3485 | sec = local_sections[r_symndx];
|
|---|
| 3486 | relocation = (sec->output_section->vma
|
|---|
| 3487 | + sec->output_offset
|
|---|
| 3488 | + sym->st_value);
|
|---|
| 3489 | }
|
|---|
| 3490 | else
|
|---|
| 3491 | {
|
|---|
| 3492 | h = alpha_elf_sym_hashes (input_bfd)[r_symndx - symtab_hdr->sh_info];
|
|---|
| 3493 |
|
|---|
| 3494 | while (h->root.root.type == bfd_link_hash_indirect
|
|---|
| 3495 | || h->root.root.type == bfd_link_hash_warning)
|
|---|
| 3496 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
|
|---|
| 3497 |
|
|---|
| 3498 | if (h->root.root.type == bfd_link_hash_defined
|
|---|
| 3499 | || h->root.root.type == bfd_link_hash_defweak)
|
|---|
| 3500 | {
|
|---|
| 3501 | sec = h->root.root.u.def.section;
|
|---|
| 3502 |
|
|---|
| 3503 | #if rth_notdef
|
|---|
| 3504 | if ((r_type == R_ALPHA_LITERAL
|
|---|
| 3505 | && elf_hash_table(info)->dynamic_sections_created
|
|---|
| 3506 | && (!info->shared
|
|---|
| 3507 | || !info->symbolic
|
|---|
| 3508 | || !(h->root.elf_link_hash_flags
|
|---|
| 3509 | & ELF_LINK_HASH_DEF_REGULAR)))
|
|---|
| 3510 | || (info->shared
|
|---|
| 3511 | && (!info->symbolic
|
|---|
| 3512 | || !(h->root.elf_link_hash_flags
|
|---|
| 3513 | & ELF_LINK_HASH_DEF_REGULAR))
|
|---|
| 3514 | && (input_section->flags & SEC_ALLOC)
|
|---|
| 3515 | && (r_type == R_ALPHA_REFLONG
|
|---|
| 3516 | || r_type == R_ALPHA_REFQUAD
|
|---|
| 3517 | || r_type == R_ALPHA_LITERAL)))
|
|---|
| 3518 | {
|
|---|
| 3519 | /* In these cases, we don't need the relocation value.
|
|---|
| 3520 | We check specially because in some obscure cases
|
|---|
| 3521 | sec->output_section will be NULL. */
|
|---|
| 3522 | relocation = 0;
|
|---|
| 3523 | }
|
|---|
| 3524 | #else
|
|---|
| 3525 | /* FIXME: Are not these obscure cases simply bugs? Let's
|
|---|
| 3526 | get something working and come back to this. */
|
|---|
| 3527 | if (sec->output_section == NULL)
|
|---|
| 3528 | relocation = 0;
|
|---|
| 3529 | #endif /* rth_notdef */
|
|---|
| 3530 | else
|
|---|
| 3531 | {
|
|---|
| 3532 | relocation = (h->root.root.u.def.value
|
|---|
| 3533 | + sec->output_section->vma
|
|---|
| 3534 | + sec->output_offset);
|
|---|
| 3535 | }
|
|---|
| 3536 | }
|
|---|
| 3537 | else if (h->root.root.type == bfd_link_hash_undefweak)
|
|---|
| 3538 | relocation = 0;
|
|---|
| 3539 | else if (info->shared && !info->symbolic
|
|---|
| 3540 | && !info->no_undefined
|
|---|
| 3541 | && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
|
|---|
| 3542 | relocation = 0;
|
|---|
| 3543 | else
|
|---|
| 3544 | {
|
|---|
| 3545 | if (!((*info->callbacks->undefined_symbol)
|
|---|
| 3546 | (info, h->root.root.root.string, input_bfd,
|
|---|
| 3547 | input_section, rel->r_offset,
|
|---|
| 3548 | (!info->shared || info->no_undefined
|
|---|
| 3549 | || ELF_ST_VISIBILITY (h->root.other)))))
|
|---|
| 3550 | return false;
|
|---|
| 3551 | relocation = 0;
|
|---|
| 3552 | }
|
|---|
| 3553 | }
|
|---|
| 3554 | addend = rel->r_addend;
|
|---|
| 3555 |
|
|---|
| 3556 | switch (r_type)
|
|---|
| 3557 | {
|
|---|
| 3558 | case R_ALPHA_GPDISP:
|
|---|
| 3559 | {
|
|---|
| 3560 | bfd_byte *p_ldah, *p_lda;
|
|---|
| 3561 |
|
|---|
| 3562 | BFD_ASSERT(gp != 0);
|
|---|
| 3563 |
|
|---|
| 3564 | relocation = (input_section->output_section->vma
|
|---|
| 3565 | + input_section->output_offset
|
|---|
| 3566 | + rel->r_offset);
|
|---|
| 3567 |
|
|---|
| 3568 | p_ldah = contents + rel->r_offset - input_section->vma;
|
|---|
| 3569 | p_lda = p_ldah + rel->r_addend;
|
|---|
| 3570 |
|
|---|
| 3571 | r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - relocation,
|
|---|
| 3572 | p_ldah, p_lda);
|
|---|
| 3573 | }
|
|---|
| 3574 | break;
|
|---|
| 3575 |
|
|---|
| 3576 | case R_ALPHA_OP_PUSH:
|
|---|
| 3577 | case R_ALPHA_OP_STORE:
|
|---|
| 3578 | case R_ALPHA_OP_PSUB:
|
|---|
| 3579 | case R_ALPHA_OP_PRSHIFT:
|
|---|
| 3580 | /* We hate these silly beasts. */
|
|---|
| 3581 | abort ();
|
|---|
| 3582 |
|
|---|
| 3583 | case R_ALPHA_LITERAL:
|
|---|
| 3584 | {
|
|---|
| 3585 | struct alpha_elf_got_entry *gotent;
|
|---|
| 3586 | boolean dynamic_symbol;
|
|---|
| 3587 |
|
|---|
| 3588 | BFD_ASSERT(sgot != NULL);
|
|---|
| 3589 | BFD_ASSERT(gp != 0);
|
|---|
| 3590 |
|
|---|
| 3591 | if (h != NULL)
|
|---|
| 3592 | {
|
|---|
| 3593 | gotent = h->got_entries;
|
|---|
| 3594 | dynamic_symbol = alpha_elf_dynamic_symbol_p (&h->root, info);
|
|---|
| 3595 | }
|
|---|
| 3596 | else
|
|---|
| 3597 | {
|
|---|
| 3598 | gotent = (alpha_elf_tdata(input_bfd)->
|
|---|
| 3599 | local_got_entries[r_symndx]);
|
|---|
| 3600 | dynamic_symbol = false;
|
|---|
| 3601 | }
|
|---|
| 3602 |
|
|---|
| 3603 | BFD_ASSERT(gotent != NULL);
|
|---|
| 3604 |
|
|---|
| 3605 | while (gotent->gotobj != gotobj || gotent->addend != addend)
|
|---|
| 3606 | gotent = gotent->next;
|
|---|
| 3607 |
|
|---|
| 3608 | BFD_ASSERT(gotent->use_count >= 1);
|
|---|
| 3609 |
|
|---|
| 3610 | /* Initialize the .got entry's value. */
|
|---|
| 3611 | if (!(gotent->flags & ALPHA_ELF_GOT_ENTRY_RELOCS_DONE))
|
|---|
| 3612 | {
|
|---|
| 3613 | bfd_put_64 (output_bfd, relocation+addend,
|
|---|
| 3614 | sgot->contents + gotent->got_offset);
|
|---|
| 3615 |
|
|---|
| 3616 | /* If the symbol has been forced local, output a
|
|---|
| 3617 | RELATIVE reloc, otherwise it will be handled in
|
|---|
| 3618 | finish_dynamic_symbol. */
|
|---|
| 3619 | if (info->shared && !dynamic_symbol)
|
|---|
| 3620 | {
|
|---|
| 3621 | Elf_Internal_Rela outrel;
|
|---|
| 3622 |
|
|---|
| 3623 | BFD_ASSERT(srelgot != NULL);
|
|---|
| 3624 |
|
|---|
| 3625 | outrel.r_offset = (sgot->output_section->vma
|
|---|
| 3626 | + sgot->output_offset
|
|---|
| 3627 | + gotent->got_offset);
|
|---|
| 3628 | outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
|
|---|
| 3629 | outrel.r_addend = 0;
|
|---|
| 3630 |
|
|---|
| 3631 | bfd_elf64_swap_reloca_out (output_bfd, &outrel,
|
|---|
| 3632 | ((Elf64_External_Rela *)
|
|---|
| 3633 | srelgot->contents)
|
|---|
| 3634 | + srelgot->reloc_count++);
|
|---|
| 3635 | BFD_ASSERT (sizeof (Elf64_External_Rela)
|
|---|
| 3636 | * srelgot->reloc_count
|
|---|
| 3637 | <= srelgot->_cooked_size);
|
|---|
| 3638 | }
|
|---|
| 3639 |
|
|---|
| 3640 | gotent->flags |= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE;
|
|---|
| 3641 | }
|
|---|
| 3642 |
|
|---|
| 3643 | /* Figure the gprel relocation. */
|
|---|
| 3644 | addend = 0;
|
|---|
| 3645 | relocation = (sgot->output_section->vma
|
|---|
| 3646 | + sgot->output_offset
|
|---|
| 3647 | + gotent->got_offset);
|
|---|
| 3648 | relocation -= gp;
|
|---|
| 3649 | }
|
|---|
| 3650 | /* overflow handled by _bfd_final_link_relocate */
|
|---|
| 3651 | goto default_reloc;
|
|---|
| 3652 |
|
|---|
| 3653 | case R_ALPHA_GPREL32:
|
|---|
| 3654 | case R_ALPHA_GPRELLOW:
|
|---|
| 3655 | BFD_ASSERT(gp != 0);
|
|---|
| 3656 | relocation -= gp;
|
|---|
| 3657 | goto default_reloc;
|
|---|
| 3658 |
|
|---|
| 3659 | case R_ALPHA_GPRELHIGH:
|
|---|
| 3660 | BFD_ASSERT(gp != 0);
|
|---|
| 3661 | relocation -= gp;
|
|---|
| 3662 | relocation += addend;
|
|---|
| 3663 | addend = 0;
|
|---|
| 3664 | relocation = (((bfd_signed_vma) relocation >> 16)
|
|---|
| 3665 | + ((relocation >> 15) & 1));
|
|---|
| 3666 | goto default_reloc;
|
|---|
| 3667 |
|
|---|
| 3668 | case R_ALPHA_BRADDR:
|
|---|
| 3669 | case R_ALPHA_HINT:
|
|---|
| 3670 | /* The regular PC-relative stuff measures from the start of
|
|---|
| 3671 | the instruction rather than the end. */
|
|---|
| 3672 | addend -= 4;
|
|---|
| 3673 | goto default_reloc;
|
|---|
| 3674 |
|
|---|
| 3675 | case R_ALPHA_REFLONG:
|
|---|
| 3676 | case R_ALPHA_REFQUAD:
|
|---|
| 3677 | {
|
|---|
| 3678 | Elf_Internal_Rela outrel;
|
|---|
| 3679 | boolean skip;
|
|---|
| 3680 |
|
|---|
| 3681 | /* Careful here to remember RELATIVE relocations for global
|
|---|
| 3682 | variables for symbolic shared objects. */
|
|---|
| 3683 |
|
|---|
| 3684 | if (h && alpha_elf_dynamic_symbol_p (&h->root, info))
|
|---|
| 3685 | {
|
|---|
| 3686 | BFD_ASSERT(h->root.dynindx != -1);
|
|---|
| 3687 | outrel.r_info = ELF64_R_INFO(h->root.dynindx, r_type);
|
|---|
| 3688 | outrel.r_addend = addend;
|
|---|
| 3689 | addend = 0, relocation = 0;
|
|---|
| 3690 | }
|
|---|
| 3691 | else if (info->shared && (input_section->flags & SEC_ALLOC))
|
|---|
| 3692 | {
|
|---|
| 3693 | outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
|
|---|
| 3694 | outrel.r_addend = 0;
|
|---|
| 3695 | }
|
|---|
| 3696 | else
|
|---|
| 3697 | goto default_reloc;
|
|---|
| 3698 |
|
|---|
| 3699 | if (!srel)
|
|---|
| 3700 | {
|
|---|
| 3701 | const char *name;
|
|---|
| 3702 |
|
|---|
| 3703 | name = (bfd_elf_string_from_elf_section
|
|---|
| 3704 | (input_bfd, elf_elfheader(input_bfd)->e_shstrndx,
|
|---|
| 3705 | elf_section_data(input_section)->rel_hdr.sh_name));
|
|---|
| 3706 | BFD_ASSERT(name != NULL);
|
|---|
| 3707 |
|
|---|
| 3708 | srel = bfd_get_section_by_name (dynobj, name);
|
|---|
| 3709 | BFD_ASSERT(srel != NULL);
|
|---|
| 3710 | }
|
|---|
| 3711 |
|
|---|
| 3712 | skip = false;
|
|---|
| 3713 |
|
|---|
| 3714 | if (elf_section_data (input_section)->stab_info == NULL)
|
|---|
| 3715 | outrel.r_offset = rel->r_offset;
|
|---|
| 3716 | else
|
|---|
| 3717 | {
|
|---|
| 3718 | bfd_vma off;
|
|---|
| 3719 |
|
|---|
| 3720 | off = (_bfd_stab_section_offset
|
|---|
| 3721 | (output_bfd, &elf_hash_table (info)->stab_info,
|
|---|
| 3722 | input_section,
|
|---|
| 3723 | &elf_section_data (input_section)->stab_info,
|
|---|
| 3724 | rel->r_offset));
|
|---|
| 3725 | if (off == (bfd_vma) -1)
|
|---|
| 3726 | skip = true;
|
|---|
| 3727 | outrel.r_offset = off;
|
|---|
| 3728 | }
|
|---|
| 3729 |
|
|---|
| 3730 | if (! skip)
|
|---|
| 3731 | outrel.r_offset += (input_section->output_section->vma
|
|---|
| 3732 | + input_section->output_offset);
|
|---|
| 3733 | else
|
|---|
| 3734 | memset (&outrel, 0, sizeof outrel);
|
|---|
| 3735 |
|
|---|
| 3736 | bfd_elf64_swap_reloca_out (output_bfd, &outrel,
|
|---|
| 3737 | ((Elf64_External_Rela *)
|
|---|
| 3738 | srel->contents)
|
|---|
| 3739 | + srel->reloc_count++);
|
|---|
| 3740 | BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count
|
|---|
| 3741 | <= srel->_cooked_size);
|
|---|
| 3742 | }
|
|---|
| 3743 | goto default_reloc;
|
|---|
| 3744 |
|
|---|
| 3745 | default:
|
|---|
| 3746 | default_reloc:
|
|---|
| 3747 | r = _bfd_final_link_relocate (howto, input_bfd, input_section,
|
|---|
| 3748 | contents, rel->r_offset, relocation,
|
|---|
| 3749 | addend);
|
|---|
| 3750 | break;
|
|---|
| 3751 | }
|
|---|
| 3752 |
|
|---|
| 3753 | switch (r)
|
|---|
| 3754 | {
|
|---|
| 3755 | case bfd_reloc_ok:
|
|---|
| 3756 | break;
|
|---|
| 3757 |
|
|---|
| 3758 | case bfd_reloc_overflow:
|
|---|
| 3759 | {
|
|---|
| 3760 | const char *name;
|
|---|
| 3761 |
|
|---|
| 3762 | if (h != NULL)
|
|---|
| 3763 | name = h->root.root.root.string;
|
|---|
| 3764 | else
|
|---|
| 3765 | {
|
|---|
| 3766 | name = (bfd_elf_string_from_elf_section
|
|---|
| 3767 | (input_bfd, symtab_hdr->sh_link, sym->st_name));
|
|---|
| 3768 | if (name == NULL)
|
|---|
| 3769 | return false;
|
|---|
| 3770 | if (*name == '\0')
|
|---|
| 3771 | name = bfd_section_name (input_bfd, sec);
|
|---|
| 3772 | }
|
|---|
| 3773 | if (! ((*info->callbacks->reloc_overflow)
|
|---|
| 3774 | (info, name, howto->name, (bfd_vma) 0,
|
|---|
| 3775 | input_bfd, input_section, rel->r_offset)))
|
|---|
| 3776 | return false;
|
|---|
| 3777 | }
|
|---|
| 3778 | break;
|
|---|
| 3779 |
|
|---|
| 3780 | default:
|
|---|
| 3781 | case bfd_reloc_outofrange:
|
|---|
| 3782 | abort ();
|
|---|
| 3783 | }
|
|---|
| 3784 | }
|
|---|
| 3785 |
|
|---|
| 3786 | return true;
|
|---|
| 3787 | }
|
|---|
| 3788 |
|
|---|
| 3789 | /* Finish up dynamic symbol handling. We set the contents of various
|
|---|
| 3790 | dynamic sections here. */
|
|---|
| 3791 |
|
|---|
| 3792 | static boolean
|
|---|
| 3793 | elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym)
|
|---|
| 3794 | bfd *output_bfd;
|
|---|
| 3795 | struct bfd_link_info *info;
|
|---|
| 3796 | struct elf_link_hash_entry *h;
|
|---|
| 3797 | Elf_Internal_Sym *sym;
|
|---|
| 3798 | {
|
|---|
| 3799 | bfd *dynobj = elf_hash_table(info)->dynobj;
|
|---|
| 3800 |
|
|---|
| 3801 | if (h->plt.offset != MINUS_ONE)
|
|---|
| 3802 | {
|
|---|
| 3803 | /* Fill in the .plt entry for this symbol. */
|
|---|
| 3804 | asection *splt, *sgot, *srel;
|
|---|
| 3805 | Elf_Internal_Rela outrel;
|
|---|
| 3806 | bfd_vma got_addr, plt_addr;
|
|---|
| 3807 | bfd_vma plt_index;
|
|---|
| 3808 | struct alpha_elf_got_entry *gotent;
|
|---|
| 3809 |
|
|---|
| 3810 | BFD_ASSERT (h->dynindx != -1);
|
|---|
| 3811 |
|
|---|
| 3812 | /* The first .got entry will be updated by the .plt with the
|
|---|
| 3813 | address of the target function. */
|
|---|
| 3814 | gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
|
|---|
| 3815 | BFD_ASSERT (gotent && gotent->addend == 0);
|
|---|
| 3816 |
|
|---|
| 3817 | splt = bfd_get_section_by_name (dynobj, ".plt");
|
|---|
| 3818 | BFD_ASSERT (splt != NULL);
|
|---|
| 3819 | srel = bfd_get_section_by_name (dynobj, ".rela.plt");
|
|---|
| 3820 | BFD_ASSERT (srel != NULL);
|
|---|
| 3821 | sgot = alpha_elf_tdata (gotent->gotobj)->got;
|
|---|
| 3822 | BFD_ASSERT (sgot != NULL);
|
|---|
| 3823 |
|
|---|
| 3824 | got_addr = (sgot->output_section->vma
|
|---|
| 3825 | + sgot->output_offset
|
|---|
| 3826 | + gotent->got_offset);
|
|---|
| 3827 | plt_addr = (splt->output_section->vma
|
|---|
| 3828 | + splt->output_offset
|
|---|
| 3829 | + h->plt.offset);
|
|---|
| 3830 |
|
|---|
| 3831 | plt_index = (h->plt.offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
|
|---|
| 3832 |
|
|---|
| 3833 | /* Fill in the entry in the procedure linkage table. */
|
|---|
| 3834 | {
|
|---|
| 3835 | unsigned insn1, insn2, insn3;
|
|---|
| 3836 |
|
|---|
| 3837 | insn1 = PLT_ENTRY_WORD1 | ((-(h->plt.offset + 4) >> 2) & 0x1fffff);
|
|---|
| 3838 | insn2 = PLT_ENTRY_WORD2;
|
|---|
| 3839 | insn3 = PLT_ENTRY_WORD3;
|
|---|
| 3840 |
|
|---|
| 3841 | bfd_put_32 (output_bfd, insn1, splt->contents + h->plt.offset);
|
|---|
| 3842 | bfd_put_32 (output_bfd, insn2, splt->contents + h->plt.offset + 4);
|
|---|
| 3843 | bfd_put_32 (output_bfd, insn3, splt->contents + h->plt.offset + 8);
|
|---|
| 3844 | }
|
|---|
| 3845 |
|
|---|
| 3846 | /* Fill in the entry in the .rela.plt section. */
|
|---|
| 3847 | outrel.r_offset = got_addr;
|
|---|
| 3848 | outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT);
|
|---|
| 3849 | outrel.r_addend = 0;
|
|---|
| 3850 |
|
|---|
| 3851 | bfd_elf64_swap_reloca_out (output_bfd, &outrel,
|
|---|
| 3852 | ((Elf64_External_Rela *)srel->contents
|
|---|
| 3853 | + plt_index));
|
|---|
| 3854 |
|
|---|
| 3855 | if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
|
|---|
| 3856 | {
|
|---|
| 3857 | /* Mark the symbol as undefined, rather than as defined in the
|
|---|
| 3858 | .plt section. Leave the value alone. */
|
|---|
| 3859 | sym->st_shndx = SHN_UNDEF;
|
|---|
| 3860 | }
|
|---|
| 3861 |
|
|---|
| 3862 | /* Fill in the entries in the .got. */
|
|---|
| 3863 | bfd_put_64 (output_bfd, plt_addr, sgot->contents + gotent->got_offset);
|
|---|
| 3864 |
|
|---|
| 3865 | /* Subsequent .got entries will continue to bounce through the .plt. */
|
|---|
| 3866 | if (gotent->next)
|
|---|
| 3867 | {
|
|---|
| 3868 | srel = bfd_get_section_by_name (dynobj, ".rela.got");
|
|---|
| 3869 | BFD_ASSERT (! info->shared || srel != NULL);
|
|---|
| 3870 |
|
|---|
| 3871 | gotent = gotent->next;
|
|---|
| 3872 | do
|
|---|
| 3873 | {
|
|---|
| 3874 | sgot = alpha_elf_tdata(gotent->gotobj)->got;
|
|---|
| 3875 | BFD_ASSERT(sgot != NULL);
|
|---|
| 3876 | BFD_ASSERT(gotent->addend == 0);
|
|---|
| 3877 |
|
|---|
| 3878 | bfd_put_64 (output_bfd, plt_addr,
|
|---|
| 3879 | sgot->contents + gotent->got_offset);
|
|---|
| 3880 |
|
|---|
| 3881 | if (info->shared)
|
|---|
| 3882 | {
|
|---|
| 3883 | outrel.r_offset = (sgot->output_section->vma
|
|---|
| 3884 | + sgot->output_offset
|
|---|
| 3885 | + gotent->got_offset);
|
|---|
| 3886 | outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
|
|---|
| 3887 | outrel.r_addend = 0;
|
|---|
| 3888 |
|
|---|
| 3889 | bfd_elf64_swap_reloca_out (output_bfd, &outrel,
|
|---|
| 3890 | ((Elf64_External_Rela *)
|
|---|
| 3891 | srel->contents)
|
|---|
| 3892 | + srel->reloc_count++);
|
|---|
| 3893 | BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count
|
|---|
| 3894 | <= srel->_cooked_size);
|
|---|
| 3895 | }
|
|---|
| 3896 |
|
|---|
| 3897 | gotent = gotent->next;
|
|---|
| 3898 | }
|
|---|
| 3899 | while (gotent != NULL);
|
|---|
| 3900 | }
|
|---|
| 3901 | }
|
|---|
| 3902 | else if (alpha_elf_dynamic_symbol_p (h, info))
|
|---|
| 3903 | {
|
|---|
| 3904 | /* Fill in the dynamic relocations for this symbol's .got entries. */
|
|---|
| 3905 | asection *srel;
|
|---|
| 3906 | Elf_Internal_Rela outrel;
|
|---|
| 3907 | struct alpha_elf_got_entry *gotent;
|
|---|
| 3908 |
|
|---|
| 3909 | srel = bfd_get_section_by_name (dynobj, ".rela.got");
|
|---|
| 3910 | BFD_ASSERT (srel != NULL);
|
|---|
| 3911 |
|
|---|
| 3912 | outrel.r_info = ELF64_R_INFO (h->dynindx, R_ALPHA_GLOB_DAT);
|
|---|
| 3913 | for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
|
|---|
| 3914 | gotent != NULL;
|
|---|
| 3915 | gotent = gotent->next)
|
|---|
| 3916 | {
|
|---|
| 3917 | asection *sgot = alpha_elf_tdata (gotent->gotobj)->got;
|
|---|
| 3918 | outrel.r_offset = (sgot->output_section->vma
|
|---|
| 3919 | + sgot->output_offset
|
|---|
| 3920 | + gotent->got_offset);
|
|---|
| 3921 | outrel.r_addend = gotent->addend;
|
|---|
| 3922 |
|
|---|
| 3923 | bfd_elf64_swap_reloca_out (output_bfd, &outrel,
|
|---|
| 3924 | ((Elf64_External_Rela *)srel->contents
|
|---|
| 3925 | + srel->reloc_count++));
|
|---|
| 3926 | BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count
|
|---|
| 3927 | <= srel->_cooked_size);
|
|---|
| 3928 | }
|
|---|
| 3929 | }
|
|---|
| 3930 |
|
|---|
| 3931 | /* Mark some specially defined symbols as absolute. */
|
|---|
| 3932 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0
|
|---|
| 3933 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
|
|---|
| 3934 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
|
|---|
| 3935 | sym->st_shndx = SHN_ABS;
|
|---|
| 3936 |
|
|---|
| 3937 | return true;
|
|---|
| 3938 | }
|
|---|
| 3939 |
|
|---|
| 3940 | /* Finish up the dynamic sections. */
|
|---|
| 3941 |
|
|---|
| 3942 | static boolean
|
|---|
| 3943 | elf64_alpha_finish_dynamic_sections (output_bfd, info)
|
|---|
| 3944 | bfd *output_bfd;
|
|---|
| 3945 | struct bfd_link_info *info;
|
|---|
| 3946 | {
|
|---|
| 3947 | bfd *dynobj;
|
|---|
| 3948 | asection *sdyn;
|
|---|
| 3949 |
|
|---|
| 3950 | dynobj = elf_hash_table (info)->dynobj;
|
|---|
| 3951 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
|
|---|
| 3952 |
|
|---|
| 3953 | if (elf_hash_table (info)->dynamic_sections_created)
|
|---|
| 3954 | {
|
|---|
| 3955 | asection *splt;
|
|---|
| 3956 | Elf64_External_Dyn *dyncon, *dynconend;
|
|---|
| 3957 |
|
|---|
| 3958 | splt = bfd_get_section_by_name (dynobj, ".plt");
|
|---|
| 3959 | BFD_ASSERT (splt != NULL && sdyn != NULL);
|
|---|
| 3960 |
|
|---|
| 3961 | dyncon = (Elf64_External_Dyn *) sdyn->contents;
|
|---|
| 3962 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
|
|---|
| 3963 | for (; dyncon < dynconend; dyncon++)
|
|---|
| 3964 | {
|
|---|
| 3965 | Elf_Internal_Dyn dyn;
|
|---|
| 3966 | const char *name;
|
|---|
| 3967 | asection *s;
|
|---|
| 3968 |
|
|---|
| 3969 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
|
|---|
| 3970 |
|
|---|
| 3971 | switch (dyn.d_tag)
|
|---|
| 3972 | {
|
|---|
| 3973 | case DT_PLTGOT:
|
|---|
| 3974 | name = ".plt";
|
|---|
| 3975 | goto get_vma;
|
|---|
| 3976 | case DT_PLTRELSZ:
|
|---|
| 3977 | name = ".rela.plt";
|
|---|
| 3978 | goto get_size;
|
|---|
| 3979 | case DT_JMPREL:
|
|---|
| 3980 | name = ".rela.plt";
|
|---|
| 3981 | goto get_vma;
|
|---|
| 3982 |
|
|---|
| 3983 | case DT_RELASZ:
|
|---|
| 3984 | /* My interpretation of the TIS v1.1 ELF document indicates
|
|---|
| 3985 | that RELASZ should not include JMPREL. This is not what
|
|---|
| 3986 | the rest of the BFD does. It is, however, what the
|
|---|
| 3987 | glibc ld.so wants. Do this fixup here until we found
|
|---|
| 3988 | out who is right. */
|
|---|
| 3989 | s = bfd_get_section_by_name (output_bfd, ".rela.plt");
|
|---|
| 3990 | if (s)
|
|---|
| 3991 | {
|
|---|
| 3992 | dyn.d_un.d_val -=
|
|---|
| 3993 | (s->_cooked_size ? s->_cooked_size : s->_raw_size);
|
|---|
| 3994 | }
|
|---|
| 3995 | break;
|
|---|
| 3996 |
|
|---|
| 3997 | get_vma:
|
|---|
| 3998 | s = bfd_get_section_by_name (output_bfd, name);
|
|---|
| 3999 | dyn.d_un.d_ptr = (s ? s->vma : 0);
|
|---|
| 4000 | break;
|
|---|
| 4001 |
|
|---|
| 4002 | get_size:
|
|---|
| 4003 | s = bfd_get_section_by_name (output_bfd, name);
|
|---|
| 4004 | dyn.d_un.d_val =
|
|---|
| 4005 | (s->_cooked_size ? s->_cooked_size : s->_raw_size);
|
|---|
| 4006 | break;
|
|---|
| 4007 | }
|
|---|
| 4008 |
|
|---|
| 4009 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
|
|---|
| 4010 | }
|
|---|
| 4011 |
|
|---|
| 4012 | /* Initialize the PLT0 entry */
|
|---|
| 4013 | if (splt->_raw_size > 0)
|
|---|
| 4014 | {
|
|---|
| 4015 | bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents);
|
|---|
| 4016 | bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4);
|
|---|
| 4017 | bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8);
|
|---|
| 4018 | bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12);
|
|---|
| 4019 |
|
|---|
| 4020 | /* The next two words will be filled in by ld.so */
|
|---|
| 4021 | bfd_put_64 (output_bfd, 0, splt->contents + 16);
|
|---|
| 4022 | bfd_put_64 (output_bfd, 0, splt->contents + 24);
|
|---|
| 4023 |
|
|---|
| 4024 | elf_section_data (splt->output_section)->this_hdr.sh_entsize =
|
|---|
| 4025 | PLT_HEADER_SIZE;
|
|---|
| 4026 | }
|
|---|
| 4027 | }
|
|---|
| 4028 |
|
|---|
| 4029 | return true;
|
|---|
| 4030 | }
|
|---|
| 4031 |
|
|---|
| 4032 | /* We need to use a special link routine to handle the .reginfo and
|
|---|
| 4033 | the .mdebug sections. We need to merge all instances of these
|
|---|
| 4034 | sections together, not write them all out sequentially. */
|
|---|
| 4035 |
|
|---|
| 4036 | static boolean
|
|---|
| 4037 | elf64_alpha_final_link (abfd, info)
|
|---|
| 4038 | bfd *abfd;
|
|---|
| 4039 | struct bfd_link_info *info;
|
|---|
| 4040 | {
|
|---|
| 4041 | asection *o;
|
|---|
| 4042 | struct bfd_link_order *p;
|
|---|
| 4043 | asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
|
|---|
| 4044 | struct ecoff_debug_info debug;
|
|---|
| 4045 | const struct ecoff_debug_swap *swap
|
|---|
| 4046 | = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
|
|---|
| 4047 | HDRR *symhdr = &debug.symbolic_header;
|
|---|
| 4048 | PTR mdebug_handle = NULL;
|
|---|
| 4049 |
|
|---|
| 4050 | #if 0
|
|---|
| 4051 | if (++ngots == 2)
|
|---|
| 4052 | {
|
|---|
| 4053 | (*info->callbacks->warning)
|
|---|
| 4054 | (info, _("using multiple gp values"), (char *) NULL,
|
|---|
| 4055 | output_bfd, (asection *) NULL, (bfd_vma) 0);
|
|---|
| 4056 | }
|
|---|
| 4057 | #endif
|
|---|
| 4058 |
|
|---|
| 4059 | /* Go through the sections and collect the .reginfo and .mdebug
|
|---|
| 4060 | information. */
|
|---|
| 4061 | reginfo_sec = NULL;
|
|---|
| 4062 | mdebug_sec = NULL;
|
|---|
| 4063 | gptab_data_sec = NULL;
|
|---|
| 4064 | gptab_bss_sec = NULL;
|
|---|
| 4065 | for (o = abfd->sections; o != (asection *) NULL; o = o->next)
|
|---|
| 4066 | {
|
|---|
| 4067 | #ifdef ERIC_neverdef
|
|---|
| 4068 | if (strcmp (o->name, ".reginfo") == 0)
|
|---|
| 4069 | {
|
|---|
| 4070 | memset (®info, 0, sizeof reginfo);
|
|---|
| 4071 |
|
|---|
| 4072 | /* We have found the .reginfo section in the output file.
|
|---|
| 4073 | Look through all the link_orders comprising it and merge
|
|---|
| 4074 | the information together. */
|
|---|
| 4075 | for (p = o->link_order_head;
|
|---|
| 4076 | p != (struct bfd_link_order *) NULL;
|
|---|
| 4077 | p = p->next)
|
|---|
| 4078 | {
|
|---|
| 4079 | asection *input_section;
|
|---|
| 4080 | bfd *input_bfd;
|
|---|
| 4081 | Elf64_External_RegInfo ext;
|
|---|
| 4082 | Elf64_RegInfo sub;
|
|---|
| 4083 |
|
|---|
| 4084 | if (p->type != bfd_indirect_link_order)
|
|---|
| 4085 | {
|
|---|
| 4086 | if (p->type == bfd_fill_link_order)
|
|---|
| 4087 | continue;
|
|---|
| 4088 | abort ();
|
|---|
| 4089 | }
|
|---|
| 4090 |
|
|---|
| 4091 | input_section = p->u.indirect.section;
|
|---|
| 4092 | input_bfd = input_section->owner;
|
|---|
| 4093 |
|
|---|
| 4094 | /* The linker emulation code has probably clobbered the
|
|---|
| 4095 | size to be zero bytes. */
|
|---|
| 4096 | if (input_section->_raw_size == 0)
|
|---|
| 4097 | input_section->_raw_size = sizeof (Elf64_External_RegInfo);
|
|---|
| 4098 |
|
|---|
| 4099 | if (! bfd_get_section_contents (input_bfd, input_section,
|
|---|
| 4100 | (PTR) &ext,
|
|---|
| 4101 | (file_ptr) 0,
|
|---|
| 4102 | sizeof ext))
|
|---|
| 4103 | return false;
|
|---|
| 4104 |
|
|---|
| 4105 | bfd_alpha_elf64_swap_reginfo_in (input_bfd, &ext, &sub);
|
|---|
| 4106 |
|
|---|
| 4107 | reginfo.ri_gprmask |= sub.ri_gprmask;
|
|---|
| 4108 | reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
|
|---|
| 4109 | reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
|
|---|
| 4110 | reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
|
|---|
| 4111 | reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
|
|---|
| 4112 |
|
|---|
| 4113 | /* ri_gp_value is set by the function
|
|---|
| 4114 | alpha_elf_section_processing when the section is
|
|---|
| 4115 | finally written out. */
|
|---|
| 4116 |
|
|---|
| 4117 | /* Hack: reset the SEC_HAS_CONTENTS flag so that
|
|---|
| 4118 | elf_link_input_bfd ignores this section. */
|
|---|
| 4119 | input_section->flags &=~ SEC_HAS_CONTENTS;
|
|---|
| 4120 | }
|
|---|
| 4121 |
|
|---|
| 4122 | /* Force the section size to the value we want. */
|
|---|
| 4123 | o->_raw_size = sizeof (Elf64_External_RegInfo);
|
|---|
| 4124 |
|
|---|
| 4125 | /* Skip this section later on (I don't think this currently
|
|---|
| 4126 | matters, but someday it might). */
|
|---|
| 4127 | o->link_order_head = (struct bfd_link_order *) NULL;
|
|---|
| 4128 |
|
|---|
| 4129 | reginfo_sec = o;
|
|---|
| 4130 | }
|
|---|
| 4131 | #endif
|
|---|
| 4132 |
|
|---|
| 4133 | if (strcmp (o->name, ".mdebug") == 0)
|
|---|
| 4134 | {
|
|---|
| 4135 | struct extsym_info einfo;
|
|---|
| 4136 |
|
|---|
| 4137 | /* We have found the .mdebug section in the output file.
|
|---|
| 4138 | Look through all the link_orders comprising it and merge
|
|---|
| 4139 | the information together. */
|
|---|
| 4140 | symhdr->magic = swap->sym_magic;
|
|---|
| 4141 | /* FIXME: What should the version stamp be? */
|
|---|
| 4142 | symhdr->vstamp = 0;
|
|---|
| 4143 | symhdr->ilineMax = 0;
|
|---|
| 4144 | symhdr->cbLine = 0;
|
|---|
| 4145 | symhdr->idnMax = 0;
|
|---|
| 4146 | symhdr->ipdMax = 0;
|
|---|
| 4147 | symhdr->isymMax = 0;
|
|---|
| 4148 | symhdr->ioptMax = 0;
|
|---|
| 4149 | symhdr->iauxMax = 0;
|
|---|
| 4150 | symhdr->issMax = 0;
|
|---|
| 4151 | symhdr->issExtMax = 0;
|
|---|
| 4152 | symhdr->ifdMax = 0;
|
|---|
| 4153 | symhdr->crfd = 0;
|
|---|
| 4154 | symhdr->iextMax = 0;
|
|---|
| 4155 |
|
|---|
| 4156 | /* We accumulate the debugging information itself in the
|
|---|
| 4157 | debug_info structure. */
|
|---|
| 4158 | debug.line = NULL;
|
|---|
| 4159 | debug.external_dnr = NULL;
|
|---|
| 4160 | debug.external_pdr = NULL;
|
|---|
| 4161 | debug.external_sym = NULL;
|
|---|
| 4162 | debug.external_opt = NULL;
|
|---|
| 4163 | debug.external_aux = NULL;
|
|---|
| 4164 | debug.ss = NULL;
|
|---|
| 4165 | debug.ssext = debug.ssext_end = NULL;
|
|---|
| 4166 | debug.external_fdr = NULL;
|
|---|
| 4167 | debug.external_rfd = NULL;
|
|---|
| 4168 | debug.external_ext = debug.external_ext_end = NULL;
|
|---|
| 4169 |
|
|---|
| 4170 | mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
|
|---|
| 4171 | if (mdebug_handle == (PTR) NULL)
|
|---|
| 4172 | return false;
|
|---|
| 4173 |
|
|---|
| 4174 | if (1)
|
|---|
| 4175 | {
|
|---|
| 4176 | asection *s;
|
|---|
| 4177 | EXTR esym;
|
|---|
| 4178 | bfd_vma last;
|
|---|
| 4179 | unsigned int i;
|
|---|
| 4180 | static const char * const name[] =
|
|---|
| 4181 | {
|
|---|
| 4182 | ".text", ".init", ".fini", ".data",
|
|---|
| 4183 | ".rodata", ".sdata", ".sbss", ".bss"
|
|---|
| 4184 | };
|
|---|
| 4185 | static const int sc[] = { scText, scInit, scFini, scData,
|
|---|
| 4186 | scRData, scSData, scSBss, scBss };
|
|---|
| 4187 |
|
|---|
| 4188 | esym.jmptbl = 0;
|
|---|
| 4189 | esym.cobol_main = 0;
|
|---|
| 4190 | esym.weakext = 0;
|
|---|
| 4191 | esym.reserved = 0;
|
|---|
| 4192 | esym.ifd = ifdNil;
|
|---|
| 4193 | esym.asym.iss = issNil;
|
|---|
| 4194 | esym.asym.st = stLocal;
|
|---|
| 4195 | esym.asym.reserved = 0;
|
|---|
| 4196 | esym.asym.index = indexNil;
|
|---|
| 4197 | for (i = 0; i < 8; i++)
|
|---|
| 4198 | {
|
|---|
| 4199 | esym.asym.sc = sc[i];
|
|---|
| 4200 | s = bfd_get_section_by_name (abfd, name[i]);
|
|---|
| 4201 | if (s != NULL)
|
|---|
| 4202 | {
|
|---|
| 4203 | esym.asym.value = s->vma;
|
|---|
| 4204 | last = s->vma + s->_raw_size;
|
|---|
| 4205 | }
|
|---|
| 4206 | else
|
|---|
| 4207 | esym.asym.value = last;
|
|---|
| 4208 |
|
|---|
| 4209 | if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
|
|---|
| 4210 | name[i], &esym))
|
|---|
| 4211 | return false;
|
|---|
| 4212 | }
|
|---|
| 4213 | }
|
|---|
| 4214 |
|
|---|
| 4215 | for (p = o->link_order_head;
|
|---|
| 4216 | p != (struct bfd_link_order *) NULL;
|
|---|
| 4217 | p = p->next)
|
|---|
| 4218 | {
|
|---|
| 4219 | asection *input_section;
|
|---|
| 4220 | bfd *input_bfd;
|
|---|
| 4221 | const struct ecoff_debug_swap *input_swap;
|
|---|
| 4222 | struct ecoff_debug_info input_debug;
|
|---|
| 4223 | char *eraw_src;
|
|---|
| 4224 | char *eraw_end;
|
|---|
| 4225 |
|
|---|
| 4226 | if (p->type != bfd_indirect_link_order)
|
|---|
| 4227 | {
|
|---|
| 4228 | if (p->type == bfd_fill_link_order)
|
|---|
| 4229 | continue;
|
|---|
| 4230 | abort ();
|
|---|
| 4231 | }
|
|---|
| 4232 |
|
|---|
| 4233 | input_section = p->u.indirect.section;
|
|---|
| 4234 | input_bfd = input_section->owner;
|
|---|
| 4235 |
|
|---|
| 4236 | if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
|
|---|
| 4237 | || (get_elf_backend_data (input_bfd)
|
|---|
| 4238 | ->elf_backend_ecoff_debug_swap) == NULL)
|
|---|
| 4239 | {
|
|---|
| 4240 | /* I don't know what a non ALPHA ELF bfd would be
|
|---|
| 4241 | doing with a .mdebug section, but I don't really
|
|---|
| 4242 | want to deal with it. */
|
|---|
| 4243 | continue;
|
|---|
| 4244 | }
|
|---|
| 4245 |
|
|---|
| 4246 | input_swap = (get_elf_backend_data (input_bfd)
|
|---|
| 4247 | ->elf_backend_ecoff_debug_swap);
|
|---|
| 4248 |
|
|---|
| 4249 | BFD_ASSERT (p->size == input_section->_raw_size);
|
|---|
| 4250 |
|
|---|
| 4251 | /* The ECOFF linking code expects that we have already
|
|---|
| 4252 | read in the debugging information and set up an
|
|---|
| 4253 | ecoff_debug_info structure, so we do that now. */
|
|---|
| 4254 | if (!elf64_alpha_read_ecoff_info (input_bfd, input_section,
|
|---|
| 4255 | &input_debug))
|
|---|
| 4256 | return false;
|
|---|
| 4257 |
|
|---|
| 4258 | if (! (bfd_ecoff_debug_accumulate
|
|---|
| 4259 | (mdebug_handle, abfd, &debug, swap, input_bfd,
|
|---|
| 4260 | &input_debug, input_swap, info)))
|
|---|
| 4261 | return false;
|
|---|
| 4262 |
|
|---|
| 4263 | /* Loop through the external symbols. For each one with
|
|---|
| 4264 | interesting information, try to find the symbol in
|
|---|
| 4265 | the linker global hash table and save the information
|
|---|
| 4266 | for the output external symbols. */
|
|---|
| 4267 | eraw_src = input_debug.external_ext;
|
|---|
| 4268 | eraw_end = (eraw_src
|
|---|
| 4269 | + (input_debug.symbolic_header.iextMax
|
|---|
| 4270 | * input_swap->external_ext_size));
|
|---|
| 4271 | for (;
|
|---|
| 4272 | eraw_src < eraw_end;
|
|---|
| 4273 | eraw_src += input_swap->external_ext_size)
|
|---|
| 4274 | {
|
|---|
| 4275 | EXTR ext;
|
|---|
| 4276 | const char *name;
|
|---|
| 4277 | struct alpha_elf_link_hash_entry *h;
|
|---|
| 4278 |
|
|---|
| 4279 | (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
|
|---|
| 4280 | if (ext.asym.sc == scNil
|
|---|
| 4281 | || ext.asym.sc == scUndefined
|
|---|
| 4282 | || ext.asym.sc == scSUndefined)
|
|---|
| 4283 | continue;
|
|---|
| 4284 |
|
|---|
| 4285 | name = input_debug.ssext + ext.asym.iss;
|
|---|
| 4286 | h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
|
|---|
| 4287 | name, false, false, true);
|
|---|
| 4288 | if (h == NULL || h->esym.ifd != -2)
|
|---|
| 4289 | continue;
|
|---|
| 4290 |
|
|---|
| 4291 | if (ext.ifd != -1)
|
|---|
| 4292 | {
|
|---|
| 4293 | BFD_ASSERT (ext.ifd
|
|---|
| 4294 | < input_debug.symbolic_header.ifdMax);
|
|---|
| 4295 | ext.ifd = input_debug.ifdmap[ext.ifd];
|
|---|
| 4296 | }
|
|---|
| 4297 |
|
|---|
| 4298 | h->esym = ext;
|
|---|
| 4299 | }
|
|---|
| 4300 |
|
|---|
| 4301 | /* Free up the information we just read. */
|
|---|
| 4302 | free (input_debug.line);
|
|---|
| 4303 | free (input_debug.external_dnr);
|
|---|
| 4304 | free (input_debug.external_pdr);
|
|---|
| 4305 | free (input_debug.external_sym);
|
|---|
| 4306 | free (input_debug.external_opt);
|
|---|
| 4307 | free (input_debug.external_aux);
|
|---|
| 4308 | free (input_debug.ss);
|
|---|
| 4309 | free (input_debug.ssext);
|
|---|
| 4310 | free (input_debug.external_fdr);
|
|---|
| 4311 | free (input_debug.external_rfd);
|
|---|
| 4312 | free (input_debug.external_ext);
|
|---|
| 4313 |
|
|---|
| 4314 | /* Hack: reset the SEC_HAS_CONTENTS flag so that
|
|---|
| 4315 | elf_link_input_bfd ignores this section. */
|
|---|
| 4316 | input_section->flags &=~ SEC_HAS_CONTENTS;
|
|---|
| 4317 | }
|
|---|
| 4318 |
|
|---|
| 4319 | #ifdef ERIC_neverdef
|
|---|
| 4320 | if (info->shared)
|
|---|
| 4321 | {
|
|---|
| 4322 | /* Create .rtproc section. */
|
|---|
| 4323 | rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
|
|---|
| 4324 | if (rtproc_sec == NULL)
|
|---|
| 4325 | {
|
|---|
| 4326 | flagword flags = (SEC_HAS_CONTENTS
|
|---|
| 4327 | | SEC_IN_MEMORY
|
|---|
| 4328 | | SEC_LINKER_CREATED
|
|---|
| 4329 | | SEC_READONLY);
|
|---|
| 4330 |
|
|---|
| 4331 | rtproc_sec = bfd_make_section (abfd, ".rtproc");
|
|---|
| 4332 | if (rtproc_sec == NULL
|
|---|
| 4333 | || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
|
|---|
| 4334 | || ! bfd_set_section_alignment (abfd, rtproc_sec, 12))
|
|---|
| 4335 | return false;
|
|---|
| 4336 | }
|
|---|
| 4337 |
|
|---|
| 4338 | if (! alpha_elf_create_procedure_table (mdebug_handle, abfd,
|
|---|
| 4339 | info, rtproc_sec, &debug))
|
|---|
| 4340 | return false;
|
|---|
| 4341 | }
|
|---|
| 4342 | #endif
|
|---|
| 4343 |
|
|---|
| 4344 | /* Build the external symbol information. */
|
|---|
| 4345 | einfo.abfd = abfd;
|
|---|
| 4346 | einfo.info = info;
|
|---|
| 4347 | einfo.debug = &debug;
|
|---|
| 4348 | einfo.swap = swap;
|
|---|
| 4349 | einfo.failed = false;
|
|---|
| 4350 | elf_link_hash_traverse (elf_hash_table (info),
|
|---|
| 4351 | elf64_alpha_output_extsym,
|
|---|
| 4352 | (PTR) &einfo);
|
|---|
| 4353 | if (einfo.failed)
|
|---|
| 4354 | return false;
|
|---|
| 4355 |
|
|---|
| 4356 | /* Set the size of the .mdebug section. */
|
|---|
| 4357 | o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
|
|---|
| 4358 |
|
|---|
| 4359 | /* Skip this section later on (I don't think this currently
|
|---|
| 4360 | matters, but someday it might). */
|
|---|
| 4361 | o->link_order_head = (struct bfd_link_order *) NULL;
|
|---|
| 4362 |
|
|---|
| 4363 | mdebug_sec = o;
|
|---|
| 4364 | }
|
|---|
| 4365 |
|
|---|
| 4366 | #ifdef ERIC_neverdef
|
|---|
| 4367 | if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
|
|---|
| 4368 | {
|
|---|
| 4369 | const char *subname;
|
|---|
| 4370 | unsigned int c;
|
|---|
| 4371 | Elf64_gptab *tab;
|
|---|
| 4372 | Elf64_External_gptab *ext_tab;
|
|---|
| 4373 | unsigned int i;
|
|---|
| 4374 |
|
|---|
| 4375 | /* The .gptab.sdata and .gptab.sbss sections hold
|
|---|
| 4376 | information describing how the small data area would
|
|---|
| 4377 | change depending upon the -G switch. These sections
|
|---|
| 4378 | not used in executables files. */
|
|---|
| 4379 | if (! info->relocateable)
|
|---|
| 4380 | {
|
|---|
| 4381 | asection **secpp;
|
|---|
| 4382 |
|
|---|
| 4383 | for (p = o->link_order_head;
|
|---|
| 4384 | p != (struct bfd_link_order *) NULL;
|
|---|
| 4385 | p = p->next)
|
|---|
| 4386 | {
|
|---|
| 4387 | asection *input_section;
|
|---|
| 4388 |
|
|---|
| 4389 | if (p->type != bfd_indirect_link_order)
|
|---|
| 4390 | {
|
|---|
| 4391 | if (p->type == bfd_fill_link_order)
|
|---|
| 4392 | continue;
|
|---|
| 4393 | abort ();
|
|---|
| 4394 | }
|
|---|
| 4395 |
|
|---|
| 4396 | input_section = p->u.indirect.section;
|
|---|
| 4397 |
|
|---|
| 4398 | /* Hack: reset the SEC_HAS_CONTENTS flag so that
|
|---|
| 4399 | elf_link_input_bfd ignores this section. */
|
|---|
| 4400 | input_section->flags &=~ SEC_HAS_CONTENTS;
|
|---|
| 4401 | }
|
|---|
| 4402 |
|
|---|
| 4403 | /* Skip this section later on (I don't think this
|
|---|
| 4404 | currently matters, but someday it might). */
|
|---|
| 4405 | o->link_order_head = (struct bfd_link_order *) NULL;
|
|---|
| 4406 |
|
|---|
| 4407 | /* Really remove the section. */
|
|---|
| 4408 | for (secpp = &abfd->sections;
|
|---|
| 4409 | *secpp != o;
|
|---|
| 4410 | secpp = &(*secpp)->next)
|
|---|
| 4411 | ;
|
|---|
| 4412 | *secpp = (*secpp)->next;
|
|---|
| 4413 | --abfd->section_count;
|
|---|
| 4414 |
|
|---|
| 4415 | continue;
|
|---|
| 4416 | }
|
|---|
| 4417 |
|
|---|
| 4418 | /* There is one gptab for initialized data, and one for
|
|---|
| 4419 | uninitialized data. */
|
|---|
| 4420 | if (strcmp (o->name, ".gptab.sdata") == 0)
|
|---|
| 4421 | gptab_data_sec = o;
|
|---|
| 4422 | else if (strcmp (o->name, ".gptab.sbss") == 0)
|
|---|
| 4423 | gptab_bss_sec = o;
|
|---|
| 4424 | else
|
|---|
| 4425 | {
|
|---|
| 4426 | (*_bfd_error_handler)
|
|---|
| 4427 | (_("%s: illegal section name `%s'"),
|
|---|
| 4428 | bfd_get_filename (abfd), o->name);
|
|---|
| 4429 | bfd_set_error (bfd_error_nonrepresentable_section);
|
|---|
| 4430 | return false;
|
|---|
| 4431 | }
|
|---|
| 4432 |
|
|---|
| 4433 | /* The linker script always combines .gptab.data and
|
|---|
| 4434 | .gptab.sdata into .gptab.sdata, and likewise for
|
|---|
| 4435 | .gptab.bss and .gptab.sbss. It is possible that there is
|
|---|
| 4436 | no .sdata or .sbss section in the output file, in which
|
|---|
| 4437 | case we must change the name of the output section. */
|
|---|
| 4438 | subname = o->name + sizeof ".gptab" - 1;
|
|---|
| 4439 | if (bfd_get_section_by_name (abfd, subname) == NULL)
|
|---|
| 4440 | {
|
|---|
| 4441 | if (o == gptab_data_sec)
|
|---|
| 4442 | o->name = ".gptab.data";
|
|---|
| 4443 | else
|
|---|
| 4444 | o->name = ".gptab.bss";
|
|---|
| 4445 | subname = o->name + sizeof ".gptab" - 1;
|
|---|
| 4446 | BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
|
|---|
| 4447 | }
|
|---|
| 4448 |
|
|---|
| 4449 | /* Set up the first entry. */
|
|---|
| 4450 | c = 1;
|
|---|
| 4451 | tab = (Elf64_gptab *) bfd_malloc (c * sizeof (Elf64_gptab));
|
|---|
| 4452 | if (tab == NULL)
|
|---|
| 4453 | return false;
|
|---|
| 4454 | tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
|
|---|
| 4455 | tab[0].gt_header.gt_unused = 0;
|
|---|
| 4456 |
|
|---|
| 4457 | /* Combine the input sections. */
|
|---|
| 4458 | for (p = o->link_order_head;
|
|---|
| 4459 | p != (struct bfd_link_order *) NULL;
|
|---|
| 4460 | p = p->next)
|
|---|
| 4461 | {
|
|---|
| 4462 | asection *input_section;
|
|---|
| 4463 | bfd *input_bfd;
|
|---|
| 4464 | bfd_size_type size;
|
|---|
| 4465 | unsigned long last;
|
|---|
| 4466 | bfd_size_type gpentry;
|
|---|
| 4467 |
|
|---|
| 4468 | if (p->type != bfd_indirect_link_order)
|
|---|
| 4469 | {
|
|---|
| 4470 | if (p->type == bfd_fill_link_order)
|
|---|
| 4471 | continue;
|
|---|
| 4472 | abort ();
|
|---|
| 4473 | }
|
|---|
| 4474 |
|
|---|
| 4475 | input_section = p->u.indirect.section;
|
|---|
| 4476 | input_bfd = input_section->owner;
|
|---|
| 4477 |
|
|---|
| 4478 | /* Combine the gptab entries for this input section one
|
|---|
| 4479 | by one. We know that the input gptab entries are
|
|---|
| 4480 | sorted by ascending -G value. */
|
|---|
| 4481 | size = bfd_section_size (input_bfd, input_section);
|
|---|
| 4482 | last = 0;
|
|---|
| 4483 | for (gpentry = sizeof (Elf64_External_gptab);
|
|---|
| 4484 | gpentry < size;
|
|---|
| 4485 | gpentry += sizeof (Elf64_External_gptab))
|
|---|
| 4486 | {
|
|---|
| 4487 | Elf64_External_gptab ext_gptab;
|
|---|
| 4488 | Elf64_gptab int_gptab;
|
|---|
| 4489 | unsigned long val;
|
|---|
| 4490 | unsigned long add;
|
|---|
| 4491 | boolean exact;
|
|---|
| 4492 | unsigned int look;
|
|---|
| 4493 |
|
|---|
| 4494 | if (! (bfd_get_section_contents
|
|---|
| 4495 | (input_bfd, input_section, (PTR) &ext_gptab,
|
|---|
| 4496 | gpentry, sizeof (Elf64_External_gptab))))
|
|---|
| 4497 | {
|
|---|
| 4498 | free (tab);
|
|---|
| 4499 | return false;
|
|---|
| 4500 | }
|
|---|
| 4501 |
|
|---|
| 4502 | bfd_alpha_elf64_swap_gptab_in (input_bfd, &ext_gptab,
|
|---|
| 4503 | &int_gptab);
|
|---|
| 4504 | val = int_gptab.gt_entry.gt_g_value;
|
|---|
| 4505 | add = int_gptab.gt_entry.gt_bytes - last;
|
|---|
| 4506 |
|
|---|
| 4507 | exact = false;
|
|---|
| 4508 | for (look = 1; look < c; look++)
|
|---|
| 4509 | {
|
|---|
| 4510 | if (tab[look].gt_entry.gt_g_value >= val)
|
|---|
| 4511 | tab[look].gt_entry.gt_bytes += add;
|
|---|
| 4512 |
|
|---|
| 4513 | if (tab[look].gt_entry.gt_g_value == val)
|
|---|
| 4514 | exact = true;
|
|---|
| 4515 | }
|
|---|
| 4516 |
|
|---|
| 4517 | if (! exact)
|
|---|
| 4518 | {
|
|---|
| 4519 | Elf64_gptab *new_tab;
|
|---|
| 4520 | unsigned int max;
|
|---|
| 4521 |
|
|---|
| 4522 | /* We need a new table entry. */
|
|---|
| 4523 | new_tab = ((Elf64_gptab *)
|
|---|
| 4524 | bfd_realloc ((PTR) tab,
|
|---|
| 4525 | (c + 1) * sizeof (Elf64_gptab)));
|
|---|
| 4526 | if (new_tab == NULL)
|
|---|
| 4527 | {
|
|---|
| 4528 | free (tab);
|
|---|
| 4529 | return false;
|
|---|
| 4530 | }
|
|---|
| 4531 | tab = new_tab;
|
|---|
| 4532 | tab[c].gt_entry.gt_g_value = val;
|
|---|
| 4533 | tab[c].gt_entry.gt_bytes = add;
|
|---|
| 4534 |
|
|---|
| 4535 | /* Merge in the size for the next smallest -G
|
|---|
| 4536 | value, since that will be implied by this new
|
|---|
| 4537 | value. */
|
|---|
| 4538 | max = 0;
|
|---|
| 4539 | for (look = 1; look < c; look++)
|
|---|
| 4540 | {
|
|---|
| 4541 | if (tab[look].gt_entry.gt_g_value < val
|
|---|
| 4542 | && (max == 0
|
|---|
| 4543 | || (tab[look].gt_entry.gt_g_value
|
|---|
| 4544 | > tab[max].gt_entry.gt_g_value)))
|
|---|
| 4545 | max = look;
|
|---|
| 4546 | }
|
|---|
| 4547 | if (max != 0)
|
|---|
| 4548 | tab[c].gt_entry.gt_bytes +=
|
|---|
| 4549 | tab[max].gt_entry.gt_bytes;
|
|---|
| 4550 |
|
|---|
| 4551 | ++c;
|
|---|
| 4552 | }
|
|---|
| 4553 |
|
|---|
| 4554 | last = int_gptab.gt_entry.gt_bytes;
|
|---|
| 4555 | }
|
|---|
| 4556 |
|
|---|
| 4557 | /* Hack: reset the SEC_HAS_CONTENTS flag so that
|
|---|
| 4558 | elf_link_input_bfd ignores this section. */
|
|---|
| 4559 | input_section->flags &=~ SEC_HAS_CONTENTS;
|
|---|
| 4560 | }
|
|---|
| 4561 |
|
|---|
| 4562 | /* The table must be sorted by -G value. */
|
|---|
| 4563 | if (c > 2)
|
|---|
| 4564 | qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
|
|---|
| 4565 |
|
|---|
| 4566 | /* Swap out the table. */
|
|---|
| 4567 | ext_tab = ((Elf64_External_gptab *)
|
|---|
| 4568 | bfd_alloc (abfd, c * sizeof (Elf64_External_gptab)));
|
|---|
| 4569 | if (ext_tab == NULL)
|
|---|
| 4570 | {
|
|---|
| 4571 | free (tab);
|
|---|
| 4572 | return false;
|
|---|
| 4573 | }
|
|---|
| 4574 |
|
|---|
| 4575 | for (i = 0; i < c; i++)
|
|---|
| 4576 | bfd_alpha_elf64_swap_gptab_out (abfd, tab + i, ext_tab + i);
|
|---|
| 4577 | free (tab);
|
|---|
| 4578 |
|
|---|
| 4579 | o->_raw_size = c * sizeof (Elf64_External_gptab);
|
|---|
| 4580 | o->contents = (bfd_byte *) ext_tab;
|
|---|
| 4581 |
|
|---|
| 4582 | /* Skip this section later on (I don't think this currently
|
|---|
| 4583 | matters, but someday it might). */
|
|---|
| 4584 | o->link_order_head = (struct bfd_link_order *) NULL;
|
|---|
| 4585 | }
|
|---|
| 4586 | #endif
|
|---|
| 4587 |
|
|---|
| 4588 | }
|
|---|
| 4589 |
|
|---|
| 4590 | /* Invoke the regular ELF backend linker to do all the work. */
|
|---|
| 4591 | if (! bfd_elf64_bfd_final_link (abfd, info))
|
|---|
| 4592 | return false;
|
|---|
| 4593 |
|
|---|
| 4594 | /* Now write out the computed sections. */
|
|---|
| 4595 |
|
|---|
| 4596 | /* The .got subsections... */
|
|---|
| 4597 | {
|
|---|
| 4598 | bfd *i, *dynobj = elf_hash_table(info)->dynobj;
|
|---|
| 4599 | for (i = alpha_elf_hash_table(info)->got_list;
|
|---|
| 4600 | i != NULL;
|
|---|
| 4601 | i = alpha_elf_tdata(i)->got_link_next)
|
|---|
| 4602 | {
|
|---|
| 4603 | asection *sgot;
|
|---|
| 4604 |
|
|---|
| 4605 | /* elf_bfd_final_link already did everything in dynobj. */
|
|---|
| 4606 | if (i == dynobj)
|
|---|
| 4607 | continue;
|
|---|
| 4608 |
|
|---|
| 4609 | sgot = alpha_elf_tdata(i)->got;
|
|---|
| 4610 | if (! bfd_set_section_contents (abfd, sgot->output_section,
|
|---|
| 4611 | sgot->contents, sgot->output_offset,
|
|---|
| 4612 | sgot->_raw_size))
|
|---|
| 4613 | return false;
|
|---|
| 4614 | }
|
|---|
| 4615 | }
|
|---|
| 4616 |
|
|---|
| 4617 | #ifdef ERIC_neverdef
|
|---|
| 4618 | if (reginfo_sec != (asection *) NULL)
|
|---|
| 4619 | {
|
|---|
| 4620 | Elf64_External_RegInfo ext;
|
|---|
| 4621 |
|
|---|
| 4622 | bfd_alpha_elf64_swap_reginfo_out (abfd, ®info, &ext);
|
|---|
| 4623 | if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
|
|---|
| 4624 | (file_ptr) 0, sizeof ext))
|
|---|
| 4625 | return false;
|
|---|
| 4626 | }
|
|---|
| 4627 | #endif
|
|---|
| 4628 |
|
|---|
| 4629 | if (mdebug_sec != (asection *) NULL)
|
|---|
| 4630 | {
|
|---|
| 4631 | BFD_ASSERT (abfd->output_has_begun);
|
|---|
| 4632 | if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
|
|---|
| 4633 | swap, info,
|
|---|
| 4634 | mdebug_sec->filepos))
|
|---|
| 4635 | return false;
|
|---|
| 4636 |
|
|---|
| 4637 | bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
|
|---|
| 4638 | }
|
|---|
| 4639 |
|
|---|
| 4640 | if (gptab_data_sec != (asection *) NULL)
|
|---|
| 4641 | {
|
|---|
| 4642 | if (! bfd_set_section_contents (abfd, gptab_data_sec,
|
|---|
| 4643 | gptab_data_sec->contents,
|
|---|
| 4644 | (file_ptr) 0,
|
|---|
| 4645 | gptab_data_sec->_raw_size))
|
|---|
| 4646 | return false;
|
|---|
| 4647 | }
|
|---|
| 4648 |
|
|---|
| 4649 | if (gptab_bss_sec != (asection *) NULL)
|
|---|
| 4650 | {
|
|---|
| 4651 | if (! bfd_set_section_contents (abfd, gptab_bss_sec,
|
|---|
| 4652 | gptab_bss_sec->contents,
|
|---|
| 4653 | (file_ptr) 0,
|
|---|
| 4654 | gptab_bss_sec->_raw_size))
|
|---|
| 4655 | return false;
|
|---|
| 4656 | }
|
|---|
| 4657 |
|
|---|
| 4658 | return true;
|
|---|
| 4659 | }
|
|---|
| 4660 | |
|---|
| 4661 |
|
|---|
| 4662 | /* ECOFF swapping routines. These are used when dealing with the
|
|---|
| 4663 | .mdebug section, which is in the ECOFF debugging format. Copied
|
|---|
| 4664 | from elf32-mips.c. */
|
|---|
| 4665 | static const struct ecoff_debug_swap
|
|---|
| 4666 | elf64_alpha_ecoff_debug_swap =
|
|---|
| 4667 | {
|
|---|
| 4668 | /* Symbol table magic number. */
|
|---|
| 4669 | magicSym2,
|
|---|
| 4670 | /* Alignment of debugging information. E.g., 4. */
|
|---|
| 4671 | 8,
|
|---|
| 4672 | /* Sizes of external symbolic information. */
|
|---|
| 4673 | sizeof (struct hdr_ext),
|
|---|
| 4674 | sizeof (struct dnr_ext),
|
|---|
| 4675 | sizeof (struct pdr_ext),
|
|---|
| 4676 | sizeof (struct sym_ext),
|
|---|
| 4677 | sizeof (struct opt_ext),
|
|---|
| 4678 | sizeof (struct fdr_ext),
|
|---|
| 4679 | sizeof (struct rfd_ext),
|
|---|
| 4680 | sizeof (struct ext_ext),
|
|---|
| 4681 | /* Functions to swap in external symbolic data. */
|
|---|
| 4682 | ecoff_swap_hdr_in,
|
|---|
| 4683 | ecoff_swap_dnr_in,
|
|---|
| 4684 | ecoff_swap_pdr_in,
|
|---|
| 4685 | ecoff_swap_sym_in,
|
|---|
| 4686 | ecoff_swap_opt_in,
|
|---|
| 4687 | ecoff_swap_fdr_in,
|
|---|
| 4688 | ecoff_swap_rfd_in,
|
|---|
| 4689 | ecoff_swap_ext_in,
|
|---|
| 4690 | _bfd_ecoff_swap_tir_in,
|
|---|
| 4691 | _bfd_ecoff_swap_rndx_in,
|
|---|
| 4692 | /* Functions to swap out external symbolic data. */
|
|---|
| 4693 | ecoff_swap_hdr_out,
|
|---|
| 4694 | ecoff_swap_dnr_out,
|
|---|
| 4695 | ecoff_swap_pdr_out,
|
|---|
| 4696 | ecoff_swap_sym_out,
|
|---|
| 4697 | ecoff_swap_opt_out,
|
|---|
| 4698 | ecoff_swap_fdr_out,
|
|---|
| 4699 | ecoff_swap_rfd_out,
|
|---|
| 4700 | ecoff_swap_ext_out,
|
|---|
| 4701 | _bfd_ecoff_swap_tir_out,
|
|---|
| 4702 | _bfd_ecoff_swap_rndx_out,
|
|---|
| 4703 | /* Function to read in symbolic data. */
|
|---|
| 4704 | elf64_alpha_read_ecoff_info
|
|---|
| 4705 | };
|
|---|
| 4706 | |
|---|
| 4707 |
|
|---|
| 4708 | /* Use a non-standard hash bucket size of 8. */
|
|---|
| 4709 |
|
|---|
| 4710 | const struct elf_size_info alpha_elf_size_info =
|
|---|
| 4711 | {
|
|---|
| 4712 | sizeof (Elf64_External_Ehdr),
|
|---|
| 4713 | sizeof (Elf64_External_Phdr),
|
|---|
| 4714 | sizeof (Elf64_External_Shdr),
|
|---|
| 4715 | sizeof (Elf64_External_Rel),
|
|---|
| 4716 | sizeof (Elf64_External_Rela),
|
|---|
| 4717 | sizeof (Elf64_External_Sym),
|
|---|
| 4718 | sizeof (Elf64_External_Dyn),
|
|---|
| 4719 | sizeof (Elf_External_Note),
|
|---|
| 4720 | 8,
|
|---|
| 4721 | 1,
|
|---|
| 4722 | 64, 8,
|
|---|
| 4723 | ELFCLASS64, EV_CURRENT,
|
|---|
| 4724 | bfd_elf64_write_out_phdrs,
|
|---|
| 4725 | bfd_elf64_write_shdrs_and_ehdr,
|
|---|
| 4726 | bfd_elf64_write_relocs,
|
|---|
| 4727 | bfd_elf64_swap_symbol_out,
|
|---|
| 4728 | bfd_elf64_slurp_reloc_table,
|
|---|
| 4729 | bfd_elf64_slurp_symbol_table,
|
|---|
| 4730 | bfd_elf64_swap_dyn_in,
|
|---|
| 4731 | bfd_elf64_swap_dyn_out,
|
|---|
| 4732 | NULL,
|
|---|
| 4733 | NULL,
|
|---|
| 4734 | NULL,
|
|---|
| 4735 | NULL
|
|---|
| 4736 | };
|
|---|
| 4737 |
|
|---|
| 4738 | #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
|
|---|
| 4739 | #define TARGET_LITTLE_NAME "elf64-alpha"
|
|---|
| 4740 | #define ELF_ARCH bfd_arch_alpha
|
|---|
| 4741 | #define ELF_MACHINE_CODE EM_ALPHA
|
|---|
| 4742 | #define ELF_MAXPAGESIZE 0x10000
|
|---|
| 4743 |
|
|---|
| 4744 | #define bfd_elf64_bfd_link_hash_table_create \
|
|---|
| 4745 | elf64_alpha_bfd_link_hash_table_create
|
|---|
| 4746 |
|
|---|
| 4747 | #define bfd_elf64_bfd_reloc_type_lookup \
|
|---|
| 4748 | elf64_alpha_bfd_reloc_type_lookup
|
|---|
| 4749 | #define elf_info_to_howto \
|
|---|
| 4750 | elf64_alpha_info_to_howto
|
|---|
| 4751 |
|
|---|
| 4752 | #define bfd_elf64_mkobject \
|
|---|
| 4753 | elf64_alpha_mkobject
|
|---|
| 4754 | #define elf_backend_object_p \
|
|---|
| 4755 | elf64_alpha_object_p
|
|---|
| 4756 |
|
|---|
| 4757 | #define elf_backend_section_from_shdr \
|
|---|
| 4758 | elf64_alpha_section_from_shdr
|
|---|
| 4759 | #define elf_backend_fake_sections \
|
|---|
| 4760 | elf64_alpha_fake_sections
|
|---|
| 4761 |
|
|---|
| 4762 | #define bfd_elf64_bfd_is_local_label_name \
|
|---|
| 4763 | elf64_alpha_is_local_label_name
|
|---|
| 4764 | #define bfd_elf64_find_nearest_line \
|
|---|
| 4765 | elf64_alpha_find_nearest_line
|
|---|
| 4766 | #define bfd_elf64_bfd_relax_section \
|
|---|
| 4767 | elf64_alpha_relax_section
|
|---|
| 4768 |
|
|---|
| 4769 | #define elf_backend_add_symbol_hook \
|
|---|
| 4770 | elf64_alpha_add_symbol_hook
|
|---|
| 4771 | #define elf_backend_check_relocs \
|
|---|
| 4772 | elf64_alpha_check_relocs
|
|---|
| 4773 | #define elf_backend_create_dynamic_sections \
|
|---|
| 4774 | elf64_alpha_create_dynamic_sections
|
|---|
| 4775 | #define elf_backend_adjust_dynamic_symbol \
|
|---|
| 4776 | elf64_alpha_adjust_dynamic_symbol
|
|---|
| 4777 | #define elf_backend_always_size_sections \
|
|---|
| 4778 | elf64_alpha_always_size_sections
|
|---|
| 4779 | #define elf_backend_size_dynamic_sections \
|
|---|
| 4780 | elf64_alpha_size_dynamic_sections
|
|---|
| 4781 | #define elf_backend_relocate_section \
|
|---|
| 4782 | elf64_alpha_relocate_section
|
|---|
| 4783 | #define elf_backend_finish_dynamic_symbol \
|
|---|
| 4784 | elf64_alpha_finish_dynamic_symbol
|
|---|
| 4785 | #define elf_backend_finish_dynamic_sections \
|
|---|
| 4786 | elf64_alpha_finish_dynamic_sections
|
|---|
| 4787 | #define bfd_elf64_bfd_final_link \
|
|---|
| 4788 | elf64_alpha_final_link
|
|---|
| 4789 |
|
|---|
| 4790 | #define elf_backend_ecoff_debug_swap \
|
|---|
| 4791 | &elf64_alpha_ecoff_debug_swap
|
|---|
| 4792 |
|
|---|
| 4793 | #define elf_backend_size_info \
|
|---|
| 4794 | alpha_elf_size_info
|
|---|
| 4795 |
|
|---|
| 4796 | /* A few constants that determine how the .plt section is set up. */
|
|---|
| 4797 | #define elf_backend_want_got_plt 0
|
|---|
| 4798 | #define elf_backend_plt_readonly 0
|
|---|
| 4799 | #define elf_backend_want_plt_sym 1
|
|---|
| 4800 | #define elf_backend_got_header_size 0
|
|---|
| 4801 | #define elf_backend_plt_header_size PLT_HEADER_SIZE
|
|---|
| 4802 |
|
|---|
| 4803 | #include "elf64-target.h"
|
|---|