| 1 | /* MMIX-specific support for 64-bit ELF.
|
|---|
| 2 | Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
|
|---|
| 3 | Contributed by Hans-Peter Nilsson <hp@bitrange.com>
|
|---|
| 4 |
|
|---|
| 5 | This file is part of BFD, the Binary File Descriptor library.
|
|---|
| 6 |
|
|---|
| 7 | This program is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 10 | (at your option) any later version.
|
|---|
| 11 |
|
|---|
| 12 | This program is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | GNU General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with this program; if not, write to the Free Software
|
|---|
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 20 |
|
|---|
| 21 | /* No specific ABI or "processor-specific supplement" defined. */
|
|---|
| 22 |
|
|---|
| 23 | /* TODO:
|
|---|
| 24 | - Linker relaxation. */
|
|---|
| 25 |
|
|---|
| 26 | #include "bfd.h"
|
|---|
| 27 | #include "sysdep.h"
|
|---|
| 28 | #include "libbfd.h"
|
|---|
| 29 | #include "elf-bfd.h"
|
|---|
| 30 | #include "elf/mmix.h"
|
|---|
| 31 | #include "opcode/mmix.h"
|
|---|
| 32 |
|
|---|
| 33 | #define MINUS_ONE (((bfd_vma) 0) - 1)
|
|---|
| 34 |
|
|---|
| 35 | /* Put these everywhere in new code. */
|
|---|
| 36 | #define FATAL_DEBUG \
|
|---|
| 37 | _bfd_abort (__FILE__, __LINE__, \
|
|---|
| 38 | "Internal: Non-debugged code (test-case missing)")
|
|---|
| 39 |
|
|---|
| 40 | #define BAD_CASE(x) \
|
|---|
| 41 | _bfd_abort (__FILE__, __LINE__, \
|
|---|
| 42 | "bad case for " #x)
|
|---|
| 43 |
|
|---|
| 44 | struct _mmix_elf_section_data
|
|---|
| 45 | {
|
|---|
| 46 | struct bfd_elf_section_data elf;
|
|---|
| 47 | union
|
|---|
| 48 | {
|
|---|
| 49 | struct bpo_reloc_section_info *reloc;
|
|---|
| 50 | struct bpo_greg_section_info *greg;
|
|---|
| 51 | } bpo;
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | #define mmix_elf_section_data(sec) \
|
|---|
| 55 | ((struct _mmix_elf_section_data *) elf_section_data (sec))
|
|---|
| 56 |
|
|---|
| 57 | /* For each section containing a base-plus-offset (BPO) reloc, we attach
|
|---|
| 58 | this struct as mmix_elf_section_data (section)->bpo, which is otherwise
|
|---|
| 59 | NULL. */
|
|---|
| 60 | struct bpo_reloc_section_info
|
|---|
| 61 | {
|
|---|
| 62 | /* The base is 1; this is the first number in this section. */
|
|---|
| 63 | size_t first_base_plus_offset_reloc;
|
|---|
| 64 |
|
|---|
| 65 | /* Number of BPO-relocs in this section. */
|
|---|
| 66 | size_t n_bpo_relocs_this_section;
|
|---|
| 67 |
|
|---|
| 68 | /* Running index, used at relocation time. */
|
|---|
| 69 | size_t bpo_index;
|
|---|
| 70 |
|
|---|
| 71 | /* We don't have access to the bfd_link_info struct in
|
|---|
| 72 | mmix_final_link_relocate. What we really want to get at is the
|
|---|
| 73 | global single struct greg_relocation, so we stash it here. */
|
|---|
| 74 | asection *bpo_greg_section;
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | /* Helper struct (in global context) for the one below.
|
|---|
| 78 | There's one of these created for every BPO reloc. */
|
|---|
| 79 | struct bpo_reloc_request
|
|---|
| 80 | {
|
|---|
| 81 | bfd_vma value;
|
|---|
| 82 |
|
|---|
| 83 | /* Valid after relaxation. The base is 0; the first register number
|
|---|
| 84 | must be added. The offset is in range 0..255. */
|
|---|
| 85 | size_t regindex;
|
|---|
| 86 | size_t offset;
|
|---|
| 87 |
|
|---|
| 88 | /* The order number for this BPO reloc, corresponding to the order in
|
|---|
| 89 | which BPO relocs were found. Used to create an index after reloc
|
|---|
| 90 | requests are sorted. */
|
|---|
| 91 | size_t bpo_reloc_no;
|
|---|
| 92 |
|
|---|
| 93 | /* Set when the value is computed. Better than coding "guard values"
|
|---|
| 94 | into the other members. Is FALSE only for BPO relocs in a GC:ed
|
|---|
| 95 | section. */
|
|---|
| 96 | bfd_boolean valid;
|
|---|
| 97 | };
|
|---|
| 98 |
|
|---|
| 99 | /* We attach this as mmix_elf_section_data (sec)->bpo in the linker-allocated
|
|---|
| 100 | greg contents section (MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME),
|
|---|
| 101 | which is linked into the register contents section
|
|---|
| 102 | (MMIX_REG_CONTENTS_SECTION_NAME). This section is created by the
|
|---|
| 103 | linker; using the same hook as for usual with BPO relocs does not
|
|---|
| 104 | collide. */
|
|---|
| 105 | struct bpo_greg_section_info
|
|---|
| 106 | {
|
|---|
| 107 | /* After GC, this reflects the number of remaining, non-excluded
|
|---|
| 108 | BPO-relocs. */
|
|---|
| 109 | size_t n_bpo_relocs;
|
|---|
| 110 |
|
|---|
| 111 | /* This is the number of allocated bpo_reloc_requests; the size of
|
|---|
| 112 | sorted_indexes. Valid after the check.*relocs functions are called
|
|---|
| 113 | for all incoming sections. It includes the number of BPO relocs in
|
|---|
| 114 | sections that were GC:ed. */
|
|---|
| 115 | size_t n_max_bpo_relocs;
|
|---|
| 116 |
|
|---|
| 117 | /* A counter used to find out when to fold the BPO gregs, since we
|
|---|
| 118 | don't have a single "after-relaxation" hook. */
|
|---|
| 119 | size_t n_remaining_bpo_relocs_this_relaxation_round;
|
|---|
| 120 |
|
|---|
| 121 | /* The number of linker-allocated GREGs resulting from BPO relocs.
|
|---|
| 122 | This is an approximation after _bfd_mmix_allocated_gregs_init and
|
|---|
| 123 | supposedly accurate after mmix_elf_relax_section is called for all
|
|---|
| 124 | incoming non-collected sections. */
|
|---|
| 125 | size_t n_allocated_bpo_gregs;
|
|---|
| 126 |
|
|---|
| 127 | /* Index into reloc_request[], sorted on increasing "value", secondary
|
|---|
| 128 | by increasing index for strict sorting order. */
|
|---|
| 129 | size_t *bpo_reloc_indexes;
|
|---|
| 130 |
|
|---|
| 131 | /* An array of all relocations, with the "value" member filled in by
|
|---|
| 132 | the relaxation function. */
|
|---|
| 133 | struct bpo_reloc_request *reloc_request;
|
|---|
| 134 | };
|
|---|
| 135 |
|
|---|
| 136 | static bfd_boolean mmix_elf_link_output_symbol_hook
|
|---|
| 137 | PARAMS ((bfd *, struct bfd_link_info *, const char *,
|
|---|
| 138 | Elf_Internal_Sym *, asection *));
|
|---|
| 139 |
|
|---|
| 140 | static bfd_reloc_status_type mmix_elf_reloc
|
|---|
| 141 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 142 |
|
|---|
| 143 | static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup
|
|---|
| 144 | PARAMS ((bfd *, bfd_reloc_code_real_type));
|
|---|
| 145 |
|
|---|
| 146 | static void mmix_info_to_howto_rela
|
|---|
| 147 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
|
|---|
| 148 |
|
|---|
| 149 | static int mmix_elf_sort_relocs PARAMS ((const PTR, const PTR));
|
|---|
| 150 |
|
|---|
| 151 | static bfd_boolean mmix_elf_new_section_hook
|
|---|
| 152 | PARAMS ((bfd *, asection *));
|
|---|
| 153 |
|
|---|
| 154 | static bfd_boolean mmix_elf_check_relocs
|
|---|
| 155 | PARAMS ((bfd *, struct bfd_link_info *, asection *,
|
|---|
| 156 | const Elf_Internal_Rela *));
|
|---|
| 157 |
|
|---|
| 158 | static bfd_boolean mmix_elf_check_common_relocs
|
|---|
| 159 | PARAMS ((bfd *, struct bfd_link_info *, asection *,
|
|---|
| 160 | const Elf_Internal_Rela *));
|
|---|
| 161 |
|
|---|
| 162 | static bfd_boolean mmix_elf_relocate_section
|
|---|
| 163 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
|
|---|
| 164 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
|
|---|
| 165 |
|
|---|
| 166 | static asection * mmix_elf_gc_mark_hook
|
|---|
| 167 | PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
|
|---|
| 168 | struct elf_link_hash_entry *, Elf_Internal_Sym *));
|
|---|
| 169 |
|
|---|
| 170 | static bfd_boolean mmix_elf_gc_sweep_hook
|
|---|
| 171 | PARAMS ((bfd *, struct bfd_link_info *, asection *,
|
|---|
| 172 | const Elf_Internal_Rela *));
|
|---|
| 173 |
|
|---|
| 174 | static bfd_reloc_status_type mmix_final_link_relocate
|
|---|
| 175 | PARAMS ((reloc_howto_type *, asection *, bfd_byte *,
|
|---|
| 176 | bfd_vma, bfd_signed_vma, bfd_vma, const char *, asection *));
|
|---|
| 177 |
|
|---|
| 178 | static bfd_reloc_status_type mmix_elf_perform_relocation
|
|---|
| 179 | PARAMS ((asection *, reloc_howto_type *, PTR, bfd_vma, bfd_vma));
|
|---|
| 180 |
|
|---|
| 181 | static bfd_boolean mmix_elf_section_from_bfd_section
|
|---|
| 182 | PARAMS ((bfd *, asection *, int *));
|
|---|
| 183 |
|
|---|
| 184 | static bfd_boolean mmix_elf_add_symbol_hook
|
|---|
| 185 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
|
|---|
| 186 | const char **, flagword *, asection **, bfd_vma *));
|
|---|
| 187 |
|
|---|
| 188 | static bfd_boolean mmix_elf_is_local_label_name
|
|---|
| 189 | PARAMS ((bfd *, const char *));
|
|---|
| 190 |
|
|---|
| 191 | static int bpo_reloc_request_sort_fn PARAMS ((const PTR, const PTR));
|
|---|
| 192 |
|
|---|
| 193 | static bfd_boolean mmix_elf_relax_section
|
|---|
| 194 | PARAMS ((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
|
|---|
| 195 | bfd_boolean *again));
|
|---|
| 196 |
|
|---|
| 197 | extern bfd_boolean mmix_elf_final_link PARAMS ((bfd *, struct bfd_link_info *));
|
|---|
| 198 |
|
|---|
| 199 | extern void mmix_elf_symbol_processing PARAMS ((bfd *, asymbol *));
|
|---|
| 200 |
|
|---|
| 201 | /* Only intended to be called from a debugger. */
|
|---|
| 202 | extern void mmix_dump_bpo_gregs
|
|---|
| 203 | PARAMS ((struct bfd_link_info *, bfd_error_handler_type));
|
|---|
| 204 |
|
|---|
| 205 | /* Watch out: this currently needs to have elements with the same index as
|
|---|
| 206 | their R_MMIX_ number. */
|
|---|
| 207 | static reloc_howto_type elf_mmix_howto_table[] =
|
|---|
| 208 | {
|
|---|
| 209 | /* This reloc does nothing. */
|
|---|
| 210 | HOWTO (R_MMIX_NONE, /* type */
|
|---|
| 211 | 0, /* rightshift */
|
|---|
| 212 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 213 | 32, /* bitsize */
|
|---|
| 214 | FALSE, /* pc_relative */
|
|---|
| 215 | 0, /* bitpos */
|
|---|
| 216 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 217 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 218 | "R_MMIX_NONE", /* name */
|
|---|
| 219 | FALSE, /* partial_inplace */
|
|---|
| 220 | 0, /* src_mask */
|
|---|
| 221 | 0, /* dst_mask */
|
|---|
| 222 | FALSE), /* pcrel_offset */
|
|---|
| 223 |
|
|---|
| 224 | /* An 8 bit absolute relocation. */
|
|---|
| 225 | HOWTO (R_MMIX_8, /* type */
|
|---|
| 226 | 0, /* rightshift */
|
|---|
| 227 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 228 | 8, /* bitsize */
|
|---|
| 229 | FALSE, /* pc_relative */
|
|---|
| 230 | 0, /* bitpos */
|
|---|
| 231 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 232 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 233 | "R_MMIX_8", /* name */
|
|---|
| 234 | FALSE, /* partial_inplace */
|
|---|
| 235 | 0, /* src_mask */
|
|---|
| 236 | 0xff, /* dst_mask */
|
|---|
| 237 | FALSE), /* pcrel_offset */
|
|---|
| 238 |
|
|---|
| 239 | /* An 16 bit absolute relocation. */
|
|---|
| 240 | HOWTO (R_MMIX_16, /* type */
|
|---|
| 241 | 0, /* rightshift */
|
|---|
| 242 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 243 | 16, /* bitsize */
|
|---|
| 244 | FALSE, /* pc_relative */
|
|---|
| 245 | 0, /* bitpos */
|
|---|
| 246 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 247 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 248 | "R_MMIX_16", /* name */
|
|---|
| 249 | FALSE, /* partial_inplace */
|
|---|
| 250 | 0, /* src_mask */
|
|---|
| 251 | 0xffff, /* dst_mask */
|
|---|
| 252 | FALSE), /* pcrel_offset */
|
|---|
| 253 |
|
|---|
| 254 | /* An 24 bit absolute relocation. */
|
|---|
| 255 | HOWTO (R_MMIX_24, /* type */
|
|---|
| 256 | 0, /* rightshift */
|
|---|
| 257 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 258 | 24, /* bitsize */
|
|---|
| 259 | FALSE, /* pc_relative */
|
|---|
| 260 | 0, /* bitpos */
|
|---|
| 261 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 262 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 263 | "R_MMIX_24", /* name */
|
|---|
| 264 | FALSE, /* partial_inplace */
|
|---|
| 265 | ~0xffffff, /* src_mask */
|
|---|
| 266 | 0xffffff, /* dst_mask */
|
|---|
| 267 | FALSE), /* pcrel_offset */
|
|---|
| 268 |
|
|---|
| 269 | /* A 32 bit absolute relocation. */
|
|---|
| 270 | HOWTO (R_MMIX_32, /* type */
|
|---|
| 271 | 0, /* rightshift */
|
|---|
| 272 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 273 | 32, /* bitsize */
|
|---|
| 274 | FALSE, /* pc_relative */
|
|---|
| 275 | 0, /* bitpos */
|
|---|
| 276 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 277 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 278 | "R_MMIX_32", /* name */
|
|---|
| 279 | FALSE, /* partial_inplace */
|
|---|
| 280 | 0, /* src_mask */
|
|---|
| 281 | 0xffffffff, /* dst_mask */
|
|---|
| 282 | FALSE), /* pcrel_offset */
|
|---|
| 283 |
|
|---|
| 284 | /* 64 bit relocation. */
|
|---|
| 285 | HOWTO (R_MMIX_64, /* type */
|
|---|
| 286 | 0, /* rightshift */
|
|---|
| 287 | 4, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 288 | 64, /* bitsize */
|
|---|
| 289 | FALSE, /* pc_relative */
|
|---|
| 290 | 0, /* bitpos */
|
|---|
| 291 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 292 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 293 | "R_MMIX_64", /* name */
|
|---|
| 294 | FALSE, /* partial_inplace */
|
|---|
| 295 | 0, /* src_mask */
|
|---|
| 296 | MINUS_ONE, /* dst_mask */
|
|---|
| 297 | FALSE), /* pcrel_offset */
|
|---|
| 298 |
|
|---|
| 299 | /* An 8 bit PC-relative relocation. */
|
|---|
| 300 | HOWTO (R_MMIX_PC_8, /* type */
|
|---|
| 301 | 0, /* rightshift */
|
|---|
| 302 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 303 | 8, /* bitsize */
|
|---|
| 304 | TRUE, /* pc_relative */
|
|---|
| 305 | 0, /* bitpos */
|
|---|
| 306 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 307 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 308 | "R_MMIX_PC_8", /* name */
|
|---|
| 309 | FALSE, /* partial_inplace */
|
|---|
| 310 | 0, /* src_mask */
|
|---|
| 311 | 0xff, /* dst_mask */
|
|---|
| 312 | TRUE), /* pcrel_offset */
|
|---|
| 313 |
|
|---|
| 314 | /* An 16 bit PC-relative relocation. */
|
|---|
| 315 | HOWTO (R_MMIX_PC_16, /* type */
|
|---|
| 316 | 0, /* rightshift */
|
|---|
| 317 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 318 | 16, /* bitsize */
|
|---|
| 319 | TRUE, /* pc_relative */
|
|---|
| 320 | 0, /* bitpos */
|
|---|
| 321 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 322 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 323 | "R_MMIX_PC_16", /* name */
|
|---|
| 324 | FALSE, /* partial_inplace */
|
|---|
| 325 | 0, /* src_mask */
|
|---|
| 326 | 0xffff, /* dst_mask */
|
|---|
| 327 | TRUE), /* pcrel_offset */
|
|---|
| 328 |
|
|---|
| 329 | /* An 24 bit PC-relative relocation. */
|
|---|
| 330 | HOWTO (R_MMIX_PC_24, /* type */
|
|---|
| 331 | 0, /* rightshift */
|
|---|
| 332 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 333 | 24, /* bitsize */
|
|---|
| 334 | TRUE, /* pc_relative */
|
|---|
| 335 | 0, /* bitpos */
|
|---|
| 336 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 337 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 338 | "R_MMIX_PC_24", /* name */
|
|---|
| 339 | FALSE, /* partial_inplace */
|
|---|
| 340 | ~0xffffff, /* src_mask */
|
|---|
| 341 | 0xffffff, /* dst_mask */
|
|---|
| 342 | TRUE), /* pcrel_offset */
|
|---|
| 343 |
|
|---|
| 344 | /* A 32 bit absolute PC-relative relocation. */
|
|---|
| 345 | HOWTO (R_MMIX_PC_32, /* type */
|
|---|
| 346 | 0, /* rightshift */
|
|---|
| 347 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 348 | 32, /* bitsize */
|
|---|
| 349 | TRUE, /* pc_relative */
|
|---|
| 350 | 0, /* bitpos */
|
|---|
| 351 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 352 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 353 | "R_MMIX_PC_32", /* name */
|
|---|
| 354 | FALSE, /* partial_inplace */
|
|---|
| 355 | 0, /* src_mask */
|
|---|
| 356 | 0xffffffff, /* dst_mask */
|
|---|
| 357 | TRUE), /* pcrel_offset */
|
|---|
| 358 |
|
|---|
| 359 | /* 64 bit PC-relative relocation. */
|
|---|
| 360 | HOWTO (R_MMIX_PC_64, /* type */
|
|---|
| 361 | 0, /* rightshift */
|
|---|
| 362 | 4, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 363 | 64, /* bitsize */
|
|---|
| 364 | TRUE, /* pc_relative */
|
|---|
| 365 | 0, /* bitpos */
|
|---|
| 366 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 367 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 368 | "R_MMIX_PC_64", /* name */
|
|---|
| 369 | FALSE, /* partial_inplace */
|
|---|
| 370 | 0, /* src_mask */
|
|---|
| 371 | MINUS_ONE, /* dst_mask */
|
|---|
| 372 | TRUE), /* pcrel_offset */
|
|---|
| 373 |
|
|---|
| 374 | /* GNU extension to record C++ vtable hierarchy. */
|
|---|
| 375 | HOWTO (R_MMIX_GNU_VTINHERIT, /* type */
|
|---|
| 376 | 0, /* rightshift */
|
|---|
| 377 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 378 | 0, /* bitsize */
|
|---|
| 379 | FALSE, /* pc_relative */
|
|---|
| 380 | 0, /* bitpos */
|
|---|
| 381 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 382 | NULL, /* special_function */
|
|---|
| 383 | "R_MMIX_GNU_VTINHERIT", /* name */
|
|---|
| 384 | FALSE, /* partial_inplace */
|
|---|
| 385 | 0, /* src_mask */
|
|---|
| 386 | 0, /* dst_mask */
|
|---|
| 387 | TRUE), /* pcrel_offset */
|
|---|
| 388 |
|
|---|
| 389 | /* GNU extension to record C++ vtable member usage. */
|
|---|
| 390 | HOWTO (R_MMIX_GNU_VTENTRY, /* type */
|
|---|
| 391 | 0, /* rightshift */
|
|---|
| 392 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 393 | 0, /* bitsize */
|
|---|
| 394 | FALSE, /* pc_relative */
|
|---|
| 395 | 0, /* bitpos */
|
|---|
| 396 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 397 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */
|
|---|
| 398 | "R_MMIX_GNU_VTENTRY", /* name */
|
|---|
| 399 | FALSE, /* partial_inplace */
|
|---|
| 400 | 0, /* src_mask */
|
|---|
| 401 | 0, /* dst_mask */
|
|---|
| 402 | FALSE), /* pcrel_offset */
|
|---|
| 403 |
|
|---|
| 404 | /* The GETA relocation is supposed to get any address that could
|
|---|
| 405 | possibly be reached by the GETA instruction. It can silently expand
|
|---|
| 406 | to get a 64-bit operand, but will complain if any of the two least
|
|---|
| 407 | significant bits are set. The howto members reflect a simple GETA. */
|
|---|
| 408 | HOWTO (R_MMIX_GETA, /* type */
|
|---|
| 409 | 2, /* rightshift */
|
|---|
| 410 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 411 | 19, /* bitsize */
|
|---|
| 412 | TRUE, /* pc_relative */
|
|---|
| 413 | 0, /* bitpos */
|
|---|
| 414 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 415 | mmix_elf_reloc, /* special_function */
|
|---|
| 416 | "R_MMIX_GETA", /* name */
|
|---|
| 417 | FALSE, /* partial_inplace */
|
|---|
| 418 | ~0x0100ffff, /* src_mask */
|
|---|
| 419 | 0x0100ffff, /* dst_mask */
|
|---|
| 420 | TRUE), /* pcrel_offset */
|
|---|
| 421 |
|
|---|
| 422 | HOWTO (R_MMIX_GETA_1, /* type */
|
|---|
| 423 | 2, /* rightshift */
|
|---|
| 424 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 425 | 19, /* bitsize */
|
|---|
| 426 | TRUE, /* pc_relative */
|
|---|
| 427 | 0, /* bitpos */
|
|---|
| 428 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 429 | mmix_elf_reloc, /* special_function */
|
|---|
| 430 | "R_MMIX_GETA_1", /* name */
|
|---|
| 431 | FALSE, /* partial_inplace */
|
|---|
| 432 | ~0x0100ffff, /* src_mask */
|
|---|
| 433 | 0x0100ffff, /* dst_mask */
|
|---|
| 434 | TRUE), /* pcrel_offset */
|
|---|
| 435 |
|
|---|
| 436 | HOWTO (R_MMIX_GETA_2, /* type */
|
|---|
| 437 | 2, /* rightshift */
|
|---|
| 438 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 439 | 19, /* bitsize */
|
|---|
| 440 | TRUE, /* pc_relative */
|
|---|
| 441 | 0, /* bitpos */
|
|---|
| 442 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 443 | mmix_elf_reloc, /* special_function */
|
|---|
| 444 | "R_MMIX_GETA_2", /* name */
|
|---|
| 445 | FALSE, /* partial_inplace */
|
|---|
| 446 | ~0x0100ffff, /* src_mask */
|
|---|
| 447 | 0x0100ffff, /* dst_mask */
|
|---|
| 448 | TRUE), /* pcrel_offset */
|
|---|
| 449 |
|
|---|
| 450 | HOWTO (R_MMIX_GETA_3, /* type */
|
|---|
| 451 | 2, /* rightshift */
|
|---|
| 452 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 453 | 19, /* bitsize */
|
|---|
| 454 | TRUE, /* pc_relative */
|
|---|
| 455 | 0, /* bitpos */
|
|---|
| 456 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 457 | mmix_elf_reloc, /* special_function */
|
|---|
| 458 | "R_MMIX_GETA_3", /* name */
|
|---|
| 459 | FALSE, /* partial_inplace */
|
|---|
| 460 | ~0x0100ffff, /* src_mask */
|
|---|
| 461 | 0x0100ffff, /* dst_mask */
|
|---|
| 462 | TRUE), /* pcrel_offset */
|
|---|
| 463 |
|
|---|
| 464 | /* The conditional branches are supposed to reach any (code) address.
|
|---|
| 465 | It can silently expand to a 64-bit operand, but will emit an error if
|
|---|
| 466 | any of the two least significant bits are set. The howto members
|
|---|
| 467 | reflect a simple branch. */
|
|---|
| 468 | HOWTO (R_MMIX_CBRANCH, /* type */
|
|---|
| 469 | 2, /* rightshift */
|
|---|
| 470 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 471 | 19, /* bitsize */
|
|---|
| 472 | TRUE, /* pc_relative */
|
|---|
| 473 | 0, /* bitpos */
|
|---|
| 474 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 475 | mmix_elf_reloc, /* special_function */
|
|---|
| 476 | "R_MMIX_CBRANCH", /* name */
|
|---|
| 477 | FALSE, /* partial_inplace */
|
|---|
| 478 | ~0x0100ffff, /* src_mask */
|
|---|
| 479 | 0x0100ffff, /* dst_mask */
|
|---|
| 480 | TRUE), /* pcrel_offset */
|
|---|
| 481 |
|
|---|
| 482 | HOWTO (R_MMIX_CBRANCH_J, /* type */
|
|---|
| 483 | 2, /* rightshift */
|
|---|
| 484 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 485 | 19, /* bitsize */
|
|---|
| 486 | TRUE, /* pc_relative */
|
|---|
| 487 | 0, /* bitpos */
|
|---|
| 488 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 489 | mmix_elf_reloc, /* special_function */
|
|---|
| 490 | "R_MMIX_CBRANCH_J", /* name */
|
|---|
| 491 | FALSE, /* partial_inplace */
|
|---|
| 492 | ~0x0100ffff, /* src_mask */
|
|---|
| 493 | 0x0100ffff, /* dst_mask */
|
|---|
| 494 | TRUE), /* pcrel_offset */
|
|---|
| 495 |
|
|---|
| 496 | HOWTO (R_MMIX_CBRANCH_1, /* type */
|
|---|
| 497 | 2, /* rightshift */
|
|---|
| 498 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 499 | 19, /* bitsize */
|
|---|
| 500 | TRUE, /* pc_relative */
|
|---|
| 501 | 0, /* bitpos */
|
|---|
| 502 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 503 | mmix_elf_reloc, /* special_function */
|
|---|
| 504 | "R_MMIX_CBRANCH_1", /* name */
|
|---|
| 505 | FALSE, /* partial_inplace */
|
|---|
| 506 | ~0x0100ffff, /* src_mask */
|
|---|
| 507 | 0x0100ffff, /* dst_mask */
|
|---|
| 508 | TRUE), /* pcrel_offset */
|
|---|
| 509 |
|
|---|
| 510 | HOWTO (R_MMIX_CBRANCH_2, /* type */
|
|---|
| 511 | 2, /* rightshift */
|
|---|
| 512 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 513 | 19, /* bitsize */
|
|---|
| 514 | TRUE, /* pc_relative */
|
|---|
| 515 | 0, /* bitpos */
|
|---|
| 516 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 517 | mmix_elf_reloc, /* special_function */
|
|---|
| 518 | "R_MMIX_CBRANCH_2", /* name */
|
|---|
| 519 | FALSE, /* partial_inplace */
|
|---|
| 520 | ~0x0100ffff, /* src_mask */
|
|---|
| 521 | 0x0100ffff, /* dst_mask */
|
|---|
| 522 | TRUE), /* pcrel_offset */
|
|---|
| 523 |
|
|---|
| 524 | HOWTO (R_MMIX_CBRANCH_3, /* type */
|
|---|
| 525 | 2, /* rightshift */
|
|---|
| 526 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 527 | 19, /* bitsize */
|
|---|
| 528 | TRUE, /* pc_relative */
|
|---|
| 529 | 0, /* bitpos */
|
|---|
| 530 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 531 | mmix_elf_reloc, /* special_function */
|
|---|
| 532 | "R_MMIX_CBRANCH_3", /* name */
|
|---|
| 533 | FALSE, /* partial_inplace */
|
|---|
| 534 | ~0x0100ffff, /* src_mask */
|
|---|
| 535 | 0x0100ffff, /* dst_mask */
|
|---|
| 536 | TRUE), /* pcrel_offset */
|
|---|
| 537 |
|
|---|
| 538 | /* The PUSHJ instruction can reach any (code) address, as long as it's
|
|---|
| 539 | the beginning of a function (no usable restriction). It can silently
|
|---|
| 540 | expand to a 64-bit operand, but will emit an error if any of the two
|
|---|
| 541 | least significant bits are set. The howto members reflect a simple
|
|---|
| 542 | PUSHJ. */
|
|---|
| 543 | HOWTO (R_MMIX_PUSHJ, /* type */
|
|---|
| 544 | 2, /* rightshift */
|
|---|
| 545 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 546 | 19, /* bitsize */
|
|---|
| 547 | TRUE, /* pc_relative */
|
|---|
| 548 | 0, /* bitpos */
|
|---|
| 549 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 550 | mmix_elf_reloc, /* special_function */
|
|---|
| 551 | "R_MMIX_PUSHJ", /* name */
|
|---|
| 552 | FALSE, /* partial_inplace */
|
|---|
| 553 | ~0x0100ffff, /* src_mask */
|
|---|
| 554 | 0x0100ffff, /* dst_mask */
|
|---|
| 555 | TRUE), /* pcrel_offset */
|
|---|
| 556 |
|
|---|
| 557 | HOWTO (R_MMIX_PUSHJ_1, /* type */
|
|---|
| 558 | 2, /* rightshift */
|
|---|
| 559 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 560 | 19, /* bitsize */
|
|---|
| 561 | TRUE, /* pc_relative */
|
|---|
| 562 | 0, /* bitpos */
|
|---|
| 563 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 564 | mmix_elf_reloc, /* special_function */
|
|---|
| 565 | "R_MMIX_PUSHJ_1", /* name */
|
|---|
| 566 | FALSE, /* partial_inplace */
|
|---|
| 567 | ~0x0100ffff, /* src_mask */
|
|---|
| 568 | 0x0100ffff, /* dst_mask */
|
|---|
| 569 | TRUE), /* pcrel_offset */
|
|---|
| 570 |
|
|---|
| 571 | HOWTO (R_MMIX_PUSHJ_2, /* type */
|
|---|
| 572 | 2, /* rightshift */
|
|---|
| 573 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 574 | 19, /* bitsize */
|
|---|
| 575 | TRUE, /* pc_relative */
|
|---|
| 576 | 0, /* bitpos */
|
|---|
| 577 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 578 | mmix_elf_reloc, /* special_function */
|
|---|
| 579 | "R_MMIX_PUSHJ_2", /* name */
|
|---|
| 580 | FALSE, /* partial_inplace */
|
|---|
| 581 | ~0x0100ffff, /* src_mask */
|
|---|
| 582 | 0x0100ffff, /* dst_mask */
|
|---|
| 583 | TRUE), /* pcrel_offset */
|
|---|
| 584 |
|
|---|
| 585 | HOWTO (R_MMIX_PUSHJ_3, /* type */
|
|---|
| 586 | 2, /* rightshift */
|
|---|
| 587 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 588 | 19, /* bitsize */
|
|---|
| 589 | TRUE, /* pc_relative */
|
|---|
| 590 | 0, /* bitpos */
|
|---|
| 591 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 592 | mmix_elf_reloc, /* special_function */
|
|---|
| 593 | "R_MMIX_PUSHJ_3", /* name */
|
|---|
| 594 | FALSE, /* partial_inplace */
|
|---|
| 595 | ~0x0100ffff, /* src_mask */
|
|---|
| 596 | 0x0100ffff, /* dst_mask */
|
|---|
| 597 | TRUE), /* pcrel_offset */
|
|---|
| 598 |
|
|---|
| 599 | /* A JMP is supposed to reach any (code) address. By itself, it can
|
|---|
| 600 | reach +-64M; the expansion can reach all 64 bits. Note that the 64M
|
|---|
| 601 | limit is soon reached if you link the program in wildly different
|
|---|
| 602 | memory segments. The howto members reflect a trivial JMP. */
|
|---|
| 603 | HOWTO (R_MMIX_JMP, /* type */
|
|---|
| 604 | 2, /* rightshift */
|
|---|
| 605 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 606 | 27, /* bitsize */
|
|---|
| 607 | TRUE, /* pc_relative */
|
|---|
| 608 | 0, /* bitpos */
|
|---|
| 609 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 610 | mmix_elf_reloc, /* special_function */
|
|---|
| 611 | "R_MMIX_JMP", /* name */
|
|---|
| 612 | FALSE, /* partial_inplace */
|
|---|
| 613 | ~0x1ffffff, /* src_mask */
|
|---|
| 614 | 0x1ffffff, /* dst_mask */
|
|---|
| 615 | TRUE), /* pcrel_offset */
|
|---|
| 616 |
|
|---|
| 617 | HOWTO (R_MMIX_JMP_1, /* type */
|
|---|
| 618 | 2, /* rightshift */
|
|---|
| 619 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 620 | 27, /* bitsize */
|
|---|
| 621 | TRUE, /* pc_relative */
|
|---|
| 622 | 0, /* bitpos */
|
|---|
| 623 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 624 | mmix_elf_reloc, /* special_function */
|
|---|
| 625 | "R_MMIX_JMP_1", /* name */
|
|---|
| 626 | FALSE, /* partial_inplace */
|
|---|
| 627 | ~0x1ffffff, /* src_mask */
|
|---|
| 628 | 0x1ffffff, /* dst_mask */
|
|---|
| 629 | TRUE), /* pcrel_offset */
|
|---|
| 630 |
|
|---|
| 631 | HOWTO (R_MMIX_JMP_2, /* type */
|
|---|
| 632 | 2, /* rightshift */
|
|---|
| 633 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 634 | 27, /* bitsize */
|
|---|
| 635 | TRUE, /* pc_relative */
|
|---|
| 636 | 0, /* bitpos */
|
|---|
| 637 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 638 | mmix_elf_reloc, /* special_function */
|
|---|
| 639 | "R_MMIX_JMP_2", /* name */
|
|---|
| 640 | FALSE, /* partial_inplace */
|
|---|
| 641 | ~0x1ffffff, /* src_mask */
|
|---|
| 642 | 0x1ffffff, /* dst_mask */
|
|---|
| 643 | TRUE), /* pcrel_offset */
|
|---|
| 644 |
|
|---|
| 645 | HOWTO (R_MMIX_JMP_3, /* type */
|
|---|
| 646 | 2, /* rightshift */
|
|---|
| 647 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 648 | 27, /* bitsize */
|
|---|
| 649 | TRUE, /* pc_relative */
|
|---|
| 650 | 0, /* bitpos */
|
|---|
| 651 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 652 | mmix_elf_reloc, /* special_function */
|
|---|
| 653 | "R_MMIX_JMP_3", /* name */
|
|---|
| 654 | FALSE, /* partial_inplace */
|
|---|
| 655 | ~0x1ffffff, /* src_mask */
|
|---|
| 656 | 0x1ffffff, /* dst_mask */
|
|---|
| 657 | TRUE), /* pcrel_offset */
|
|---|
| 658 |
|
|---|
| 659 | /* When we don't emit link-time-relaxable code from the assembler, or
|
|---|
| 660 | when relaxation has done all it can do, these relocs are used. For
|
|---|
| 661 | GETA/PUSHJ/branches. */
|
|---|
| 662 | HOWTO (R_MMIX_ADDR19, /* type */
|
|---|
| 663 | 2, /* rightshift */
|
|---|
| 664 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 665 | 19, /* bitsize */
|
|---|
| 666 | TRUE, /* pc_relative */
|
|---|
| 667 | 0, /* bitpos */
|
|---|
| 668 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 669 | mmix_elf_reloc, /* special_function */
|
|---|
| 670 | "R_MMIX_ADDR19", /* name */
|
|---|
| 671 | FALSE, /* partial_inplace */
|
|---|
| 672 | ~0x0100ffff, /* src_mask */
|
|---|
| 673 | 0x0100ffff, /* dst_mask */
|
|---|
| 674 | TRUE), /* pcrel_offset */
|
|---|
| 675 |
|
|---|
| 676 | /* For JMP. */
|
|---|
| 677 | HOWTO (R_MMIX_ADDR27, /* type */
|
|---|
| 678 | 2, /* rightshift */
|
|---|
| 679 | 2, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 680 | 27, /* bitsize */
|
|---|
| 681 | TRUE, /* pc_relative */
|
|---|
| 682 | 0, /* bitpos */
|
|---|
| 683 | complain_overflow_signed, /* complain_on_overflow */
|
|---|
| 684 | mmix_elf_reloc, /* special_function */
|
|---|
| 685 | "R_MMIX_ADDR27", /* name */
|
|---|
| 686 | FALSE, /* partial_inplace */
|
|---|
| 687 | ~0x1ffffff, /* src_mask */
|
|---|
| 688 | 0x1ffffff, /* dst_mask */
|
|---|
| 689 | TRUE), /* pcrel_offset */
|
|---|
| 690 |
|
|---|
| 691 | /* A general register or the value 0..255. If a value, then the
|
|---|
| 692 | instruction (offset -3) needs adjusting. */
|
|---|
| 693 | HOWTO (R_MMIX_REG_OR_BYTE, /* type */
|
|---|
| 694 | 0, /* rightshift */
|
|---|
| 695 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 696 | 8, /* bitsize */
|
|---|
| 697 | FALSE, /* pc_relative */
|
|---|
| 698 | 0, /* bitpos */
|
|---|
| 699 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 700 | mmix_elf_reloc, /* special_function */
|
|---|
| 701 | "R_MMIX_REG_OR_BYTE", /* name */
|
|---|
| 702 | FALSE, /* partial_inplace */
|
|---|
| 703 | 0, /* src_mask */
|
|---|
| 704 | 0xff, /* dst_mask */
|
|---|
| 705 | FALSE), /* pcrel_offset */
|
|---|
| 706 |
|
|---|
| 707 | /* A general register. */
|
|---|
| 708 | HOWTO (R_MMIX_REG, /* type */
|
|---|
| 709 | 0, /* rightshift */
|
|---|
| 710 | 1, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 711 | 8, /* bitsize */
|
|---|
| 712 | FALSE, /* pc_relative */
|
|---|
| 713 | 0, /* bitpos */
|
|---|
| 714 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 715 | mmix_elf_reloc, /* special_function */
|
|---|
| 716 | "R_MMIX_REG", /* name */
|
|---|
| 717 | FALSE, /* partial_inplace */
|
|---|
| 718 | 0, /* src_mask */
|
|---|
| 719 | 0xff, /* dst_mask */
|
|---|
| 720 | FALSE), /* pcrel_offset */
|
|---|
| 721 |
|
|---|
| 722 | /* A register plus an index, corresponding to the relocation expression.
|
|---|
| 723 | The sizes must correspond to the valid range of the expression, while
|
|---|
| 724 | the bitmasks correspond to what we store in the image. */
|
|---|
| 725 | HOWTO (R_MMIX_BASE_PLUS_OFFSET, /* type */
|
|---|
| 726 | 0, /* rightshift */
|
|---|
| 727 | 4, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 728 | 64, /* bitsize */
|
|---|
| 729 | FALSE, /* pc_relative */
|
|---|
| 730 | 0, /* bitpos */
|
|---|
| 731 | complain_overflow_bitfield, /* complain_on_overflow */
|
|---|
| 732 | mmix_elf_reloc, /* special_function */
|
|---|
| 733 | "R_MMIX_BASE_PLUS_OFFSET", /* name */
|
|---|
| 734 | FALSE, /* partial_inplace */
|
|---|
| 735 | 0, /* src_mask */
|
|---|
| 736 | 0xffff, /* dst_mask */
|
|---|
| 737 | FALSE), /* pcrel_offset */
|
|---|
| 738 |
|
|---|
| 739 | /* A "magic" relocation for a LOCAL expression, asserting that the
|
|---|
| 740 | expression is less than the number of global registers. No actual
|
|---|
| 741 | modification of the contents is done. Implementing this as a
|
|---|
| 742 | relocation was less intrusive than e.g. putting such expressions in a
|
|---|
| 743 | section to discard *after* relocation. */
|
|---|
| 744 | HOWTO (R_MMIX_LOCAL, /* type */
|
|---|
| 745 | 0, /* rightshift */
|
|---|
| 746 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 747 | 0, /* bitsize */
|
|---|
| 748 | FALSE, /* pc_relative */
|
|---|
| 749 | 0, /* bitpos */
|
|---|
| 750 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 751 | mmix_elf_reloc, /* special_function */
|
|---|
| 752 | "R_MMIX_LOCAL", /* name */
|
|---|
| 753 | FALSE, /* partial_inplace */
|
|---|
| 754 | 0, /* src_mask */
|
|---|
| 755 | 0, /* dst_mask */
|
|---|
| 756 | FALSE), /* pcrel_offset */
|
|---|
| 757 | };
|
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 | /* Map BFD reloc types to MMIX ELF reloc types. */
|
|---|
| 761 |
|
|---|
| 762 | struct mmix_reloc_map
|
|---|
| 763 | {
|
|---|
| 764 | bfd_reloc_code_real_type bfd_reloc_val;
|
|---|
| 765 | enum elf_mmix_reloc_type elf_reloc_val;
|
|---|
| 766 | };
|
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 | static const struct mmix_reloc_map mmix_reloc_map[] =
|
|---|
| 770 | {
|
|---|
| 771 | {BFD_RELOC_NONE, R_MMIX_NONE},
|
|---|
| 772 | {BFD_RELOC_8, R_MMIX_8},
|
|---|
| 773 | {BFD_RELOC_16, R_MMIX_16},
|
|---|
| 774 | {BFD_RELOC_24, R_MMIX_24},
|
|---|
| 775 | {BFD_RELOC_32, R_MMIX_32},
|
|---|
| 776 | {BFD_RELOC_64, R_MMIX_64},
|
|---|
| 777 | {BFD_RELOC_8_PCREL, R_MMIX_PC_8},
|
|---|
| 778 | {BFD_RELOC_16_PCREL, R_MMIX_PC_16},
|
|---|
| 779 | {BFD_RELOC_24_PCREL, R_MMIX_PC_24},
|
|---|
| 780 | {BFD_RELOC_32_PCREL, R_MMIX_PC_32},
|
|---|
| 781 | {BFD_RELOC_64_PCREL, R_MMIX_PC_64},
|
|---|
| 782 | {BFD_RELOC_VTABLE_INHERIT, R_MMIX_GNU_VTINHERIT},
|
|---|
| 783 | {BFD_RELOC_VTABLE_ENTRY, R_MMIX_GNU_VTENTRY},
|
|---|
| 784 | {BFD_RELOC_MMIX_GETA, R_MMIX_GETA},
|
|---|
| 785 | {BFD_RELOC_MMIX_CBRANCH, R_MMIX_CBRANCH},
|
|---|
| 786 | {BFD_RELOC_MMIX_PUSHJ, R_MMIX_PUSHJ},
|
|---|
| 787 | {BFD_RELOC_MMIX_JMP, R_MMIX_JMP},
|
|---|
| 788 | {BFD_RELOC_MMIX_ADDR19, R_MMIX_ADDR19},
|
|---|
| 789 | {BFD_RELOC_MMIX_ADDR27, R_MMIX_ADDR27},
|
|---|
| 790 | {BFD_RELOC_MMIX_REG_OR_BYTE, R_MMIX_REG_OR_BYTE},
|
|---|
| 791 | {BFD_RELOC_MMIX_REG, R_MMIX_REG},
|
|---|
| 792 | {BFD_RELOC_MMIX_BASE_PLUS_OFFSET, R_MMIX_BASE_PLUS_OFFSET},
|
|---|
| 793 | {BFD_RELOC_MMIX_LOCAL, R_MMIX_LOCAL}
|
|---|
| 794 | };
|
|---|
| 795 |
|
|---|
| 796 | static reloc_howto_type *
|
|---|
| 797 | bfd_elf64_bfd_reloc_type_lookup (abfd, code)
|
|---|
| 798 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 799 | bfd_reloc_code_real_type code;
|
|---|
| 800 | {
|
|---|
| 801 | unsigned int i;
|
|---|
| 802 |
|
|---|
| 803 | for (i = 0;
|
|---|
| 804 | i < sizeof (mmix_reloc_map) / sizeof (mmix_reloc_map[0]);
|
|---|
| 805 | i++)
|
|---|
| 806 | {
|
|---|
| 807 | if (mmix_reloc_map[i].bfd_reloc_val == code)
|
|---|
| 808 | return &elf_mmix_howto_table[mmix_reloc_map[i].elf_reloc_val];
|
|---|
| 809 | }
|
|---|
| 810 |
|
|---|
| 811 | return NULL;
|
|---|
| 812 | }
|
|---|
| 813 |
|
|---|
| 814 | static bfd_boolean
|
|---|
| 815 | mmix_elf_new_section_hook (abfd, sec)
|
|---|
| 816 | bfd *abfd;
|
|---|
| 817 | asection *sec;
|
|---|
| 818 | {
|
|---|
| 819 | struct _mmix_elf_section_data *sdata;
|
|---|
| 820 | bfd_size_type amt = sizeof (*sdata);
|
|---|
| 821 |
|
|---|
| 822 | sdata = (struct _mmix_elf_section_data *) bfd_zalloc (abfd, amt);
|
|---|
| 823 | if (sdata == NULL)
|
|---|
| 824 | return FALSE;
|
|---|
| 825 | sec->used_by_bfd = (PTR) sdata;
|
|---|
| 826 |
|
|---|
| 827 | return _bfd_elf_new_section_hook (abfd, sec);
|
|---|
| 828 | }
|
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 | /* This function performs the actual bitfiddling and sanity check for a
|
|---|
| 832 | final relocation. Each relocation gets its *worst*-case expansion
|
|---|
| 833 | in size when it arrives here; any reduction in size should have been
|
|---|
| 834 | caught in linker relaxation earlier. When we get here, the relocation
|
|---|
| 835 | looks like the smallest instruction with SWYM:s (nop:s) appended to the
|
|---|
| 836 | max size. We fill in those nop:s.
|
|---|
| 837 |
|
|---|
| 838 | R_MMIX_GETA: (FIXME: Relaxation should break this up in 1, 2, 3 tetra)
|
|---|
| 839 | GETA $N,foo
|
|---|
| 840 | ->
|
|---|
| 841 | SETL $N,foo & 0xffff
|
|---|
| 842 | INCML $N,(foo >> 16) & 0xffff
|
|---|
| 843 | INCMH $N,(foo >> 32) & 0xffff
|
|---|
| 844 | INCH $N,(foo >> 48) & 0xffff
|
|---|
| 845 |
|
|---|
| 846 | R_MMIX_CBRANCH: (FIXME: Relaxation should break this up, but
|
|---|
| 847 | condbranches needing relaxation might be rare enough to not be
|
|---|
| 848 | worthwhile.)
|
|---|
| 849 | [P]Bcc $N,foo
|
|---|
| 850 | ->
|
|---|
| 851 | [~P]B~cc $N,.+20
|
|---|
| 852 | SETL $255,foo & ...
|
|---|
| 853 | INCML ...
|
|---|
| 854 | INCMH ...
|
|---|
| 855 | INCH ...
|
|---|
| 856 | GO $255,$255,0
|
|---|
| 857 |
|
|---|
| 858 | R_MMIX_PUSHJ: (FIXME: Relaxation...)
|
|---|
| 859 | PUSHJ $N,foo
|
|---|
| 860 | ->
|
|---|
| 861 | SETL $255,foo & ...
|
|---|
| 862 | INCML ...
|
|---|
| 863 | INCMH ...
|
|---|
| 864 | INCH ...
|
|---|
| 865 | PUSHGO $N,$255,0
|
|---|
| 866 |
|
|---|
| 867 | R_MMIX_JMP: (FIXME: Relaxation...)
|
|---|
| 868 | JMP foo
|
|---|
| 869 | ->
|
|---|
| 870 | SETL $255,foo & ...
|
|---|
| 871 | INCML ...
|
|---|
| 872 | INCMH ...
|
|---|
| 873 | INCH ...
|
|---|
| 874 | GO $255,$255,0
|
|---|
| 875 |
|
|---|
| 876 | R_MMIX_ADDR19 and R_MMIX_ADDR27 are just filled in. */
|
|---|
| 877 |
|
|---|
| 878 | static bfd_reloc_status_type
|
|---|
| 879 | mmix_elf_perform_relocation (isec, howto, datap, addr, value)
|
|---|
| 880 | asection *isec;
|
|---|
| 881 | reloc_howto_type *howto;
|
|---|
| 882 | PTR datap;
|
|---|
| 883 | bfd_vma addr ATTRIBUTE_UNUSED;
|
|---|
| 884 | bfd_vma value;
|
|---|
| 885 | {
|
|---|
| 886 | bfd *abfd = isec->owner;
|
|---|
| 887 | bfd_reloc_status_type flag = bfd_reloc_ok;
|
|---|
| 888 | bfd_reloc_status_type r;
|
|---|
| 889 | int offs = 0;
|
|---|
| 890 | int reg = 255;
|
|---|
| 891 |
|
|---|
| 892 | /* The worst case bits are all similar SETL/INCML/INCMH/INCH sequences.
|
|---|
| 893 | We handle the differences here and the common sequence later. */
|
|---|
| 894 | switch (howto->type)
|
|---|
| 895 | {
|
|---|
| 896 | case R_MMIX_GETA:
|
|---|
| 897 | offs = 0;
|
|---|
| 898 | reg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
|
|---|
| 899 |
|
|---|
| 900 | /* We change to an absolute value. */
|
|---|
| 901 | value += addr;
|
|---|
| 902 | break;
|
|---|
| 903 |
|
|---|
| 904 | case R_MMIX_CBRANCH:
|
|---|
| 905 | {
|
|---|
| 906 | int in1 = bfd_get_16 (abfd, (bfd_byte *) datap) << 16;
|
|---|
| 907 |
|
|---|
| 908 | /* Invert the condition and prediction bit, and set the offset
|
|---|
| 909 | to five instructions ahead.
|
|---|
| 910 |
|
|---|
| 911 | We *can* do better if we want to. If the branch is found to be
|
|---|
| 912 | within limits, we could leave the branch as is; there'll just
|
|---|
| 913 | be a bunch of NOP:s after it. But we shouldn't see this
|
|---|
| 914 | sequence often enough that it's worth doing it. */
|
|---|
| 915 |
|
|---|
| 916 | bfd_put_32 (abfd,
|
|---|
| 917 | (((in1 ^ ((PRED_INV_BIT | COND_INV_BIT) << 24)) & ~0xffff)
|
|---|
| 918 | | (24/4)),
|
|---|
| 919 | (bfd_byte *) datap);
|
|---|
| 920 |
|
|---|
| 921 | /* Put a "GO $255,$255,0" after the common sequence. */
|
|---|
| 922 | bfd_put_32 (abfd,
|
|---|
| 923 | ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24) | 0xffff00,
|
|---|
| 924 | (bfd_byte *) datap + 20);
|
|---|
| 925 |
|
|---|
| 926 | /* Common sequence starts at offset 4. */
|
|---|
| 927 | offs = 4;
|
|---|
| 928 |
|
|---|
| 929 | /* We change to an absolute value. */
|
|---|
| 930 | value += addr;
|
|---|
| 931 | }
|
|---|
| 932 | break;
|
|---|
| 933 |
|
|---|
| 934 | case R_MMIX_PUSHJ:
|
|---|
| 935 | {
|
|---|
| 936 | int inreg = bfd_get_8 (abfd, (bfd_byte *) datap + 1);
|
|---|
| 937 |
|
|---|
| 938 | /* Put a "PUSHGO $N,$255,0" after the common sequence. */
|
|---|
| 939 | bfd_put_32 (abfd,
|
|---|
| 940 | ((PUSHGO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
|
|---|
| 941 | | (inreg << 16)
|
|---|
| 942 | | 0xff00,
|
|---|
| 943 | (bfd_byte *) datap + 16);
|
|---|
| 944 |
|
|---|
| 945 | /* We change to an absolute value. */
|
|---|
| 946 | value += addr;
|
|---|
| 947 | }
|
|---|
| 948 | break;
|
|---|
| 949 |
|
|---|
| 950 | case R_MMIX_JMP:
|
|---|
| 951 | /* This one is a little special. If we get here on a non-relaxing
|
|---|
| 952 | link, and the destination is actually in range, we don't need to
|
|---|
| 953 | execute the nops.
|
|---|
| 954 | If so, we fall through to the bit-fiddling relocs.
|
|---|
| 955 |
|
|---|
| 956 | FIXME: bfd_check_overflow seems broken; the relocation is
|
|---|
| 957 | rightshifted before testing, so supply a zero rightshift. */
|
|---|
| 958 |
|
|---|
| 959 | if (! ((value & 3) == 0
|
|---|
| 960 | && (r = bfd_check_overflow (complain_overflow_signed,
|
|---|
| 961 | howto->bitsize,
|
|---|
| 962 | 0,
|
|---|
| 963 | bfd_arch_bits_per_address (abfd),
|
|---|
| 964 | value)) == bfd_reloc_ok))
|
|---|
| 965 | {
|
|---|
| 966 | /* If the relocation doesn't fit in a JMP, we let the NOP:s be
|
|---|
| 967 | modified below, and put a "GO $255,$255,0" after the
|
|---|
| 968 | address-loading sequence. */
|
|---|
| 969 | bfd_put_32 (abfd,
|
|---|
| 970 | ((GO_INSN_BYTE | IMM_OFFSET_BIT) << 24)
|
|---|
| 971 | | 0xffff00,
|
|---|
| 972 | (bfd_byte *) datap + 16);
|
|---|
| 973 |
|
|---|
| 974 | /* We change to an absolute value. */
|
|---|
| 975 | value += addr;
|
|---|
| 976 | break;
|
|---|
| 977 | }
|
|---|
| 978 | /* FALLTHROUGH. */
|
|---|
| 979 | case R_MMIX_ADDR19:
|
|---|
| 980 | case R_MMIX_ADDR27:
|
|---|
| 981 | /* These must be in range, or else we emit an error. */
|
|---|
| 982 | if ((value & 3) == 0
|
|---|
| 983 | /* Note rightshift 0; see above. */
|
|---|
| 984 | && (r = bfd_check_overflow (complain_overflow_signed,
|
|---|
| 985 | howto->bitsize,
|
|---|
| 986 | 0,
|
|---|
| 987 | bfd_arch_bits_per_address (abfd),
|
|---|
| 988 | value)) == bfd_reloc_ok)
|
|---|
| 989 | {
|
|---|
| 990 | bfd_vma in1
|
|---|
| 991 | = bfd_get_32 (abfd, (bfd_byte *) datap);
|
|---|
| 992 | bfd_vma highbit;
|
|---|
| 993 |
|
|---|
| 994 | if ((bfd_signed_vma) value < 0)
|
|---|
| 995 | {
|
|---|
| 996 | highbit = (1 << 24);
|
|---|
| 997 | value += (1 << (howto->bitsize - 1));
|
|---|
| 998 | }
|
|---|
| 999 | else
|
|---|
| 1000 | highbit = 0;
|
|---|
| 1001 |
|
|---|
| 1002 | value >>= 2;
|
|---|
| 1003 |
|
|---|
| 1004 | bfd_put_32 (abfd,
|
|---|
| 1005 | (in1 & howto->src_mask)
|
|---|
| 1006 | | highbit
|
|---|
| 1007 | | (value & howto->dst_mask),
|
|---|
| 1008 | (bfd_byte *) datap);
|
|---|
| 1009 |
|
|---|
| 1010 | return bfd_reloc_ok;
|
|---|
| 1011 | }
|
|---|
| 1012 | else
|
|---|
| 1013 | return bfd_reloc_overflow;
|
|---|
| 1014 |
|
|---|
| 1015 | case R_MMIX_BASE_PLUS_OFFSET:
|
|---|
| 1016 | {
|
|---|
| 1017 | struct bpo_reloc_section_info *bpodata
|
|---|
| 1018 | = mmix_elf_section_data (isec)->bpo.reloc;
|
|---|
| 1019 | asection *bpo_greg_section
|
|---|
| 1020 | = bpodata->bpo_greg_section;
|
|---|
| 1021 | struct bpo_greg_section_info *gregdata
|
|---|
| 1022 | = mmix_elf_section_data (bpo_greg_section)->bpo.greg;
|
|---|
| 1023 | size_t bpo_index
|
|---|
| 1024 | = gregdata->bpo_reloc_indexes[bpodata->bpo_index++];
|
|---|
| 1025 |
|
|---|
| 1026 | /* A consistency check: The value we now have in "relocation" must
|
|---|
| 1027 | be the same as the value we stored for that relocation. It
|
|---|
| 1028 | doesn't cost much, so can be left in at all times. */
|
|---|
| 1029 | if (value != gregdata->reloc_request[bpo_index].value)
|
|---|
| 1030 | {
|
|---|
| 1031 | (*_bfd_error_handler)
|
|---|
| 1032 | (_("%s: Internal inconsistency error for value for\n\
|
|---|
| 1033 | linker-allocated global register: linked: 0x%lx%08lx != relaxed: 0x%lx%08lx\n"),
|
|---|
| 1034 | bfd_get_filename (isec->owner),
|
|---|
| 1035 | (unsigned long) (value >> 32), (unsigned long) value,
|
|---|
| 1036 | (unsigned long) (gregdata->reloc_request[bpo_index].value
|
|---|
| 1037 | >> 32),
|
|---|
| 1038 | (unsigned long) gregdata->reloc_request[bpo_index].value);
|
|---|
| 1039 | bfd_set_error (bfd_error_bad_value);
|
|---|
| 1040 | return bfd_reloc_overflow;
|
|---|
| 1041 | }
|
|---|
| 1042 |
|
|---|
| 1043 | /* Then store the register number and offset for that register
|
|---|
| 1044 | into datap and datap + 1 respectively. */
|
|---|
| 1045 | bfd_put_8 (abfd,
|
|---|
| 1046 | gregdata->reloc_request[bpo_index].regindex
|
|---|
| 1047 | + bpo_greg_section->output_section->vma / 8,
|
|---|
| 1048 | datap);
|
|---|
| 1049 | bfd_put_8 (abfd,
|
|---|
| 1050 | gregdata->reloc_request[bpo_index].offset,
|
|---|
| 1051 | ((unsigned char *) datap) + 1);
|
|---|
| 1052 | return bfd_reloc_ok;
|
|---|
| 1053 | }
|
|---|
| 1054 |
|
|---|
| 1055 | case R_MMIX_REG_OR_BYTE:
|
|---|
| 1056 | case R_MMIX_REG:
|
|---|
| 1057 | if (value > 255)
|
|---|
| 1058 | return bfd_reloc_overflow;
|
|---|
| 1059 | bfd_put_8 (abfd, value, datap);
|
|---|
| 1060 | return bfd_reloc_ok;
|
|---|
| 1061 |
|
|---|
| 1062 | default:
|
|---|
| 1063 | BAD_CASE (howto->type);
|
|---|
| 1064 | }
|
|---|
| 1065 |
|
|---|
| 1066 | /* This code adds the common SETL/INCML/INCMH/INCH worst-case
|
|---|
| 1067 | sequence. */
|
|---|
| 1068 |
|
|---|
| 1069 | /* Lowest two bits must be 0. We return bfd_reloc_overflow for
|
|---|
| 1070 | everything that looks strange. */
|
|---|
| 1071 | if (value & 3)
|
|---|
| 1072 | flag = bfd_reloc_overflow;
|
|---|
| 1073 |
|
|---|
| 1074 | bfd_put_32 (abfd,
|
|---|
| 1075 | (SETL_INSN_BYTE << 24) | (value & 0xffff) | (reg << 16),
|
|---|
| 1076 | (bfd_byte *) datap + offs);
|
|---|
| 1077 | bfd_put_32 (abfd,
|
|---|
| 1078 | (INCML_INSN_BYTE << 24) | ((value >> 16) & 0xffff) | (reg << 16),
|
|---|
| 1079 | (bfd_byte *) datap + offs + 4);
|
|---|
| 1080 | bfd_put_32 (abfd,
|
|---|
| 1081 | (INCMH_INSN_BYTE << 24) | ((value >> 32) & 0xffff) | (reg << 16),
|
|---|
| 1082 | (bfd_byte *) datap + offs + 8);
|
|---|
| 1083 | bfd_put_32 (abfd,
|
|---|
| 1084 | (INCH_INSN_BYTE << 24) | ((value >> 48) & 0xffff) | (reg << 16),
|
|---|
| 1085 | (bfd_byte *) datap + offs + 12);
|
|---|
| 1086 |
|
|---|
| 1087 | return flag;
|
|---|
| 1088 | }
|
|---|
| 1089 |
|
|---|
| 1090 | /* Set the howto pointer for an MMIX ELF reloc (type RELA). */
|
|---|
| 1091 |
|
|---|
| 1092 | static void
|
|---|
| 1093 | mmix_info_to_howto_rela (abfd, cache_ptr, dst)
|
|---|
| 1094 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 1095 | arelent *cache_ptr;
|
|---|
| 1096 | Elf_Internal_Rela *dst;
|
|---|
| 1097 | {
|
|---|
| 1098 | unsigned int r_type;
|
|---|
| 1099 |
|
|---|
| 1100 | r_type = ELF64_R_TYPE (dst->r_info);
|
|---|
| 1101 | BFD_ASSERT (r_type < (unsigned int) R_MMIX_max);
|
|---|
| 1102 | cache_ptr->howto = &elf_mmix_howto_table[r_type];
|
|---|
| 1103 | }
|
|---|
| 1104 |
|
|---|
| 1105 | /* Any MMIX-specific relocation gets here at assembly time or when linking
|
|---|
| 1106 | to other formats (such as mmo); this is the relocation function from
|
|---|
| 1107 | the reloc_table. We don't get here for final pure ELF linking. */
|
|---|
| 1108 |
|
|---|
| 1109 | static bfd_reloc_status_type
|
|---|
| 1110 | mmix_elf_reloc (abfd, reloc_entry, symbol, data, input_section,
|
|---|
| 1111 | output_bfd, error_message)
|
|---|
| 1112 | bfd *abfd;
|
|---|
| 1113 | arelent *reloc_entry;
|
|---|
| 1114 | asymbol *symbol;
|
|---|
| 1115 | PTR data;
|
|---|
| 1116 | asection *input_section;
|
|---|
| 1117 | bfd *output_bfd;
|
|---|
| 1118 | char **error_message ATTRIBUTE_UNUSED;
|
|---|
| 1119 | {
|
|---|
| 1120 | bfd_vma relocation;
|
|---|
| 1121 | bfd_reloc_status_type r;
|
|---|
| 1122 | asection *reloc_target_output_section;
|
|---|
| 1123 | bfd_reloc_status_type flag = bfd_reloc_ok;
|
|---|
| 1124 | bfd_vma output_base = 0;
|
|---|
| 1125 | bfd_vma addr;
|
|---|
| 1126 |
|
|---|
| 1127 | r = bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
|
|---|
| 1128 | input_section, output_bfd, error_message);
|
|---|
| 1129 |
|
|---|
| 1130 | /* If that was all that was needed (i.e. this isn't a final link, only
|
|---|
| 1131 | some segment adjustments), we're done. */
|
|---|
| 1132 | if (r != bfd_reloc_continue)
|
|---|
| 1133 | return r;
|
|---|
| 1134 |
|
|---|
| 1135 | if (bfd_is_und_section (symbol->section)
|
|---|
| 1136 | && (symbol->flags & BSF_WEAK) == 0
|
|---|
| 1137 | && output_bfd == (bfd *) NULL)
|
|---|
| 1138 | return bfd_reloc_undefined;
|
|---|
| 1139 |
|
|---|
| 1140 | /* Is the address of the relocation really within the section? */
|
|---|
| 1141 | if (reloc_entry->address > input_section->_cooked_size)
|
|---|
| 1142 | return bfd_reloc_outofrange;
|
|---|
| 1143 |
|
|---|
| 1144 | /* Work out which section the relocation is targetted at and the
|
|---|
| 1145 | initial relocation command value. */
|
|---|
| 1146 |
|
|---|
| 1147 | /* Get symbol value. (Common symbols are special.) */
|
|---|
| 1148 | if (bfd_is_com_section (symbol->section))
|
|---|
| 1149 | relocation = 0;
|
|---|
| 1150 | else
|
|---|
| 1151 | relocation = symbol->value;
|
|---|
| 1152 |
|
|---|
| 1153 | reloc_target_output_section = bfd_get_output_section (symbol);
|
|---|
| 1154 |
|
|---|
| 1155 | /* Here the variable relocation holds the final address of the symbol we
|
|---|
| 1156 | are relocating against, plus any addend. */
|
|---|
| 1157 | if (output_bfd)
|
|---|
| 1158 | output_base = 0;
|
|---|
| 1159 | else
|
|---|
| 1160 | output_base = reloc_target_output_section->vma;
|
|---|
| 1161 |
|
|---|
| 1162 | relocation += output_base + symbol->section->output_offset;
|
|---|
| 1163 |
|
|---|
| 1164 | /* Get position of relocation. */
|
|---|
| 1165 | addr = (reloc_entry->address + input_section->output_section->vma
|
|---|
| 1166 | + input_section->output_offset);
|
|---|
| 1167 | if (output_bfd != (bfd *) NULL)
|
|---|
| 1168 | {
|
|---|
| 1169 | /* Add in supplied addend. */
|
|---|
| 1170 | relocation += reloc_entry->addend;
|
|---|
| 1171 |
|
|---|
| 1172 | /* This is a partial relocation, and we want to apply the
|
|---|
| 1173 | relocation to the reloc entry rather than the raw data.
|
|---|
| 1174 | Modify the reloc inplace to reflect what we now know. */
|
|---|
| 1175 | reloc_entry->addend = relocation;
|
|---|
| 1176 | reloc_entry->address += input_section->output_offset;
|
|---|
| 1177 | return flag;
|
|---|
| 1178 | }
|
|---|
| 1179 |
|
|---|
| 1180 | return mmix_final_link_relocate (reloc_entry->howto, input_section,
|
|---|
| 1181 | data, reloc_entry->address,
|
|---|
| 1182 | reloc_entry->addend, relocation,
|
|---|
| 1183 | bfd_asymbol_name (symbol),
|
|---|
| 1184 | reloc_target_output_section);
|
|---|
| 1185 | }
|
|---|
| 1186 | |
|---|
| 1187 |
|
|---|
| 1188 | /* Relocate an MMIX ELF section. Modified from elf32-fr30.c; look to it
|
|---|
| 1189 | for guidance if you're thinking of copying this. */
|
|---|
| 1190 |
|
|---|
| 1191 | static bfd_boolean
|
|---|
| 1192 | mmix_elf_relocate_section (output_bfd, info, input_bfd, input_section,
|
|---|
| 1193 | contents, relocs, local_syms, local_sections)
|
|---|
| 1194 | bfd *output_bfd ATTRIBUTE_UNUSED;
|
|---|
| 1195 | struct bfd_link_info *info;
|
|---|
| 1196 | bfd *input_bfd;
|
|---|
| 1197 | asection *input_section;
|
|---|
| 1198 | bfd_byte *contents;
|
|---|
| 1199 | Elf_Internal_Rela *relocs;
|
|---|
| 1200 | Elf_Internal_Sym *local_syms;
|
|---|
| 1201 | asection **local_sections;
|
|---|
| 1202 | {
|
|---|
| 1203 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 1204 | struct elf_link_hash_entry **sym_hashes;
|
|---|
| 1205 | Elf_Internal_Rela *rel;
|
|---|
| 1206 | Elf_Internal_Rela *relend;
|
|---|
| 1207 |
|
|---|
| 1208 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
|
|---|
| 1209 | sym_hashes = elf_sym_hashes (input_bfd);
|
|---|
| 1210 | relend = relocs + input_section->reloc_count;
|
|---|
| 1211 |
|
|---|
| 1212 | for (rel = relocs; rel < relend; rel ++)
|
|---|
| 1213 | {
|
|---|
| 1214 | reloc_howto_type *howto;
|
|---|
| 1215 | unsigned long r_symndx;
|
|---|
| 1216 | Elf_Internal_Sym *sym;
|
|---|
| 1217 | asection *sec;
|
|---|
| 1218 | struct elf_link_hash_entry *h;
|
|---|
| 1219 | bfd_vma relocation;
|
|---|
| 1220 | bfd_reloc_status_type r;
|
|---|
| 1221 | const char *name = NULL;
|
|---|
| 1222 | int r_type;
|
|---|
| 1223 | bfd_boolean undefined_signalled = FALSE;
|
|---|
| 1224 |
|
|---|
| 1225 | r_type = ELF64_R_TYPE (rel->r_info);
|
|---|
| 1226 |
|
|---|
| 1227 | if (r_type == R_MMIX_GNU_VTINHERIT
|
|---|
| 1228 | || r_type == R_MMIX_GNU_VTENTRY)
|
|---|
| 1229 | continue;
|
|---|
| 1230 |
|
|---|
| 1231 | r_symndx = ELF64_R_SYM (rel->r_info);
|
|---|
| 1232 |
|
|---|
| 1233 | if (info->relocateable)
|
|---|
| 1234 | {
|
|---|
| 1235 | /* This is a relocateable link. We don't have to change
|
|---|
| 1236 | anything, unless the reloc is against a section symbol,
|
|---|
| 1237 | in which case we have to adjust according to where the
|
|---|
| 1238 | section symbol winds up in the output section. */
|
|---|
| 1239 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 1240 | {
|
|---|
| 1241 | sym = local_syms + r_symndx;
|
|---|
| 1242 |
|
|---|
| 1243 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
|
|---|
| 1244 | {
|
|---|
| 1245 | sec = local_sections [r_symndx];
|
|---|
| 1246 | rel->r_addend += sec->output_offset + sym->st_value;
|
|---|
| 1247 | }
|
|---|
| 1248 | }
|
|---|
| 1249 |
|
|---|
| 1250 | continue;
|
|---|
| 1251 | }
|
|---|
| 1252 |
|
|---|
| 1253 | /* This is a final link. */
|
|---|
| 1254 | howto = elf_mmix_howto_table + ELF64_R_TYPE (rel->r_info);
|
|---|
| 1255 | h = NULL;
|
|---|
| 1256 | sym = NULL;
|
|---|
| 1257 | sec = NULL;
|
|---|
| 1258 |
|
|---|
| 1259 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 1260 | {
|
|---|
| 1261 | sym = local_syms + r_symndx;
|
|---|
| 1262 | sec = local_sections [r_symndx];
|
|---|
| 1263 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
|
|---|
| 1264 |
|
|---|
| 1265 | name = bfd_elf_string_from_elf_section
|
|---|
| 1266 | (input_bfd, symtab_hdr->sh_link, sym->st_name);
|
|---|
| 1267 | name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
|
|---|
| 1268 | }
|
|---|
| 1269 | else
|
|---|
| 1270 | {
|
|---|
| 1271 | h = sym_hashes [r_symndx - symtab_hdr->sh_info];
|
|---|
| 1272 |
|
|---|
| 1273 | while (h->root.type == bfd_link_hash_indirect
|
|---|
| 1274 | || h->root.type == bfd_link_hash_warning)
|
|---|
| 1275 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
|---|
| 1276 |
|
|---|
| 1277 | name = h->root.root.string;
|
|---|
| 1278 |
|
|---|
| 1279 | if (h->root.type == bfd_link_hash_defined
|
|---|
| 1280 | || h->root.type == bfd_link_hash_defweak)
|
|---|
| 1281 | {
|
|---|
| 1282 | sec = h->root.u.def.section;
|
|---|
| 1283 | relocation = (h->root.u.def.value
|
|---|
| 1284 | + sec->output_section->vma
|
|---|
| 1285 | + sec->output_offset);
|
|---|
| 1286 | }
|
|---|
| 1287 | else if (h->root.type == bfd_link_hash_undefweak)
|
|---|
| 1288 | relocation = 0;
|
|---|
| 1289 | else if (info->shared
|
|---|
| 1290 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
|
|---|
| 1291 | relocation = 0;
|
|---|
| 1292 | else
|
|---|
| 1293 | {
|
|---|
| 1294 | /* The test on undefined_signalled is redundant at the
|
|---|
| 1295 | moment, but kept for symmetry. */
|
|---|
| 1296 | if (! undefined_signalled
|
|---|
| 1297 | && ! ((*info->callbacks->undefined_symbol)
|
|---|
| 1298 | (info, h->root.root.string, input_bfd,
|
|---|
| 1299 | input_section, rel->r_offset, TRUE)))
|
|---|
| 1300 | return FALSE;
|
|---|
| 1301 | undefined_signalled = TRUE;
|
|---|
| 1302 | relocation = 0;
|
|---|
| 1303 | }
|
|---|
| 1304 | }
|
|---|
| 1305 |
|
|---|
| 1306 | r = mmix_final_link_relocate (howto, input_section,
|
|---|
| 1307 | contents, rel->r_offset,
|
|---|
| 1308 | rel->r_addend, relocation, name, sec);
|
|---|
| 1309 |
|
|---|
| 1310 | if (r != bfd_reloc_ok)
|
|---|
| 1311 | {
|
|---|
| 1312 | bfd_boolean check_ok = TRUE;
|
|---|
| 1313 | const char * msg = (const char *) NULL;
|
|---|
| 1314 |
|
|---|
| 1315 | switch (r)
|
|---|
| 1316 | {
|
|---|
| 1317 | case bfd_reloc_overflow:
|
|---|
| 1318 | check_ok = info->callbacks->reloc_overflow
|
|---|
| 1319 | (info, name, howto->name, (bfd_vma) 0,
|
|---|
| 1320 | input_bfd, input_section, rel->r_offset);
|
|---|
| 1321 | break;
|
|---|
| 1322 |
|
|---|
| 1323 | case bfd_reloc_undefined:
|
|---|
| 1324 | /* We may have sent this message above. */
|
|---|
| 1325 | if (! undefined_signalled)
|
|---|
| 1326 | check_ok = info->callbacks->undefined_symbol
|
|---|
| 1327 | (info, name, input_bfd, input_section, rel->r_offset,
|
|---|
| 1328 | TRUE);
|
|---|
| 1329 | undefined_signalled = TRUE;
|
|---|
| 1330 | break;
|
|---|
| 1331 |
|
|---|
| 1332 | case bfd_reloc_outofrange:
|
|---|
| 1333 | msg = _("internal error: out of range error");
|
|---|
| 1334 | break;
|
|---|
| 1335 |
|
|---|
| 1336 | case bfd_reloc_notsupported:
|
|---|
| 1337 | msg = _("internal error: unsupported relocation error");
|
|---|
| 1338 | break;
|
|---|
| 1339 |
|
|---|
| 1340 | case bfd_reloc_dangerous:
|
|---|
| 1341 | msg = _("internal error: dangerous relocation");
|
|---|
| 1342 | break;
|
|---|
| 1343 |
|
|---|
| 1344 | default:
|
|---|
| 1345 | msg = _("internal error: unknown error");
|
|---|
| 1346 | break;
|
|---|
| 1347 | }
|
|---|
| 1348 |
|
|---|
| 1349 | if (msg)
|
|---|
| 1350 | check_ok = info->callbacks->warning
|
|---|
| 1351 | (info, msg, name, input_bfd, input_section, rel->r_offset);
|
|---|
| 1352 |
|
|---|
| 1353 | if (! check_ok)
|
|---|
| 1354 | return FALSE;
|
|---|
| 1355 | }
|
|---|
| 1356 | }
|
|---|
| 1357 |
|
|---|
| 1358 | return TRUE;
|
|---|
| 1359 | }
|
|---|
| 1360 | |
|---|
| 1361 |
|
|---|
| 1362 | /* Perform a single relocation. By default we use the standard BFD
|
|---|
| 1363 | routines. A few relocs we have to do ourselves. */
|
|---|
| 1364 |
|
|---|
| 1365 | static bfd_reloc_status_type
|
|---|
| 1366 | mmix_final_link_relocate (howto, input_section, contents,
|
|---|
| 1367 | r_offset, r_addend, relocation, symname, symsec)
|
|---|
| 1368 | reloc_howto_type *howto;
|
|---|
| 1369 | asection *input_section;
|
|---|
| 1370 | bfd_byte *contents;
|
|---|
| 1371 | bfd_vma r_offset;
|
|---|
| 1372 | bfd_signed_vma r_addend;
|
|---|
| 1373 | bfd_vma relocation;
|
|---|
| 1374 | const char *symname;
|
|---|
| 1375 | asection *symsec;
|
|---|
| 1376 | {
|
|---|
| 1377 | bfd_reloc_status_type r = bfd_reloc_ok;
|
|---|
| 1378 | bfd_vma addr
|
|---|
| 1379 | = (input_section->output_section->vma
|
|---|
| 1380 | + input_section->output_offset
|
|---|
| 1381 | + r_offset);
|
|---|
| 1382 | bfd_signed_vma srel
|
|---|
| 1383 | = (bfd_signed_vma) relocation + r_addend;
|
|---|
| 1384 |
|
|---|
| 1385 | switch (howto->type)
|
|---|
| 1386 | {
|
|---|
| 1387 | /* All these are PC-relative. */
|
|---|
| 1388 | case R_MMIX_PUSHJ:
|
|---|
| 1389 | case R_MMIX_CBRANCH:
|
|---|
| 1390 | case R_MMIX_ADDR19:
|
|---|
| 1391 | case R_MMIX_GETA:
|
|---|
| 1392 | case R_MMIX_ADDR27:
|
|---|
| 1393 | case R_MMIX_JMP:
|
|---|
| 1394 | contents += r_offset;
|
|---|
| 1395 |
|
|---|
| 1396 | srel -= (input_section->output_section->vma
|
|---|
| 1397 | + input_section->output_offset
|
|---|
| 1398 | + r_offset);
|
|---|
| 1399 |
|
|---|
| 1400 | r = mmix_elf_perform_relocation (input_section, howto, contents,
|
|---|
| 1401 | addr, srel);
|
|---|
| 1402 | break;
|
|---|
| 1403 |
|
|---|
| 1404 | case R_MMIX_BASE_PLUS_OFFSET:
|
|---|
| 1405 | if (symsec == NULL)
|
|---|
| 1406 | return bfd_reloc_undefined;
|
|---|
| 1407 |
|
|---|
| 1408 | /* Check that we're not relocating against a register symbol. */
|
|---|
| 1409 | if (strcmp (bfd_get_section_name (symsec->owner, symsec),
|
|---|
| 1410 | MMIX_REG_CONTENTS_SECTION_NAME) == 0
|
|---|
| 1411 | || strcmp (bfd_get_section_name (symsec->owner, symsec),
|
|---|
| 1412 | MMIX_REG_SECTION_NAME) == 0)
|
|---|
| 1413 | {
|
|---|
| 1414 | /* Note: This is separated out into two messages in order
|
|---|
| 1415 | to ease the translation into other languages. */
|
|---|
| 1416 | if (symname == NULL || *symname == 0)
|
|---|
| 1417 | (*_bfd_error_handler)
|
|---|
| 1418 | (_("%s: base-plus-offset relocation against register symbol: (unknown) in %s"),
|
|---|
| 1419 | bfd_get_filename (input_section->owner),
|
|---|
| 1420 | bfd_get_section_name (symsec->owner, symsec));
|
|---|
| 1421 | else
|
|---|
| 1422 | (*_bfd_error_handler)
|
|---|
| 1423 | (_("%s: base-plus-offset relocation against register symbol: %s in %s"),
|
|---|
| 1424 | bfd_get_filename (input_section->owner), symname,
|
|---|
| 1425 | bfd_get_section_name (symsec->owner, symsec));
|
|---|
| 1426 | return bfd_reloc_overflow;
|
|---|
| 1427 | }
|
|---|
| 1428 | goto do_mmix_reloc;
|
|---|
| 1429 |
|
|---|
| 1430 | case R_MMIX_REG_OR_BYTE:
|
|---|
| 1431 | case R_MMIX_REG:
|
|---|
| 1432 | /* For now, we handle these alike. They must refer to an register
|
|---|
| 1433 | symbol, which is either relative to the register section and in
|
|---|
| 1434 | the range 0..255, or is in the register contents section with vma
|
|---|
| 1435 | regno * 8. */
|
|---|
| 1436 |
|
|---|
| 1437 | /* FIXME: A better way to check for reg contents section?
|
|---|
| 1438 | FIXME: Postpone section->scaling to mmix_elf_perform_relocation? */
|
|---|
| 1439 | if (symsec == NULL)
|
|---|
| 1440 | return bfd_reloc_undefined;
|
|---|
| 1441 |
|
|---|
| 1442 | if (strcmp (bfd_get_section_name (symsec->owner, symsec),
|
|---|
| 1443 | MMIX_REG_CONTENTS_SECTION_NAME) == 0)
|
|---|
| 1444 | {
|
|---|
| 1445 | if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
|
|---|
| 1446 | {
|
|---|
| 1447 | /* The bfd_reloc_outofrange return value, though intuitively
|
|---|
| 1448 | a better value, will not get us an error. */
|
|---|
| 1449 | return bfd_reloc_overflow;
|
|---|
| 1450 | }
|
|---|
| 1451 | srel /= 8;
|
|---|
| 1452 | }
|
|---|
| 1453 | else if (strcmp (bfd_get_section_name (symsec->owner, symsec),
|
|---|
| 1454 | MMIX_REG_SECTION_NAME) == 0)
|
|---|
| 1455 | {
|
|---|
| 1456 | if (srel < 0 || srel > 255)
|
|---|
| 1457 | /* The bfd_reloc_outofrange return value, though intuitively a
|
|---|
| 1458 | better value, will not get us an error. */
|
|---|
| 1459 | return bfd_reloc_overflow;
|
|---|
| 1460 | }
|
|---|
| 1461 | else
|
|---|
| 1462 | {
|
|---|
| 1463 | /* Note: This is separated out into two messages in order
|
|---|
| 1464 | to ease the translation into other languages. */
|
|---|
| 1465 | if (symname == NULL || *symname == 0)
|
|---|
| 1466 | (*_bfd_error_handler)
|
|---|
| 1467 | (_("%s: register relocation against non-register symbol: (unknown) in %s"),
|
|---|
| 1468 | bfd_get_filename (input_section->owner),
|
|---|
| 1469 | bfd_get_section_name (symsec->owner, symsec));
|
|---|
| 1470 | else
|
|---|
| 1471 | (*_bfd_error_handler)
|
|---|
| 1472 | (_("%s: register relocation against non-register symbol: %s in %s"),
|
|---|
| 1473 | bfd_get_filename (input_section->owner), symname,
|
|---|
| 1474 | bfd_get_section_name (symsec->owner, symsec));
|
|---|
| 1475 |
|
|---|
| 1476 | /* The bfd_reloc_outofrange return value, though intuitively a
|
|---|
| 1477 | better value, will not get us an error. */
|
|---|
| 1478 | return bfd_reloc_overflow;
|
|---|
| 1479 | }
|
|---|
| 1480 | do_mmix_reloc:
|
|---|
| 1481 | contents += r_offset;
|
|---|
| 1482 | r = mmix_elf_perform_relocation (input_section, howto, contents,
|
|---|
| 1483 | addr, srel);
|
|---|
| 1484 | break;
|
|---|
| 1485 |
|
|---|
| 1486 | case R_MMIX_LOCAL:
|
|---|
| 1487 | /* This isn't a real relocation, it's just an assertion that the
|
|---|
| 1488 | final relocation value corresponds to a local register. We
|
|---|
| 1489 | ignore the actual relocation; nothing is changed. */
|
|---|
| 1490 | {
|
|---|
| 1491 | asection *regsec
|
|---|
| 1492 | = bfd_get_section_by_name (input_section->output_section->owner,
|
|---|
| 1493 | MMIX_REG_CONTENTS_SECTION_NAME);
|
|---|
| 1494 | bfd_vma first_global;
|
|---|
| 1495 |
|
|---|
| 1496 | /* Check that this is an absolute value, or a reference to the
|
|---|
| 1497 | register contents section or the register (symbol) section.
|
|---|
| 1498 | Absolute numbers can get here as undefined section. Undefined
|
|---|
| 1499 | symbols are signalled elsewhere, so there's no conflict in us
|
|---|
| 1500 | accidentally handling it. */
|
|---|
| 1501 | if (!bfd_is_abs_section (symsec)
|
|---|
| 1502 | && !bfd_is_und_section (symsec)
|
|---|
| 1503 | && strcmp (bfd_get_section_name (symsec->owner, symsec),
|
|---|
| 1504 | MMIX_REG_CONTENTS_SECTION_NAME) != 0
|
|---|
| 1505 | && strcmp (bfd_get_section_name (symsec->owner, symsec),
|
|---|
| 1506 | MMIX_REG_SECTION_NAME) != 0)
|
|---|
| 1507 | {
|
|---|
| 1508 | (*_bfd_error_handler)
|
|---|
| 1509 | (_("%s: directive LOCAL valid only with a register or absolute value"),
|
|---|
| 1510 | bfd_get_filename (input_section->owner));
|
|---|
| 1511 |
|
|---|
| 1512 | return bfd_reloc_overflow;
|
|---|
| 1513 | }
|
|---|
| 1514 |
|
|---|
| 1515 | /* If we don't have a register contents section, then $255 is the
|
|---|
| 1516 | first global register. */
|
|---|
| 1517 | if (regsec == NULL)
|
|---|
| 1518 | first_global = 255;
|
|---|
| 1519 | else
|
|---|
| 1520 | {
|
|---|
| 1521 | first_global = bfd_get_section_vma (abfd, regsec) / 8;
|
|---|
| 1522 | if (strcmp (bfd_get_section_name (symsec->owner, symsec),
|
|---|
| 1523 | MMIX_REG_CONTENTS_SECTION_NAME) == 0)
|
|---|
| 1524 | {
|
|---|
| 1525 | if ((srel & 7) != 0 || srel < 32*8 || srel > 255*8)
|
|---|
| 1526 | /* The bfd_reloc_outofrange return value, though
|
|---|
| 1527 | intuitively a better value, will not get us an error. */
|
|---|
| 1528 | return bfd_reloc_overflow;
|
|---|
| 1529 | srel /= 8;
|
|---|
| 1530 | }
|
|---|
| 1531 | }
|
|---|
| 1532 |
|
|---|
| 1533 | if ((bfd_vma) srel >= first_global)
|
|---|
| 1534 | {
|
|---|
| 1535 | /* FIXME: Better error message. */
|
|---|
| 1536 | (*_bfd_error_handler)
|
|---|
| 1537 | (_("%s: LOCAL directive: Register $%ld is not a local register. First global register is $%ld."),
|
|---|
| 1538 | bfd_get_filename (input_section->owner), (long) srel, (long) first_global);
|
|---|
| 1539 |
|
|---|
| 1540 | return bfd_reloc_overflow;
|
|---|
| 1541 | }
|
|---|
| 1542 | }
|
|---|
| 1543 | r = bfd_reloc_ok;
|
|---|
| 1544 | break;
|
|---|
| 1545 |
|
|---|
| 1546 | default:
|
|---|
| 1547 | r = _bfd_final_link_relocate (howto, input_section->owner, input_section,
|
|---|
| 1548 | contents, r_offset,
|
|---|
| 1549 | relocation, r_addend);
|
|---|
| 1550 | }
|
|---|
| 1551 |
|
|---|
| 1552 | return r;
|
|---|
| 1553 | }
|
|---|
| 1554 | |
|---|
| 1555 |
|
|---|
| 1556 | /* Return the section that should be marked against GC for a given
|
|---|
| 1557 | relocation. */
|
|---|
| 1558 |
|
|---|
| 1559 | static asection *
|
|---|
| 1560 | mmix_elf_gc_mark_hook (sec, info, rel, h, sym)
|
|---|
| 1561 | asection *sec;
|
|---|
| 1562 | struct bfd_link_info *info ATTRIBUTE_UNUSED;
|
|---|
| 1563 | Elf_Internal_Rela *rel;
|
|---|
| 1564 | struct elf_link_hash_entry *h;
|
|---|
| 1565 | Elf_Internal_Sym *sym;
|
|---|
| 1566 | {
|
|---|
| 1567 | if (h != NULL)
|
|---|
| 1568 | {
|
|---|
| 1569 | switch (ELF64_R_TYPE (rel->r_info))
|
|---|
| 1570 | {
|
|---|
| 1571 | case R_MMIX_GNU_VTINHERIT:
|
|---|
| 1572 | case R_MMIX_GNU_VTENTRY:
|
|---|
| 1573 | break;
|
|---|
| 1574 |
|
|---|
| 1575 | default:
|
|---|
| 1576 | switch (h->root.type)
|
|---|
| 1577 | {
|
|---|
| 1578 | case bfd_link_hash_defined:
|
|---|
| 1579 | case bfd_link_hash_defweak:
|
|---|
| 1580 | return h->root.u.def.section;
|
|---|
| 1581 |
|
|---|
| 1582 | case bfd_link_hash_common:
|
|---|
| 1583 | return h->root.u.c.p->section;
|
|---|
| 1584 |
|
|---|
| 1585 | default:
|
|---|
| 1586 | break;
|
|---|
| 1587 | }
|
|---|
| 1588 | }
|
|---|
| 1589 | }
|
|---|
| 1590 | else
|
|---|
| 1591 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
|
|---|
| 1592 |
|
|---|
| 1593 | return NULL;
|
|---|
| 1594 | }
|
|---|
| 1595 |
|
|---|
| 1596 | /* Update relocation info for a GC-excluded section. We could supposedly
|
|---|
| 1597 | perform the allocation after GC, but there's no suitable hook between
|
|---|
| 1598 | GC (or section merge) and the point when all input sections must be
|
|---|
| 1599 | present. Better to waste some memory and (perhaps) a little time. */
|
|---|
| 1600 |
|
|---|
| 1601 | static bfd_boolean
|
|---|
| 1602 | mmix_elf_gc_sweep_hook (abfd, info, sec, relocs)
|
|---|
| 1603 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 1604 | struct bfd_link_info *info ATTRIBUTE_UNUSED;
|
|---|
| 1605 | asection *sec ATTRIBUTE_UNUSED;
|
|---|
| 1606 | const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
|
|---|
| 1607 | {
|
|---|
| 1608 | struct bpo_reloc_section_info *bpodata
|
|---|
| 1609 | = mmix_elf_section_data (sec)->bpo.reloc;
|
|---|
| 1610 | asection *allocated_gregs_section;
|
|---|
| 1611 |
|
|---|
| 1612 | /* If no bpodata here, we have nothing to do. */
|
|---|
| 1613 | if (bpodata == NULL)
|
|---|
| 1614 | return TRUE;
|
|---|
| 1615 |
|
|---|
| 1616 | allocated_gregs_section = bpodata->bpo_greg_section;
|
|---|
| 1617 |
|
|---|
| 1618 | mmix_elf_section_data (allocated_gregs_section)->bpo.greg->n_bpo_relocs
|
|---|
| 1619 | -= bpodata->n_bpo_relocs_this_section;
|
|---|
| 1620 |
|
|---|
| 1621 | return TRUE;
|
|---|
| 1622 | }
|
|---|
| 1623 | |
|---|
| 1624 |
|
|---|
| 1625 | /* Sort register relocs to come before expanding relocs. */
|
|---|
| 1626 |
|
|---|
| 1627 | static int
|
|---|
| 1628 | mmix_elf_sort_relocs (p1, p2)
|
|---|
| 1629 | const PTR p1;
|
|---|
| 1630 | const PTR p2;
|
|---|
| 1631 | {
|
|---|
| 1632 | const Elf_Internal_Rela *r1 = (const Elf_Internal_Rela *) p1;
|
|---|
| 1633 | const Elf_Internal_Rela *r2 = (const Elf_Internal_Rela *) p2;
|
|---|
| 1634 | int r1_is_reg, r2_is_reg;
|
|---|
| 1635 |
|
|---|
| 1636 | /* Sort primarily on r_offset & ~3, so relocs are done to consecutive
|
|---|
| 1637 | insns. */
|
|---|
| 1638 | if ((r1->r_offset & ~(bfd_vma) 3) > (r2->r_offset & ~(bfd_vma) 3))
|
|---|
| 1639 | return 1;
|
|---|
| 1640 | else if ((r1->r_offset & ~(bfd_vma) 3) < (r2->r_offset & ~(bfd_vma) 3))
|
|---|
| 1641 | return -1;
|
|---|
| 1642 |
|
|---|
| 1643 | r1_is_reg
|
|---|
| 1644 | = (ELF64_R_TYPE (r1->r_info) == R_MMIX_REG_OR_BYTE
|
|---|
| 1645 | || ELF64_R_TYPE (r1->r_info) == R_MMIX_REG);
|
|---|
| 1646 | r2_is_reg
|
|---|
| 1647 | = (ELF64_R_TYPE (r2->r_info) == R_MMIX_REG_OR_BYTE
|
|---|
| 1648 | || ELF64_R_TYPE (r2->r_info) == R_MMIX_REG);
|
|---|
| 1649 | if (r1_is_reg != r2_is_reg)
|
|---|
| 1650 | return r2_is_reg - r1_is_reg;
|
|---|
| 1651 |
|
|---|
| 1652 | /* Neither or both are register relocs. Then sort on full offset. */
|
|---|
| 1653 | if (r1->r_offset > r2->r_offset)
|
|---|
| 1654 | return 1;
|
|---|
| 1655 | else if (r1->r_offset < r2->r_offset)
|
|---|
| 1656 | return -1;
|
|---|
| 1657 | return 0;
|
|---|
| 1658 | }
|
|---|
| 1659 |
|
|---|
| 1660 | /* Subset of mmix_elf_check_relocs, common to ELF and mmo linking. */
|
|---|
| 1661 |
|
|---|
| 1662 | static bfd_boolean
|
|---|
| 1663 | mmix_elf_check_common_relocs (abfd, info, sec, relocs)
|
|---|
| 1664 | bfd *abfd;
|
|---|
| 1665 | struct bfd_link_info *info;
|
|---|
| 1666 | asection *sec;
|
|---|
| 1667 | const Elf_Internal_Rela *relocs;
|
|---|
| 1668 | {
|
|---|
| 1669 | bfd *bpo_greg_owner = NULL;
|
|---|
| 1670 | asection *allocated_gregs_section = NULL;
|
|---|
| 1671 | struct bpo_greg_section_info *gregdata = NULL;
|
|---|
| 1672 | struct bpo_reloc_section_info *bpodata = NULL;
|
|---|
| 1673 | const Elf_Internal_Rela *rel;
|
|---|
| 1674 | const Elf_Internal_Rela *rel_end;
|
|---|
| 1675 |
|
|---|
| 1676 | if (info->relocateable)
|
|---|
| 1677 | return TRUE;
|
|---|
| 1678 |
|
|---|
| 1679 | /* We currently have to abuse this COFF-specific member, since there's
|
|---|
| 1680 | no target-machine-dedicated member. There's no alternative outside
|
|---|
| 1681 | the bfd_link_info struct; we can't specialize a hash-table since
|
|---|
| 1682 | they're different between ELF and mmo. */
|
|---|
| 1683 | bpo_greg_owner = (bfd *) info->base_file;
|
|---|
| 1684 |
|
|---|
| 1685 | rel_end = relocs + sec->reloc_count;
|
|---|
| 1686 | for (rel = relocs; rel < rel_end; rel++)
|
|---|
| 1687 | {
|
|---|
| 1688 | switch (ELF64_R_TYPE (rel->r_info))
|
|---|
| 1689 | {
|
|---|
| 1690 | /* This relocation causes a GREG allocation. We need to count
|
|---|
| 1691 | them, and we need to create a section for them, so we need an
|
|---|
| 1692 | object to fake as the owner of that section. We can't use
|
|---|
| 1693 | the ELF dynobj for this, since the ELF bits assume lots of
|
|---|
| 1694 | DSO-related stuff if that member is non-NULL. */
|
|---|
| 1695 | case R_MMIX_BASE_PLUS_OFFSET:
|
|---|
| 1696 | if (bpo_greg_owner == NULL)
|
|---|
| 1697 | {
|
|---|
| 1698 | bpo_greg_owner = abfd;
|
|---|
| 1699 | info->base_file = (PTR) bpo_greg_owner;
|
|---|
| 1700 | }
|
|---|
| 1701 |
|
|---|
| 1702 | if (allocated_gregs_section == NULL)
|
|---|
| 1703 | allocated_gregs_section
|
|---|
| 1704 | = bfd_get_section_by_name (bpo_greg_owner,
|
|---|
| 1705 | MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
|
|---|
| 1706 |
|
|---|
| 1707 | if (allocated_gregs_section == NULL)
|
|---|
| 1708 | {
|
|---|
| 1709 | allocated_gregs_section
|
|---|
| 1710 | = bfd_make_section (bpo_greg_owner,
|
|---|
| 1711 | MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
|
|---|
| 1712 | /* Setting both SEC_ALLOC and SEC_LOAD means the section is
|
|---|
| 1713 | treated like any other section, and we'd get errors for
|
|---|
| 1714 | address overlap with the text section. Let's set none of
|
|---|
| 1715 | those flags, as that is what currently happens for usual
|
|---|
| 1716 | GREG allocations, and that works. */
|
|---|
| 1717 | if (allocated_gregs_section == NULL
|
|---|
| 1718 | || !bfd_set_section_flags (bpo_greg_owner,
|
|---|
| 1719 | allocated_gregs_section,
|
|---|
| 1720 | (SEC_HAS_CONTENTS
|
|---|
| 1721 | | SEC_IN_MEMORY
|
|---|
| 1722 | | SEC_LINKER_CREATED))
|
|---|
| 1723 | || !bfd_set_section_alignment (bpo_greg_owner,
|
|---|
| 1724 | allocated_gregs_section,
|
|---|
| 1725 | 3))
|
|---|
| 1726 | return FALSE;
|
|---|
| 1727 |
|
|---|
| 1728 | gregdata = (struct bpo_greg_section_info *)
|
|---|
| 1729 | bfd_zalloc (bpo_greg_owner, sizeof (struct bpo_greg_section_info));
|
|---|
| 1730 | if (gregdata == NULL)
|
|---|
| 1731 | return FALSE;
|
|---|
| 1732 | mmix_elf_section_data (allocated_gregs_section)->bpo.greg
|
|---|
| 1733 | = gregdata;
|
|---|
| 1734 | }
|
|---|
| 1735 | else if (gregdata == NULL)
|
|---|
| 1736 | gregdata
|
|---|
| 1737 | = mmix_elf_section_data (allocated_gregs_section)->bpo.greg;
|
|---|
| 1738 |
|
|---|
| 1739 | /* Get ourselves some auxiliary info for the BPO-relocs. */
|
|---|
| 1740 | if (bpodata == NULL)
|
|---|
| 1741 | {
|
|---|
| 1742 | /* No use doing a separate iteration pass to find the upper
|
|---|
| 1743 | limit - just use the number of relocs. */
|
|---|
| 1744 | bpodata = (struct bpo_reloc_section_info *)
|
|---|
| 1745 | bfd_alloc (bpo_greg_owner,
|
|---|
| 1746 | sizeof (struct bpo_reloc_section_info)
|
|---|
| 1747 | * (sec->reloc_count + 1));
|
|---|
| 1748 | if (bpodata == NULL)
|
|---|
| 1749 | return FALSE;
|
|---|
| 1750 | mmix_elf_section_data (sec)->bpo.reloc = bpodata;
|
|---|
| 1751 | bpodata->first_base_plus_offset_reloc
|
|---|
| 1752 | = bpodata->bpo_index
|
|---|
| 1753 | = gregdata->n_max_bpo_relocs;
|
|---|
| 1754 | bpodata->bpo_greg_section
|
|---|
| 1755 | = allocated_gregs_section;
|
|---|
| 1756 | bpodata->n_bpo_relocs_this_section = 0;
|
|---|
| 1757 | }
|
|---|
| 1758 |
|
|---|
| 1759 | bpodata->n_bpo_relocs_this_section++;
|
|---|
| 1760 | gregdata->n_max_bpo_relocs++;
|
|---|
| 1761 |
|
|---|
| 1762 | /* We don't get another chance to set this before GC; we've not
|
|---|
| 1763 | set up set up any hook that runs before GC. */
|
|---|
| 1764 | gregdata->n_bpo_relocs
|
|---|
| 1765 | = gregdata->n_max_bpo_relocs;
|
|---|
| 1766 | break;
|
|---|
| 1767 | }
|
|---|
| 1768 | }
|
|---|
| 1769 |
|
|---|
| 1770 | return TRUE;
|
|---|
| 1771 | }
|
|---|
| 1772 |
|
|---|
| 1773 | /* Look through the relocs for a section during the first phase. */
|
|---|
| 1774 |
|
|---|
| 1775 | static bfd_boolean
|
|---|
| 1776 | mmix_elf_check_relocs (abfd, info, sec, relocs)
|
|---|
| 1777 | bfd *abfd;
|
|---|
| 1778 | struct bfd_link_info *info;
|
|---|
| 1779 | asection *sec;
|
|---|
| 1780 | const Elf_Internal_Rela *relocs;
|
|---|
| 1781 | {
|
|---|
| 1782 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 1783 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
|
|---|
| 1784 | const Elf_Internal_Rela *rel;
|
|---|
| 1785 | const Elf_Internal_Rela *rel_end;
|
|---|
| 1786 |
|
|---|
| 1787 | if (info->relocateable)
|
|---|
| 1788 | return TRUE;
|
|---|
| 1789 |
|
|---|
| 1790 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
|---|
| 1791 | sym_hashes = elf_sym_hashes (abfd);
|
|---|
| 1792 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf64_External_Sym);
|
|---|
| 1793 | if (!elf_bad_symtab (abfd))
|
|---|
| 1794 | sym_hashes_end -= symtab_hdr->sh_info;
|
|---|
| 1795 |
|
|---|
| 1796 | /* First we sort the relocs so that any register relocs come before
|
|---|
| 1797 | expansion-relocs to the same insn. FIXME: Not done for mmo. */
|
|---|
| 1798 | qsort ((PTR) relocs, sec->reloc_count, sizeof (Elf_Internal_Rela),
|
|---|
| 1799 | mmix_elf_sort_relocs);
|
|---|
| 1800 |
|
|---|
| 1801 | /* Do the common part. */
|
|---|
| 1802 | if (!mmix_elf_check_common_relocs (abfd, info, sec, relocs))
|
|---|
| 1803 | return FALSE;
|
|---|
| 1804 |
|
|---|
| 1805 | rel_end = relocs + sec->reloc_count;
|
|---|
| 1806 | for (rel = relocs; rel < rel_end; rel++)
|
|---|
| 1807 | {
|
|---|
| 1808 | struct elf_link_hash_entry *h;
|
|---|
| 1809 | unsigned long r_symndx;
|
|---|
| 1810 |
|
|---|
| 1811 | r_symndx = ELF64_R_SYM (rel->r_info);
|
|---|
| 1812 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 1813 | h = NULL;
|
|---|
| 1814 | else
|
|---|
| 1815 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
|---|
| 1816 |
|
|---|
| 1817 | switch (ELF64_R_TYPE (rel->r_info))
|
|---|
| 1818 | {
|
|---|
| 1819 | /* This relocation describes the C++ object vtable hierarchy.
|
|---|
| 1820 | Reconstruct it for later use during GC. */
|
|---|
| 1821 | case R_MMIX_GNU_VTINHERIT:
|
|---|
| 1822 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
|
|---|
| 1823 | return FALSE;
|
|---|
| 1824 | break;
|
|---|
| 1825 |
|
|---|
| 1826 | /* This relocation describes which C++ vtable entries are actually
|
|---|
| 1827 | used. Record for later use during GC. */
|
|---|
| 1828 | case R_MMIX_GNU_VTENTRY:
|
|---|
| 1829 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
|
|---|
| 1830 | return FALSE;
|
|---|
| 1831 | break;
|
|---|
| 1832 | }
|
|---|
| 1833 | }
|
|---|
| 1834 |
|
|---|
| 1835 | return TRUE;
|
|---|
| 1836 | }
|
|---|
| 1837 |
|
|---|
| 1838 | /* Wrapper for mmix_elf_check_common_relocs, called when linking to mmo.
|
|---|
| 1839 | Copied from elf_link_add_object_symbols. */
|
|---|
| 1840 |
|
|---|
| 1841 | bfd_boolean
|
|---|
| 1842 | _bfd_mmix_check_all_relocs (abfd, info)
|
|---|
| 1843 | bfd *abfd;
|
|---|
| 1844 | struct bfd_link_info *info;
|
|---|
| 1845 | {
|
|---|
| 1846 | asection *o;
|
|---|
| 1847 |
|
|---|
| 1848 | for (o = abfd->sections; o != NULL; o = o->next)
|
|---|
| 1849 | {
|
|---|
| 1850 | Elf_Internal_Rela *internal_relocs;
|
|---|
| 1851 | bfd_boolean ok;
|
|---|
| 1852 |
|
|---|
| 1853 | if ((o->flags & SEC_RELOC) == 0
|
|---|
| 1854 | || o->reloc_count == 0
|
|---|
| 1855 | || ((info->strip == strip_all || info->strip == strip_debugger)
|
|---|
| 1856 | && (o->flags & SEC_DEBUGGING) != 0)
|
|---|
| 1857 | || bfd_is_abs_section (o->output_section))
|
|---|
| 1858 | continue;
|
|---|
| 1859 |
|
|---|
| 1860 | internal_relocs
|
|---|
| 1861 | = _bfd_elf64_link_read_relocs (abfd, o, (PTR) NULL,
|
|---|
| 1862 | (Elf_Internal_Rela *) NULL,
|
|---|
| 1863 | info->keep_memory);
|
|---|
| 1864 | if (internal_relocs == NULL)
|
|---|
| 1865 | return FALSE;
|
|---|
| 1866 |
|
|---|
| 1867 | ok = mmix_elf_check_common_relocs (abfd, info, o, internal_relocs);
|
|---|
| 1868 |
|
|---|
| 1869 | if (! info->keep_memory)
|
|---|
| 1870 | free (internal_relocs);
|
|---|
| 1871 |
|
|---|
| 1872 | if (! ok)
|
|---|
| 1873 | return FALSE;
|
|---|
| 1874 | }
|
|---|
| 1875 |
|
|---|
| 1876 | return TRUE;
|
|---|
| 1877 | }
|
|---|
| 1878 | |
|---|
| 1879 |
|
|---|
| 1880 | /* Change symbols relative to the reg contents section to instead be to
|
|---|
| 1881 | the register section, and scale them down to correspond to the register
|
|---|
| 1882 | number. */
|
|---|
| 1883 |
|
|---|
| 1884 | static bfd_boolean
|
|---|
| 1885 | mmix_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec)
|
|---|
| 1886 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 1887 | struct bfd_link_info *info ATTRIBUTE_UNUSED;
|
|---|
| 1888 | const char *name ATTRIBUTE_UNUSED;
|
|---|
| 1889 | Elf_Internal_Sym *sym;
|
|---|
| 1890 | asection *input_sec;
|
|---|
| 1891 | {
|
|---|
| 1892 | if (input_sec != NULL
|
|---|
| 1893 | && input_sec->name != NULL
|
|---|
| 1894 | && ELF_ST_TYPE (sym->st_info) != STT_SECTION
|
|---|
| 1895 | && strcmp (input_sec->name, MMIX_REG_CONTENTS_SECTION_NAME) == 0)
|
|---|
| 1896 | {
|
|---|
| 1897 | sym->st_value /= 8;
|
|---|
| 1898 | sym->st_shndx = SHN_REGISTER;
|
|---|
| 1899 | }
|
|---|
| 1900 |
|
|---|
| 1901 | return TRUE;
|
|---|
| 1902 | }
|
|---|
| 1903 |
|
|---|
| 1904 | /* We fake a register section that holds values that are register numbers.
|
|---|
| 1905 | Having a SHN_REGISTER and register section translates better to other
|
|---|
| 1906 | formats (e.g. mmo) than for example a STT_REGISTER attribute.
|
|---|
| 1907 | This section faking is based on a construct in elf32-mips.c. */
|
|---|
| 1908 | static asection mmix_elf_reg_section;
|
|---|
| 1909 | static asymbol mmix_elf_reg_section_symbol;
|
|---|
| 1910 | static asymbol *mmix_elf_reg_section_symbol_ptr;
|
|---|
| 1911 |
|
|---|
| 1912 | /* Handle the special MIPS section numbers that a symbol may use.
|
|---|
| 1913 | This is used for both the 32-bit and the 64-bit ABI. */
|
|---|
| 1914 |
|
|---|
| 1915 | void
|
|---|
| 1916 | mmix_elf_symbol_processing (abfd, asym)
|
|---|
| 1917 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 1918 | asymbol *asym;
|
|---|
| 1919 | {
|
|---|
| 1920 | elf_symbol_type *elfsym;
|
|---|
| 1921 |
|
|---|
| 1922 | elfsym = (elf_symbol_type *) asym;
|
|---|
| 1923 | switch (elfsym->internal_elf_sym.st_shndx)
|
|---|
| 1924 | {
|
|---|
| 1925 | case SHN_REGISTER:
|
|---|
| 1926 | if (mmix_elf_reg_section.name == NULL)
|
|---|
| 1927 | {
|
|---|
| 1928 | /* Initialize the register section. */
|
|---|
| 1929 | mmix_elf_reg_section.name = MMIX_REG_SECTION_NAME;
|
|---|
| 1930 | mmix_elf_reg_section.flags = SEC_NO_FLAGS;
|
|---|
| 1931 | mmix_elf_reg_section.output_section = &mmix_elf_reg_section;
|
|---|
| 1932 | mmix_elf_reg_section.symbol = &mmix_elf_reg_section_symbol;
|
|---|
| 1933 | mmix_elf_reg_section.symbol_ptr_ptr = &mmix_elf_reg_section_symbol_ptr;
|
|---|
| 1934 | mmix_elf_reg_section_symbol.name = MMIX_REG_SECTION_NAME;
|
|---|
| 1935 | mmix_elf_reg_section_symbol.flags = BSF_SECTION_SYM;
|
|---|
| 1936 | mmix_elf_reg_section_symbol.section = &mmix_elf_reg_section;
|
|---|
| 1937 | mmix_elf_reg_section_symbol_ptr = &mmix_elf_reg_section_symbol;
|
|---|
| 1938 | }
|
|---|
| 1939 | asym->section = &mmix_elf_reg_section;
|
|---|
| 1940 | break;
|
|---|
| 1941 |
|
|---|
| 1942 | default:
|
|---|
| 1943 | break;
|
|---|
| 1944 | }
|
|---|
| 1945 | }
|
|---|
| 1946 |
|
|---|
| 1947 | /* Given a BFD section, try to locate the corresponding ELF section
|
|---|
| 1948 | index. */
|
|---|
| 1949 |
|
|---|
| 1950 | static bfd_boolean
|
|---|
| 1951 | mmix_elf_section_from_bfd_section (abfd, sec, retval)
|
|---|
| 1952 | bfd * abfd ATTRIBUTE_UNUSED;
|
|---|
| 1953 | asection * sec;
|
|---|
| 1954 | int * retval;
|
|---|
| 1955 | {
|
|---|
| 1956 | if (strcmp (bfd_get_section_name (abfd, sec), MMIX_REG_SECTION_NAME) == 0)
|
|---|
| 1957 | *retval = SHN_REGISTER;
|
|---|
| 1958 | else
|
|---|
| 1959 | return FALSE;
|
|---|
| 1960 |
|
|---|
| 1961 | return TRUE;
|
|---|
| 1962 | }
|
|---|
| 1963 |
|
|---|
| 1964 | /* Hook called by the linker routine which adds symbols from an object
|
|---|
| 1965 | file. We must handle the special SHN_REGISTER section number here.
|
|---|
| 1966 |
|
|---|
| 1967 | We also check that we only have *one* each of the section-start
|
|---|
| 1968 | symbols, since otherwise having two with the same value would cause
|
|---|
| 1969 | them to be "merged", but with the contents serialized. */
|
|---|
| 1970 |
|
|---|
| 1971 | bfd_boolean
|
|---|
| 1972 | mmix_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
|
|---|
| 1973 | bfd *abfd;
|
|---|
| 1974 | struct bfd_link_info *info ATTRIBUTE_UNUSED;
|
|---|
| 1975 | const Elf_Internal_Sym *sym;
|
|---|
| 1976 | const char **namep ATTRIBUTE_UNUSED;
|
|---|
| 1977 | flagword *flagsp ATTRIBUTE_UNUSED;
|
|---|
| 1978 | asection **secp;
|
|---|
| 1979 | bfd_vma *valp ATTRIBUTE_UNUSED;
|
|---|
| 1980 | {
|
|---|
| 1981 | if (sym->st_shndx == SHN_REGISTER)
|
|---|
| 1982 | *secp = bfd_make_section_old_way (abfd, MMIX_REG_SECTION_NAME);
|
|---|
| 1983 | else if ((*namep)[0] == '_' && (*namep)[1] == '_' && (*namep)[2] == '.'
|
|---|
| 1984 | && strncmp (*namep, MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
|
|---|
| 1985 | strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX)) == 0)
|
|---|
| 1986 | {
|
|---|
| 1987 | /* See if we have another one. */
|
|---|
| 1988 | struct bfd_link_hash_entry *h = bfd_link_hash_lookup (info->hash,
|
|---|
| 1989 | *namep,
|
|---|
| 1990 | FALSE,
|
|---|
| 1991 | FALSE,
|
|---|
| 1992 | FALSE);
|
|---|
| 1993 |
|
|---|
| 1994 | if (h != NULL && h->type != bfd_link_hash_undefined)
|
|---|
| 1995 | {
|
|---|
| 1996 | /* How do we get the asymbol (or really: the filename) from h?
|
|---|
| 1997 | h->u.def.section->owner is NULL. */
|
|---|
| 1998 | ((*_bfd_error_handler)
|
|---|
| 1999 | (_("%s: Error: multiple definition of `%s'; start of %s is set in a earlier linked file\n"),
|
|---|
| 2000 | bfd_get_filename (abfd), *namep,
|
|---|
| 2001 | *namep + strlen (MMIX_LOC_SECTION_START_SYMBOL_PREFIX)));
|
|---|
| 2002 | bfd_set_error (bfd_error_bad_value);
|
|---|
| 2003 | return FALSE;
|
|---|
| 2004 | }
|
|---|
| 2005 | }
|
|---|
| 2006 |
|
|---|
| 2007 | return TRUE;
|
|---|
| 2008 | }
|
|---|
| 2009 |
|
|---|
| 2010 | /* We consider symbols matching "L.*:[0-9]+" to be local symbols. */
|
|---|
| 2011 |
|
|---|
| 2012 | bfd_boolean
|
|---|
| 2013 | mmix_elf_is_local_label_name (abfd, name)
|
|---|
| 2014 | bfd *abfd;
|
|---|
| 2015 | const char *name;
|
|---|
| 2016 | {
|
|---|
| 2017 | const char *colpos;
|
|---|
| 2018 | int digits;
|
|---|
| 2019 |
|
|---|
| 2020 | /* Also include the default local-label definition. */
|
|---|
| 2021 | if (_bfd_elf_is_local_label_name (abfd, name))
|
|---|
| 2022 | return TRUE;
|
|---|
| 2023 |
|
|---|
| 2024 | if (*name != 'L')
|
|---|
| 2025 | return FALSE;
|
|---|
| 2026 |
|
|---|
| 2027 | /* If there's no ":", or more than one, it's not a local symbol. */
|
|---|
| 2028 | colpos = strchr (name, ':');
|
|---|
| 2029 | if (colpos == NULL || strchr (colpos + 1, ':') != NULL)
|
|---|
| 2030 | return FALSE;
|
|---|
| 2031 |
|
|---|
| 2032 | /* Check that there are remaining characters and that they are digits. */
|
|---|
| 2033 | if (colpos[1] == 0)
|
|---|
| 2034 | return FALSE;
|
|---|
| 2035 |
|
|---|
| 2036 | digits = strspn (colpos + 1, "0123456789");
|
|---|
| 2037 | return digits != 0 && colpos[1 + digits] == 0;
|
|---|
| 2038 | }
|
|---|
| 2039 |
|
|---|
| 2040 | /* We get rid of the register section here. */
|
|---|
| 2041 |
|
|---|
| 2042 | bfd_boolean
|
|---|
| 2043 | mmix_elf_final_link (abfd, info)
|
|---|
| 2044 | bfd *abfd;
|
|---|
| 2045 | struct bfd_link_info *info;
|
|---|
| 2046 | {
|
|---|
| 2047 | /* We never output a register section, though we create one for
|
|---|
| 2048 | temporary measures. Check that nobody entered contents into it. */
|
|---|
| 2049 | asection *reg_section;
|
|---|
| 2050 | asection **secpp;
|
|---|
| 2051 |
|
|---|
| 2052 | reg_section = bfd_get_section_by_name (abfd, MMIX_REG_SECTION_NAME);
|
|---|
| 2053 |
|
|---|
| 2054 | if (reg_section != NULL)
|
|---|
| 2055 | {
|
|---|
| 2056 | /* FIXME: Pass error state gracefully. */
|
|---|
| 2057 | if (bfd_get_section_flags (abfd, reg_section) & SEC_HAS_CONTENTS)
|
|---|
| 2058 | _bfd_abort (__FILE__, __LINE__, _("Register section has contents\n"));
|
|---|
| 2059 |
|
|---|
| 2060 | /* Really remove the section. */
|
|---|
| 2061 | for (secpp = &abfd->sections;
|
|---|
| 2062 | *secpp != reg_section;
|
|---|
| 2063 | secpp = &(*secpp)->next)
|
|---|
| 2064 | ;
|
|---|
| 2065 | bfd_section_list_remove (abfd, secpp);
|
|---|
| 2066 | --abfd->section_count;
|
|---|
| 2067 | }
|
|---|
| 2068 |
|
|---|
| 2069 | if (! bfd_elf64_bfd_final_link (abfd, info))
|
|---|
| 2070 | return FALSE;
|
|---|
| 2071 |
|
|---|
| 2072 | /* Since this section is marked SEC_LINKER_CREATED, it isn't output by
|
|---|
| 2073 | the regular linker machinery. We do it here, like other targets with
|
|---|
| 2074 | special sections. */
|
|---|
| 2075 | if (info->base_file != NULL)
|
|---|
| 2076 | {
|
|---|
| 2077 | asection *greg_section
|
|---|
| 2078 | = bfd_get_section_by_name ((bfd *) info->base_file,
|
|---|
| 2079 | MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
|
|---|
| 2080 | if (!bfd_set_section_contents (abfd,
|
|---|
| 2081 | greg_section->output_section,
|
|---|
| 2082 | greg_section->contents,
|
|---|
| 2083 | (file_ptr) greg_section->output_offset,
|
|---|
| 2084 | greg_section->_cooked_size))
|
|---|
| 2085 | return FALSE;
|
|---|
| 2086 | }
|
|---|
| 2087 | return TRUE;
|
|---|
| 2088 | }
|
|---|
| 2089 |
|
|---|
| 2090 | /* Initialize stuff for the linker-generated GREGs to match
|
|---|
| 2091 | R_MMIX_BASE_PLUS_OFFSET relocs seen by the linker. */
|
|---|
| 2092 |
|
|---|
| 2093 | bfd_boolean
|
|---|
| 2094 | _bfd_mmix_prepare_linker_allocated_gregs (abfd, info)
|
|---|
| 2095 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 2096 | struct bfd_link_info *info;
|
|---|
| 2097 | {
|
|---|
| 2098 | asection *bpo_gregs_section;
|
|---|
| 2099 | bfd *bpo_greg_owner;
|
|---|
| 2100 | struct bpo_greg_section_info *gregdata;
|
|---|
| 2101 | size_t n_gregs;
|
|---|
| 2102 | bfd_vma gregs_size;
|
|---|
| 2103 | size_t i;
|
|---|
| 2104 | size_t *bpo_reloc_indexes;
|
|---|
| 2105 |
|
|---|
| 2106 | /* The bpo_greg_owner bfd is supposed to have been set by
|
|---|
| 2107 | mmix_elf_check_relocs when the first R_MMIX_BASE_PLUS_OFFSET is seen.
|
|---|
| 2108 | If there is no such object, there was no R_MMIX_BASE_PLUS_OFFSET. */
|
|---|
| 2109 | bpo_greg_owner = (bfd *) info->base_file;
|
|---|
| 2110 | if (bpo_greg_owner == NULL)
|
|---|
| 2111 | return TRUE;
|
|---|
| 2112 |
|
|---|
| 2113 | bpo_gregs_section
|
|---|
| 2114 | = bfd_get_section_by_name (bpo_greg_owner,
|
|---|
| 2115 | MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
|
|---|
| 2116 |
|
|---|
| 2117 | if (bpo_gregs_section == NULL)
|
|---|
| 2118 | return TRUE;
|
|---|
| 2119 |
|
|---|
| 2120 | /* We use the target-data handle in the ELF section data. */
|
|---|
| 2121 | gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
|
|---|
| 2122 | if (gregdata == NULL)
|
|---|
| 2123 | return FALSE;
|
|---|
| 2124 |
|
|---|
| 2125 | n_gregs = gregdata->n_bpo_relocs;
|
|---|
| 2126 | gregdata->n_allocated_bpo_gregs = n_gregs;
|
|---|
| 2127 |
|
|---|
| 2128 | /* When this reaches zero during relaxation, all entries have been
|
|---|
| 2129 | filled in and the size of the linker gregs can be calculated. */
|
|---|
| 2130 | gregdata->n_remaining_bpo_relocs_this_relaxation_round = n_gregs;
|
|---|
| 2131 |
|
|---|
| 2132 | /* Set the zeroth-order estimate for the GREGs size. */
|
|---|
| 2133 | gregs_size = n_gregs * 8;
|
|---|
| 2134 |
|
|---|
| 2135 | if (!bfd_set_section_size (bpo_greg_owner, bpo_gregs_section, gregs_size))
|
|---|
| 2136 | return FALSE;
|
|---|
| 2137 |
|
|---|
| 2138 | /* Allocate and set up the GREG arrays. They're filled in at relaxation
|
|---|
| 2139 | time. Note that we must use the max number ever noted for the array,
|
|---|
| 2140 | since the index numbers were created before GC. */
|
|---|
| 2141 | gregdata->reloc_request
|
|---|
| 2142 | = bfd_zalloc (bpo_greg_owner,
|
|---|
| 2143 | sizeof (struct bpo_reloc_request)
|
|---|
| 2144 | * gregdata->n_max_bpo_relocs);
|
|---|
| 2145 |
|
|---|
| 2146 | gregdata->bpo_reloc_indexes
|
|---|
| 2147 | = bpo_reloc_indexes
|
|---|
| 2148 | = bfd_alloc (bpo_greg_owner,
|
|---|
| 2149 | gregdata->n_max_bpo_relocs
|
|---|
| 2150 | * sizeof (size_t));
|
|---|
| 2151 | if (bpo_reloc_indexes == NULL)
|
|---|
| 2152 | return FALSE;
|
|---|
| 2153 |
|
|---|
| 2154 | /* The default order is an identity mapping. */
|
|---|
| 2155 | for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
|
|---|
| 2156 | {
|
|---|
| 2157 | bpo_reloc_indexes[i] = i;
|
|---|
| 2158 | gregdata->reloc_request[i].bpo_reloc_no = i;
|
|---|
| 2159 | }
|
|---|
| 2160 |
|
|---|
| 2161 | return TRUE;
|
|---|
| 2162 | }
|
|---|
| 2163 | |
|---|
| 2164 |
|
|---|
| 2165 | /* Fill in contents in the linker allocated gregs. Everything is
|
|---|
| 2166 | calculated at this point; we just move the contents into place here. */
|
|---|
| 2167 |
|
|---|
| 2168 | bfd_boolean
|
|---|
| 2169 | _bfd_mmix_finalize_linker_allocated_gregs (abfd, link_info)
|
|---|
| 2170 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 2171 | struct bfd_link_info *link_info;
|
|---|
| 2172 | {
|
|---|
| 2173 | asection *bpo_gregs_section;
|
|---|
| 2174 | bfd *bpo_greg_owner;
|
|---|
| 2175 | struct bpo_greg_section_info *gregdata;
|
|---|
| 2176 | size_t n_gregs;
|
|---|
| 2177 | size_t i, j;
|
|---|
| 2178 | size_t lastreg;
|
|---|
| 2179 | bfd_byte *contents;
|
|---|
| 2180 |
|
|---|
| 2181 | /* The bpo_greg_owner bfd is supposed to have been set by mmix_elf_check_relocs
|
|---|
| 2182 | when the first R_MMIX_BASE_PLUS_OFFSET is seen. If there is no such
|
|---|
| 2183 | object, there was no R_MMIX_BASE_PLUS_OFFSET. */
|
|---|
| 2184 | bpo_greg_owner = (bfd *) link_info->base_file;
|
|---|
| 2185 | if (bpo_greg_owner == NULL)
|
|---|
| 2186 | return TRUE;
|
|---|
| 2187 |
|
|---|
| 2188 | bpo_gregs_section
|
|---|
| 2189 | = bfd_get_section_by_name (bpo_greg_owner,
|
|---|
| 2190 | MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
|
|---|
| 2191 |
|
|---|
| 2192 | /* This can't happen without DSO handling. When DSOs are handled
|
|---|
| 2193 | without any R_MMIX_BASE_PLUS_OFFSET seen, there will be no such
|
|---|
| 2194 | section. */
|
|---|
| 2195 | if (bpo_gregs_section == NULL)
|
|---|
| 2196 | return TRUE;
|
|---|
| 2197 |
|
|---|
| 2198 | /* We use the target-data handle in the ELF section data. */
|
|---|
| 2199 |
|
|---|
| 2200 | gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
|
|---|
| 2201 | if (gregdata == NULL)
|
|---|
| 2202 | return FALSE;
|
|---|
| 2203 |
|
|---|
| 2204 | n_gregs = gregdata->n_allocated_bpo_gregs;
|
|---|
| 2205 |
|
|---|
| 2206 | /* We need to have a _raw_size contents even though there's only
|
|---|
| 2207 | _cooked_size worth of data, since the generic relocation machinery
|
|---|
| 2208 | will allocate and copy that much temporarily. */
|
|---|
| 2209 | bpo_gregs_section->contents
|
|---|
| 2210 | = contents = bfd_alloc (bpo_greg_owner, bpo_gregs_section->_raw_size);
|
|---|
| 2211 | if (contents == NULL)
|
|---|
| 2212 | return FALSE;
|
|---|
| 2213 |
|
|---|
| 2214 | /* Sanity check: If these numbers mismatch, some relocation has not been
|
|---|
| 2215 | accounted for and the rest of gregdata is probably inconsistent.
|
|---|
| 2216 | It's a bug, but it's more helpful to identify it than segfaulting
|
|---|
| 2217 | below. */
|
|---|
| 2218 | if (gregdata->n_remaining_bpo_relocs_this_relaxation_round
|
|---|
| 2219 | != gregdata->n_bpo_relocs)
|
|---|
| 2220 | {
|
|---|
| 2221 | (*_bfd_error_handler)
|
|---|
| 2222 | (_("Internal inconsistency: remaining %u != max %u.\n\
|
|---|
| 2223 | Please report this bug."),
|
|---|
| 2224 | gregdata->n_remaining_bpo_relocs_this_relaxation_round,
|
|---|
| 2225 | gregdata->n_bpo_relocs);
|
|---|
| 2226 | return FALSE;
|
|---|
| 2227 | }
|
|---|
| 2228 |
|
|---|
| 2229 | for (lastreg = 255, i = 0, j = 0; j < n_gregs; i++)
|
|---|
| 2230 | if (gregdata->reloc_request[i].regindex != lastreg)
|
|---|
| 2231 | {
|
|---|
| 2232 | bfd_put_64 (bpo_greg_owner, gregdata->reloc_request[i].value,
|
|---|
| 2233 | contents + j * 8);
|
|---|
| 2234 | lastreg = gregdata->reloc_request[i].regindex;
|
|---|
| 2235 | j++;
|
|---|
| 2236 | }
|
|---|
| 2237 |
|
|---|
| 2238 | return TRUE;
|
|---|
| 2239 | }
|
|---|
| 2240 |
|
|---|
| 2241 | /* Sort valid relocs to come before non-valid relocs, then on increasing
|
|---|
| 2242 | value. */
|
|---|
| 2243 |
|
|---|
| 2244 | static int
|
|---|
| 2245 | bpo_reloc_request_sort_fn (p1, p2)
|
|---|
| 2246 | const PTR p1;
|
|---|
| 2247 | const PTR p2;
|
|---|
| 2248 | {
|
|---|
| 2249 | const struct bpo_reloc_request *r1 = (const struct bpo_reloc_request *) p1;
|
|---|
| 2250 | const struct bpo_reloc_request *r2 = (const struct bpo_reloc_request *) p2;
|
|---|
| 2251 |
|
|---|
| 2252 | /* Primary function is validity; non-valid relocs sorted after valid
|
|---|
| 2253 | ones. */
|
|---|
| 2254 | if (r1->valid != r2->valid)
|
|---|
| 2255 | return r2->valid - r1->valid;
|
|---|
| 2256 |
|
|---|
| 2257 | /* Then sort on value. Don't simplify and return just the difference of
|
|---|
| 2258 | the values: the upper bits of the 64-bit value would be truncated on
|
|---|
| 2259 | a host with 32-bit ints. */
|
|---|
| 2260 | if (r1->value != r2->value)
|
|---|
| 2261 | return r1->value > r2->value ? 1 : -1;
|
|---|
| 2262 |
|
|---|
| 2263 | /* As a last re-sort, use the relocation number, so we get a stable
|
|---|
| 2264 | sort. The *addresses* aren't stable since items are swapped during
|
|---|
| 2265 | sorting. It depends on the qsort implementation if this actually
|
|---|
| 2266 | happens. */
|
|---|
| 2267 | return r1->bpo_reloc_no > r2->bpo_reloc_no
|
|---|
| 2268 | ? 1 : (r1->bpo_reloc_no < r2->bpo_reloc_no ? -1 : 0);
|
|---|
| 2269 | }
|
|---|
| 2270 |
|
|---|
| 2271 | /* For debug use only. Dumps the global register allocations resulting
|
|---|
| 2272 | from base-plus-offset relocs. */
|
|---|
| 2273 |
|
|---|
| 2274 | void
|
|---|
| 2275 | mmix_dump_bpo_gregs (link_info, pf)
|
|---|
| 2276 | struct bfd_link_info *link_info;
|
|---|
| 2277 | bfd_error_handler_type pf;
|
|---|
| 2278 | {
|
|---|
| 2279 | bfd *bpo_greg_owner;
|
|---|
| 2280 | asection *bpo_gregs_section;
|
|---|
| 2281 | struct bpo_greg_section_info *gregdata;
|
|---|
| 2282 | unsigned int i;
|
|---|
| 2283 |
|
|---|
| 2284 | if (link_info == NULL || link_info->base_file == NULL)
|
|---|
| 2285 | return;
|
|---|
| 2286 |
|
|---|
| 2287 | bpo_greg_owner = (bfd *) link_info->base_file;
|
|---|
| 2288 |
|
|---|
| 2289 | bpo_gregs_section
|
|---|
| 2290 | = bfd_get_section_by_name (bpo_greg_owner,
|
|---|
| 2291 | MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME);
|
|---|
| 2292 |
|
|---|
| 2293 | if (bpo_gregs_section == NULL)
|
|---|
| 2294 | return;
|
|---|
| 2295 |
|
|---|
| 2296 | gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
|
|---|
| 2297 | if (gregdata == NULL)
|
|---|
| 2298 | return;
|
|---|
| 2299 |
|
|---|
| 2300 | if (pf == NULL)
|
|---|
| 2301 | pf = _bfd_error_handler;
|
|---|
| 2302 |
|
|---|
| 2303 | /* These format strings are not translated. They are for debug purposes
|
|---|
| 2304 | only and never displayed to an end user. Should they escape, we
|
|---|
| 2305 | surely want them in original. */
|
|---|
| 2306 | (*pf) (" n_bpo_relocs: %u\n n_max_bpo_relocs: %u\n n_remain...round: %u\n\
|
|---|
| 2307 | n_allocated_bpo_gregs: %u\n", gregdata->n_bpo_relocs,
|
|---|
| 2308 | gregdata->n_max_bpo_relocs,
|
|---|
| 2309 | gregdata->n_remaining_bpo_relocs_this_relaxation_round,
|
|---|
| 2310 | gregdata->n_allocated_bpo_gregs);
|
|---|
| 2311 |
|
|---|
| 2312 | if (gregdata->reloc_request)
|
|---|
| 2313 | for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
|
|---|
| 2314 | (*pf) ("%4u (%4u)/%4u#%u: 0x%08lx%08lx r: %3u o: %3u\n",
|
|---|
| 2315 | i,
|
|---|
| 2316 | (gregdata->bpo_reloc_indexes != NULL
|
|---|
| 2317 | ? gregdata->bpo_reloc_indexes[i] : (size_t) -1),
|
|---|
| 2318 | gregdata->reloc_request[i].bpo_reloc_no,
|
|---|
| 2319 | gregdata->reloc_request[i].valid,
|
|---|
| 2320 |
|
|---|
| 2321 | (unsigned long) (gregdata->reloc_request[i].value >> 32),
|
|---|
| 2322 | (unsigned long) gregdata->reloc_request[i].value,
|
|---|
| 2323 | gregdata->reloc_request[i].regindex,
|
|---|
| 2324 | gregdata->reloc_request[i].offset);
|
|---|
| 2325 | }
|
|---|
| 2326 |
|
|---|
| 2327 | /* This links all R_MMIX_BASE_PLUS_OFFSET relocs into a special array, and
|
|---|
| 2328 | when the last such reloc is done, an index-array is sorted according to
|
|---|
| 2329 | the values and iterated over to produce register numbers (indexed by 0
|
|---|
| 2330 | from the first allocated register number) and offsets for use in real
|
|---|
| 2331 | relocation.
|
|---|
| 2332 |
|
|---|
| 2333 | Symbol- and reloc-reading infrastructure copied from elf-m10200.c. */
|
|---|
| 2334 |
|
|---|
| 2335 | static bfd_boolean
|
|---|
| 2336 | mmix_elf_relax_section (abfd, sec, link_info, again)
|
|---|
| 2337 | bfd *abfd;
|
|---|
| 2338 | asection *sec;
|
|---|
| 2339 | struct bfd_link_info *link_info;
|
|---|
| 2340 | bfd_boolean *again;
|
|---|
| 2341 | {
|
|---|
| 2342 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 2343 | Elf_Internal_Rela *internal_relocs;
|
|---|
| 2344 | Elf_Internal_Rela *irel, *irelend;
|
|---|
| 2345 | asection *bpo_gregs_section = NULL;
|
|---|
| 2346 | struct bpo_greg_section_info *gregdata;
|
|---|
| 2347 | struct bpo_reloc_section_info *bpodata
|
|---|
| 2348 | = mmix_elf_section_data (sec)->bpo.reloc;
|
|---|
| 2349 | size_t bpono;
|
|---|
| 2350 | bfd *bpo_greg_owner;
|
|---|
| 2351 | Elf_Internal_Sym *isymbuf = NULL;
|
|---|
| 2352 |
|
|---|
| 2353 | /* Assume nothing changes. */
|
|---|
| 2354 | *again = FALSE;
|
|---|
| 2355 |
|
|---|
| 2356 | /* If this is the first time we have been called for this section,
|
|---|
| 2357 | initialize the cooked size. */
|
|---|
| 2358 | if (sec->_cooked_size == 0)
|
|---|
| 2359 | sec->_cooked_size = sec->_raw_size;
|
|---|
| 2360 |
|
|---|
| 2361 | /* We don't have to do anything for a relocateable link, if
|
|---|
| 2362 | this section does not have relocs, or if this is not a
|
|---|
| 2363 | code section. */
|
|---|
| 2364 | if (link_info->relocateable
|
|---|
| 2365 | || (sec->flags & SEC_RELOC) == 0
|
|---|
| 2366 | || sec->reloc_count == 0
|
|---|
| 2367 | || (sec->flags & SEC_CODE) == 0
|
|---|
| 2368 | || (sec->flags & SEC_LINKER_CREATED) != 0
|
|---|
| 2369 | /* If no R_MMIX_BASE_PLUS_OFFSET relocs, then nothing to do. */
|
|---|
| 2370 | || bpodata == NULL)
|
|---|
| 2371 | return TRUE;
|
|---|
| 2372 |
|
|---|
| 2373 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
|---|
| 2374 |
|
|---|
| 2375 | bpo_greg_owner = (bfd *) link_info->base_file;
|
|---|
| 2376 | bpo_gregs_section = bpodata->bpo_greg_section;
|
|---|
| 2377 | gregdata = mmix_elf_section_data (bpo_gregs_section)->bpo.greg;
|
|---|
| 2378 |
|
|---|
| 2379 | bpono = bpodata->first_base_plus_offset_reloc;
|
|---|
| 2380 |
|
|---|
| 2381 | /* Get a copy of the native relocations. */
|
|---|
| 2382 | internal_relocs
|
|---|
| 2383 | = _bfd_elf64_link_read_relocs (abfd, sec, (PTR) NULL,
|
|---|
| 2384 | (Elf_Internal_Rela *) NULL,
|
|---|
| 2385 | link_info->keep_memory);
|
|---|
| 2386 | if (internal_relocs == NULL)
|
|---|
| 2387 | goto error_return;
|
|---|
| 2388 |
|
|---|
| 2389 | /* Walk through them looking for relaxing opportunities. */
|
|---|
| 2390 | irelend = internal_relocs + sec->reloc_count;
|
|---|
| 2391 | for (irel = internal_relocs; irel < irelend; irel++)
|
|---|
| 2392 | {
|
|---|
| 2393 | bfd_vma symval;
|
|---|
| 2394 |
|
|---|
| 2395 | if (ELF64_R_TYPE (irel->r_info) != (int) R_MMIX_BASE_PLUS_OFFSET)
|
|---|
| 2396 | continue;
|
|---|
| 2397 |
|
|---|
| 2398 | /* Get the value of the symbol referred to by the reloc. */
|
|---|
| 2399 | if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
|
|---|
| 2400 | {
|
|---|
| 2401 | /* A local symbol. */
|
|---|
| 2402 | Elf_Internal_Sym *isym;
|
|---|
| 2403 | asection *sym_sec;
|
|---|
| 2404 |
|
|---|
| 2405 | /* Read this BFD's local symbols if we haven't already. */
|
|---|
| 2406 | if (isymbuf == NULL)
|
|---|
| 2407 | {
|
|---|
| 2408 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
|
|---|
| 2409 | if (isymbuf == NULL)
|
|---|
| 2410 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
|
|---|
| 2411 | symtab_hdr->sh_info, 0,
|
|---|
| 2412 | NULL, NULL, NULL);
|
|---|
| 2413 | if (isymbuf == 0)
|
|---|
| 2414 | goto error_return;
|
|---|
| 2415 | }
|
|---|
| 2416 |
|
|---|
| 2417 | isym = isymbuf + ELF64_R_SYM (irel->r_info);
|
|---|
| 2418 | if (isym->st_shndx == SHN_UNDEF)
|
|---|
| 2419 | sym_sec = bfd_und_section_ptr;
|
|---|
| 2420 | else if (isym->st_shndx == SHN_ABS)
|
|---|
| 2421 | sym_sec = bfd_abs_section_ptr;
|
|---|
| 2422 | else if (isym->st_shndx == SHN_COMMON)
|
|---|
| 2423 | sym_sec = bfd_com_section_ptr;
|
|---|
| 2424 | else
|
|---|
| 2425 | sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
|
|---|
| 2426 | symval = (isym->st_value
|
|---|
| 2427 | + sym_sec->output_section->vma
|
|---|
| 2428 | + sym_sec->output_offset);
|
|---|
| 2429 | }
|
|---|
| 2430 | else
|
|---|
| 2431 | {
|
|---|
| 2432 | unsigned long indx;
|
|---|
| 2433 | struct elf_link_hash_entry *h;
|
|---|
| 2434 |
|
|---|
| 2435 | /* An external symbol. */
|
|---|
| 2436 | indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
|
|---|
| 2437 | h = elf_sym_hashes (abfd)[indx];
|
|---|
| 2438 | BFD_ASSERT (h != NULL);
|
|---|
| 2439 | if (h->root.type != bfd_link_hash_defined
|
|---|
| 2440 | && h->root.type != bfd_link_hash_defweak)
|
|---|
| 2441 | {
|
|---|
| 2442 | /* This appears to be a reference to an undefined symbol.
|
|---|
| 2443 | Just ignore it--it will be caught by the regular reloc
|
|---|
| 2444 | processing. We need to keep BPO reloc accounting
|
|---|
| 2445 | consistent, though. */
|
|---|
| 2446 | gregdata->n_remaining_bpo_relocs_this_relaxation_round--;
|
|---|
| 2447 | bpono++;
|
|---|
| 2448 | continue;
|
|---|
| 2449 | }
|
|---|
| 2450 |
|
|---|
| 2451 | symval = (h->root.u.def.value
|
|---|
| 2452 | + h->root.u.def.section->output_section->vma
|
|---|
| 2453 | + h->root.u.def.section->output_offset);
|
|---|
| 2454 | }
|
|---|
| 2455 |
|
|---|
| 2456 | gregdata->reloc_request[gregdata->bpo_reloc_indexes[bpono]].value
|
|---|
| 2457 | = symval + irel->r_addend;
|
|---|
| 2458 | gregdata->reloc_request[gregdata->bpo_reloc_indexes[bpono++]].valid = TRUE;
|
|---|
| 2459 | gregdata->n_remaining_bpo_relocs_this_relaxation_round--;
|
|---|
| 2460 | }
|
|---|
| 2461 |
|
|---|
| 2462 | /* Check if that was the last BPO-reloc. If so, sort the values and
|
|---|
| 2463 | calculate how many registers we need to cover them. Set the size of
|
|---|
| 2464 | the linker gregs, and if the number of registers changed, indicate
|
|---|
| 2465 | that we need to relax some more because we have more work to do. */
|
|---|
| 2466 | if (gregdata->n_remaining_bpo_relocs_this_relaxation_round == 0)
|
|---|
| 2467 | {
|
|---|
| 2468 | size_t i;
|
|---|
| 2469 | bfd_vma prev_base;
|
|---|
| 2470 | size_t regindex;
|
|---|
| 2471 |
|
|---|
| 2472 | /* First, reset the remaining relocs for the next round. */
|
|---|
| 2473 | gregdata->n_remaining_bpo_relocs_this_relaxation_round
|
|---|
| 2474 | = gregdata->n_bpo_relocs;
|
|---|
| 2475 |
|
|---|
| 2476 | qsort ((PTR) gregdata->reloc_request,
|
|---|
| 2477 | gregdata->n_max_bpo_relocs,
|
|---|
| 2478 | sizeof (struct bpo_reloc_request),
|
|---|
| 2479 | bpo_reloc_request_sort_fn);
|
|---|
| 2480 |
|
|---|
| 2481 | /* Recalculate indexes. When we find a change (however unlikely
|
|---|
| 2482 | after the initial iteration), we know we need to relax again,
|
|---|
| 2483 | since items in the GREG-array are sorted by increasing value and
|
|---|
| 2484 | stored in the relaxation phase. */
|
|---|
| 2485 | for (i = 0; i < gregdata->n_max_bpo_relocs; i++)
|
|---|
| 2486 | if (gregdata->bpo_reloc_indexes[gregdata->reloc_request[i].bpo_reloc_no]
|
|---|
| 2487 | != i)
|
|---|
| 2488 | {
|
|---|
| 2489 | gregdata->bpo_reloc_indexes[gregdata->reloc_request[i].bpo_reloc_no]
|
|---|
| 2490 | = i;
|
|---|
| 2491 | *again = TRUE;
|
|---|
| 2492 | }
|
|---|
| 2493 |
|
|---|
| 2494 | /* Allocate register numbers (indexing from 0). Stop at the first
|
|---|
| 2495 | non-valid reloc. */
|
|---|
| 2496 | for (i = 0, regindex = 0, prev_base = gregdata->reloc_request[0].value;
|
|---|
| 2497 | i < gregdata->n_bpo_relocs;
|
|---|
| 2498 | i++)
|
|---|
| 2499 | {
|
|---|
| 2500 | if (gregdata->reloc_request[i].value > prev_base + 255)
|
|---|
| 2501 | {
|
|---|
| 2502 | regindex++;
|
|---|
| 2503 | prev_base = gregdata->reloc_request[i].value;
|
|---|
| 2504 | }
|
|---|
| 2505 | gregdata->reloc_request[i].regindex = regindex;
|
|---|
| 2506 | gregdata->reloc_request[i].offset
|
|---|
| 2507 | = gregdata->reloc_request[i].value - prev_base;
|
|---|
| 2508 | }
|
|---|
| 2509 |
|
|---|
| 2510 | /* If it's not the same as the last time, we need to relax again,
|
|---|
| 2511 | because the size of the section has changed. I'm not sure we
|
|---|
| 2512 | actually need to do any adjustments since the shrinking happens
|
|---|
| 2513 | at the start of this section, but better safe than sorry. */
|
|---|
| 2514 | if (gregdata->n_allocated_bpo_gregs != regindex + 1)
|
|---|
| 2515 | {
|
|---|
| 2516 | gregdata->n_allocated_bpo_gregs = regindex + 1;
|
|---|
| 2517 | *again = TRUE;
|
|---|
| 2518 | }
|
|---|
| 2519 |
|
|---|
| 2520 | bpo_gregs_section->_cooked_size = (regindex + 1) * 8;
|
|---|
| 2521 | }
|
|---|
| 2522 |
|
|---|
| 2523 | if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
|
|---|
| 2524 | {
|
|---|
| 2525 | if (! link_info->keep_memory)
|
|---|
| 2526 | free (isymbuf);
|
|---|
| 2527 | else
|
|---|
| 2528 | {
|
|---|
| 2529 | /* Cache the symbols for elf_link_input_bfd. */
|
|---|
| 2530 | symtab_hdr->contents = (unsigned char *) isymbuf;
|
|---|
| 2531 | }
|
|---|
| 2532 | }
|
|---|
| 2533 |
|
|---|
| 2534 | if (internal_relocs != NULL
|
|---|
| 2535 | && elf_section_data (sec)->relocs != internal_relocs)
|
|---|
| 2536 | free (internal_relocs);
|
|---|
| 2537 |
|
|---|
| 2538 | return TRUE;
|
|---|
| 2539 |
|
|---|
| 2540 | error_return:
|
|---|
| 2541 | if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
|
|---|
| 2542 | free (isymbuf);
|
|---|
| 2543 | if (internal_relocs != NULL
|
|---|
| 2544 | && elf_section_data (sec)->relocs != internal_relocs)
|
|---|
| 2545 | free (internal_relocs);
|
|---|
| 2546 | return FALSE;
|
|---|
| 2547 | }
|
|---|
| 2548 | |
|---|
| 2549 |
|
|---|
| 2550 | #define ELF_ARCH bfd_arch_mmix
|
|---|
| 2551 | #define ELF_MACHINE_CODE EM_MMIX
|
|---|
| 2552 |
|
|---|
| 2553 | /* According to mmix-doc page 36 (paragraph 45), this should be (1LL << 48LL).
|
|---|
| 2554 | However, that's too much for something somewhere in the linker part of
|
|---|
| 2555 | BFD; perhaps the start-address has to be a non-zero multiple of this
|
|---|
| 2556 | number, or larger than this number. The symptom is that the linker
|
|---|
| 2557 | complains: "warning: allocated section `.text' not in segment". We
|
|---|
| 2558 | settle for 64k; the page-size used in examples is 8k.
|
|---|
| 2559 | #define ELF_MAXPAGESIZE 0x10000
|
|---|
| 2560 |
|
|---|
| 2561 | Unfortunately, this causes excessive padding in the supposedly small
|
|---|
| 2562 | for-education programs that are the expected usage (where people would
|
|---|
| 2563 | inspect output). We stick to 256 bytes just to have *some* default
|
|---|
| 2564 | alignment. */
|
|---|
| 2565 | #define ELF_MAXPAGESIZE 0x100
|
|---|
| 2566 |
|
|---|
| 2567 | #define TARGET_BIG_SYM bfd_elf64_mmix_vec
|
|---|
| 2568 | #define TARGET_BIG_NAME "elf64-mmix"
|
|---|
| 2569 |
|
|---|
| 2570 | #define elf_info_to_howto_rel NULL
|
|---|
| 2571 | #define elf_info_to_howto mmix_info_to_howto_rela
|
|---|
| 2572 | #define elf_backend_relocate_section mmix_elf_relocate_section
|
|---|
| 2573 | #define elf_backend_gc_mark_hook mmix_elf_gc_mark_hook
|
|---|
| 2574 | #define elf_backend_gc_sweep_hook mmix_elf_gc_sweep_hook
|
|---|
| 2575 |
|
|---|
| 2576 | #define elf_backend_link_output_symbol_hook \
|
|---|
| 2577 | mmix_elf_link_output_symbol_hook
|
|---|
| 2578 | #define elf_backend_add_symbol_hook mmix_elf_add_symbol_hook
|
|---|
| 2579 |
|
|---|
| 2580 | #define elf_backend_check_relocs mmix_elf_check_relocs
|
|---|
| 2581 | #define elf_backend_symbol_processing mmix_elf_symbol_processing
|
|---|
| 2582 |
|
|---|
| 2583 | #define bfd_elf64_bfd_is_local_label_name \
|
|---|
| 2584 | mmix_elf_is_local_label_name
|
|---|
| 2585 |
|
|---|
| 2586 | #define elf_backend_may_use_rel_p 0
|
|---|
| 2587 | #define elf_backend_may_use_rela_p 1
|
|---|
| 2588 | #define elf_backend_default_use_rela_p 1
|
|---|
| 2589 |
|
|---|
| 2590 | #define elf_backend_can_gc_sections 1
|
|---|
| 2591 | #define elf_backend_section_from_bfd_section \
|
|---|
| 2592 | mmix_elf_section_from_bfd_section
|
|---|
| 2593 |
|
|---|
| 2594 | #define bfd_elf64_new_section_hook mmix_elf_new_section_hook
|
|---|
| 2595 | #define bfd_elf64_bfd_final_link mmix_elf_final_link
|
|---|
| 2596 | #define bfd_elf64_bfd_relax_section mmix_elf_relax_section
|
|---|
| 2597 |
|
|---|
| 2598 | #include "elf64-target.h"
|
|---|