1 1.1 christos /* V850-specific support for 32-bit ELF 2 1.1.1.11 christos Copyright (C) 1996-2024 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of BFD, the Binary File Descriptor library. 5 1.1 christos 6 1.1 christos This program is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3 of the License, or 9 1.1 christos (at your option) any later version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program; if not, write to the Free Software 18 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 1.1 christos MA 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos 22 1.1 christos /* XXX FIXME: This code is littered with 32bit int, 16bit short, 8bit char 23 1.1 christos dependencies. As is the gas & simulator code for the v850. */ 24 1.1 christos 25 1.1 christos #include "sysdep.h" 26 1.1 christos #include "bfd.h" 27 1.1 christos #include "bfdlink.h" 28 1.1 christos #include "libbfd.h" 29 1.1 christos #include "elf-bfd.h" 30 1.1 christos #include "elf/v850.h" 31 1.1 christos #include "libiberty.h" 32 1.1.1.9 christos #include "elf32-v850.h" 33 1.1 christos 34 1.1 christos /* Sign-extend a 17-bit number. */ 35 1.1 christos #define SEXT17(x) ((((x) & 0x1ffff) ^ 0x10000) - 0x10000) 36 1.1 christos 37 1.1 christos /* Sign-extend a 22-bit number. */ 38 1.1 christos #define SEXT22(x) ((((x) & 0x3fffff) ^ 0x200000) - 0x200000) 39 1.1 christos 40 1.1 christos static reloc_howto_type v850_elf_howto_table[]; 41 1.1 christos 42 1.1 christos /* Look through the relocs for a section during the first phase, and 43 1.1 christos allocate space in the global offset table or procedure linkage 44 1.1 christos table. */ 45 1.1 christos 46 1.1.1.10 christos static bool 47 1.1 christos v850_elf_check_relocs (bfd *abfd, 48 1.1 christos struct bfd_link_info *info, 49 1.1 christos asection *sec, 50 1.1 christos const Elf_Internal_Rela *relocs) 51 1.1 christos { 52 1.1.1.10 christos bool ret = true; 53 1.1 christos Elf_Internal_Shdr *symtab_hdr; 54 1.1 christos struct elf_link_hash_entry **sym_hashes; 55 1.1 christos const Elf_Internal_Rela *rel; 56 1.1 christos const Elf_Internal_Rela *rel_end; 57 1.1.1.2 christos unsigned int r_type; 58 1.1 christos int other = 0; 59 1.1 christos const char *common = NULL; 60 1.1 christos 61 1.1.1.6 christos if (bfd_link_relocatable (info)) 62 1.1.1.10 christos return true; 63 1.1 christos 64 1.1 christos #ifdef DEBUG 65 1.1.1.8 christos _bfd_error_handler ("v850_elf_check_relocs called for section %pA in %pB", 66 1.1 christos sec, abfd); 67 1.1 christos #endif 68 1.1 christos 69 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 70 1.1 christos sym_hashes = elf_sym_hashes (abfd); 71 1.1 christos 72 1.1 christos rel_end = relocs + sec->reloc_count; 73 1.1 christos for (rel = relocs; rel < rel_end; rel++) 74 1.1 christos { 75 1.1 christos unsigned long r_symndx; 76 1.1 christos struct elf_link_hash_entry *h; 77 1.1 christos 78 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 79 1.1 christos if (r_symndx < symtab_hdr->sh_info) 80 1.1 christos h = NULL; 81 1.1 christos else 82 1.1 christos { 83 1.1 christos h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 84 1.1 christos while (h->root.type == bfd_link_hash_indirect 85 1.1 christos || h->root.type == bfd_link_hash_warning) 86 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link; 87 1.1 christos } 88 1.1 christos 89 1.1.1.2 christos r_type = ELF32_R_TYPE (rel->r_info); 90 1.1 christos switch (r_type) 91 1.1 christos { 92 1.1 christos default: 93 1.1 christos break; 94 1.1 christos 95 1.1.1.8 christos /* This relocation describes the C++ object vtable hierarchy. 96 1.1.1.8 christos Reconstruct it for later use during GC. */ 97 1.1.1.8 christos case R_V850_GNU_VTINHERIT: 98 1.1.1.8 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 99 1.1.1.10 christos return false; 100 1.1.1.8 christos break; 101 1.1 christos 102 1.1.1.8 christos /* This relocation describes which C++ vtable entries 103 1.1 christos are actually used. Record for later use during GC. */ 104 1.1.1.8 christos case R_V850_GNU_VTENTRY: 105 1.1.1.9 christos if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 106 1.1.1.10 christos return false; 107 1.1.1.8 christos break; 108 1.1 christos 109 1.1 christos case R_V850_SDA_16_16_SPLIT_OFFSET: 110 1.1 christos case R_V850_SDA_16_16_OFFSET: 111 1.1 christos case R_V850_SDA_15_16_OFFSET: 112 1.1.1.2 christos case R_V810_GPWLO_1: 113 1.1.1.2 christos case R_V850_HWLO: 114 1.1.1.2 christos case R_V850_HWLO_1: 115 1.1 christos other = V850_OTHER_SDA; 116 1.1 christos common = ".scommon"; 117 1.1 christos goto small_data_common; 118 1.1 christos 119 1.1 christos case R_V850_ZDA_16_16_SPLIT_OFFSET: 120 1.1 christos case R_V850_ZDA_16_16_OFFSET: 121 1.1 christos case R_V850_ZDA_15_16_OFFSET: 122 1.1 christos other = V850_OTHER_ZDA; 123 1.1 christos common = ".zcommon"; 124 1.1 christos goto small_data_common; 125 1.1 christos 126 1.1 christos case R_V850_TDA_4_4_OFFSET: 127 1.1 christos case R_V850_TDA_4_5_OFFSET: 128 1.1 christos case R_V850_TDA_7_7_OFFSET: 129 1.1 christos case R_V850_TDA_6_8_OFFSET: 130 1.1 christos case R_V850_TDA_7_8_OFFSET: 131 1.1 christos case R_V850_TDA_16_16_OFFSET: 132 1.1 christos other = V850_OTHER_TDA; 133 1.1 christos common = ".tcommon"; 134 1.1 christos /* fall through */ 135 1.1 christos 136 1.1 christos #define V850_OTHER_MASK (V850_OTHER_TDA | V850_OTHER_SDA | V850_OTHER_ZDA) 137 1.1 christos 138 1.1 christos small_data_common: 139 1.1 christos if (h) 140 1.1 christos { 141 1.1 christos /* Flag which type of relocation was used. */ 142 1.1 christos h->other |= other; 143 1.1 christos if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK) 144 1.1 christos && (h->other & V850_OTHER_ERROR) == 0) 145 1.1 christos { 146 1.1 christos const char * msg; 147 1.1.1.10 christos char *buff; 148 1.1 christos 149 1.1 christos switch (h->other & V850_OTHER_MASK) 150 1.1 christos { 151 1.1 christos default: 152 1.1.1.8 christos msg = _("variable `%s' cannot occupy in multiple small data regions"); 153 1.1 christos break; 154 1.1 christos case V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA: 155 1.1.1.8 christos msg = _("variable `%s' can only be in one of the small, zero, and tiny data regions"); 156 1.1 christos break; 157 1.1 christos case V850_OTHER_SDA | V850_OTHER_ZDA: 158 1.1.1.8 christos msg = _("variable `%s' cannot be in both small and zero data regions simultaneously"); 159 1.1 christos break; 160 1.1 christos case V850_OTHER_SDA | V850_OTHER_TDA: 161 1.1.1.8 christos msg = _("variable `%s' cannot be in both small and tiny data regions simultaneously"); 162 1.1 christos break; 163 1.1 christos case V850_OTHER_ZDA | V850_OTHER_TDA: 164 1.1.1.8 christos msg = _("variable `%s' cannot be in both zero and tiny data regions simultaneously"); 165 1.1 christos break; 166 1.1 christos } 167 1.1 christos 168 1.1.1.10 christos if (asprintf (&buff, msg, h->root.root.string) < 0) 169 1.1.1.10 christos buff = NULL; 170 1.1.1.10 christos else 171 1.1.1.10 christos msg = buff; 172 1.1.1.10 christos info->callbacks->warning (info, msg, h->root.root.string, 173 1.1 christos abfd, h->root.u.def.section, 174 1.1 christos (bfd_vma) 0); 175 1.1.1.10 christos free (buff); 176 1.1 christos 177 1.1 christos bfd_set_error (bfd_error_bad_value); 178 1.1 christos h->other |= V850_OTHER_ERROR; 179 1.1.1.10 christos ret = false; 180 1.1 christos } 181 1.1 christos } 182 1.1 christos 183 1.1 christos if (h && h->root.type == bfd_link_hash_common 184 1.1 christos && h->root.u.c.p 185 1.1.1.9 christos && !strcmp (bfd_section_name (h->root.u.c.p->section), "COMMON")) 186 1.1 christos { 187 1.1 christos asection * section; 188 1.1 christos 189 1.1 christos section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common); 190 1.1.1.9 christos section->flags |= SEC_IS_COMMON | SEC_SMALL_DATA; 191 1.1 christos } 192 1.1 christos 193 1.1 christos #ifdef DEBUG 194 1.1 christos fprintf (stderr, "v850_elf_check_relocs, found %s relocation for %s%s\n", 195 1.1 christos v850_elf_howto_table[ (int)r_type ].name, 196 1.1 christos (h && h->root.root.string) ? h->root.root.string : "<unknown>", 197 1.1 christos (h->root.type == bfd_link_hash_common) ? ", symbol is common" : ""); 198 1.1 christos #endif 199 1.1 christos break; 200 1.1 christos } 201 1.1 christos } 202 1.1 christos 203 1.1 christos return ret; 204 1.1 christos } 205 1.1 christos 206 1.1 christos /* In the old version, when an entry was checked out from the table, 207 1.1 christos it was deleted. This produced an error if the entry was needed 208 1.1 christos more than once, as the second attempted retry failed. 209 1.1 christos 210 1.1 christos In the current version, the entry is not deleted, instead we set 211 1.1 christos the field 'found' to TRUE. If a second lookup matches the same 212 1.1 christos entry, then we know that the hi16s reloc has already been updated 213 1.1 christos and does not need to be updated a second time. 214 1.1 christos 215 1.1 christos TODO - TOFIX: If it is possible that we need to restore 2 different 216 1.1 christos addresses from the same table entry, where the first generates an 217 1.1 christos overflow, whilst the second do not, then this code will fail. */ 218 1.1 christos 219 1.1 christos typedef struct hi16s_location 220 1.1 christos { 221 1.1.1.10 christos bfd_vma addend; 222 1.1.1.10 christos bfd_byte *address; 223 1.1.1.10 christos unsigned long counter; 224 1.1.1.10 christos bool found; 225 1.1.1.10 christos struct hi16s_location *next; 226 1.1 christos } 227 1.1 christos hi16s_location; 228 1.1 christos 229 1.1 christos static hi16s_location * previous_hi16s; 230 1.1 christos static hi16s_location * free_hi16s; 231 1.1 christos static unsigned long hi16s_counter; 232 1.1 christos 233 1.1 christos static void 234 1.1 christos remember_hi16s_reloc (bfd *abfd, bfd_vma addend, bfd_byte *address) 235 1.1 christos { 236 1.1 christos hi16s_location * entry = NULL; 237 1.1.1.9 christos size_t amt = sizeof (* free_hi16s); 238 1.1 christos 239 1.1 christos /* Find a free structure. */ 240 1.1 christos if (free_hi16s == NULL) 241 1.1 christos free_hi16s = bfd_zalloc (abfd, amt); 242 1.1 christos 243 1.1 christos entry = free_hi16s; 244 1.1 christos free_hi16s = free_hi16s->next; 245 1.1 christos 246 1.1 christos entry->addend = addend; 247 1.1 christos entry->address = address; 248 1.1 christos entry->counter = hi16s_counter ++; 249 1.1.1.10 christos entry->found = false; 250 1.1 christos entry->next = previous_hi16s; 251 1.1 christos previous_hi16s = entry; 252 1.1 christos 253 1.1 christos /* Cope with wrap around of our counter. */ 254 1.1 christos if (hi16s_counter == 0) 255 1.1 christos { 256 1.1 christos /* XXX: Assume that all counter entries differ only in their low 16 bits. */ 257 1.1 christos for (entry = previous_hi16s; entry != NULL; entry = entry->next) 258 1.1 christos entry->counter &= 0xffff; 259 1.1 christos 260 1.1 christos hi16s_counter = 0x10000; 261 1.1 christos } 262 1.1 christos } 263 1.1 christos 264 1.1 christos static bfd_byte * 265 1.1.1.10 christos find_remembered_hi16s_reloc (bfd_vma addend, bool *already_found) 266 1.1 christos { 267 1.1 christos hi16s_location *match = NULL; 268 1.1 christos hi16s_location *entry; 269 1.1 christos bfd_byte *addr; 270 1.1 christos 271 1.1 christos /* Search the table. Record the most recent entry that matches. */ 272 1.1 christos for (entry = previous_hi16s; entry; entry = entry->next) 273 1.1 christos { 274 1.1 christos if (entry->addend == addend 275 1.1 christos && (match == NULL || match->counter < entry->counter)) 276 1.1 christos { 277 1.1 christos match = entry; 278 1.1 christos } 279 1.1 christos } 280 1.1 christos 281 1.1 christos if (match == NULL) 282 1.1 christos return NULL; 283 1.1 christos 284 1.1 christos /* Extract the address. */ 285 1.1 christos addr = match->address; 286 1.1 christos 287 1.1 christos /* Remember if this entry has already been used before. */ 288 1.1 christos if (already_found) 289 1.1 christos * already_found = match->found; 290 1.1 christos 291 1.1 christos /* Note that this entry has now been used. */ 292 1.1.1.10 christos match->found = true; 293 1.1 christos 294 1.1 christos return addr; 295 1.1 christos } 296 1.1 christos 297 1.1 christos /* Calculate the final operand value for a R_V850_LO16 or 298 1.1 christos R_V850_LO16_SPLIT_OFFSET. *INSN is the current operand value and 299 1.1 christos ADDEND is the sum of the relocation symbol and offset. Store the 300 1.1 christos operand value in *INSN and return true on success. 301 1.1 christos 302 1.1 christos The assembler has already done some of this: If the value stored in 303 1.1 christos the instruction has its 15th bit set, (counting from zero) then the 304 1.1 christos assembler will have added 1 to the value stored in the associated 305 1.1 christos HI16S reloc. So for example, these relocations: 306 1.1 christos 307 1.1 christos movhi hi( fred ), r0, r1 308 1.1 christos movea lo( fred ), r1, r1 309 1.1 christos 310 1.1 christos will store 0 in the value fields for the MOVHI and MOVEA instructions 311 1.1 christos and addend will be the address of fred, but for these instructions: 312 1.1 christos 313 1.1 christos movhi hi( fred + 0x123456 ), r0, r1 314 1.1 christos movea lo( fred + 0x123456 ), r1, r1 315 1.1 christos 316 1.1 christos the value stored in the MOVHI instruction will be 0x12 and the value 317 1.1 christos stored in the MOVEA instruction will be 0x3456. If however the 318 1.1 christos instructions were: 319 1.1 christos 320 1.1 christos movhi hi( fred + 0x10ffff ), r0, r1 321 1.1 christos movea lo( fred + 0x10ffff ), r1, r1 322 1.1 christos 323 1.1 christos then the value stored in the MOVHI instruction would be 0x11 (not 324 1.1 christos 0x10) and the value stored in the MOVEA instruction would be 0xffff. 325 1.1 christos Thus (assuming for the moment that the addend is 0), at run time the 326 1.1 christos MOVHI instruction loads 0x110000 into r1, then the MOVEA instruction 327 1.1 christos adds 0xffffffff (sign extension!) producing 0x10ffff. Similarly if 328 1.1 christos the instructions were: 329 1.1 christos 330 1.1 christos movhi hi( fred - 1 ), r0, r1 331 1.1 christos movea lo( fred - 1 ), r1, r1 332 1.1 christos 333 1.1 christos then 0 is stored in the MOVHI instruction and -1 is stored in the 334 1.1 christos MOVEA instruction. 335 1.1 christos 336 1.1 christos Overflow can occur if the addition of the value stored in the 337 1.1 christos instruction plus the addend sets the 15th bit when before it was clear. 338 1.1 christos This is because the 15th bit will be sign extended into the high part, 339 1.1 christos thus reducing its value by one, but since the 15th bit was originally 340 1.1 christos clear, the assembler will not have added 1 to the previous HI16S reloc 341 1.1 christos to compensate for this effect. For example: 342 1.1 christos 343 1.1 christos movhi hi( fred + 0x123456 ), r0, r1 344 1.1 christos movea lo( fred + 0x123456 ), r1, r1 345 1.1 christos 346 1.1 christos The value stored in HI16S reloc is 0x12, the value stored in the LO16 347 1.1 christos reloc is 0x3456. If we assume that the address of fred is 0x00007000 348 1.1 christos then the relocations become: 349 1.1 christos 350 1.1 christos HI16S: 0x0012 + (0x00007000 >> 16) = 0x12 351 1.1 christos LO16: 0x3456 + (0x00007000 & 0xffff) = 0xa456 352 1.1 christos 353 1.1 christos but when the instructions are executed, the MOVEA instruction's value 354 1.1 christos is signed extended, so the sum becomes: 355 1.1 christos 356 1.1 christos 0x00120000 357 1.1 christos + 0xffffa456 358 1.1 christos ------------ 359 1.1 christos 0x0011a456 but 'fred + 0x123456' = 0x0012a456 360 1.1 christos 361 1.1 christos Note that if the 15th bit was set in the value stored in the LO16 362 1.1 christos reloc, then we do not have to do anything: 363 1.1 christos 364 1.1 christos movhi hi( fred + 0x10ffff ), r0, r1 365 1.1 christos movea lo( fred + 0x10ffff ), r1, r1 366 1.1 christos 367 1.1 christos HI16S: 0x0011 + (0x00007000 >> 16) = 0x11 368 1.1 christos LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff 369 1.1 christos 370 1.1 christos 0x00110000 371 1.1 christos + 0x00006fff 372 1.1 christos ------------ 373 1.1 christos 0x00116fff = fred + 0x10ffff = 0x7000 + 0x10ffff 374 1.1 christos 375 1.1 christos Overflow can also occur if the computation carries into the 16th bit 376 1.1 christos and it also results in the 15th bit having the same value as the 15th 377 1.1 christos bit of the original value. What happens is that the HI16S reloc 378 1.1 christos will have already examined the 15th bit of the original value and 379 1.1 christos added 1 to the high part if the bit is set. This compensates for the 380 1.1 christos sign extension of 15th bit of the result of the computation. But now 381 1.1 christos there is a carry into the 16th bit, and this has not been allowed for. 382 1.1 christos 383 1.1 christos So, for example if fred is at address 0xf000: 384 1.1 christos 385 1.1 christos movhi hi( fred + 0xffff ), r0, r1 [bit 15 of the offset is set] 386 1.1 christos movea lo( fred + 0xffff ), r1, r1 387 1.1 christos 388 1.1 christos HI16S: 0x0001 + (0x0000f000 >> 16) = 0x0001 389 1.1 christos LO16: 0xffff + (0x0000f000 & 0xffff) = 0xefff (carry into bit 16 is lost) 390 1.1 christos 391 1.1 christos 0x00010000 392 1.1 christos + 0xffffefff 393 1.1 christos ------------ 394 1.1 christos 0x0000efff but 'fred + 0xffff' = 0x0001efff 395 1.1 christos 396 1.1 christos Similarly, if the 15th bit remains clear, but overflow occurs into 397 1.1 christos the 16th bit then (assuming the address of fred is 0xf000): 398 1.1 christos 399 1.1 christos movhi hi( fred + 0x7000 ), r0, r1 [bit 15 of the offset is clear] 400 1.1 christos movea lo( fred + 0x7000 ), r1, r1 401 1.1 christos 402 1.1 christos HI16S: 0x0000 + (0x0000f000 >> 16) = 0x0000 403 1.1 christos LO16: 0x7000 + (0x0000f000 & 0xffff) = 0x6fff (carry into bit 16 is lost) 404 1.1 christos 405 1.1 christos 0x00000000 406 1.1 christos + 0x00006fff 407 1.1 christos ------------ 408 1.1 christos 0x00006fff but 'fred + 0x7000' = 0x00016fff 409 1.1 christos 410 1.1 christos Note - there is no need to change anything if a carry occurs, and the 411 1.1 christos 15th bit changes its value from being set to being clear, as the HI16S 412 1.1 christos reloc will have already added in 1 to the high part for us: 413 1.1 christos 414 1.1 christos movhi hi( fred + 0xffff ), r0, r1 [bit 15 of the offset is set] 415 1.1 christos movea lo( fred + 0xffff ), r1, r1 416 1.1 christos 417 1.1 christos HI16S: 0x0001 + (0x00007000 >> 16) 418 1.1 christos LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff (carry into bit 16 is lost) 419 1.1 christos 420 1.1 christos 0x00010000 421 1.1 christos + 0x00006fff (bit 15 not set, so the top half is zero) 422 1.1 christos ------------ 423 1.1 christos 0x00016fff which is right (assuming that fred is at 0x7000) 424 1.1 christos 425 1.1 christos but if the 15th bit goes from being clear to being set, then we must 426 1.1 christos once again handle overflow: 427 1.1 christos 428 1.1 christos movhi hi( fred + 0x7000 ), r0, r1 [bit 15 of the offset is clear] 429 1.1 christos movea lo( fred + 0x7000 ), r1, r1 430 1.1 christos 431 1.1 christos HI16S: 0x0000 + (0x0000ffff >> 16) 432 1.1 christos LO16: 0x7000 + (0x0000ffff & 0xffff) = 0x6fff (carry into bit 16) 433 1.1 christos 434 1.1 christos 0x00000000 435 1.1 christos + 0x00006fff (bit 15 not set, so the top half is zero) 436 1.1 christos ------------ 437 1.1 christos 0x00006fff which is wrong (assuming that fred is at 0xffff). */ 438 1.1 christos 439 1.1.1.10 christos static bool 440 1.1 christos v850_elf_perform_lo16_relocation (bfd *abfd, unsigned long *insn, 441 1.1 christos unsigned long addend) 442 1.1 christos { 443 1.1 christos #define BIT15_SET(x) ((x) & 0x8000) 444 1.1 christos #define OVERFLOWS(a,i) ((((a) & 0xffff) + (i)) > 0xffff) 445 1.1 christos 446 1.1 christos if ((BIT15_SET (*insn + addend) && ! BIT15_SET (addend)) 447 1.1 christos || (OVERFLOWS (addend, *insn) 448 1.1 christos && ((! BIT15_SET (*insn)) || (BIT15_SET (addend))))) 449 1.1 christos { 450 1.1.1.10 christos bool already_updated; 451 1.1 christos bfd_byte *hi16s_address = find_remembered_hi16s_reloc 452 1.1 christos (addend, & already_updated); 453 1.1 christos 454 1.1 christos /* Amend the matching HI16_S relocation. */ 455 1.1 christos if (hi16s_address != NULL) 456 1.1 christos { 457 1.1 christos if (! already_updated) 458 1.1 christos { 459 1.1 christos unsigned long hi_insn = bfd_get_16 (abfd, hi16s_address); 460 1.1 christos hi_insn += 1; 461 1.1 christos bfd_put_16 (abfd, hi_insn, hi16s_address); 462 1.1 christos } 463 1.1 christos } 464 1.1 christos else 465 1.1 christos { 466 1.1.1.8 christos _bfd_error_handler (_("failed to find previous HI16 reloc")); 467 1.1.1.10 christos return false; 468 1.1 christos } 469 1.1 christos } 470 1.1 christos #undef OVERFLOWS 471 1.1 christos #undef BIT15_SET 472 1.1 christos 473 1.1 christos /* Do not complain if value has top bit set, as this has been 474 1.1 christos anticipated. */ 475 1.1 christos *insn = (*insn + addend) & 0xffff; 476 1.1.1.10 christos return true; 477 1.1 christos } 478 1.1 christos 479 1.1 christos /* FIXME: The code here probably ought to be removed and the code in reloc.c 480 1.1 christos allowed to do its stuff instead. At least for most of the relocs, anyway. */ 481 1.1 christos 482 1.1 christos static bfd_reloc_status_type 483 1.1 christos v850_elf_perform_relocation (bfd *abfd, 484 1.1 christos unsigned int r_type, 485 1.1 christos bfd_vma addend, 486 1.1 christos bfd_byte *address) 487 1.1 christos { 488 1.1 christos unsigned long insn; 489 1.1 christos unsigned long result; 490 1.1 christos bfd_signed_vma saddend = (bfd_signed_vma) addend; 491 1.1 christos 492 1.1 christos switch (r_type) 493 1.1 christos { 494 1.1 christos default: 495 1.1.1.2 christos #ifdef DEBUG 496 1.1.1.8 christos _bfd_error_handler ("%pB: unsupported relocation type %#x", 497 1.1.1.8 christos abfd, r_type); 498 1.1.1.2 christos #endif 499 1.1 christos return bfd_reloc_notsupported; 500 1.1 christos 501 1.1 christos case R_V850_REL32: 502 1.1 christos case R_V850_ABS32: 503 1.1.1.2 christos case R_V810_WORD: 504 1.1.1.2 christos case R_V850_PC32: 505 1.1 christos bfd_put_32 (abfd, addend, address); 506 1.1 christos return bfd_reloc_ok; 507 1.1 christos 508 1.1.1.2 christos case R_V850_WLO23: 509 1.1 christos case R_V850_23: 510 1.1 christos insn = bfd_get_32 (abfd, address); 511 1.1 christos insn &= ~((0x7f << 4) | (0x7fff80 << (16-7))); 512 1.1 christos insn |= ((addend & 0x7f) << 4) | ((addend & 0x7fff80) << (16-7)); 513 1.1 christos bfd_put_32 (abfd, (bfd_vma) insn, address); 514 1.1 christos return bfd_reloc_ok; 515 1.1 christos 516 1.1.1.2 christos case R_V850_PCR22: 517 1.1 christos case R_V850_22_PCREL: 518 1.1 christos if (saddend > 0x1fffff || saddend < -0x200000) 519 1.1 christos return bfd_reloc_overflow; 520 1.1 christos 521 1.1 christos if ((addend % 2) != 0) 522 1.1 christos return bfd_reloc_dangerous; 523 1.1 christos 524 1.1 christos insn = bfd_get_32 (abfd, address); 525 1.1 christos insn &= ~0xfffe003f; 526 1.1 christos insn |= (((addend & 0xfffe) << 16) | ((addend & 0x3f0000) >> 16)); 527 1.1 christos bfd_put_32 (abfd, (bfd_vma) insn, address); 528 1.1 christos return bfd_reloc_ok; 529 1.1 christos 530 1.1.1.2 christos case R_V850_PC17: 531 1.1 christos case R_V850_17_PCREL: 532 1.1 christos if (saddend > 0xffff || saddend < -0x10000) 533 1.1 christos return bfd_reloc_overflow; 534 1.1 christos 535 1.1 christos if ((addend % 2) != 0) 536 1.1 christos return bfd_reloc_dangerous; 537 1.1 christos 538 1.1 christos insn = bfd_get_32 (abfd, address); 539 1.1 christos insn &= ~ 0xfffe0010; 540 1.1 christos insn |= ((addend & 0xfffe) << 16) | ((addend & 0x10000) >> (16-4)); 541 1.1 christos break; 542 1.1 christos 543 1.1.1.2 christos case R_V850_PC16U: 544 1.1 christos case R_V850_16_PCREL: 545 1.1 christos if ((saddend < -0xffff) || (saddend > 0)) 546 1.1 christos return bfd_reloc_overflow; 547 1.1 christos 548 1.1 christos if ((addend % 2) != 0) 549 1.1 christos return bfd_reloc_dangerous; 550 1.1 christos 551 1.1 christos insn = bfd_get_16 (abfd, address); 552 1.1 christos insn &= ~0xfffe; 553 1.1 christos insn |= (-addend & 0xfffe); 554 1.1 christos break; 555 1.1 christos 556 1.1.1.2 christos case R_V850_PC9: 557 1.1 christos case R_V850_9_PCREL: 558 1.1 christos if (saddend > 0xff || saddend < -0x100) 559 1.1 christos return bfd_reloc_overflow; 560 1.1 christos 561 1.1 christos if ((addend % 2) != 0) 562 1.1 christos return bfd_reloc_dangerous; 563 1.1 christos 564 1.1 christos insn = bfd_get_16 (abfd, address); 565 1.1 christos insn &= ~ 0xf870; 566 1.1 christos insn |= ((addend & 0x1f0) << 7) | ((addend & 0x0e) << 3); 567 1.1 christos break; 568 1.1 christos 569 1.1.1.2 christos case R_V810_WHI: 570 1.1 christos case R_V850_HI16: 571 1.1 christos addend += (bfd_get_16 (abfd, address) << 16); 572 1.1 christos addend = (addend >> 16); 573 1.1 christos insn = addend; 574 1.1 christos break; 575 1.1 christos 576 1.1.1.2 christos case R_V810_WHI1: 577 1.1 christos case R_V850_HI16_S: 578 1.1 christos /* Remember where this relocation took place. */ 579 1.1 christos remember_hi16s_reloc (abfd, addend, address); 580 1.1 christos 581 1.1 christos addend += (bfd_get_16 (abfd, address) << 16); 582 1.1 christos addend = (addend >> 16) + ((addend & 0x8000) != 0); 583 1.1 christos 584 1.1 christos /* This relocation cannot overflow. */ 585 1.1 christos if (addend > 0xffff) 586 1.1 christos addend = 0; 587 1.1 christos 588 1.1 christos insn = addend; 589 1.1 christos break; 590 1.1 christos 591 1.1.1.2 christos case R_V810_WLO: 592 1.1 christos case R_V850_LO16: 593 1.1 christos insn = bfd_get_16 (abfd, address); 594 1.1 christos if (! v850_elf_perform_lo16_relocation (abfd, &insn, addend)) 595 1.1 christos return bfd_reloc_overflow; 596 1.1 christos break; 597 1.1 christos 598 1.1.1.2 christos case R_V810_BYTE: 599 1.1 christos case R_V850_8: 600 1.1 christos addend += (char) bfd_get_8 (abfd, address); 601 1.1 christos 602 1.1 christos saddend = (bfd_signed_vma) addend; 603 1.1 christos 604 1.1 christos if (saddend > 0x7f || saddend < -0x80) 605 1.1 christos return bfd_reloc_overflow; 606 1.1 christos 607 1.1 christos bfd_put_8 (abfd, addend, address); 608 1.1 christos return bfd_reloc_ok; 609 1.1 christos 610 1.1 christos case R_V850_CALLT_16_16_OFFSET: 611 1.1 christos addend += bfd_get_16 (abfd, address); 612 1.1 christos 613 1.1 christos saddend = (bfd_signed_vma) addend; 614 1.1 christos 615 1.1 christos if (saddend > 0xffff || saddend < 0) 616 1.1 christos return bfd_reloc_overflow; 617 1.1 christos 618 1.1 christos insn = addend; 619 1.1 christos break; 620 1.1 christos 621 1.1 christos case R_V850_CALLT_15_16_OFFSET: 622 1.1 christos insn = bfd_get_16 (abfd, address); 623 1.1 christos 624 1.1.1.2 christos addend += insn & 0xfffe; 625 1.1 christos 626 1.1 christos saddend = (bfd_signed_vma) addend; 627 1.1 christos 628 1.1 christos if (saddend > 0xffff || saddend < 0) 629 1.1 christos return bfd_reloc_overflow; 630 1.1 christos 631 1.1 christos insn = (0xfffe & addend) 632 1.1 christos | (insn & ~0xfffe); 633 1.1 christos break; 634 1.1 christos 635 1.1 christos case R_V850_CALLT_6_7_OFFSET: 636 1.1 christos insn = bfd_get_16 (abfd, address); 637 1.1 christos addend += ((insn & 0x3f) << 1); 638 1.1 christos 639 1.1 christos saddend = (bfd_signed_vma) addend; 640 1.1 christos 641 1.1 christos if (saddend > 0x7e || saddend < 0) 642 1.1 christos return bfd_reloc_overflow; 643 1.1 christos 644 1.1 christos if (addend & 1) 645 1.1 christos return bfd_reloc_dangerous; 646 1.1 christos 647 1.1 christos insn &= 0xff80; 648 1.1 christos insn |= (addend >> 1); 649 1.1 christos break; 650 1.1 christos 651 1.1 christos case R_V850_16: 652 1.1.1.2 christos case R_V810_HWORD: 653 1.1 christos case R_V850_SDA_16_16_OFFSET: 654 1.1 christos case R_V850_ZDA_16_16_OFFSET: 655 1.1 christos case R_V850_TDA_16_16_OFFSET: 656 1.1 christos addend += bfd_get_16 (abfd, address); 657 1.1 christos 658 1.1 christos saddend = (bfd_signed_vma) addend; 659 1.1 christos 660 1.1 christos if (saddend > 0x7fff || saddend < -0x8000) 661 1.1 christos return bfd_reloc_overflow; 662 1.1 christos 663 1.1 christos insn = addend; 664 1.1 christos break; 665 1.1 christos 666 1.1 christos case R_V850_16_S1: 667 1.1 christos case R_V850_SDA_15_16_OFFSET: 668 1.1 christos case R_V850_ZDA_15_16_OFFSET: 669 1.1.1.2 christos case R_V810_GPWLO_1: 670 1.1 christos insn = bfd_get_16 (abfd, address); 671 1.1 christos addend += (insn & 0xfffe); 672 1.1 christos 673 1.1 christos saddend = (bfd_signed_vma) addend; 674 1.1 christos 675 1.1 christos if (saddend > 0x7ffe || saddend < -0x8000) 676 1.1 christos return bfd_reloc_overflow; 677 1.1 christos 678 1.1 christos if (addend & 1) 679 1.1.1.8 christos return bfd_reloc_dangerous; 680 1.1 christos 681 1.1 christos insn = (addend &~ (bfd_vma) 1) | (insn & 1); 682 1.1 christos break; 683 1.1 christos 684 1.1 christos case R_V850_TDA_6_8_OFFSET: 685 1.1 christos insn = bfd_get_16 (abfd, address); 686 1.1 christos addend += ((insn & 0x7e) << 1); 687 1.1 christos 688 1.1 christos saddend = (bfd_signed_vma) addend; 689 1.1 christos 690 1.1 christos if (saddend > 0xfc || saddend < 0) 691 1.1 christos return bfd_reloc_overflow; 692 1.1 christos 693 1.1 christos if (addend & 3) 694 1.1 christos return bfd_reloc_dangerous; 695 1.1 christos 696 1.1 christos insn &= 0xff81; 697 1.1 christos insn |= (addend >> 1); 698 1.1 christos break; 699 1.1 christos 700 1.1 christos case R_V850_TDA_7_8_OFFSET: 701 1.1 christos insn = bfd_get_16 (abfd, address); 702 1.1 christos addend += ((insn & 0x7f) << 1); 703 1.1 christos 704 1.1 christos saddend = (bfd_signed_vma) addend; 705 1.1 christos 706 1.1 christos if (saddend > 0xfe || saddend < 0) 707 1.1 christos return bfd_reloc_overflow; 708 1.1 christos 709 1.1 christos if (addend & 1) 710 1.1 christos return bfd_reloc_dangerous; 711 1.1 christos 712 1.1 christos insn &= 0xff80; 713 1.1 christos insn |= (addend >> 1); 714 1.1 christos break; 715 1.1 christos 716 1.1 christos case R_V850_TDA_7_7_OFFSET: 717 1.1 christos insn = bfd_get_16 (abfd, address); 718 1.1 christos addend += insn & 0x7f; 719 1.1 christos 720 1.1 christos saddend = (bfd_signed_vma) addend; 721 1.1 christos 722 1.1 christos if (saddend > 0x7f || saddend < 0) 723 1.1 christos return bfd_reloc_overflow; 724 1.1 christos 725 1.1 christos insn &= 0xff80; 726 1.1 christos insn |= addend; 727 1.1 christos break; 728 1.1 christos 729 1.1 christos case R_V850_TDA_4_5_OFFSET: 730 1.1 christos insn = bfd_get_16 (abfd, address); 731 1.1 christos addend += ((insn & 0xf) << 1); 732 1.1 christos 733 1.1 christos saddend = (bfd_signed_vma) addend; 734 1.1 christos 735 1.1 christos if (saddend > 0x1e || saddend < 0) 736 1.1 christos return bfd_reloc_overflow; 737 1.1 christos 738 1.1 christos if (addend & 1) 739 1.1 christos return bfd_reloc_dangerous; 740 1.1 christos 741 1.1 christos insn &= 0xfff0; 742 1.1 christos insn |= (addend >> 1); 743 1.1 christos break; 744 1.1 christos 745 1.1 christos case R_V850_TDA_4_4_OFFSET: 746 1.1 christos insn = bfd_get_16 (abfd, address); 747 1.1 christos addend += insn & 0xf; 748 1.1 christos 749 1.1 christos saddend = (bfd_signed_vma) addend; 750 1.1 christos 751 1.1 christos if (saddend > 0xf || saddend < 0) 752 1.1 christos return bfd_reloc_overflow; 753 1.1 christos 754 1.1 christos insn &= 0xfff0; 755 1.1 christos insn |= addend; 756 1.1 christos break; 757 1.1 christos 758 1.1.1.2 christos case R_V810_WLO_1: 759 1.1.1.2 christos case R_V850_HWLO: 760 1.1.1.2 christos case R_V850_HWLO_1: 761 1.1 christos case R_V850_LO16_S1: 762 1.1 christos insn = bfd_get_16 (abfd, address); 763 1.1 christos result = insn & 0xfffe; 764 1.1 christos if (! v850_elf_perform_lo16_relocation (abfd, &result, addend)) 765 1.1 christos return bfd_reloc_overflow; 766 1.1 christos if (result & 1) 767 1.1 christos return bfd_reloc_overflow; 768 1.1 christos insn = (result & 0xfffe) 769 1.1 christos | (insn & ~0xfffe); 770 1.1 christos bfd_put_16 (abfd, insn, address); 771 1.1 christos return bfd_reloc_ok; 772 1.1 christos 773 1.1.1.2 christos case R_V850_BLO: 774 1.1 christos case R_V850_LO16_SPLIT_OFFSET: 775 1.1 christos insn = bfd_get_32 (abfd, address); 776 1.1 christos result = ((insn & 0xfffe0000) >> 16) | ((insn & 0x20) >> 5); 777 1.1 christos if (! v850_elf_perform_lo16_relocation (abfd, &result, addend)) 778 1.1 christos return bfd_reloc_overflow; 779 1.1 christos insn = (((result << 16) & 0xfffe0000) 780 1.1 christos | ((result << 5) & 0x20) 781 1.1 christos | (insn & ~0xfffe0020)); 782 1.1 christos bfd_put_32 (abfd, insn, address); 783 1.1 christos return bfd_reloc_ok; 784 1.1 christos 785 1.1 christos case R_V850_16_SPLIT_OFFSET: 786 1.1 christos case R_V850_SDA_16_16_SPLIT_OFFSET: 787 1.1 christos case R_V850_ZDA_16_16_SPLIT_OFFSET: 788 1.1 christos insn = bfd_get_32 (abfd, address); 789 1.1 christos addend += ((insn & 0xfffe0000) >> 16) + ((insn & 0x20) >> 5); 790 1.1 christos 791 1.1 christos saddend = (bfd_signed_vma) addend; 792 1.1 christos 793 1.1 christos if (saddend > 0x7fff || saddend < -0x8000) 794 1.1 christos return bfd_reloc_overflow; 795 1.1 christos 796 1.1 christos insn &= 0x0001ffdf; 797 1.1 christos insn |= (addend & 1) << 5; 798 1.1 christos insn |= (addend &~ (bfd_vma) 1) << 16; 799 1.1 christos 800 1.1 christos bfd_put_32 (abfd, (bfd_vma) insn, address); 801 1.1 christos return bfd_reloc_ok; 802 1.1 christos 803 1.1 christos case R_V850_GNU_VTINHERIT: 804 1.1 christos case R_V850_GNU_VTENTRY: 805 1.1 christos return bfd_reloc_ok; 806 1.1 christos 807 1.1 christos } 808 1.1 christos 809 1.1 christos bfd_put_16 (abfd, (bfd_vma) insn, address); 810 1.1 christos return bfd_reloc_ok; 811 1.1 christos } 812 1.1 christos 813 1.1 christos /* Insert the addend into the instruction. */ 815 1.1 christos 816 1.1 christos static bfd_reloc_status_type 817 1.1 christos v850_elf_reloc (bfd *abfd ATTRIBUTE_UNUSED, 818 1.1 christos arelent *reloc, 819 1.1 christos asymbol *symbol, 820 1.1 christos void * data ATTRIBUTE_UNUSED, 821 1.1 christos asection *isection, 822 1.1 christos bfd *obfd, 823 1.1 christos char **err ATTRIBUTE_UNUSED) 824 1.1 christos { 825 1.1 christos long relocation; 826 1.1 christos 827 1.1 christos /* If there is an output BFD, 828 1.1 christos and the symbol is not a section name (which is only defined at final link time), 829 1.1 christos and either we are not putting the addend into the instruction 830 1.1 christos or the addend is zero, so there is nothing to add into the instruction 831 1.1 christos then just fixup the address and return. */ 832 1.1 christos if (obfd != NULL 833 1.1 christos && (symbol->flags & BSF_SECTION_SYM) == 0 834 1.1 christos && (! reloc->howto->partial_inplace 835 1.1 christos || reloc->addend == 0)) 836 1.1 christos { 837 1.1 christos reloc->address += isection->output_offset; 838 1.1 christos return bfd_reloc_ok; 839 1.1 christos } 840 1.1 christos 841 1.1 christos /* Catch relocs involving undefined symbols. */ 842 1.1 christos if (bfd_is_und_section (symbol->section) 843 1.1 christos && (symbol->flags & BSF_WEAK) == 0 844 1.1 christos && obfd == NULL) 845 1.1 christos return bfd_reloc_undefined; 846 1.1 christos 847 1.1 christos /* We handle final linking of some relocs ourselves. */ 848 1.1 christos 849 1.1 christos /* Is the address of the relocation really within the section? */ 850 1.1 christos if (reloc->address > bfd_get_section_limit (abfd, isection)) 851 1.1 christos return bfd_reloc_outofrange; 852 1.1 christos 853 1.1 christos /* Work out which section the relocation is targeted at and the 854 1.1 christos initial relocation command value. */ 855 1.1 christos 856 1.1 christos if (reloc->howto->pc_relative) 857 1.1 christos return bfd_reloc_ok; 858 1.1 christos 859 1.1 christos /* Get symbol value. (Common symbols are special.) */ 860 1.1 christos if (bfd_is_com_section (symbol->section)) 861 1.1 christos relocation = 0; 862 1.1 christos else 863 1.1 christos relocation = symbol->value; 864 1.1 christos 865 1.1 christos /* Convert input-section-relative symbol value to absolute + addend. */ 866 1.1 christos relocation += symbol->section->output_section->vma; 867 1.1 christos relocation += symbol->section->output_offset; 868 1.1 christos relocation += reloc->addend; 869 1.1 christos 870 1.1 christos reloc->addend = relocation; 871 1.1 christos return bfd_reloc_ok; 872 1.1 christos } 873 1.1 christos 874 1.1 christos /* This function is used for relocs which are only used 875 1.1 christos for relaxing, which the linker should otherwise ignore. */ 876 1.1 christos 877 1.1 christos static bfd_reloc_status_type 878 1.1 christos v850_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, 879 1.1 christos arelent *reloc_entry, 880 1.1 christos asymbol *symbol ATTRIBUTE_UNUSED, 881 1.1 christos void * data ATTRIBUTE_UNUSED, 882 1.1 christos asection *input_section, 883 1.1 christos bfd *output_bfd, 884 1.1 christos char **error_message ATTRIBUTE_UNUSED) 885 1.1 christos { 886 1.1 christos if (output_bfd != NULL) 887 1.1 christos reloc_entry->address += input_section->output_offset; 888 1.1 christos 889 1.1 christos return bfd_reloc_ok; 890 1.1 christos } 891 1.1 christos /* Note: It is REQUIRED that the 'type' value of each entry 892 1.1.1.2 christos in this array match the index of the entry in the array. 893 1.1 christos SeeAlso: RELOC_NUBMER in include/elf/v850.h. */ 894 1.1 christos static reloc_howto_type v850_elf_howto_table[] = 895 1.1 christos { 896 1.1 christos /* This reloc does nothing. */ 897 1.1 christos HOWTO (R_V850_NONE, /* Type. */ 898 1.1.1.10 christos 0, /* Rightshift. */ 899 1.1.1.5 christos 0, /* Size. */ 900 1.1.1.10 christos 0, /* Bitsize. */ 901 1.1 christos false, /* PC_relative. */ 902 1.1.1.5 christos 0, /* Bitpos. */ 903 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 904 1.1 christos bfd_elf_generic_reloc, /* Special_function. */ 905 1.1.1.10 christos "R_V850_NONE", /* Name. */ 906 1.1 christos false, /* Partial_inplace. */ 907 1.1 christos 0, /* Src_mask. */ 908 1.1.1.10 christos 0, /* Dst_mask. */ 909 1.1 christos false), /* PCrel_offset. */ 910 1.1 christos 911 1.1 christos /* A PC relative 9 bit branch. */ 912 1.1 christos HOWTO (R_V850_9_PCREL, /* Type. */ 913 1.1.1.10 christos 0, /* Rightshift. */ 914 1.1 christos 2, /* Size. */ 915 1.1.1.10 christos 9, /* Bitsize. */ 916 1.1 christos true, /* PC_relative. */ 917 1.1 christos 0, /* Bitpos. */ 918 1.1 christos complain_overflow_bitfield, /* Complain_on_overflow. */ 919 1.1 christos v850_elf_reloc, /* Special_function. */ 920 1.1.1.10 christos "R_V850_9_PCREL", /* Name. */ 921 1.1 christos false, /* Partial_inplace. */ 922 1.1 christos 0x00ffffff, /* Src_mask. */ 923 1.1.1.10 christos 0x00ffffff, /* Dst_mask. */ 924 1.1 christos true), /* PCrel_offset. */ 925 1.1 christos 926 1.1 christos /* A PC relative 22 bit branch. */ 927 1.1 christos HOWTO (R_V850_22_PCREL, /* Type. */ 928 1.1.1.10 christos 0, /* Rightshift. */ 929 1.1 christos 4, /* Size. */ 930 1.1.1.10 christos 22, /* Bitsize. */ 931 1.1 christos true, /* PC_relative. */ 932 1.1 christos 0, /* Bitpos. */ 933 1.1 christos complain_overflow_signed, /* Complain_on_overflow. */ 934 1.1 christos v850_elf_reloc, /* Special_function. */ 935 1.1.1.10 christos "R_V850_22_PCREL", /* Name. */ 936 1.1 christos false, /* Partial_inplace. */ 937 1.1 christos 0x07ffff80, /* Src_mask. */ 938 1.1.1.10 christos 0x07ffff80, /* Dst_mask. */ 939 1.1 christos true), /* PCrel_offset. */ 940 1.1 christos 941 1.1 christos /* High 16 bits of symbol value. */ 942 1.1 christos HOWTO (R_V850_HI16_S, /* Type. */ 943 1.1.1.10 christos 0, /* Rightshift. */ 944 1.1 christos 2, /* Size. */ 945 1.1.1.10 christos 16, /* Bitsize. */ 946 1.1 christos false, /* PC_relative. */ 947 1.1 christos 0, /* Bitpos. */ 948 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 949 1.1 christos v850_elf_reloc, /* Special_function. */ 950 1.1.1.10 christos "R_V850_HI16_S", /* Name. */ 951 1.1 christos false, /* Partial_inplace. */ 952 1.1 christos 0xffff, /* Src_mask. */ 953 1.1.1.10 christos 0xffff, /* Dst_mask. */ 954 1.1 christos false), /* PCrel_offset. */ 955 1.1 christos 956 1.1 christos /* High 16 bits of symbol value. */ 957 1.1 christos HOWTO (R_V850_HI16, /* Type. */ 958 1.1.1.10 christos 0, /* Rightshift. */ 959 1.1 christos 2, /* Size. */ 960 1.1.1.10 christos 16, /* Bitsize. */ 961 1.1 christos false, /* PC_relative. */ 962 1.1 christos 0, /* Bitpos. */ 963 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 964 1.1 christos v850_elf_reloc, /* Special_function. */ 965 1.1.1.10 christos "R_V850_HI16", /* Name. */ 966 1.1 christos false, /* Partial_inplace. */ 967 1.1 christos 0xffff, /* Src_mask. */ 968 1.1.1.10 christos 0xffff, /* Dst_mask. */ 969 1.1 christos false), /* PCrel_offset. */ 970 1.1 christos 971 1.1 christos /* Low 16 bits of symbol value. */ 972 1.1 christos HOWTO (R_V850_LO16, /* Type. */ 973 1.1.1.10 christos 0, /* Rightshift. */ 974 1.1 christos 2, /* Size. */ 975 1.1.1.10 christos 16, /* Bitsize. */ 976 1.1 christos false, /* PC_relative. */ 977 1.1 christos 0, /* Bitpos. */ 978 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 979 1.1 christos v850_elf_reloc, /* Special_function. */ 980 1.1.1.10 christos "R_V850_LO16", /* Name. */ 981 1.1 christos false, /* Partial_inplace. */ 982 1.1 christos 0xffff, /* Src_mask. */ 983 1.1.1.10 christos 0xffff, /* Dst_mask. */ 984 1.1 christos false), /* PCrel_offset. */ 985 1.1 christos 986 1.1 christos /* Simple 32bit reloc. */ 987 1.1 christos HOWTO (R_V850_ABS32, /* Type. */ 988 1.1.1.10 christos 0, /* Rightshift. */ 989 1.1 christos 4, /* Size. */ 990 1.1.1.10 christos 32, /* Bitsize. */ 991 1.1 christos false, /* PC_relative. */ 992 1.1 christos 0, /* Bitpos. */ 993 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 994 1.1 christos v850_elf_reloc, /* Special_function. */ 995 1.1.1.10 christos "R_V850_ABS32", /* Name. */ 996 1.1 christos false, /* Partial_inplace. */ 997 1.1 christos 0xffffffff, /* Src_mask. */ 998 1.1.1.10 christos 0xffffffff, /* Dst_mask. */ 999 1.1 christos false), /* PCrel_offset. */ 1000 1.1 christos 1001 1.1 christos /* Simple 16bit reloc. */ 1002 1.1 christos HOWTO (R_V850_16, /* Type. */ 1003 1.1.1.10 christos 0, /* Rightshift. */ 1004 1.1 christos 2, /* Size. */ 1005 1.1.1.10 christos 16, /* Bitsize. */ 1006 1.1 christos false, /* PC_relative. */ 1007 1.1 christos 0, /* Bitpos. */ 1008 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1009 1.1 christos bfd_elf_generic_reloc, /* Special_function. */ 1010 1.1.1.10 christos "R_V850_16", /* Name. */ 1011 1.1 christos false, /* Partial_inplace. */ 1012 1.1 christos 0xffff, /* Src_mask. */ 1013 1.1.1.10 christos 0xffff, /* Dst_mask. */ 1014 1.1 christos false), /* PCrel_offset. */ 1015 1.1.1.8 christos 1016 1.1 christos /* Simple 8bit reloc. */ 1017 1.1 christos HOWTO (R_V850_8, /* Type. */ 1018 1.1.1.10 christos 0, /* Rightshift. */ 1019 1.1 christos 1, /* Size. */ 1020 1.1.1.10 christos 8, /* Bitsize. */ 1021 1.1 christos false, /* PC_relative. */ 1022 1.1 christos 0, /* Bitpos. */ 1023 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1024 1.1 christos bfd_elf_generic_reloc, /* Special_function. */ 1025 1.1.1.10 christos "R_V850_8", /* Name. */ 1026 1.1 christos false, /* Partial_inplace. */ 1027 1.1 christos 0xff, /* Src_mask. */ 1028 1.1.1.10 christos 0xff, /* Dst_mask. */ 1029 1.1 christos false), /* PCrel_offset. */ 1030 1.1 christos 1031 1.1 christos /* 16 bit offset from the short data area pointer. */ 1032 1.1 christos HOWTO (R_V850_SDA_16_16_OFFSET, /* Type. */ 1033 1.1.1.10 christos 0, /* Rightshift. */ 1034 1.1 christos 2, /* Size. */ 1035 1.1.1.10 christos 16, /* Bitsize. */ 1036 1.1 christos false, /* PC_relative. */ 1037 1.1 christos 0, /* Bitpos. */ 1038 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1039 1.1 christos v850_elf_reloc, /* Special_function. */ 1040 1.1.1.10 christos "R_V850_SDA_16_16_OFFSET", /* Name. */ 1041 1.1 christos false, /* Partial_inplace. */ 1042 1.1 christos 0xffff, /* Src_mask. */ 1043 1.1.1.10 christos 0xffff, /* Dst_mask. */ 1044 1.1 christos false), /* PCrel_offset. */ 1045 1.1 christos 1046 1.1 christos /* 15 bit offset from the short data area pointer. */ 1047 1.1 christos HOWTO (R_V850_SDA_15_16_OFFSET, /* Type. */ 1048 1.1.1.10 christos 1, /* Rightshift. */ 1049 1.1 christos 2, /* Size. */ 1050 1.1.1.10 christos 16, /* Bitsize. */ 1051 1.1 christos false, /* PC_relative. */ 1052 1.1 christos 1, /* Bitpos. */ 1053 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1054 1.1 christos v850_elf_reloc, /* Special_function. */ 1055 1.1.1.10 christos "R_V850_SDA_15_16_OFFSET", /* Name. */ 1056 1.1 christos false, /* Partial_inplace. */ 1057 1.1 christos 0xfffe, /* Src_mask. */ 1058 1.1.1.10 christos 0xfffe, /* Dst_mask. */ 1059 1.1 christos false), /* PCrel_offset. */ 1060 1.1 christos 1061 1.1 christos /* 16 bit offset from the zero data area pointer. */ 1062 1.1 christos HOWTO (R_V850_ZDA_16_16_OFFSET, /* Type. */ 1063 1.1.1.10 christos 0, /* Rightshift. */ 1064 1.1 christos 2, /* Size. */ 1065 1.1.1.10 christos 16, /* Bitsize. */ 1066 1.1 christos false, /* PC_relative. */ 1067 1.1 christos 0, /* Bitpos. */ 1068 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1069 1.1 christos v850_elf_reloc, /* Special_function. */ 1070 1.1.1.10 christos "R_V850_ZDA_16_16_OFFSET", /* Name. */ 1071 1.1 christos false, /* Partial_inplace. */ 1072 1.1 christos 0xffff, /* Src_mask. */ 1073 1.1.1.10 christos 0xffff, /* Dst_mask. */ 1074 1.1 christos false), /* PCrel_offset. */ 1075 1.1 christos 1076 1.1 christos /* 15 bit offset from the zero data area pointer. */ 1077 1.1 christos HOWTO (R_V850_ZDA_15_16_OFFSET, /* Type. */ 1078 1.1.1.10 christos 1, /* Rightshift. */ 1079 1.1 christos 2, /* Size. */ 1080 1.1.1.10 christos 16, /* Bitsize. */ 1081 1.1 christos false, /* PC_relative. */ 1082 1.1 christos 1, /* Bitpos. */ 1083 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1084 1.1 christos v850_elf_reloc, /* Special_function. */ 1085 1.1.1.10 christos "R_V850_ZDA_15_16_OFFSET", /* Name. */ 1086 1.1 christos false, /* Partial_inplace. */ 1087 1.1 christos 0xfffe, /* Src_mask. */ 1088 1.1.1.10 christos 0xfffe, /* Dst_mask. */ 1089 1.1 christos false), /* PCrel_offset. */ 1090 1.1 christos 1091 1.1 christos /* 6 bit offset from the tiny data area pointer. */ 1092 1.1 christos HOWTO (R_V850_TDA_6_8_OFFSET, /* Type. */ 1093 1.1.1.10 christos 2, /* Rightshift. */ 1094 1.1 christos 2, /* Size. */ 1095 1.1.1.10 christos 8, /* Bitsize. */ 1096 1.1 christos false, /* PC_relative. */ 1097 1.1 christos 1, /* Bitpos. */ 1098 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1099 1.1 christos v850_elf_reloc, /* Special_function. */ 1100 1.1.1.10 christos "R_V850_TDA_6_8_OFFSET", /* Name. */ 1101 1.1 christos false, /* Partial_inplace. */ 1102 1.1 christos 0x7e, /* Src_mask. */ 1103 1.1.1.10 christos 0x7e, /* Dst_mask. */ 1104 1.1 christos false), /* PCrel_offset. */ 1105 1.1 christos 1106 1.1 christos /* 8 bit offset from the tiny data area pointer. */ 1107 1.1 christos HOWTO (R_V850_TDA_7_8_OFFSET, /* Type. */ 1108 1.1.1.10 christos 1, /* Rightshift. */ 1109 1.1 christos 2, /* Size. */ 1110 1.1.1.10 christos 8, /* Bitsize. */ 1111 1.1 christos false, /* PC_relative. */ 1112 1.1 christos 0, /* Bitpos. */ 1113 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1114 1.1 christos v850_elf_reloc, /* Special_function. */ 1115 1.1.1.10 christos "R_V850_TDA_7_8_OFFSET", /* Name. */ 1116 1.1 christos false, /* Partial_inplace. */ 1117 1.1 christos 0x7f, /* Src_mask. */ 1118 1.1.1.10 christos 0x7f, /* Dst_mask. */ 1119 1.1 christos false), /* PCrel_offset. */ 1120 1.1 christos 1121 1.1 christos /* 7 bit offset from the tiny data area pointer. */ 1122 1.1 christos HOWTO (R_V850_TDA_7_7_OFFSET, /* Type. */ 1123 1.1.1.10 christos 0, /* Rightshift. */ 1124 1.1 christos 2, /* Size. */ 1125 1.1.1.10 christos 7, /* Bitsize. */ 1126 1.1 christos false, /* PC_relative. */ 1127 1.1 christos 0, /* Bitpos. */ 1128 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1129 1.1 christos v850_elf_reloc, /* Special_function. */ 1130 1.1.1.10 christos "R_V850_TDA_7_7_OFFSET", /* Name. */ 1131 1.1 christos false, /* Partial_inplace. */ 1132 1.1 christos 0x7f, /* Src_mask. */ 1133 1.1.1.10 christos 0x7f, /* Dst_mask. */ 1134 1.1 christos false), /* PCrel_offset. */ 1135 1.1 christos 1136 1.1 christos /* 16 bit offset from the tiny data area pointer! */ 1137 1.1 christos HOWTO (R_V850_TDA_16_16_OFFSET, /* Type. */ 1138 1.1.1.10 christos 0, /* Rightshift. */ 1139 1.1 christos 2, /* Size. */ 1140 1.1.1.10 christos 16, /* Bitsize. */ 1141 1.1 christos false, /* PC_relative. */ 1142 1.1 christos 0, /* Bitpos. */ 1143 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1144 1.1 christos v850_elf_reloc, /* Special_function. */ 1145 1.1.1.10 christos "R_V850_TDA_16_16_OFFSET", /* Name. */ 1146 1.1 christos false, /* Partial_inplace. */ 1147 1.1 christos 0xffff, /* Src_mask. */ 1148 1.1.1.10 christos 0xfff, /* Dst_mask. */ 1149 1.1 christos false), /* PCrel_offset. */ 1150 1.1 christos 1151 1.1 christos /* 5 bit offset from the tiny data area pointer. */ 1152 1.1 christos HOWTO (R_V850_TDA_4_5_OFFSET, /* Type. */ 1153 1.1.1.10 christos 1, /* Rightshift. */ 1154 1.1 christos 2, /* Size. */ 1155 1.1.1.10 christos 5, /* Bitsize. */ 1156 1.1 christos false, /* PC_relative. */ 1157 1.1 christos 0, /* Bitpos. */ 1158 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1159 1.1 christos v850_elf_reloc, /* Special_function. */ 1160 1.1.1.10 christos "R_V850_TDA_4_5_OFFSET", /* Name. */ 1161 1.1 christos false, /* Partial_inplace. */ 1162 1.1 christos 0x0f, /* Src_mask. */ 1163 1.1.1.10 christos 0x0f, /* Dst_mask. */ 1164 1.1 christos false), /* PCrel_offset. */ 1165 1.1 christos 1166 1.1 christos /* 4 bit offset from the tiny data area pointer. */ 1167 1.1 christos HOWTO (R_V850_TDA_4_4_OFFSET, /* Type. */ 1168 1.1.1.10 christos 0, /* Rightshift. */ 1169 1.1 christos 2, /* Size. */ 1170 1.1.1.10 christos 4, /* Bitsize. */ 1171 1.1 christos false, /* PC_relative. */ 1172 1.1 christos 0, /* Bitpos. */ 1173 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1174 1.1 christos v850_elf_reloc, /* Special_function. */ 1175 1.1.1.10 christos "R_V850_TDA_4_4_OFFSET", /* Name. */ 1176 1.1 christos false, /* Partial_inplace. */ 1177 1.1 christos 0x0f, /* Src_mask. */ 1178 1.1.1.10 christos 0x0f, /* Dst_mask. */ 1179 1.1 christos false), /* PCrel_offset. */ 1180 1.1 christos 1181 1.1 christos /* 16 bit offset from the short data area pointer. */ 1182 1.1 christos HOWTO (R_V850_SDA_16_16_SPLIT_OFFSET, /* Type. */ 1183 1.1.1.10 christos 0, /* Rightshift. */ 1184 1.1 christos 4, /* Size. */ 1185 1.1.1.10 christos 16, /* Bitsize. */ 1186 1.1 christos false, /* PC_relative. */ 1187 1.1 christos 0, /* Bitpos. */ 1188 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1189 1.1 christos v850_elf_reloc, /* Special_function. */ 1190 1.1.1.10 christos "R_V850_SDA_16_16_SPLIT_OFFSET",/* Name. */ 1191 1.1 christos false, /* Partial_inplace. */ 1192 1.1 christos 0xfffe0020, /* Src_mask. */ 1193 1.1.1.10 christos 0xfffe0020, /* Dst_mask. */ 1194 1.1 christos false), /* PCrel_offset. */ 1195 1.1 christos 1196 1.1 christos /* 16 bit offset from the zero data area pointer. */ 1197 1.1 christos HOWTO (R_V850_ZDA_16_16_SPLIT_OFFSET, /* Type. */ 1198 1.1.1.10 christos 0, /* Rightshift. */ 1199 1.1 christos 4, /* Size. */ 1200 1.1.1.10 christos 16, /* Bitsize. */ 1201 1.1 christos false, /* PC_relative. */ 1202 1.1 christos 0, /* Bitpos. */ 1203 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1204 1.1 christos v850_elf_reloc, /* Special_function. */ 1205 1.1.1.10 christos "R_V850_ZDA_16_16_SPLIT_OFFSET",/* Name. */ 1206 1.1 christos false, /* Partial_inplace. */ 1207 1.1 christos 0xfffe0020, /* Src_mask. */ 1208 1.1.1.10 christos 0xfffe0020, /* Dst_mask. */ 1209 1.1 christos false), /* PCrel_offset. */ 1210 1.1 christos 1211 1.1 christos /* 6 bit offset from the call table base pointer. */ 1212 1.1 christos HOWTO (R_V850_CALLT_6_7_OFFSET, /* Type. */ 1213 1.1.1.10 christos 0, /* Rightshift. */ 1214 1.1 christos 2, /* Size. */ 1215 1.1.1.10 christos 7, /* Bitsize. */ 1216 1.1 christos false, /* PC_relative. */ 1217 1.1 christos 0, /* Bitpos. */ 1218 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1219 1.1 christos v850_elf_reloc, /* Special_function. */ 1220 1.1.1.10 christos "R_V850_CALLT_6_7_OFFSET", /* Name. */ 1221 1.1 christos false, /* Partial_inplace. */ 1222 1.1 christos 0x3f, /* Src_mask. */ 1223 1.1.1.10 christos 0x3f, /* Dst_mask. */ 1224 1.1 christos false), /* PCrel_offset. */ 1225 1.1 christos 1226 1.1 christos /* 16 bit offset from the call table base pointer. */ 1227 1.1 christos HOWTO (R_V850_CALLT_16_16_OFFSET, /* Type. */ 1228 1.1.1.10 christos 0, /* Rightshift. */ 1229 1.1 christos 2, /* Size. */ 1230 1.1.1.10 christos 16, /* Bitsize. */ 1231 1.1 christos false, /* PC_relative. */ 1232 1.1 christos 0, /* Bitpos. */ 1233 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1234 1.1 christos v850_elf_reloc, /* Special_function. */ 1235 1.1.1.10 christos "R_V850_CALLT_16_16_OFFSET", /* Name. */ 1236 1.1 christos false, /* Partial_inplace. */ 1237 1.1 christos 0xffff, /* Src_mask. */ 1238 1.1.1.10 christos 0xffff, /* Dst_mask. */ 1239 1.1 christos false), /* PCrel_offset. */ 1240 1.1 christos 1241 1.1 christos 1242 1.1 christos /* GNU extension to record C++ vtable hierarchy */ 1243 1.1.1.8 christos HOWTO (R_V850_GNU_VTINHERIT, /* Type. */ 1244 1.1.1.10 christos 0, /* Rightshift. */ 1245 1.1.1.8 christos 4, /* Size. */ 1246 1.1.1.10 christos 0, /* Bitsize. */ 1247 1.1.1.8 christos false, /* PC_relative. */ 1248 1.1 christos 0, /* Bitpos. */ 1249 1.1.1.8 christos complain_overflow_dont, /* Complain_on_overflow. */ 1250 1.1 christos NULL, /* Special_function. */ 1251 1.1.1.10 christos "R_V850_GNU_VTINHERIT", /* Name. */ 1252 1.1.1.8 christos false, /* Partial_inplace. */ 1253 1.1.1.8 christos 0, /* Src_mask. */ 1254 1.1.1.10 christos 0, /* Dst_mask. */ 1255 1.1 christos false), /* PCrel_offset. */ 1256 1.1 christos 1257 1.1.1.8 christos /* GNU extension to record C++ vtable member usage. */ 1258 1.1.1.8 christos HOWTO (R_V850_GNU_VTENTRY, /* Type. */ 1259 1.1.1.10 christos 0, /* Rightshift. */ 1260 1.1.1.8 christos 4, /* Size. */ 1261 1.1.1.10 christos 0, /* Bitsize. */ 1262 1.1.1.8 christos false, /* PC_relative. */ 1263 1.1 christos 0, /* Bitpos. */ 1264 1.1.1.8 christos complain_overflow_dont, /* Complain_on_overflow. */ 1265 1.1.1.8 christos _bfd_elf_rel_vtable_reloc_fn, /* Special_function. */ 1266 1.1.1.10 christos "R_V850_GNU_VTENTRY", /* Name. */ 1267 1.1.1.8 christos false, /* Partial_inplace. */ 1268 1.1.1.8 christos 0, /* Src_mask. */ 1269 1.1.1.10 christos 0, /* Dst_mask. */ 1270 1.1 christos false), /* PCrel_offset. */ 1271 1.1 christos 1272 1.1 christos /* Indicates a .longcall pseudo-op. The compiler will generate a .longcall 1273 1.1 christos pseudo-op when it finds a function call which can be relaxed. */ 1274 1.1.1.8 christos HOWTO (R_V850_LONGCALL, /* Type. */ 1275 1.1.1.10 christos 0, /* Rightshift. */ 1276 1.1.1.8 christos 4, /* Size. */ 1277 1.1.1.10 christos 32, /* Bitsize. */ 1278 1.1.1.8 christos true, /* PC_relative. */ 1279 1.1 christos 0, /* Bitpos. */ 1280 1.1 christos complain_overflow_signed, /* Complain_on_overflow. */ 1281 1.1.1.8 christos v850_elf_ignore_reloc, /* Special_function. */ 1282 1.1.1.10 christos "R_V850_LONGCALL", /* Name. */ 1283 1.1.1.8 christos false, /* Partial_inplace. */ 1284 1.1.1.8 christos 0, /* Src_mask. */ 1285 1.1.1.10 christos 0, /* Dst_mask. */ 1286 1.1 christos true), /* PCrel_offset. */ 1287 1.1 christos 1288 1.1 christos /* Indicates a .longjump pseudo-op. The compiler will generate a 1289 1.1 christos .longjump pseudo-op when it finds a branch which can be relaxed. */ 1290 1.1.1.8 christos HOWTO (R_V850_LONGJUMP, /* Type. */ 1291 1.1.1.10 christos 0, /* Rightshift. */ 1292 1.1.1.8 christos 4, /* Size. */ 1293 1.1.1.10 christos 32, /* Bitsize. */ 1294 1.1.1.8 christos true, /* PC_relative. */ 1295 1.1 christos 0, /* Bitpos. */ 1296 1.1 christos complain_overflow_signed, /* Complain_on_overflow. */ 1297 1.1.1.8 christos v850_elf_ignore_reloc, /* Special_function. */ 1298 1.1.1.10 christos "R_V850_LONGJUMP", /* Name. */ 1299 1.1.1.8 christos false, /* Partial_inplace. */ 1300 1.1.1.8 christos 0, /* Src_mask. */ 1301 1.1.1.10 christos 0, /* Dst_mask. */ 1302 1.1.1.8 christos true), /* PCrel_offset. */ 1303 1.1.1.8 christos 1304 1.1.1.8 christos HOWTO (R_V850_ALIGN, /* Type. */ 1305 1.1.1.10 christos 0, /* Rightshift. */ 1306 1.1.1.8 christos 2, /* Size. */ 1307 1.1.1.10 christos 0, /* Bitsize. */ 1308 1.1.1.8 christos false, /* PC_relative. */ 1309 1.1 christos 0, /* Bitpos. */ 1310 1.1 christos complain_overflow_unsigned, /* Complain_on_overflow. */ 1311 1.1.1.8 christos v850_elf_ignore_reloc, /* Special_function. */ 1312 1.1.1.10 christos "R_V850_ALIGN", /* Name. */ 1313 1.1.1.8 christos false, /* Partial_inplace. */ 1314 1.1.1.8 christos 0, /* Src_mask. */ 1315 1.1.1.10 christos 0, /* Dst_mask. */ 1316 1.1 christos true), /* PCrel_offset. */ 1317 1.1 christos 1318 1.1 christos /* Simple pc-relative 32bit reloc. */ 1319 1.1 christos HOWTO (R_V850_REL32, /* Type. */ 1320 1.1.1.10 christos 0, /* Rightshift. */ 1321 1.1 christos 4, /* Size. */ 1322 1.1.1.10 christos 32, /* Bitsize. */ 1323 1.1 christos true, /* PC_relative. */ 1324 1.1 christos 0, /* Bitpos. */ 1325 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1326 1.1 christos v850_elf_reloc, /* Special_function. */ 1327 1.1.1.10 christos "R_V850_REL32", /* Name. */ 1328 1.1 christos false, /* Partial_inplace. */ 1329 1.1 christos 0xffffffff, /* Src_mask. */ 1330 1.1.1.10 christos 0xffffffff, /* Dst_mask. */ 1331 1.1 christos false), /* PCrel_offset. */ 1332 1.1 christos 1333 1.1 christos /* An ld.bu version of R_V850_LO16. */ 1334 1.1 christos HOWTO (R_V850_LO16_SPLIT_OFFSET, /* Type. */ 1335 1.1.1.10 christos 0, /* Rightshift. */ 1336 1.1 christos 4, /* Size. */ 1337 1.1.1.10 christos 16, /* Bitsize. */ 1338 1.1 christos false, /* PC_relative. */ 1339 1.1 christos 0, /* Bitpos. */ 1340 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1341 1.1 christos v850_elf_reloc, /* Special_function. */ 1342 1.1.1.10 christos "R_V850_LO16_SPLIT_OFFSET", /* Name. */ 1343 1.1 christos false, /* Partial_inplace. */ 1344 1.1 christos 0xfffe0020, /* Src_mask. */ 1345 1.1.1.10 christos 0xfffe0020, /* Dst_mask. */ 1346 1.1 christos false), /* PCrel_offset. */ 1347 1.1 christos 1348 1.1 christos /* A unsigned PC relative 16 bit loop. */ 1349 1.1 christos HOWTO (R_V850_16_PCREL, /* Type. */ 1350 1.1.1.10 christos 0, /* Rightshift. */ 1351 1.1 christos 2, /* Size. */ 1352 1.1.1.10 christos 16, /* Bitsize. */ 1353 1.1 christos true, /* PC_relative. */ 1354 1.1 christos 0, /* Bitpos. */ 1355 1.1 christos complain_overflow_bitfield, /* Complain_on_overflow. */ 1356 1.1 christos v850_elf_reloc, /* Special_function. */ 1357 1.1.1.10 christos "R_V850_16_PCREL", /* Name. */ 1358 1.1 christos false, /* Partial_inplace. */ 1359 1.1 christos 0xfffe, /* Src_mask. */ 1360 1.1.1.10 christos 0xfffe, /* Dst_mask. */ 1361 1.1 christos true), /* PCrel_offset. */ 1362 1.1 christos 1363 1.1 christos /* A PC relative 17 bit branch. */ 1364 1.1 christos HOWTO (R_V850_17_PCREL, /* Type. */ 1365 1.1.1.10 christos 0, /* Rightshift. */ 1366 1.1 christos 4, /* Size. */ 1367 1.1.1.10 christos 17, /* Bitsize. */ 1368 1.1 christos true, /* PC_relative. */ 1369 1.1 christos 0, /* Bitpos. */ 1370 1.1 christos complain_overflow_bitfield, /* Complain_on_overflow. */ 1371 1.1 christos v850_elf_reloc, /* Special_function. */ 1372 1.1.1.10 christos "R_V850_17_PCREL", /* Name. */ 1373 1.1 christos false, /* Partial_inplace. */ 1374 1.1 christos 0x0010fffe, /* Src_mask. */ 1375 1.1.1.10 christos 0x0010fffe, /* Dst_mask. */ 1376 1.1 christos true), /* PCrel_offset. */ 1377 1.1 christos 1378 1.1 christos /* A 23bit offset ld/st. */ 1379 1.1 christos HOWTO (R_V850_23, /* type. */ 1380 1.1.1.10 christos 0, /* rightshift. */ 1381 1.1 christos 4, /* size. */ 1382 1.1.1.10 christos 23, /* bitsize. */ 1383 1.1 christos false, /* pc_relative. */ 1384 1.1 christos 0, /* bitpos. */ 1385 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 1386 1.1 christos v850_elf_reloc, /* special_function. */ 1387 1.1.1.10 christos "R_V850_23", /* name. */ 1388 1.1 christos false, /* partial_inplace. */ 1389 1.1 christos 0xffff07f0, /* src_mask. */ 1390 1.1.1.10 christos 0xffff07f0, /* dst_mask. */ 1391 1.1 christos false), /* pcrel_offset. */ 1392 1.1 christos 1393 1.1 christos /* A PC relative 32 bit branch. */ 1394 1.1 christos HOWTO (R_V850_32_PCREL, /* type. */ 1395 1.1.1.10 christos 1, /* rightshift. */ 1396 1.1 christos 4, /* size. */ 1397 1.1.1.10 christos 32, /* bitsize. */ 1398 1.1 christos true, /* pc_relative. */ 1399 1.1 christos 1, /* bitpos. */ 1400 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 1401 1.1 christos v850_elf_reloc, /* special_function. */ 1402 1.1.1.10 christos "R_V850_32_PCREL", /* name. */ 1403 1.1 christos false, /* partial_inplace. */ 1404 1.1 christos 0xfffffffe, /* src_mask. */ 1405 1.1.1.10 christos 0xfffffffe, /* dst_mask. */ 1406 1.1 christos true), /* pcrel_offset. */ 1407 1.1.1.8 christos 1408 1.1 christos /* A absolute 32 bit branch. */ 1409 1.1 christos HOWTO (R_V850_32_ABS, /* type. */ 1410 1.1.1.10 christos 1, /* rightshift. */ 1411 1.1 christos 4, /* size. */ 1412 1.1.1.10 christos 32, /* bitsize. */ 1413 1.1 christos true, /* pc_relative. */ 1414 1.1 christos 1, /* bitpos. */ 1415 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 1416 1.1 christos v850_elf_reloc, /* special_function. */ 1417 1.1.1.10 christos "R_V850_32_ABS", /* name. */ 1418 1.1 christos false, /* partial_inplace. */ 1419 1.1 christos 0xfffffffe, /* src_mask. */ 1420 1.1.1.10 christos 0xfffffffe, /* dst_mask. */ 1421 1.1 christos false), /* pcrel_offset. */ 1422 1.1 christos 1423 1.1 christos /* High 16 bits of symbol value. */ 1424 1.1 christos HOWTO (R_V850_HI16, /* Type. */ 1425 1.1.1.10 christos 0, /* Rightshift. */ 1426 1.1 christos 2, /* Size. */ 1427 1.1.1.10 christos 16, /* Bitsize. */ 1428 1.1 christos false, /* PC_relative. */ 1429 1.1 christos 0, /* Bitpos. */ 1430 1.1 christos complain_overflow_dont, /* Complain_on_overflow. */ 1431 1.1 christos v850_elf_reloc, /* Special_function. */ 1432 1.1.1.10 christos "R_V850_HI16", /* Name. */ 1433 1.1 christos false, /* Partial_inplace. */ 1434 1.1 christos 0xffff, /* Src_mask. */ 1435 1.1.1.10 christos 0xffff, /* Dst_mask. */ 1436 1.1 christos false), /* PCrel_offset. */ 1437 1.1 christos 1438 1.1 christos /* Low 16 bits of symbol value. */ 1439 1.1 christos HOWTO (R_V850_16_S1, /* type. */ 1440 1.1.1.10 christos 1, /* rightshift. */ 1441 1.1 christos 2, /* size. */ 1442 1.1.1.10 christos 16, /* bitsize. */ 1443 1.1 christos false, /* pc_relative. */ 1444 1.1 christos 1, /* bitpos. */ 1445 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 1446 1.1 christos v850_elf_reloc, /* special_function. */ 1447 1.1.1.10 christos "R_V850_16_S1", /* name. */ 1448 1.1 christos false, /* partial_inplace. */ 1449 1.1 christos 0xfffe, /* src_mask. */ 1450 1.1.1.10 christos 0xfffe, /* dst_mask. */ 1451 1.1 christos false), /* pcrel_offset. */ 1452 1.1 christos 1453 1.1 christos /* Low 16 bits of symbol value. */ 1454 1.1 christos HOWTO (R_V850_LO16_S1, /* type. */ 1455 1.1.1.10 christos 1, /* rightshift. */ 1456 1.1 christos 2, /* size. */ 1457 1.1.1.10 christos 16, /* bitsize. */ 1458 1.1 christos false, /* pc_relative. */ 1459 1.1 christos 1, /* bitpos. */ 1460 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 1461 1.1 christos v850_elf_reloc, /* special_function. */ 1462 1.1.1.10 christos "R_V850_LO16_S1", /* name. */ 1463 1.1 christos false, /* partial_inplace. */ 1464 1.1 christos 0xfffe, /* src_mask. */ 1465 1.1.1.10 christos 0xfffe, /* dst_mask. */ 1466 1.1 christos false), /* pcrel_offset. */ 1467 1.1 christos 1468 1.1 christos /* 16 bit offset from the call table base pointer. */ 1469 1.1 christos HOWTO (R_V850_CALLT_15_16_OFFSET, /* type. */ 1470 1.1.1.10 christos 1, /* rightshift. */ 1471 1.1 christos 2, /* size. */ 1472 1.1.1.10 christos 16, /* bitsize. */ 1473 1.1 christos false, /* pc_relative. */ 1474 1.1 christos 1, /* bitpos. */ 1475 1.1 christos complain_overflow_dont, /* complain_on_overflow. */ 1476 1.1 christos v850_elf_reloc, /* special_function. */ 1477 1.1.1.10 christos "R_V850_CALLT_15_16_OFFSET", /* name. */ 1478 1.1 christos false, /* partial_inplace. */ 1479 1.1 christos 0xfffe, /* src_mask. */ 1480 1.1.1.10 christos 0xfffe, /* dst_mask. */ 1481 1.1 christos false), /* pcrel_offset. */ 1482 1.1 christos 1483 1.1 christos /* Like R_V850_32 PCREL, but referring to the GOT table entry for 1484 1.1 christos the symbol. */ 1485 1.1 christos HOWTO (R_V850_32_GOTPCREL, /* type. */ 1486 1.1.1.10 christos 0, /* rightshift. */ 1487 1.1 christos 4, /* size. */ 1488 1.1.1.10 christos 32, /* bitsize. */ 1489 1.1 christos true, /* pc_relative. */ 1490 1.1 christos 0, /* bitpos. */ 1491 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 1492 1.1 christos v850_elf_reloc, /* special_function. */ 1493 1.1.1.10 christos "R_V850_32_GOTPCREL", /* name. */ 1494 1.1 christos false, /* partial_inplace. */ 1495 1.1 christos 0xffffffff, /* src_mask. */ 1496 1.1.1.10 christos 0xffffffff, /* dst_mask. */ 1497 1.1 christos true), /* pcrel_offset. */ 1498 1.1 christos 1499 1.1 christos /* Like R_V850_SDA_, but referring to the GOT table entry for 1500 1.1 christos the symbol. */ 1501 1.1 christos HOWTO (R_V850_16_GOT, /* type. */ 1502 1.1.1.10 christos 0, /* rightshift. */ 1503 1.1 christos 4, /* size. */ 1504 1.1.1.10 christos 16, /* bitsize. */ 1505 1.1 christos false, /* pc_relative. */ 1506 1.1 christos 0, /* bitpos. */ 1507 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 1508 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1509 1.1.1.10 christos "R_V850_16_GOT", /* name. */ 1510 1.1 christos false, /* partial_inplace. */ 1511 1.1 christos 0xffff, /* src_mask. */ 1512 1.1.1.10 christos 0xffff, /* dst_mask. */ 1513 1.1 christos false), /* pcrel_offset. */ 1514 1.1 christos 1515 1.1 christos HOWTO (R_V850_32_GOT, /* type. */ 1516 1.1.1.10 christos 0, /* rightshift. */ 1517 1.1 christos 4, /* size. */ 1518 1.1.1.10 christos 32, /* bitsize. */ 1519 1.1 christos false, /* pc_relative. */ 1520 1.1 christos 0, /* bitpos. */ 1521 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 1522 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1523 1.1.1.10 christos "R_V850_32_GOT", /* name. */ 1524 1.1 christos false, /* partial_inplace. */ 1525 1.1 christos 0xffffffff, /* src_mask. */ 1526 1.1.1.10 christos 0xffffffff, /* dst_mask. */ 1527 1.1 christos false), /* pcrel_offset. */ 1528 1.1 christos 1529 1.1 christos /* Like R_V850_22_PCREL, but referring to the procedure linkage table 1530 1.1 christos entry for the symbol. */ 1531 1.1 christos HOWTO (R_V850_22_PLT, /* type. */ 1532 1.1.1.10 christos 1, /* rightshift. */ 1533 1.1 christos 4, /* size. */ 1534 1.1.1.10 christos 22, /* bitsize. */ 1535 1.1 christos true, /* pc_relative. */ 1536 1.1 christos 7, /* bitpos. */ 1537 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 1538 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1539 1.1.1.10 christos "R_V850_22_PLT", /* name. */ 1540 1.1 christos false, /* partial_inplace. */ 1541 1.1 christos 0x07ffff80, /* src_mask. */ 1542 1.1.1.10 christos 0x07ffff80, /* dst_mask. */ 1543 1.1 christos true), /* pcrel_offset. */ 1544 1.1 christos 1545 1.1 christos HOWTO (R_V850_32_PLT, /* type. */ 1546 1.1.1.10 christos 1, /* rightshift. */ 1547 1.1 christos 4, /* size. */ 1548 1.1.1.10 christos 32, /* bitsize. */ 1549 1.1 christos true, /* pc_relative. */ 1550 1.1 christos 1, /* bitpos. */ 1551 1.1 christos complain_overflow_signed, /* complain_on_overflow. */ 1552 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1553 1.1.1.10 christos "R_V850_32_PLT", /* name. */ 1554 1.1 christos false, /* partial_inplace. */ 1555 1.1 christos 0xffffffff, /* src_mask. */ 1556 1.1.1.10 christos 0xffffffff, /* dst_mask. */ 1557 1.1 christos true), /* pcrel_offset. */ 1558 1.1 christos 1559 1.1 christos /* This is used only by the dynamic linker. The symbol should exist 1560 1.1 christos both in the object being run and in some shared library. The 1561 1.1 christos dynamic linker copies the data addressed by the symbol from the 1562 1.1 christos shared library into the object, because the object being 1563 1.1 christos run has to have the data at some particular address. */ 1564 1.1 christos HOWTO (R_V850_COPY, /* type. */ 1565 1.1.1.10 christos 0, /* rightshift. */ 1566 1.1 christos 4, /* size. */ 1567 1.1.1.10 christos 32, /* bitsize. */ 1568 1.1 christos false, /* pc_relative. */ 1569 1.1 christos 0, /* bitpos. */ 1570 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 1571 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1572 1.1.1.10 christos "R_V850_COPY", /* name. */ 1573 1.1 christos false, /* partial_inplace. */ 1574 1.1 christos 0xffffffff, /* src_mask. */ 1575 1.1.1.10 christos 0xffffffff, /* dst_mask. */ 1576 1.1 christos false), /* pcrel_offset. */ 1577 1.1 christos 1578 1.1 christos /* Like R_M32R_24, but used when setting global offset table 1579 1.1 christos entries. */ 1580 1.1 christos HOWTO (R_V850_GLOB_DAT, /* type. */ 1581 1.1.1.10 christos 0, /* rightshift. */ 1582 1.1 christos 4, /* size */ 1583 1.1.1.10 christos 32, /* bitsize. */ 1584 1.1 christos false, /* pc_relative. */ 1585 1.1 christos 0, /* bitpos. */ 1586 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 1587 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1588 1.1.1.10 christos "R_V850_GLOB_DAT", /* name. */ 1589 1.1 christos false, /* partial_inplace. */ 1590 1.1 christos 0xffffffff, /* src_mask. */ 1591 1.1.1.10 christos 0xffffffff, /* dst_mask. */ 1592 1.1 christos false), /* pcrel_offset. */ 1593 1.1 christos 1594 1.1 christos /* Marks a procedure linkage table entry for a symbol. */ 1595 1.1 christos HOWTO (R_V850_JMP_SLOT, /* type. */ 1596 1.1.1.10 christos 0, /* rightshift. */ 1597 1.1 christos 4, /* size */ 1598 1.1.1.10 christos 32, /* bitsize. */ 1599 1.1 christos false, /* pc_relative. */ 1600 1.1 christos 0, /* bitpos. */ 1601 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 1602 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1603 1.1.1.10 christos "R_V850_JMP_SLOT", /* name. */ 1604 1.1 christos false, /* partial_inplace. */ 1605 1.1 christos 0xffffffff, /* src_mask. */ 1606 1.1.1.10 christos 0xffffffff, /* dst_mask. */ 1607 1.1 christos false), /* pcrel_offset. */ 1608 1.1 christos 1609 1.1 christos /* Used only by the dynamic linker. When the object is run, this 1610 1.1 christos longword is set to the load address of the object, plus the 1611 1.1 christos addend. */ 1612 1.1 christos HOWTO (R_V850_RELATIVE, /* type. */ 1613 1.1.1.10 christos 0, /* rightshift. */ 1614 1.1 christos 4, /* size */ 1615 1.1.1.10 christos 32, /* bitsize. */ 1616 1.1 christos false, /* pc_relative. */ 1617 1.1 christos 0, /* bitpos. */ 1618 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 1619 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1620 1.1.1.10 christos "R_V850_RELATIVE", /* name. */ 1621 1.1 christos false, /* partial_inplace. */ 1622 1.1 christos 0xffffffff, /* src_mask. */ 1623 1.1.1.10 christos 0xffffffff, /* dst_mask. */ 1624 1.1 christos false), /* pcrel_offset. */ 1625 1.1 christos 1626 1.1 christos HOWTO (R_V850_16_GOTOFF, /* type. */ 1627 1.1.1.10 christos 0, /* rightshift. */ 1628 1.1 christos 4, /* size */ 1629 1.1.1.10 christos 16, /* bitsize. */ 1630 1.1 christos false, /* pc_relative. */ 1631 1.1 christos 0, /* bitpos. */ 1632 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 1633 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1634 1.1.1.10 christos "R_V850_16_GOTOFF", /* name. */ 1635 1.1 christos false, /* partial_inplace. */ 1636 1.1 christos 0xffff, /* src_mask. */ 1637 1.1.1.10 christos 0xffff, /* dst_mask. */ 1638 1.1 christos false), /* pcrel_offset. */ 1639 1.1 christos 1640 1.1 christos HOWTO (R_V850_32_GOTOFF, /* type. */ 1641 1.1.1.10 christos 0, /* rightshift. */ 1642 1.1 christos 4, /* size */ 1643 1.1.1.10 christos 32, /* bitsize. */ 1644 1.1 christos false, /* pc_relative. */ 1645 1.1 christos 0, /* bitpos. */ 1646 1.1 christos complain_overflow_bitfield, /* complain_on_overflow. */ 1647 1.1 christos bfd_elf_generic_reloc, /* special_function. */ 1648 1.1.1.10 christos "R_V850_32_GOTOFF", /* name. */ 1649 1.1 christos false, /* partial_inplace. */ 1650 1.1 christos 0xffffffff, /* src_mask. */ 1651 1.1.1.10 christos 0xffffffff, /* dst_mask. */ 1652 1.1 christos false), /* pcrel_offset. */ 1653 1.1 christos 1654 1.1 christos HOWTO (R_V850_CODE, /* type. */ 1655 1.1.1.10 christos 0, /* rightshift. */ 1656 1.1 christos 2, /* size */ 1657 1.1.1.10 christos 0, /* bitsize. */ 1658 1.1 christos false, /* pc_relative. */ 1659 1.1 christos 0, /* bitpos. */ 1660 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 1661 1.1 christos v850_elf_ignore_reloc, /* special_function. */ 1662 1.1.1.10 christos "R_V850_CODE", /* name. */ 1663 1.1 christos false, /* partial_inplace. */ 1664 1.1 christos 0, /* src_mask. */ 1665 1.1.1.10 christos 0, /* dst_mask. */ 1666 1.1 christos true), /* pcrel_offset. */ 1667 1.1 christos 1668 1.1 christos HOWTO (R_V850_DATA, /* type. */ 1669 1.1.1.10 christos 0, /* rightshift. */ 1670 1.1 christos 2, /* size */ 1671 1.1.1.10 christos 0, /* bitsize. */ 1672 1.1 christos false, /* pc_relative. */ 1673 1.1 christos 0, /* bitpos. */ 1674 1.1 christos complain_overflow_unsigned, /* complain_on_overflow. */ 1675 1.1 christos v850_elf_ignore_reloc, /* special_function. */ 1676 1.1.1.10 christos "R_V850_DATA", /* name. */ 1677 1.1 christos false, /* partial_inplace. */ 1678 1.1 christos 0, /* src_mask. */ 1679 1.1.1.10 christos 0, /* dst_mask. */ 1680 1.1 christos true), /* pcrel_offset. */ 1681 1.1 christos 1682 1.1 christos }; 1683 1.1 christos 1684 1.1 christos /* Map BFD reloc types to V850 ELF reloc types. */ 1685 1.1 christos 1686 1.1 christos struct v850_elf_reloc_map 1687 1.1 christos { 1688 1.1 christos /* BFD_RELOC_V850_CALLT_16_16_OFFSET is 258, which will not fix in an 1689 1.1 christos unsigned char. */ 1690 1.1 christos bfd_reloc_code_real_type bfd_reloc_val; 1691 1.1 christos unsigned int elf_reloc_val; 1692 1.1 christos }; 1693 1.1 christos 1694 1.1 christos static const struct v850_elf_reloc_map v850_elf_reloc_map[] = 1695 1.1.1.8 christos { 1696 1.1.1.8 christos { BFD_RELOC_NONE, R_V850_NONE }, 1697 1.1.1.8 christos { BFD_RELOC_V850_9_PCREL, R_V850_9_PCREL }, 1698 1.1.1.8 christos { BFD_RELOC_V850_22_PCREL, R_V850_22_PCREL }, 1699 1.1.1.8 christos { BFD_RELOC_HI16_S, R_V850_HI16_S }, 1700 1.1.1.8 christos { BFD_RELOC_HI16, R_V850_HI16 }, 1701 1.1.1.8 christos { BFD_RELOC_LO16, R_V850_LO16 }, 1702 1.1.1.8 christos { BFD_RELOC_32, R_V850_ABS32 }, 1703 1.1.1.8 christos { BFD_RELOC_32_PCREL, R_V850_REL32 }, 1704 1.1.1.8 christos { BFD_RELOC_16, R_V850_16 }, 1705 1.1.1.8 christos { BFD_RELOC_8, R_V850_8 }, 1706 1.1.1.8 christos { BFD_RELOC_V850_SDA_16_16_OFFSET, R_V850_SDA_16_16_OFFSET }, 1707 1.1.1.8 christos { BFD_RELOC_V850_SDA_15_16_OFFSET, R_V850_SDA_15_16_OFFSET }, 1708 1.1.1.8 christos { BFD_RELOC_V850_ZDA_16_16_OFFSET, R_V850_ZDA_16_16_OFFSET }, 1709 1.1.1.8 christos { BFD_RELOC_V850_ZDA_15_16_OFFSET, R_V850_ZDA_15_16_OFFSET }, 1710 1.1.1.8 christos { BFD_RELOC_V850_TDA_6_8_OFFSET, R_V850_TDA_6_8_OFFSET }, 1711 1.1.1.8 christos { BFD_RELOC_V850_TDA_7_8_OFFSET, R_V850_TDA_7_8_OFFSET }, 1712 1.1.1.8 christos { BFD_RELOC_V850_TDA_7_7_OFFSET, R_V850_TDA_7_7_OFFSET }, 1713 1.1.1.8 christos { BFD_RELOC_V850_TDA_16_16_OFFSET, R_V850_TDA_16_16_OFFSET }, 1714 1.1.1.8 christos { BFD_RELOC_V850_TDA_4_5_OFFSET, R_V850_TDA_4_5_OFFSET }, 1715 1.1.1.8 christos { BFD_RELOC_V850_TDA_4_4_OFFSET, R_V850_TDA_4_4_OFFSET }, 1716 1.1 christos { BFD_RELOC_V850_LO16_SPLIT_OFFSET, R_V850_LO16_SPLIT_OFFSET }, 1717 1.1 christos { BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET, R_V850_SDA_16_16_SPLIT_OFFSET }, 1718 1.1.1.8 christos { BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET, R_V850_ZDA_16_16_SPLIT_OFFSET }, 1719 1.1.1.8 christos { BFD_RELOC_V850_CALLT_6_7_OFFSET, R_V850_CALLT_6_7_OFFSET }, 1720 1.1.1.8 christos { BFD_RELOC_V850_CALLT_16_16_OFFSET, R_V850_CALLT_16_16_OFFSET }, 1721 1.1.1.8 christos { BFD_RELOC_VTABLE_INHERIT, R_V850_GNU_VTINHERIT }, 1722 1.1.1.8 christos { BFD_RELOC_VTABLE_ENTRY, R_V850_GNU_VTENTRY }, 1723 1.1.1.8 christos { BFD_RELOC_V850_LONGCALL, R_V850_LONGCALL }, 1724 1.1.1.8 christos { BFD_RELOC_V850_LONGJUMP, R_V850_LONGJUMP }, 1725 1.1.1.8 christos { BFD_RELOC_V850_ALIGN, R_V850_ALIGN }, 1726 1.1.1.8 christos { BFD_RELOC_V850_16_PCREL, R_V850_16_PCREL }, 1727 1.1.1.8 christos { BFD_RELOC_V850_17_PCREL, R_V850_17_PCREL }, 1728 1.1.1.8 christos { BFD_RELOC_V850_23, R_V850_23 }, 1729 1.1.1.8 christos { BFD_RELOC_V850_32_PCREL, R_V850_32_PCREL }, 1730 1.1.1.8 christos { BFD_RELOC_V850_32_ABS, R_V850_32_ABS }, 1731 1.1.1.8 christos { BFD_RELOC_V850_16_SPLIT_OFFSET, R_V850_HI16 }, 1732 1.1.1.8 christos { BFD_RELOC_V850_16_S1, R_V850_16_S1 }, 1733 1.1.1.8 christos { BFD_RELOC_V850_LO16_S1, R_V850_LO16_S1 }, 1734 1.1.1.8 christos { BFD_RELOC_V850_CALLT_15_16_OFFSET, R_V850_CALLT_15_16_OFFSET }, 1735 1.1.1.8 christos { BFD_RELOC_V850_32_GOTPCREL, R_V850_32_GOTPCREL }, 1736 1.1.1.8 christos { BFD_RELOC_V850_16_GOT, R_V850_16_GOT }, 1737 1.1.1.8 christos { BFD_RELOC_V850_32_GOT, R_V850_32_GOT }, 1738 1.1.1.8 christos { BFD_RELOC_V850_22_PLT_PCREL, R_V850_22_PLT }, 1739 1.1.1.8 christos { BFD_RELOC_V850_32_PLT_PCREL, R_V850_32_PLT }, 1740 1.1.1.8 christos { BFD_RELOC_V850_COPY, R_V850_COPY }, 1741 1.1.1.8 christos { BFD_RELOC_V850_GLOB_DAT, R_V850_GLOB_DAT }, 1742 1.1.1.8 christos { BFD_RELOC_V850_JMP_SLOT, R_V850_JMP_SLOT }, 1743 1.1.1.8 christos { BFD_RELOC_V850_RELATIVE, R_V850_RELATIVE }, 1744 1.1.1.8 christos { BFD_RELOC_V850_16_GOTOFF, R_V850_16_GOTOFF }, 1745 1.1.1.8 christos { BFD_RELOC_V850_32_GOTOFF, R_V850_32_GOTOFF }, 1746 1.1.1.8 christos { BFD_RELOC_V850_CODE, R_V850_CODE }, 1747 1.1 christos { BFD_RELOC_V850_DATA, R_V850_DATA }, 1748 1.1.1.2 christos }; 1749 1.1.1.2 christos 1750 1.1.1.2 christos #define V800_RELOC(name,sz,bit,shift,complain,pcrel,resolver) \ 1751 1.1.1.10 christos HOWTO (name, shift, sz, bit, pcrel, 0, complain_overflow_ ## complain, \ 1752 1.1.1.2 christos bfd_elf_ ## resolver ## _reloc, #name, false, 0, ~0, false) 1753 1.1.1.2 christos 1754 1.1.1.2 christos #define V800_EMPTY(name) EMPTY_HOWTO (name - R_V810_NONE) 1755 1.1.1.2 christos 1756 1.1.1.2 christos #define bfd_elf_v850_reloc v850_elf_reloc 1757 1.1.1.2 christos 1758 1.1.1.2 christos /* Note: It is REQUIRED that the 'type' value (R_V810_...) of each entry 1759 1.1.1.2 christos in this array match the index of the entry in the array minus 0x30. 1760 1.1.1.2 christos See: bfd_elf_v850_relocate_section(), v800_elf_reloc_type_lookup() 1761 1.1.1.2 christos and v800_elf_info_to_howto(). */ 1762 1.1.1.2 christos 1763 1.1.1.2 christos static reloc_howto_type v800_elf_howto_table[] = 1764 1.1.1.10 christos { 1765 1.1.1.10 christos V800_RELOC (R_V810_NONE, 0, 0, 0, dont, false, generic), /* Type = 0x30 */ 1766 1.1.1.10 christos V800_RELOC (R_V810_BYTE, 1, 8, 0, dont, false, generic), 1767 1.1.1.10 christos V800_RELOC (R_V810_HWORD, 2, 16, 0, dont, false, generic), 1768 1.1.1.10 christos V800_RELOC (R_V810_WORD, 4, 32, 0, dont, false, generic), 1769 1.1.1.10 christos V800_RELOC (R_V810_WLO, 2, 16, 0, dont, false, generic), 1770 1.1.1.10 christos V800_RELOC (R_V810_WHI, 2, 16, 0, dont, false, generic), 1771 1.1.1.10 christos V800_RELOC (R_V810_WHI1, 2, 16, 0, dont, false, generic), 1772 1.1.1.10 christos V800_RELOC (R_V810_GPBYTE, 1, 8, 0, dont, false, v850), 1773 1.1.1.10 christos V800_RELOC (R_V810_GPHWORD, 2, 16, 0, dont, false, v850), 1774 1.1.1.10 christos V800_RELOC (R_V810_GPWORD, 4, 32, 0, dont, false, v850), 1775 1.1.1.10 christos V800_RELOC (R_V810_GPWLO, 2, 16, 0, dont, false, v850), 1776 1.1.1.10 christos V800_RELOC (R_V810_GPWHI, 2, 16, 0, dont, false, v850), 1777 1.1.1.10 christos V800_RELOC (R_V810_GPWHI1, 2, 16, 0, dont, false, v850), 1778 1.1.1.2 christos V800_RELOC (R_V850_HWLO, 2, 16, 0, dont, false, generic), 1779 1.1.1.10 christos V800_EMPTY (R_V810_reserved1), 1780 1.1.1.10 christos V800_RELOC (R_V850_EP7BIT, 1, 7, 0, unsigned, false, v850), 1781 1.1.1.10 christos V800_RELOC (R_V850_EPHBYTE, 1, 8, 1, unsigned, false, v850), 1782 1.1.1.10 christos V800_RELOC (R_V850_EPWBYTE, 1, 8, 2, unsigned, false, v850), 1783 1.1.1.2 christos V800_RELOC (R_V850_REGHWLO, 2, 16, 0, dont, false, v850), 1784 1.1.1.10 christos V800_EMPTY (R_V810_reserved2), 1785 1.1.1.2 christos V800_RELOC (R_V850_GPHWLO, 2, 16, 0, dont, false, v850), 1786 1.1.1.10 christos V800_EMPTY (R_V810_reserved3), 1787 1.1.1.10 christos V800_RELOC (R_V850_PCR22, 4, 22, 0, signed, true, generic), 1788 1.1.1.10 christos V800_RELOC (R_V850_BLO, 4, 24, 0, dont, false, v850), 1789 1.1.1.10 christos V800_RELOC (R_V850_EP4BIT, 1, 4, 0, unsigned, false, v850), 1790 1.1.1.10 christos V800_RELOC (R_V850_EP5BIT, 1, 5, 0, unsigned, false, v850), 1791 1.1.1.10 christos V800_RELOC (R_V850_REGBLO, 4, 24, 0, dont, false, v850), 1792 1.1.1.10 christos V800_RELOC (R_V850_GPBLO, 4, 24, 0, dont, false, v850), 1793 1.1.1.10 christos V800_RELOC (R_V810_WLO_1, 2, 16, 0, dont, false, v850), 1794 1.1.1.10 christos V800_RELOC (R_V810_GPWLO_1, 2, 16, 0, signed, false, v850), 1795 1.1.1.10 christos V800_RELOC (R_V850_BLO_1, 4, 16, 0, signed, false, v850), 1796 1.1.1.2 christos V800_RELOC (R_V850_HWLO_1, 2, 16, 0, signed, false, v850), 1797 1.1.1.10 christos V800_EMPTY (R_V810_reserved4), 1798 1.1.1.10 christos V800_RELOC (R_V850_GPBLO_1, 4, 16, 1, signed, false, v850), 1799 1.1.1.2 christos V800_RELOC (R_V850_GPHWLO_1, 2, 16, 1, signed, false, v850), 1800 1.1.1.10 christos V800_EMPTY (R_V810_reserved5), 1801 1.1.1.10 christos V800_RELOC (R_V850_EPBLO, 4, 16, 1, signed, false, v850), 1802 1.1.1.2 christos V800_RELOC (R_V850_EPHWLO, 2, 16, 1, signed, false, v850), 1803 1.1.1.10 christos V800_EMPTY (R_V810_reserved6), 1804 1.1.1.10 christos V800_RELOC (R_V850_EPWLO_N, 2, 16, 1, signed, false, v850), 1805 1.1.1.10 christos V800_RELOC (R_V850_PC32, 4, 32, 1, signed, true, v850), 1806 1.1.1.10 christos V800_RELOC (R_V850_W23BIT, 4, 23, 1, signed, false, v850), 1807 1.1.1.10 christos V800_RELOC (R_V850_GPW23BIT, 4, 23, 1, signed, false, v850), 1808 1.1.1.10 christos V800_RELOC (R_V850_EPW23BIT, 4, 23, 1, signed, false, v850), 1809 1.1.1.10 christos V800_RELOC (R_V850_B23BIT, 4, 23, 1, signed, false, v850), 1810 1.1.1.10 christos V800_RELOC (R_V850_GPB23BIT, 4, 23, 1, signed, false, v850), 1811 1.1.1.10 christos V800_RELOC (R_V850_EPB23BIT, 4, 23, 1, signed, false, v850), 1812 1.1.1.10 christos V800_RELOC (R_V850_PC16U, 2, 16, 1, unsigned, true, generic), 1813 1.1.1.10 christos V800_RELOC (R_V850_PC17, 4, 17, 1, signed, true, generic), 1814 1.1.1.10 christos V800_RELOC (R_V850_DW8, 4, 8, 2, signed, false, v850), 1815 1.1.1.10 christos V800_RELOC (R_V850_GPDW8, 4, 8, 2, signed, false, v850), 1816 1.1.1.10 christos V800_RELOC (R_V850_EPDW8, 4, 8, 2, signed, false, v850), 1817 1.1.1.10 christos V800_RELOC (R_V850_PC9, 2, 9, 3, signed, true, v850), 1818 1.1.1.10 christos V800_RELOC (R_V810_REGBYTE, 1, 8, 0, dont, false, v850), 1819 1.1.1.10 christos V800_RELOC (R_V810_REGHWORD, 2, 16, 0, dont, false, v850), 1820 1.1.1.10 christos V800_RELOC (R_V810_REGWORD, 4, 32, 0, dont, false, v850), 1821 1.1.1.10 christos V800_RELOC (R_V810_REGWLO, 2, 16, 0, dont, false, v850), 1822 1.1.1.10 christos V800_RELOC (R_V810_REGWHI, 2, 16, 0, dont, false, v850), 1823 1.1.1.10 christos V800_RELOC (R_V810_REGWHI1, 2, 16, 0, dont, false, v850), 1824 1.1.1.10 christos V800_RELOC (R_V850_REGW23BIT, 4, 23, 1, signed, false, v850), 1825 1.1.1.10 christos V800_RELOC (R_V850_REGB23BIT, 4, 23, 1, signed, false, v850), 1826 1.1.1.10 christos V800_RELOC (R_V850_REGDW8, 4, 8, 2, signed, false, v850), 1827 1.1.1.10 christos V800_RELOC (R_V810_EPBYTE, 1, 8, 0, dont, false, v850), 1828 1.1.1.10 christos V800_RELOC (R_V810_EPHWORD, 2, 16, 0, dont, false, v850), 1829 1.1.1.10 christos V800_RELOC (R_V810_EPWORD, 4, 32, 0, dont, false, v850), 1830 1.1.1.10 christos V800_RELOC (R_V850_WLO23, 4, 32, 1, dont, false, v850), 1831 1.1.1.10 christos V800_RELOC (R_V850_WORD_E, 4, 32, 1, dont, false, v850), 1832 1.1.1.10 christos V800_RELOC (R_V850_REGWORD_E, 4, 32, 1, dont, false, v850), 1833 1.1.1.10 christos V800_RELOC (R_V850_WORD, 4, 32, 0, dont, false, v850), 1834 1.1.1.10 christos V800_RELOC (R_V850_GPWORD, 4, 32, 0, dont, false, v850), 1835 1.1.1.10 christos V800_RELOC (R_V850_REGWORD, 4, 32, 0, dont, false, v850), 1836 1.1.1.10 christos V800_RELOC (R_V850_EPWORD, 4, 32, 0, dont, false, v850), 1837 1.1.1.10 christos V800_RELOC (R_V810_TPBYTE, 1, 8, 0, dont, false, v850), 1838 1.1.1.10 christos V800_RELOC (R_V810_TPHWORD, 2, 16, 0, dont, false, v850), 1839 1.1.1.10 christos V800_RELOC (R_V810_TPWORD, 4, 32, 0, dont, false, v850), 1840 1.1.1.10 christos V800_RELOC (R_V810_TPWLO, 2, 16, 0, dont, false, v850), 1841 1.1.1.10 christos V800_RELOC (R_V810_TPWHI, 2, 16, 0, dont, false, v850), 1842 1.1.1.10 christos V800_RELOC (R_V810_TPWHI1, 2, 16, 0, dont, false, v850), 1843 1.1.1.10 christos V800_RELOC (R_V850_TPHWLO, 2, 16, 1, dont, false, v850), 1844 1.1.1.10 christos V800_RELOC (R_V850_TPBLO, 4, 24, 0, dont, false, v850), 1845 1.1.1.10 christos V800_RELOC (R_V810_TPWLO_1, 2, 16, 0, signed, false, v850), 1846 1.1.1.10 christos V800_RELOC (R_V850_TPBLO_1, 4, 16, 0, signed, false, v850), 1847 1.1.1.10 christos V800_RELOC (R_V850_TPHWLO_1, 2, 16, 0, signed, false, v850), 1848 1.1.1.10 christos V800_RELOC (R_V850_TP23BIT, 4, 23, 0, signed, false, v850), 1849 1.1.1.10 christos V800_RELOC (R_V850_TPW23BIT, 4, 23, 0, signed, false, v850), 1850 1.1.1.2 christos V800_RELOC (R_V850_TPDW8, 4, 8, 0, signed, false, v850) 1851 1.1 christos }; 1852 1.1 christos 1853 1.1 christos /* Map a bfd relocation into the appropriate howto structure. */ 1855 1.1 christos 1856 1.1 christos static reloc_howto_type * 1857 1.1 christos v850_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1858 1.1 christos bfd_reloc_code_real_type code) 1859 1.1 christos { 1860 1.1 christos unsigned int i; 1861 1.1 christos 1862 1.1 christos for (i = ARRAY_SIZE (v850_elf_reloc_map); i --;) 1863 1.1 christos if (v850_elf_reloc_map[i].bfd_reloc_val == code) 1864 1.1 christos { 1865 1.1 christos unsigned int elf_reloc_val = v850_elf_reloc_map[i].elf_reloc_val; 1866 1.1 christos 1867 1.1 christos BFD_ASSERT (v850_elf_howto_table[elf_reloc_val].type == elf_reloc_val); 1868 1.1 christos 1869 1.1 christos return v850_elf_howto_table + elf_reloc_val; 1870 1.1 christos } 1871 1.1 christos 1872 1.1 christos return NULL; 1873 1.1 christos } 1874 1.1 christos 1875 1.1 christos static reloc_howto_type * 1876 1.1 christos v850_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1877 1.1 christos const char *r_name) 1878 1.1 christos { 1879 1.1 christos unsigned int i; 1880 1.1 christos 1881 1.1 christos for (i = 0; 1882 1.1 christos i < sizeof (v850_elf_howto_table) / sizeof (v850_elf_howto_table[0]); 1883 1.1 christos i++) 1884 1.1 christos if (v850_elf_howto_table[i].name != NULL 1885 1.1 christos && strcasecmp (v850_elf_howto_table[i].name, r_name) == 0) 1886 1.1 christos return &v850_elf_howto_table[i]; 1887 1.1 christos 1888 1.1 christos return NULL; 1889 1.1 christos } 1890 1.1 christos 1891 1.1.1.10 christos /* Set the howto pointer for an V850 ELF reloc. */ 1893 1.1 christos 1894 1.1 christos static bool 1895 1.1 christos v850_elf_info_to_howto_rel (bfd *abfd, 1896 1.1 christos arelent *cache_ptr, 1897 1.1 christos Elf_Internal_Rela *dst) 1898 1.1 christos { 1899 1.1.1.4 christos unsigned int r_type; 1900 1.1.1.4 christos 1901 1.1.1.7 christos r_type = ELF32_R_TYPE (dst->r_info); 1902 1.1.1.8 christos if (r_type >= (unsigned int) R_V850_max) 1903 1.1.1.8 christos { 1904 1.1.1.8 christos /* xgettext:c-format */ 1905 1.1.1.10 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 1906 1.1.1.4 christos abfd, r_type); 1907 1.1 christos bfd_set_error (bfd_error_bad_value); 1908 1.1.1.10 christos return false; 1909 1.1 christos } 1910 1.1 christos cache_ptr->howto = &v850_elf_howto_table[r_type]; 1911 1.1 christos return true; 1912 1.1 christos } 1913 1.1.1.10 christos 1914 1.1.1.8 christos /* Set the howto pointer for a V850 ELF reloc (type RELA). */ 1915 1.1 christos 1916 1.1 christos static bool 1917 1.1 christos v850_elf_info_to_howto_rela (bfd *abfd, 1918 1.1 christos arelent * cache_ptr, 1919 1.1 christos Elf_Internal_Rela *dst) 1920 1.1 christos { 1921 1.1.1.5 christos unsigned int r_type; 1922 1.1.1.5 christos 1923 1.1.1.7 christos r_type = ELF32_R_TYPE (dst->r_info); 1924 1.1.1.8 christos if (r_type >= (unsigned int) R_V850_max) 1925 1.1.1.8 christos { 1926 1.1.1.8 christos /* xgettext:c-format */ 1927 1.1.1.10 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 1928 1.1.1.5 christos abfd, r_type); 1929 1.1 christos bfd_set_error (bfd_error_bad_value); 1930 1.1.1.10 christos return false; 1931 1.1 christos } 1932 1.1 christos cache_ptr->howto = &v850_elf_howto_table[r_type]; 1933 1.1.1.10 christos return true; 1934 1.1 christos } 1935 1.1 christos 1936 1.1.1.12 christos static bool 1938 1.1.1.12 christos v850_elf_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name) 1939 1.1.1.12 christos { 1940 1.1.1.12 christos if (name[0] == '.' && (name[1] == 'L' || name[1] == '.')) 1941 1.1 christos return true; 1942 1.1.1.3 christos if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_') 1943 1.1.1.10 christos return true; 1944 1.1.1.3 christos return false; 1945 1.1.1.3 christos } 1946 1.1.1.3 christos 1947 1.1.1.3 christos static bool 1948 1.1 christos v850_elf_is_target_special_symbol (bfd *abfd, asymbol *sym) 1949 1.1 christos { 1950 1.1 christos return v850_elf_is_local_label_name (abfd, sym->name); 1951 1.1 christos } 1952 1.1 christos 1953 1.1 christos /* We overload some of the bfd_reloc error codes for own purposes. */ 1955 1.1 christos #define bfd_reloc_gp_not_found bfd_reloc_other 1956 1.1 christos #define bfd_reloc_ep_not_found bfd_reloc_continue 1957 1.1 christos #define bfd_reloc_ctbp_not_found (bfd_reloc_dangerous + 1) 1958 1.1 christos 1959 1.1 christos /* Perform a relocation as part of a final link. */ 1960 1.1 christos 1961 1.1 christos static bfd_reloc_status_type 1962 1.1 christos v850_elf_final_link_relocate (reloc_howto_type *howto, 1963 1.1 christos bfd *input_bfd, 1964 1.1 christos bfd *output_bfd ATTRIBUTE_UNUSED, 1965 1.1 christos asection *input_section, 1966 1.1 christos bfd_byte *contents, 1967 1.1 christos bfd_vma offset, 1968 1.1 christos bfd_vma value, 1969 1.1 christos bfd_vma addend, 1970 1.1 christos struct bfd_link_info *info, 1971 1.1 christos asection *sym_sec, 1972 1.1 christos int is_local ATTRIBUTE_UNUSED) 1973 1.1 christos { 1974 1.1 christos unsigned int r_type = howto->type; 1975 1.1.1.2 christos bfd_byte *hit_data = contents + offset; 1976 1.1 christos 1977 1.1 christos /* Adjust the value according to the relocation. */ 1978 1.1 christos switch (r_type) 1979 1.1 christos { 1980 1.1 christos case R_V850_PC9: 1981 1.1 christos case R_V850_9_PCREL: 1982 1.1.1.2 christos value -= (input_section->output_section->vma 1983 1.1 christos + input_section->output_offset); 1984 1.1 christos value -= offset; 1985 1.1 christos break; 1986 1.1 christos 1987 1.1 christos case R_V850_PC16U: 1988 1.1 christos case R_V850_16_PCREL: 1989 1.1 christos value -= (input_section->output_section->vma 1990 1.1 christos + input_section->output_offset 1991 1.1 christos + offset); 1992 1.1 christos 1993 1.1 christos /* If the sign extension will corrupt the value then we have overflowed. */ 1994 1.1.1.2 christos if ((value & 0xffff0000) != 0xffff0000) 1995 1.1 christos return bfd_reloc_overflow; 1996 1.1 christos 1997 1.1 christos break; 1998 1.1 christos 1999 1.1 christos case R_V850_PC17: 2000 1.1 christos case R_V850_17_PCREL: 2001 1.1 christos value -= (input_section->output_section->vma 2002 1.1 christos + input_section->output_offset 2003 1.1 christos + offset); 2004 1.1 christos 2005 1.1 christos /* If the sign extension will corrupt the value then we have overflowed. */ 2006 1.1 christos if (((value & 0xffff0000) != 0x0) && ((value & 0xffff0000) != 0xffff0000)) 2007 1.1.1.2 christos return bfd_reloc_overflow; 2008 1.1 christos 2009 1.1 christos value = SEXT17 (value); 2010 1.1 christos break; 2011 1.1 christos 2012 1.1 christos case R_V850_PCR22: 2013 1.1 christos case R_V850_22_PCREL: 2014 1.1 christos value -= (input_section->output_section->vma 2015 1.1 christos + input_section->output_offset 2016 1.1 christos + offset); 2017 1.1 christos 2018 1.1 christos /* If the sign extension will corrupt the value then we have overflowed. */ 2019 1.1 christos if (((value & 0xffe00000) != 0x0) && ((value & 0xffe00000) != 0xffe00000)) 2020 1.1 christos return bfd_reloc_overflow; 2021 1.1.1.2 christos 2022 1.1 christos /* Only the bottom 22 bits of the PC are valid. */ 2023 1.1 christos value = SEXT22 (value); 2024 1.1 christos break; 2025 1.1 christos 2026 1.1 christos case R_V850_PC32: 2027 1.1 christos case R_V850_32_PCREL: 2028 1.1 christos value -= (input_section->output_section->vma 2029 1.1 christos + input_section->output_offset 2030 1.1 christos + offset); 2031 1.1 christos break; 2032 1.1 christos 2033 1.1 christos case R_V850_32_ABS: 2034 1.1 christos case R_V850_23: 2035 1.1 christos case R_V850_HI16_S: 2036 1.1 christos case R_V850_HI16: 2037 1.1 christos case R_V850_LO16: 2038 1.1.1.2 christos case R_V850_LO16_S1: 2039 1.1.1.2 christos case R_V850_LO16_SPLIT_OFFSET: 2040 1.1.1.2 christos case R_V850_16: 2041 1.1.1.2 christos case R_V850_ABS32: 2042 1.1.1.2 christos case R_V850_8: 2043 1.1.1.2 christos case R_V810_BYTE: 2044 1.1.1.2 christos case R_V810_HWORD: 2045 1.1.1.2 christos case R_V810_WORD: 2046 1.1.1.2 christos case R_V810_WLO: 2047 1.1 christos case R_V810_WHI: 2048 1.1 christos case R_V810_WHI1: 2049 1.1 christos case R_V810_WLO_1: 2050 1.1 christos case R_V850_WLO23: 2051 1.1 christos case R_V850_BLO: 2052 1.1 christos break; 2053 1.1 christos 2054 1.1 christos case R_V850_ZDA_15_16_OFFSET: 2055 1.1 christos case R_V850_ZDA_16_16_OFFSET: 2056 1.1 christos case R_V850_ZDA_16_16_SPLIT_OFFSET: 2057 1.1 christos if (sym_sec == NULL) 2058 1.1 christos return bfd_reloc_undefined; 2059 1.1 christos 2060 1.1 christos value -= sym_sec->output_section->vma; 2061 1.1.1.2 christos break; 2062 1.1 christos 2063 1.1.1.8 christos case R_V850_SDA_15_16_OFFSET: 2064 1.1 christos case R_V850_SDA_16_16_OFFSET: 2065 1.1 christos case R_V850_SDA_16_16_SPLIT_OFFSET: 2066 1.1 christos case R_V810_GPWLO_1: 2067 1.1 christos { 2068 1.1 christos unsigned long gp; 2069 1.1 christos struct bfd_link_hash_entry * h; 2070 1.1.1.10 christos 2071 1.1 christos if (sym_sec == NULL) 2072 1.1 christos return bfd_reloc_undefined; 2073 1.1 christos 2074 1.1 christos /* Get the value of __gp. */ 2075 1.1 christos h = bfd_link_hash_lookup (info->hash, "__gp", false, false, true); 2076 1.1 christos if (h == NULL 2077 1.1 christos || h->type != bfd_link_hash_defined) 2078 1.1 christos return bfd_reloc_gp_not_found; 2079 1.1 christos 2080 1.1 christos gp = (h->u.def.value 2081 1.1 christos + h->u.def.section->output_section->vma 2082 1.1 christos + h->u.def.section->output_offset); 2083 1.1 christos 2084 1.1 christos value -= sym_sec->output_section->vma; 2085 1.1 christos value -= (gp - sym_sec->output_section->vma); 2086 1.1 christos } 2087 1.1 christos break; 2088 1.1 christos 2089 1.1 christos case R_V850_TDA_4_4_OFFSET: 2090 1.1 christos case R_V850_TDA_4_5_OFFSET: 2091 1.1.1.8 christos case R_V850_TDA_7_7_OFFSET: 2092 1.1 christos case R_V850_TDA_7_8_OFFSET: 2093 1.1 christos case R_V850_TDA_6_8_OFFSET: 2094 1.1 christos case R_V850_TDA_16_16_OFFSET: 2095 1.1.1.10 christos { 2096 1.1 christos unsigned long ep; 2097 1.1 christos struct bfd_link_hash_entry * h; 2098 1.1 christos 2099 1.1 christos /* Get the value of __ep. */ 2100 1.1 christos h = bfd_link_hash_lookup (info->hash, "__ep", false, false, true); 2101 1.1 christos if (h == NULL 2102 1.1 christos || h->type != bfd_link_hash_defined) 2103 1.1 christos return bfd_reloc_ep_not_found; 2104 1.1 christos 2105 1.1 christos ep = (h->u.def.value 2106 1.1 christos + h->u.def.section->output_section->vma 2107 1.1 christos + h->u.def.section->output_offset); 2108 1.1 christos 2109 1.1 christos value -= ep; 2110 1.1.1.8 christos } 2111 1.1 christos break; 2112 1.1 christos 2113 1.1 christos case R_V850_CALLT_6_7_OFFSET: 2114 1.1.1.10 christos { 2115 1.1 christos unsigned long ctbp; 2116 1.1 christos struct bfd_link_hash_entry * h; 2117 1.1 christos 2118 1.1 christos /* Get the value of __ctbp. */ 2119 1.1 christos h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true); 2120 1.1 christos if (h == NULL 2121 1.1 christos || h->type != bfd_link_hash_defined) 2122 1.1 christos return bfd_reloc_ctbp_not_found; 2123 1.1 christos 2124 1.1 christos ctbp = (h->u.def.value 2125 1.1 christos + h->u.def.section->output_section->vma 2126 1.1 christos + h->u.def.section->output_offset); 2127 1.1 christos value -= ctbp; 2128 1.1 christos } 2129 1.1.1.8 christos break; 2130 1.1 christos 2131 1.1 christos case R_V850_CALLT_15_16_OFFSET: 2132 1.1 christos case R_V850_CALLT_16_16_OFFSET: 2133 1.1 christos { 2134 1.1 christos unsigned long ctbp; 2135 1.1 christos struct bfd_link_hash_entry * h; 2136 1.1.1.10 christos 2137 1.1 christos if (sym_sec == NULL) 2138 1.1 christos return bfd_reloc_undefined; 2139 1.1 christos 2140 1.1 christos /* Get the value of __ctbp. */ 2141 1.1 christos h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true); 2142 1.1 christos if (h == NULL 2143 1.1 christos || h->type != bfd_link_hash_defined) 2144 1.1 christos return bfd_reloc_ctbp_not_found; 2145 1.1 christos 2146 1.1 christos ctbp = (h->u.def.value 2147 1.1 christos + h->u.def.section->output_section->vma 2148 1.1 christos + h->u.def.section->output_offset); 2149 1.1 christos 2150 1.1 christos value -= sym_sec->output_section->vma; 2151 1.1.1.2 christos value -= (ctbp - sym_sec->output_section->vma); 2152 1.1 christos } 2153 1.1 christos break; 2154 1.1 christos 2155 1.1 christos case R_V850_NONE: 2156 1.1 christos case R_V810_NONE: 2157 1.1 christos case R_V850_GNU_VTINHERIT: 2158 1.1 christos case R_V850_GNU_VTENTRY: 2159 1.1 christos case R_V850_LONGCALL: 2160 1.1.1.2 christos case R_V850_LONGJUMP: 2161 1.1.1.8 christos case R_V850_ALIGN: 2162 1.1.1.8 christos return bfd_reloc_ok; 2163 1.1.1.2 christos 2164 1.1 christos default: 2165 1.1 christos #ifdef DEBUG 2166 1.1 christos _bfd_error_handler ("%pB: unsupported relocation type %#x", 2167 1.1 christos input_bfd, r_type); 2168 1.1 christos #endif 2169 1.1 christos return bfd_reloc_notsupported; 2170 1.1 christos } 2171 1.1 christos 2172 1.1 christos /* Perform the relocation. */ 2173 1.1.1.10 christos return v850_elf_perform_relocation (input_bfd, r_type, value + addend, hit_data); 2174 1.1 christos } 2175 1.1 christos 2176 1.1 christos /* Relocate an V850 ELF section. */ 2178 1.1 christos 2179 1.1 christos static int 2180 1.1 christos v850_elf_relocate_section (bfd *output_bfd, 2181 1.1 christos struct bfd_link_info *info, 2182 1.1 christos bfd *input_bfd, 2183 1.1 christos asection *input_section, 2184 1.1 christos bfd_byte *contents, 2185 1.1 christos Elf_Internal_Rela *relocs, 2186 1.1 christos Elf_Internal_Sym *local_syms, 2187 1.1 christos asection **local_sections) 2188 1.1 christos { 2189 1.1 christos Elf_Internal_Shdr *symtab_hdr; 2190 1.1 christos struct elf_link_hash_entry **sym_hashes; 2191 1.1 christos Elf_Internal_Rela *rel; 2192 1.1 christos Elf_Internal_Rela *relend; 2193 1.1 christos 2194 1.1 christos symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; 2195 1.1 christos sym_hashes = elf_sym_hashes (input_bfd); 2196 1.1 christos 2197 1.1 christos /* Reset the list of remembered HI16S relocs to empty. */ 2198 1.1 christos free_hi16s = previous_hi16s; 2199 1.1 christos previous_hi16s = NULL; 2200 1.1.1.2 christos hi16s_counter = 0; 2201 1.1 christos 2202 1.1 christos rel = relocs; 2203 1.1 christos relend = relocs + input_section->reloc_count; 2204 1.1 christos for (; rel < relend; rel++) 2205 1.1 christos { 2206 1.1 christos unsigned int r_type; 2207 1.1 christos reloc_howto_type *howto; 2208 1.1 christos unsigned long r_symndx; 2209 1.1 christos Elf_Internal_Sym *sym; 2210 1.1 christos asection *sec; 2211 1.1 christos struct elf_link_hash_entry *h; 2212 1.1 christos bfd_vma relocation; 2213 1.1.1.8 christos bfd_reloc_status_type r; 2214 1.1.1.8 christos 2215 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info); 2216 1.1.1.2 christos r_type = ELF32_R_TYPE (rel->r_info); 2217 1.1.1.2 christos 2218 1.1.1.2 christos if (r_type == R_V850_GNU_VTENTRY 2219 1.1.1.2 christos || r_type == R_V850_GNU_VTINHERIT) 2220 1.1.1.2 christos continue; 2221 1.1.1.2 christos 2222 1.1.1.2 christos if (bfd_get_arch (input_bfd) == bfd_arch_v850_rh850) 2223 1.1 christos howto = v800_elf_howto_table + (r_type - R_V810_NONE); 2224 1.1 christos else 2225 1.1 christos howto = v850_elf_howto_table + r_type; 2226 1.1 christos 2227 1.1 christos BFD_ASSERT (r_type == howto->type); 2228 1.1 christos 2229 1.1 christos h = NULL; 2230 1.1 christos sym = NULL; 2231 1.1 christos sec = NULL; 2232 1.1 christos if (r_symndx < symtab_hdr->sh_info) 2233 1.1 christos { 2234 1.1.1.10 christos sym = local_syms + r_symndx; 2235 1.1 christos sec = local_sections[r_symndx]; 2236 1.1 christos relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 2237 1.1 christos } 2238 1.1 christos else 2239 1.1 christos { 2240 1.1 christos bool unresolved_reloc, warned, ignored; 2241 1.1 christos 2242 1.1 christos /* Note - this check is delayed until now as it is possible and 2243 1.1 christos valid to have a file without any symbols but with relocs that 2244 1.1 christos can be processed. */ 2245 1.1.1.10 christos if (sym_hashes == NULL) 2246 1.1 christos { 2247 1.1 christos info->callbacks->warning 2248 1.1 christos (info, "no hash table available", 2249 1.1 christos NULL, input_bfd, input_section, (bfd_vma) 0); 2250 1.1 christos 2251 1.1.1.3 christos return false; 2252 1.1 christos } 2253 1.1 christos 2254 1.1.1.2 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 2255 1.1 christos r_symndx, symtab_hdr, sym_hashes, 2256 1.1.1.2 christos h, sec, relocation, 2257 1.1 christos unresolved_reloc, warned, ignored); 2258 1.1.1.6 christos } 2259 1.1 christos 2260 1.1 christos if (sec != NULL && discarded_section (sec)) 2261 1.1 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 2262 1.1 christos rel, 1, relend, howto, 0, contents); 2263 1.1 christos 2264 1.1 christos if (bfd_link_relocatable (info)) 2265 1.1 christos continue; 2266 1.1 christos 2267 1.1 christos /* FIXME: We should use the addend, but the COFF relocations don't. */ 2268 1.1 christos r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd, 2269 1.1 christos input_section, 2270 1.1 christos contents, rel->r_offset, 2271 1.1 christos relocation, rel->r_addend, 2272 1.1 christos info, sec, h == NULL); 2273 1.1 christos 2274 1.1 christos if (r != bfd_reloc_ok) 2275 1.1 christos { 2276 1.1 christos const char * name; 2277 1.1 christos const char * msg = NULL; 2278 1.1 christos 2279 1.1 christos if (h != NULL) 2280 1.1.1.9 christos name = h->root.root.string; 2281 1.1 christos else 2282 1.1 christos { 2283 1.1 christos name = (bfd_elf_string_from_elf_section 2284 1.1 christos (input_bfd, symtab_hdr->sh_link, sym->st_name)); 2285 1.1 christos if (name == NULL || *name == '\0') 2286 1.1.1.6 christos name = bfd_section_name (sec); 2287 1.1.1.6 christos } 2288 1.1.1.6 christos 2289 1.1 christos switch ((int) r) 2290 1.1 christos { 2291 1.1 christos case bfd_reloc_overflow: 2292 1.1.1.6 christos (*info->callbacks->reloc_overflow) 2293 1.1.1.10 christos (info, (h ? &h->root : NULL), name, howto->name, 2294 1.1 christos (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 2295 1.1 christos break; 2296 1.1 christos 2297 1.1 christos case bfd_reloc_undefined: 2298 1.1 christos (*info->callbacks->undefined_symbol) 2299 1.1 christos (info, name, input_bfd, input_section, rel->r_offset, true); 2300 1.1 christos break; 2301 1.1 christos 2302 1.1 christos case bfd_reloc_outofrange: 2303 1.1 christos msg = _("internal error: out of range error"); 2304 1.1 christos goto common_error; 2305 1.1 christos 2306 1.1 christos case bfd_reloc_notsupported: 2307 1.1 christos msg = _("internal error: unsupported relocation error"); 2308 1.1 christos goto common_error; 2309 1.1 christos 2310 1.1 christos case bfd_reloc_dangerous: 2311 1.1 christos msg = _("internal error: dangerous relocation"); 2312 1.1 christos goto common_error; 2313 1.1 christos 2314 1.1 christos case bfd_reloc_gp_not_found: 2315 1.1 christos msg = _("could not locate special linker symbol __gp"); 2316 1.1 christos goto common_error; 2317 1.1 christos 2318 1.1 christos case bfd_reloc_ep_not_found: 2319 1.1 christos msg = _("could not locate special linker symbol __ep"); 2320 1.1 christos goto common_error; 2321 1.1 christos 2322 1.1 christos case bfd_reloc_ctbp_not_found: 2323 1.1 christos msg = _("could not locate special linker symbol __ctbp"); 2324 1.1 christos goto common_error; 2325 1.1.1.6 christos 2326 1.1.1.6 christos default: 2327 1.1 christos msg = _("internal error: unknown error"); 2328 1.1 christos /* fall through */ 2329 1.1 christos 2330 1.1 christos common_error: 2331 1.1 christos (*info->callbacks->warning) (info, msg, name, input_bfd, 2332 1.1.1.10 christos input_section, rel->r_offset); 2333 1.1 christos break; 2334 1.1 christos } 2335 1.1 christos } 2336 1.1 christos } 2337 1.1 christos 2338 1.1 christos return true; 2339 1.1 christos } 2340 1.1 christos 2341 1.1 christos static asection * 2342 1.1 christos v850_elf_gc_mark_hook (asection *sec, 2343 1.1 christos struct bfd_link_info *info, 2344 1.1 christos Elf_Internal_Rela *rel, 2345 1.1 christos struct elf_link_hash_entry *h, 2346 1.1 christos Elf_Internal_Sym *sym) 2347 1.1 christos { 2348 1.1 christos if (h != NULL) 2349 1.1 christos switch (ELF32_R_TYPE (rel->r_info)) 2350 1.1 christos { 2351 1.1 christos case R_V850_GNU_VTINHERIT: 2352 1.1 christos case R_V850_GNU_VTENTRY: 2353 1.1.1.5 christos return NULL; 2354 1.1.1.5 christos } 2355 1.1.1.5 christos 2356 1.1.1.5 christos return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); 2357 1.1.1.5 christos } 2358 1.1.1.5 christos 2359 1.1.1.5 christos static void 2360 1.1.1.5 christos v850_set_note (bfd * abfd, asection * s, enum v850_notes note, unsigned int val) 2361 1.1.1.5 christos { 2362 1.1.1.5 christos bfd_byte * data = s->contents + ((note - 1) * SIZEOF_V850_NOTE); 2363 1.1.1.5 christos 2364 1.1.1.5 christos bfd_put_32 (abfd, 4, data + 0); 2365 1.1.1.5 christos bfd_put_32 (abfd, 4, data + 4); 2366 1.1.1.5 christos bfd_put_32 (abfd, note, data + 8); 2367 1.1.1.5 christos memcpy (data + 12, V850_NOTE_NAME, 4); 2368 1.1.1.5 christos bfd_put_32 (abfd, val, data + 16); 2369 1.1.1.5 christos } 2370 1.1.1.6 christos 2371 1.1.1.5 christos /* Create the note section if not already present. This is done early so 2372 1.1.1.5 christos that the linker maps the sections to the right place in the output. */ 2373 1.1.1.5 christos 2374 1.1.1.5 christos static asection * 2375 1.1.1.5 christos v850_elf_make_note_section (bfd * abfd) 2376 1.1.1.5 christos { 2377 1.1.1.5 christos asection *s; 2378 1.1.1.5 christos bfd_byte *data; 2379 1.1.1.5 christos flagword flags; 2380 1.1.1.5 christos enum v850_notes id; 2381 1.1.1.5 christos 2382 1.1.1.5 christos /* Make the note section. */ 2383 1.1.1.9 christos flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_MERGE; 2384 1.1.1.5 christos 2385 1.1.1.5 christos s = bfd_make_section_anyway_with_flags (abfd, V850_NOTE_SECNAME, flags); 2386 1.1.1.5 christos if (s == NULL) 2387 1.1.1.9 christos return NULL; 2388 1.1.1.5 christos 2389 1.1.1.5 christos if (!bfd_set_section_alignment (s, 2)) 2390 1.1.1.5 christos return NULL; 2391 1.1.1.5 christos 2392 1.1.1.5 christos /* Allocate space for all known notes. */ 2393 1.1.1.5 christos if (!bfd_set_section_size (s, NUM_V850_NOTES * SIZEOF_V850_NOTE)) 2394 1.1.1.5 christos return NULL; 2395 1.1.1.5 christos 2396 1.1.1.5 christos data = bfd_zalloc (abfd, NUM_V850_NOTES * SIZEOF_V850_NOTE); 2397 1.1.1.5 christos if (data == NULL) 2398 1.1.1.5 christos return NULL; 2399 1.1.1.5 christos 2400 1.1.1.5 christos s->contents = data; 2401 1.1.1.5 christos 2402 1.1.1.5 christos /* Provide default (= uninitilaised) values for all of the notes. */ 2403 1.1.1.5 christos for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++) 2404 1.1.1.5 christos v850_set_note (abfd, s, id, 0); 2405 1.1.1.5 christos 2406 1.1.1.10 christos return s; 2407 1.1.1.5 christos } 2408 1.1.1.5 christos 2409 1.1.1.5 christos /* Create the note section if not already present. This is done early so 2410 1.1.1.5 christos that the linker maps the sections to the right place in the output. */ 2411 1.1.1.5 christos 2412 1.1.1.5 christos bool 2413 1.1.1.5 christos v850_elf_create_sections (struct bfd_link_info * info) 2414 1.1.1.10 christos { 2415 1.1.1.5 christos bfd * ibfd; 2416 1.1.1.5 christos 2417 1.1.1.5 christos /* If we already have a note section, do not make another. */ 2418 1.1.1.5 christos for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) 2419 1.1.1.10 christos if (bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME) != NULL) 2420 1.1.1.10 christos return true; 2421 1.1.1.5 christos 2422 1.1.1.5 christos return v850_elf_make_note_section (info->input_bfds) != NULL; 2423 1.1.1.5 christos } 2424 1.1.1.5 christos 2425 1.1.1.5 christos bool 2426 1.1.1.10 christos v850_elf_set_note (bfd * abfd, unsigned int note, unsigned int val) 2427 1.1.1.5 christos { 2428 1.1.1.5 christos asection * notes = bfd_get_section_by_name (abfd, V850_NOTE_SECNAME); 2429 1.1.1.5 christos 2430 1.1.1.5 christos if (val > 2) 2431 1.1.1.10 christos /* At the moment, no known note has a value over 2. */ 2432 1.1.1.5 christos return false; 2433 1.1.1.5 christos 2434 1.1.1.10 christos if (notes == NULL) 2435 1.1.1.5 christos notes = v850_elf_make_note_section (abfd); 2436 1.1.1.5 christos if (notes == NULL) 2437 1.1.1.6 christos return false; 2438 1.1.1.5 christos 2439 1.1.1.6 christos v850_set_note (abfd, notes, note, val); 2440 1.1.1.6 christos return true; 2441 1.1.1.5 christos } 2442 1.1.1.5 christos 2443 1.1.1.5 christos /* Copy a v850 note section from one object module to another. */ 2444 1.1.1.5 christos 2445 1.1.1.5 christos static void 2446 1.1.1.5 christos v850_elf_copy_notes (bfd *ibfd, bfd *obfd) 2447 1.1.1.5 christos { 2448 1.1.1.5 christos asection * onotes; 2449 1.1.1.6 christos asection * inotes; 2450 1.1.1.5 christos 2451 1.1.1.6 christos /* If the output bfd does not have a note section, then 2452 1.1.1.6 christos skip the merge. The normal input to output section 2453 1.1.1.6 christos copying will take care of everythng for us. */ 2454 1.1.1.9 christos if ((onotes = bfd_get_section_by_name (obfd, V850_NOTE_SECNAME)) == NULL) 2455 1.1.1.5 christos return; 2456 1.1.1.5 christos 2457 1.1.1.5 christos if ((inotes = bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME)) == NULL) 2458 1.1.1.5 christos return; 2459 1.1.1.5 christos 2460 1.1.1.5 christos if (bfd_section_size (inotes) == bfd_section_size (onotes)) 2461 1.1.1.5 christos { 2462 1.1.1.5 christos bfd_byte * icont; 2463 1.1.1.8 christos bfd_byte * ocont; 2464 1.1.1.8 christos 2465 1.1.1.8 christos if ((icont = elf_section_data (inotes)->this_hdr.contents) == NULL) 2466 1.1.1.5 christos BFD_ASSERT (bfd_malloc_and_get_section (ibfd, inotes, & icont)); 2467 1.1.1.5 christos 2468 1.1.1.9 christos if ((ocont = elf_section_data (onotes)->this_hdr.contents) == NULL) 2469 1.1.1.5 christos /* If the output is being stripped then it is possible for 2470 1.1.1.6 christos the notes section to disappear. In this case do nothing. */ 2471 1.1.1.5 christos return; 2472 1.1.1.6 christos 2473 1.1.1.6 christos /* Copy/overwrite notes from the input to the output. */ 2474 1.1.1.10 christos memcpy (ocont, icont, bfd_section_size (onotes)); 2475 1.1.1.6 christos } 2476 1.1.1.6 christos } 2477 1.1.1.6 christos 2478 1.1.1.6 christos /* Copy backend specific data from one object module to another. */ 2479 1.1.1.5 christos 2480 1.1.1.5 christos static bool 2481 1.1.1.5 christos v850_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd) 2482 1.1.1.10 christos { 2483 1.1.1.5 christos v850_elf_copy_notes (ibfd, obfd); 2484 1.1.1.5 christos return _bfd_elf_copy_private_bfd_data (ibfd, obfd); 2485 1.1.1.5 christos } 2486 1.1.1.5 christos #define bfd_elf32_bfd_copy_private_bfd_data v850_elf_copy_private_bfd_data 2487 1.1.1.10 christos 2488 1.1.1.5 christos static bool 2489 1.1.1.5 christos v850_elf_merge_notes (bfd * ibfd, bfd *obfd) 2490 1.1.1.5 christos { 2491 1.1.1.5 christos asection * onotes; 2492 1.1.1.5 christos asection * inotes; 2493 1.1.1.10 christos bool result = true; 2494 1.1.1.5 christos 2495 1.1.1.5 christos /* If the output bfd does not have a note section, then 2496 1.1.1.5 christos skip the merge. The normal input to output section 2497 1.1.1.5 christos copying will take care of everythng for us. */ 2498 1.1.1.5 christos if ((onotes = bfd_get_section_by_name (obfd, V850_NOTE_SECNAME)) == NULL) 2499 1.1.1.5 christos return true; 2500 1.1.1.5 christos 2501 1.1.1.9 christos if ((inotes = bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME)) != NULL) 2502 1.1.1.5 christos { 2503 1.1.1.5 christos enum v850_notes id; 2504 1.1.1.5 christos bfd_byte * icont; 2505 1.1.1.5 christos bfd_byte * ocont; 2506 1.1.1.5 christos 2507 1.1.1.5 christos BFD_ASSERT (bfd_section_size (inotes) == bfd_section_size (onotes)); 2508 1.1.1.5 christos 2509 1.1.1.5 christos if ((icont = elf_section_data (inotes)->this_hdr.contents) == NULL) 2510 1.1.1.5 christos BFD_ASSERT (bfd_malloc_and_get_section (ibfd, inotes, & icont)); 2511 1.1.1.5 christos 2512 1.1.1.5 christos if ((ocont = elf_section_data (onotes)->this_hdr.contents) == NULL) 2513 1.1.1.5 christos BFD_ASSERT (bfd_malloc_and_get_section (obfd, onotes, & ocont)); 2514 1.1.1.5 christos 2515 1.1.1.5 christos for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++) 2516 1.1.1.5 christos { 2517 1.1.1.5 christos unsigned int ival; 2518 1.1.1.5 christos unsigned int oval; 2519 1.1.1.5 christos bfd_byte * idata = icont + ((id - 1) * SIZEOF_V850_NOTE) + 16; 2520 1.1.1.5 christos bfd_byte * odata = ocont + ((id - 1) * SIZEOF_V850_NOTE) + 16; 2521 1.1.1.6 christos 2522 1.1.1.5 christos ival = bfd_get_32 (ibfd, idata); 2523 1.1.1.5 christos oval = bfd_get_32 (obfd, odata); 2524 1.1.1.5 christos 2525 1.1.1.5 christos if (ival == 0 || ival == oval) 2526 1.1.1.5 christos continue; 2527 1.1.1.5 christos 2528 1.1.1.5 christos if (oval == 0) 2529 1.1.1.5 christos { 2530 1.1.1.5 christos bfd_put_32 (obfd, ival, odata); 2531 1.1.1.5 christos v850_set_note (obfd, onotes, id, ival); 2532 1.1.1.5 christos continue; 2533 1.1.1.5 christos } 2534 1.1.1.5 christos 2535 1.1.1.5 christos /* We have a mismatch. The ABI defines how to handle 2536 1.1.1.5 christos this siutation on a per note type basis. */ 2537 1.1.1.7 christos switch (id) 2538 1.1.1.8 christos { 2539 1.1.1.5 christos case V850_NOTE_ALIGNMENT: 2540 1.1.1.10 christos if (oval == EF_RH850_DATA_ALIGN4) 2541 1.1.1.5 christos { 2542 1.1.1.5 christos _bfd_error_handler 2543 1.1.1.5 christos /* xgettext:c-format */ 2544 1.1.1.5 christos (_("error: %pB needs 8-byte alignment but %pB is set for 4-byte alignment"), 2545 1.1.1.5 christos ibfd, obfd); 2546 1.1.1.5 christos result = false; 2547 1.1.1.5 christos } 2548 1.1.1.5 christos else 2549 1.1.1.5 christos /* ibfd uses 4-byte alignment, obfd uses 8-byte alignment. 2550 1.1.1.5 christos Leave the obfd alignment as it is. */ 2551 1.1.1.5 christos BFD_ASSERT (oval == EF_RH850_DATA_ALIGN8); 2552 1.1.1.7 christos 2553 1.1.1.7 christos break; 2554 1.1.1.8 christos 2555 1.1.1.8 christos case V850_NOTE_DATA_SIZE: 2556 1.1.1.10 christos if (oval == EF_RH850_DOUBLE32) 2557 1.1.1.5 christos { 2558 1.1.1.5 christos _bfd_error_handler 2559 1.1.1.5 christos /* xgettext:c-format */ 2560 1.1.1.5 christos (_("error: %pB uses 64-bit doubles but " 2561 1.1.1.5 christos "%pB uses 32-bit doubles"), ibfd, obfd); 2562 1.1.1.5 christos result = false; 2563 1.1.1.5 christos } 2564 1.1.1.5 christos else 2565 1.1.1.5 christos /* ibfd uses 32-bit doubles, obfd uses 64-bit doubles. 2566 1.1.1.5 christos This is acceptable. Honest, that is what the ABI says. */ 2567 1.1.1.7 christos BFD_ASSERT (oval == EF_RH850_DOUBLE64); 2568 1.1.1.7 christos break; 2569 1.1.1.8 christos 2570 1.1.1.7 christos case V850_NOTE_FPU_INFO: 2571 1.1.1.10 christos if (oval == EF_RH850_FPU20) 2572 1.1.1.5 christos { 2573 1.1.1.5 christos _bfd_error_handler 2574 1.1.1.5 christos /* xgettext:c-format */ 2575 1.1.1.5 christos (_("error: %pB uses FPU-3.0 but %pB only supports FPU-2.0"), 2576 1.1.1.5 christos ibfd, obfd); 2577 1.1.1.5 christos result = false; 2578 1.1.1.5 christos } 2579 1.1.1.5 christos else 2580 1.1.1.5 christos /* ibfd uses FPU-2.0, obfd uses FPU-3.0. Leave obfd as it is. */ 2581 1.1.1.5 christos BFD_ASSERT (oval == EF_RH850_FPU30); 2582 1.1.1.5 christos 2583 1.1.1.5 christos break; 2584 1.1.1.5 christos 2585 1.1.1.5 christos default: 2586 1.1.1.5 christos /* None of the other conflicts matter. 2587 1.1.1.5 christos Stick with the current output values. */ 2588 1.1.1.5 christos break; 2589 1.1.1.5 christos } 2590 1.1.1.5 christos } 2591 1.1.1.5 christos 2592 1.1.1.5 christos /* FIXME: We should also check for conflicts between the notes 2593 1.1.1.5 christos and the EF flags in the ELF header. */ 2594 1.1.1.5 christos } 2595 1.1.1.5 christos 2596 1.1.1.5 christos return result; 2597 1.1.1.5 christos } 2598 1.1.1.5 christos 2599 1.1.1.5 christos static void 2600 1.1.1.5 christos print_v850_note (bfd * abfd, FILE * file, bfd_byte * data, enum v850_notes id) 2601 1.1.1.5 christos { 2602 1.1.1.5 christos unsigned int value = bfd_get_32 (abfd, data + ((id - 1) * SIZEOF_V850_NOTE) + 16); 2603 1.1.1.5 christos 2604 1.1.1.5 christos switch (id) 2605 1.1.1.5 christos { 2606 1.1.1.5 christos case V850_NOTE_ALIGNMENT: 2607 1.1.1.5 christos fprintf (file, _(" alignment of 8-byte entities: ")); 2608 1.1.1.5 christos switch (value) 2609 1.1.1.5 christos { 2610 1.1.1.5 christos case EF_RH850_DATA_ALIGN4: fprintf (file, _("4-byte")); break; 2611 1.1.1.6 christos case EF_RH850_DATA_ALIGN8: fprintf (file, _("8-byte")); break; 2612 1.1.1.5 christos case 0: fprintf (file, _("not set")); break; 2613 1.1.1.5 christos default: fprintf (file, _("unknown: %x"), value); break; 2614 1.1.1.5 christos } 2615 1.1.1.5 christos fputc ('\n', file); 2616 1.1.1.5 christos break; 2617 1.1.1.5 christos 2618 1.1.1.5 christos case V850_NOTE_DATA_SIZE: 2619 1.1.1.5 christos fprintf (file, _(" size of doubles: ")); 2620 1.1.1.5 christos switch (value) 2621 1.1.1.5 christos { 2622 1.1.1.5 christos case EF_RH850_DOUBLE32: fprintf (file, _("4-bytes")); break; 2623 1.1.1.6 christos case EF_RH850_DOUBLE64: fprintf (file, _("8-bytes")); break; 2624 1.1.1.5 christos case 0: fprintf (file, _("not set")); break; 2625 1.1.1.5 christos default: fprintf (file, _("unknown: %x"), value); break; 2626 1.1.1.5 christos } 2627 1.1.1.5 christos fputc ('\n', file); 2628 1.1.1.5 christos break; 2629 1.1.1.5 christos 2630 1.1.1.5 christos case V850_NOTE_FPU_INFO: 2631 1.1.1.5 christos fprintf (file, _(" FPU support required: ")); 2632 1.1.1.5 christos switch (value) 2633 1.1.1.5 christos { 2634 1.1.1.5 christos case EF_RH850_FPU20: fprintf (file, _("FPU-2.0")); break; 2635 1.1.1.6 christos case EF_RH850_FPU30: fprintf (file, _("FPU-3.0")); break; 2636 1.1.1.5 christos case 0: fprintf (file, _("none")); break; 2637 1.1.1.5 christos default: fprintf (file, _("unknown: %x"), value); break; 2638 1.1.1.5 christos } 2639 1.1.1.5 christos fputc ('\n', file); 2640 1.1.1.5 christos break; 2641 1.1.1.5 christos 2642 1.1.1.5 christos case V850_NOTE_SIMD_INFO: 2643 1.1.1.5 christos fprintf (file, _("SIMD use: ")); 2644 1.1.1.5 christos switch (value) 2645 1.1.1.5 christos { 2646 1.1.1.6 christos case EF_RH850_SIMD: fprintf (file, _("yes")); break; 2647 1.1.1.5 christos case 0: fprintf (file, _("no")); break; 2648 1.1.1.5 christos default: fprintf (file, _("unknown: %x"), value); break; 2649 1.1.1.5 christos } 2650 1.1.1.5 christos fputc ('\n', file); 2651 1.1.1.5 christos break; 2652 1.1.1.5 christos 2653 1.1.1.5 christos case V850_NOTE_CACHE_INFO: 2654 1.1.1.5 christos fprintf (file, _("CACHE use: ")); 2655 1.1.1.5 christos switch (value) 2656 1.1.1.5 christos { 2657 1.1.1.6 christos case EF_RH850_CACHE: fprintf (file, _("yes")); break; 2658 1.1.1.5 christos case 0: fprintf (file, _("no")); break; 2659 1.1.1.5 christos default: fprintf (file, _("unknown: %x"), value); break; 2660 1.1.1.5 christos } 2661 1.1.1.5 christos fputc ('\n', file); 2662 1.1.1.5 christos break; 2663 1.1.1.5 christos 2664 1.1.1.5 christos case V850_NOTE_MMU_INFO: 2665 1.1.1.5 christos fprintf (file, _("MMU use: ")); 2666 1.1.1.5 christos switch (value) 2667 1.1.1.5 christos { 2668 1.1.1.6 christos case EF_RH850_MMU: fprintf (file, _("yes")); break; 2669 1.1.1.5 christos case 0: fprintf (file, _("no")); break; 2670 1.1.1.5 christos default: fprintf (file, _("unknown: %x"), value); break; 2671 1.1.1.5 christos } 2672 1.1.1.5 christos fputc ('\n', file); 2673 1.1.1.5 christos break; 2674 1.1.1.5 christos 2675 1.1.1.5 christos default: 2676 1.1.1.5 christos BFD_ASSERT (0); 2677 1.1.1.5 christos } 2678 1.1.1.5 christos } 2679 1.1.1.5 christos 2680 1.1.1.5 christos static void 2681 1.1.1.5 christos v850_elf_print_notes (bfd * abfd, FILE * file) 2682 1.1.1.5 christos { 2683 1.1.1.9 christos asection * notes = bfd_get_section_by_name (abfd, V850_NOTE_SECNAME); 2684 1.1.1.5 christos enum v850_notes id; 2685 1.1.1.5 christos 2686 1.1.1.5 christos if (notes == NULL || notes->contents == NULL) 2687 1.1.1.5 christos return; 2688 1.1.1.5 christos 2689 1.1.1.2 christos BFD_ASSERT (bfd_section_size (notes) == NUM_V850_NOTES * SIZEOF_V850_NOTE); 2690 1.1 christos 2691 1.1.1.10 christos for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++) 2692 1.1 christos print_v850_note (abfd, file, notes->contents, id); 2693 1.1 christos } 2694 1.1.1.2 christos 2695 1.1.1.2 christos /* Set the right machine number and architecture. */ 2696 1.1.1.2 christos 2697 1.1.1.2 christos static bool 2698 1.1 christos v850_elf_object_p (bfd *abfd) 2699 1.1.1.2 christos { 2700 1.1.1.2 christos enum bfd_architecture arch; 2701 1.1.1.2 christos unsigned long mach; 2702 1.1.1.2 christos 2703 1.1 christos switch (elf_elfheader (abfd)->e_machine) 2704 1.1.1.2 christos { 2705 1.1.1.2 christos case EM_V800: 2706 1.1.1.2 christos arch = bfd_arch_v850_rh850; 2707 1.1.1.2 christos mach = (elf_elfheader (abfd)->e_flags & EF_V800_850E3) 2708 1.1.1.2 christos ? bfd_mach_v850e3v5 : bfd_mach_v850e2v3; 2709 1.1.1.2 christos break; 2710 1.1.1.2 christos 2711 1.1.1.2 christos case EM_CYGNUS_V850: 2712 1.1.1.2 christos case EM_V850: 2713 1.1.1.2 christos arch = bfd_arch_v850; 2714 1.1.1.2 christos switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH) 2715 1.1.1.2 christos { 2716 1.1.1.2 christos default: 2717 1.1.1.2 christos case E_V850_ARCH: mach = bfd_mach_v850; break; 2718 1.1 christos case E_V850E_ARCH: mach = bfd_mach_v850e; break; 2719 1.1.1.2 christos case E_V850E1_ARCH: mach = bfd_mach_v850e1; break; 2720 1.1.1.2 christos case E_V850E2_ARCH: mach = bfd_mach_v850e2; break; 2721 1.1.1.10 christos case E_V850E2V3_ARCH: mach = bfd_mach_v850e2v3; break; 2722 1.1 christos case E_V850E3V5_ARCH: mach = bfd_mach_v850e3v5; break; 2723 1.1.1.2 christos } 2724 1.1.1.2 christos break; 2725 1.1 christos 2726 1.1 christos default: 2727 1.1 christos return false; 2728 1.1 christos } 2729 1.1.1.10 christos 2730 1.1.1.9 christos return bfd_default_set_arch_mach (abfd, arch, mach); 2731 1.1 christos } 2732 1.1 christos 2733 1.1 christos /* Store the machine number in the flags field. */ 2734 1.1.1.2 christos 2735 1.1 christos static bool 2736 1.1.1.2 christos v850_elf_final_write_processing (bfd *abfd) 2737 1.1.1.2 christos { 2738 1.1.1.2 christos unsigned long val; 2739 1.1.1.2 christos 2740 1.1.1.2 christos switch (bfd_get_arch (abfd)) 2741 1.1.1.2 christos { 2742 1.1.1.2 christos case bfd_arch_v850_rh850: 2743 1.1.1.2 christos val = EF_RH850_ABI; 2744 1.1.1.2 christos if (bfd_get_mach (abfd) == bfd_mach_v850e3v5) 2745 1.1.1.2 christos val |= EF_V800_850E3; 2746 1.1.1.2 christos elf_elfheader (abfd)->e_flags |= val; 2747 1.1.1.2 christos break; 2748 1.1.1.2 christos 2749 1.1.1.2 christos case bfd_arch_v850: 2750 1.1.1.2 christos switch (bfd_get_mach (abfd)) 2751 1.1.1.2 christos { 2752 1.1.1.2 christos default: 2753 1.1.1.2 christos case bfd_mach_v850: val = E_V850_ARCH; break; 2754 1.1.1.2 christos case bfd_mach_v850e: val = E_V850E_ARCH; break; 2755 1.1.1.2 christos case bfd_mach_v850e1: val = E_V850E1_ARCH; break; 2756 1.1.1.2 christos case bfd_mach_v850e2: val = E_V850E2_ARCH; break; 2757 1.1 christos case bfd_mach_v850e2v3: val = E_V850E2V3_ARCH; break; 2758 1.1.1.2 christos case bfd_mach_v850e3v5: val = E_V850E3V5_ARCH; break; 2759 1.1 christos } 2760 1.1.1.9 christos elf_elfheader (abfd)->e_flags &=~ EF_V850_ARCH; 2761 1.1 christos elf_elfheader (abfd)->e_flags |= val; 2762 1.1 christos break; 2763 1.1 christos default: 2764 1.1 christos break; 2765 1.1.1.10 christos } 2766 1.1 christos return _bfd_elf_final_write_processing (abfd); 2767 1.1 christos } 2768 1.1 christos 2769 1.1 christos /* Function to keep V850 specific file flags. */ 2770 1.1 christos 2771 1.1 christos static bool 2772 1.1.1.10 christos v850_elf_set_private_flags (bfd *abfd, flagword flags) 2773 1.1.1.10 christos { 2774 1.1 christos BFD_ASSERT (!elf_flags_init (abfd) 2775 1.1 christos || elf_elfheader (abfd)->e_flags == flags); 2776 1.1 christos 2777 1.1 christos elf_elfheader (abfd)->e_flags = flags; 2778 1.1 christos elf_flags_init (abfd) = true; 2779 1.1.1.10 christos return true; 2780 1.1.1.7 christos } 2781 1.1 christos 2782 1.1.1.7 christos /* Merge backend specific data from an object file 2783 1.1 christos to the output object file when linking. */ 2784 1.1 christos 2785 1.1.1.10 christos static bool 2786 1.1 christos v850_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) 2787 1.1 christos { 2788 1.1 christos bfd *obfd = info->output_bfd; 2789 1.1.1.10 christos flagword out_flags; 2790 1.1 christos flagword in_flags; 2791 1.1.1.5 christos bool result = true; 2792 1.1.1.5 christos 2793 1.1 christos if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour 2794 1.1 christos || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 2795 1.1 christos return true; 2796 1.1 christos 2797 1.1 christos result &= v850_elf_merge_notes (ibfd, obfd); 2798 1.1 christos 2799 1.1 christos in_flags = elf_elfheader (ibfd)->e_flags; 2800 1.1 christos out_flags = elf_elfheader (obfd)->e_flags; 2801 1.1 christos 2802 1.1 christos if (! elf_flags_init (obfd)) 2803 1.1 christos { 2804 1.1 christos /* If the input is the default architecture then do not 2805 1.1.1.10 christos bother setting the flags for the output architecture, 2806 1.1 christos instead allow future merges to do this. If no future 2807 1.1.1.10 christos merges ever set these flags then they will retain their 2808 1.1 christos unitialised values, which surprise surprise, correspond 2809 1.1 christos to the default values. */ 2810 1.1 christos if (bfd_get_arch_info (ibfd)->the_default) 2811 1.1 christos return true; 2812 1.1.1.5 christos 2813 1.1 christos elf_flags_init (obfd) = true; 2814 1.1.1.5 christos elf_elfheader (obfd)->e_flags = in_flags; 2815 1.1 christos 2816 1.1 christos if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) 2817 1.1 christos && bfd_get_arch_info (obfd)->the_default) 2818 1.1 christos result &= bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); 2819 1.1.1.5 christos 2820 1.1 christos return result; 2821 1.1.1.2 christos } 2822 1.1.1.2 christos 2823 1.1.1.2 christos /* Check flag compatibility. */ 2824 1.1.1.2 christos if (in_flags == out_flags) 2825 1.1.1.7 christos return result; 2826 1.1.1.8 christos 2827 1.1.1.2 christos if (bfd_get_arch (obfd) == bfd_arch_v850_rh850) 2828 1.1.1.2 christos { 2829 1.1.1.2 christos if ((in_flags & EF_V800_850E3) != (out_flags & EF_V800_850E3)) 2830 1.1.1.5 christos { 2831 1.1.1.2 christos _bfd_error_handler 2832 1.1.1.2 christos (_("%pB: architecture mismatch with previous modules"), ibfd); 2833 1.1 christos elf_elfheader (obfd)->e_flags |= EF_V800_850E3; 2834 1.1 christos } 2835 1.1 christos 2836 1.1.1.2 christos return result; 2837 1.1.1.8 christos } 2838 1.1.1.8 christos 2839 1.1.1.2 christos if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH) 2840 1.1.1.8 christos && (in_flags & EF_V850_ARCH) != E_V850_ARCH) 2841 1.1.1.8 christos { 2842 1.1 christos /* Allow earlier architecture binaries to be linked with later binaries. 2843 1.1.1.2 christos Set the output binary to the later architecture, except for v850e1, 2844 1.1 christos which we set to v850e. */ 2845 1.1 christos if ( (in_flags & EF_V850_ARCH) == E_V850E1_ARCH 2846 1.1 christos && (out_flags & EF_V850_ARCH) == E_V850E_ARCH) 2847 1.1 christos return result; 2848 1.1.1.5 christos 2849 1.1 christos if ( (in_flags & EF_V850_ARCH) == E_V850_ARCH 2850 1.1 christos && (out_flags & EF_V850_ARCH) == E_V850E_ARCH) 2851 1.1.1.2 christos { 2852 1.1 christos elf_elfheader (obfd)->e_flags = 2853 1.1 christos ((out_flags & ~ EF_V850_ARCH) | E_V850E_ARCH); 2854 1.1 christos return result; 2855 1.1 christos } 2856 1.1 christos 2857 1.1.1.5 christos if (( (in_flags & EF_V850_ARCH) == E_V850_ARCH 2858 1.1 christos || (in_flags & EF_V850_ARCH) == E_V850E_ARCH) 2859 1.1 christos && (out_flags & EF_V850_ARCH) == E_V850E2_ARCH) 2860 1.1.1.2 christos { 2861 1.1 christos elf_elfheader (obfd)->e_flags = 2862 1.1 christos ((out_flags & ~ EF_V850_ARCH) | E_V850E2_ARCH); 2863 1.1 christos return result; 2864 1.1 christos } 2865 1.1 christos 2866 1.1 christos if (( (in_flags & EF_V850_ARCH) == E_V850_ARCH 2867 1.1.1.5 christos || (in_flags & EF_V850_ARCH) == E_V850E_ARCH 2868 1.1 christos || (in_flags & EF_V850_ARCH) == E_V850E2_ARCH) 2869 1.1 christos && (out_flags & EF_V850_ARCH) == E_V850E2V3_ARCH) 2870 1.1.1.2 christos { 2871 1.1.1.2 christos elf_elfheader (obfd)->e_flags = 2872 1.1.1.2 christos ((out_flags & ~ EF_V850_ARCH) | E_V850E2V3_ARCH); 2873 1.1.1.8 christos return result; 2874 1.1.1.2 christos } 2875 1.1.1.2 christos 2876 1.1.1.2 christos if (( (in_flags & EF_V850_ARCH) == E_V850_ARCH 2877 1.1.1.2 christos || (in_flags & EF_V850_ARCH) == E_V850E_ARCH 2878 1.1.1.5 christos || (in_flags & EF_V850_ARCH) == E_V850E2_ARCH 2879 1.1.1.2 christos || (in_flags & EF_V850_ARCH) == E_V850E2V3_ARCH) 2880 1.1.1.2 christos && (out_flags & EF_V850_ARCH) == E_V850E3V5_ARCH) 2881 1.1.1.7 christos { 2882 1.1.1.8 christos elf_elfheader (obfd)->e_flags = 2883 1.1 christos ((out_flags & ~ EF_V850_ARCH) | E_V850E3V5_ARCH); 2884 1.1 christos return result; 2885 1.1.1.5 christos } 2886 1.1 christos 2887 1.1 christos _bfd_error_handler 2888 1.1 christos (_("%pB: architecture mismatch with previous modules"), ibfd); 2889 1.1 christos } 2890 1.1.1.10 christos 2891 1.1 christos return result; 2892 1.1 christos } 2893 1.1 christos 2894 1.1 christos /* Display the flags field. */ 2895 1.1 christos 2896 1.1 christos static bool 2897 1.1 christos v850_elf_print_private_bfd_data (bfd *abfd, void * ptr) 2898 1.1 christos { 2899 1.1 christos FILE * file = (FILE *) ptr; 2900 1.1 christos 2901 1.1 christos BFD_ASSERT (abfd != NULL && ptr != NULL); 2902 1.1.1.2 christos 2903 1.1 christos _bfd_elf_print_private_bfd_data (abfd, ptr); 2904 1.1.1.2 christos 2905 1.1.1.2 christos /* xgettext:c-format. */ 2906 1.1.1.2 christos fprintf (file, _("private flags = %lx: "), elf_elfheader (abfd)->e_flags); 2907 1.1.1.2 christos 2908 1.1.1.2 christos if (bfd_get_arch (abfd) == bfd_arch_v850_rh850) 2909 1.1.1.2 christos { 2910 1.1.1.2 christos if ((elf_elfheader (abfd)->e_flags & EF_RH850_ABI) != EF_RH850_ABI) 2911 1.1.1.2 christos fprintf (file, _("unknown v850 architecture")); 2912 1.1.1.2 christos else if (elf_elfheader (abfd)->e_flags & EF_V800_850E3) 2913 1.1.1.2 christos fprintf (file, _("v850 E3 architecture")); 2914 1.1.1.2 christos else 2915 1.1.1.2 christos fprintf (file, _("v850 architecture")); 2916 1.1.1.2 christos } 2917 1.1.1.2 christos else 2918 1.1.1.2 christos { 2919 1.1.1.2 christos switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH) 2920 1.1.1.2 christos { 2921 1.1.1.2 christos default: 2922 1.1.1.2 christos case E_V850_ARCH: fprintf (file, _("v850 architecture")); break; 2923 1.1 christos case E_V850E_ARCH: fprintf (file, _("v850e architecture")); break; 2924 1.1 christos case E_V850E1_ARCH: fprintf (file, _("v850e1 architecture")); break; 2925 1.1 christos case E_V850E2_ARCH: fprintf (file, _("v850e2 architecture")); break; 2926 1.1 christos case E_V850E2V3_ARCH: fprintf (file, _("v850e2v3 architecture")); break; 2927 1.1.1.5 christos case E_V850E3V5_ARCH: fprintf (file, _("v850e3v5 architecture")); break; 2928 1.1.1.5 christos } 2929 1.1.1.10 christos } 2930 1.1 christos 2931 1.1 christos fputc ('\n', file); 2932 1.1 christos 2933 1.1 christos v850_elf_print_notes (abfd, file); 2934 1.1 christos 2935 1.1 christos return true; 2936 1.1 christos } 2937 1.1 christos 2938 1.1 christos /* V850 ELF uses four common sections. One is the usual one, and the 2939 1.1.1.10 christos others are for (small) objects in one of the special data areas: 2940 1.1.1.10 christos small, tiny and zero. All the objects are kept together, and then 2941 1.1.1.10 christos referenced via the gp register, the ep register or the r0 register 2942 1.1.1.10 christos respectively, which yields smaller, faster assembler code. This 2943 1.1.1.10 christos approach is copied from elf32-mips.c. */ 2944 1.1.1.10 christos 2945 1.1.1.10 christos static asection v850_elf_scom_section; 2946 1.1.1.10 christos static const asymbol v850_elf_scom_symbol = 2947 1.1.1.10 christos GLOBAL_SYM_INIT (".scommon", &v850_elf_scom_section); 2948 1.1.1.10 christos static asection v850_elf_scom_section = 2949 1.1.1.10 christos BFD_FAKE_SECTION (v850_elf_scom_section, &v850_elf_scom_symbol, 2950 1.1.1.10 christos ".scommon", 0, 2951 1.1.1.10 christos SEC_IS_COMMON | SEC_SMALL_DATA | SEC_ALLOC | SEC_DATA); 2952 1.1.1.10 christos 2953 1.1.1.10 christos static asection v850_elf_tcom_section; 2954 1.1.1.10 christos static const asymbol v850_elf_tcom_symbol = 2955 1.1.1.10 christos GLOBAL_SYM_INIT (".tcommon", &v850_elf_tcom_section); 2956 1.1.1.10 christos static asection v850_elf_tcom_section = 2957 1.1.1.10 christos BFD_FAKE_SECTION (v850_elf_tcom_section, &v850_elf_tcom_symbol, 2958 1.1.1.10 christos ".tcommon", 0, 2959 1.1.1.10 christos SEC_IS_COMMON | SEC_SMALL_DATA); 2960 1.1.1.10 christos 2961 1.1.1.10 christos static asection v850_elf_zcom_section; 2962 1.1 christos static const asymbol v850_elf_zcom_symbol = 2963 1.1 christos GLOBAL_SYM_INIT (".zcommon", &v850_elf_zcom_section); 2964 1.1 christos static asection v850_elf_zcom_section = 2965 1.1 christos BFD_FAKE_SECTION (v850_elf_zcom_section, &v850_elf_zcom_symbol, 2966 1.1.1.10 christos ".zcommon", 0, 2967 1.1 christos SEC_IS_COMMON | SEC_SMALL_DATA); 2968 1.1 christos 2969 1.1 christos /* Given a BFD section, try to locate the 2970 1.1 christos corresponding ELF section index. */ 2971 1.1.1.9 christos 2972 1.1 christos static bool 2973 1.1.1.9 christos v850_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED, 2974 1.1 christos asection *sec, 2975 1.1.1.9 christos int *retval) 2976 1.1 christos { 2977 1.1 christos if (strcmp (bfd_section_name (sec), ".scommon") == 0) 2978 1.1.1.10 christos *retval = SHN_V850_SCOMMON; 2979 1.1 christos else if (strcmp (bfd_section_name (sec), ".tcommon") == 0) 2980 1.1.1.10 christos *retval = SHN_V850_TCOMMON; 2981 1.1 christos else if (strcmp (bfd_section_name (sec), ".zcommon") == 0) 2982 1.1 christos *retval = SHN_V850_ZCOMMON; 2983 1.1 christos else 2984 1.1 christos return false; 2985 1.1 christos 2986 1.1 christos return true; 2987 1.1 christos } 2988 1.1 christos 2989 1.1 christos /* Handle the special V850 section numbers that a symbol may use. */ 2990 1.1 christos 2991 1.1 christos static void 2992 1.1 christos v850_elf_symbol_processing (bfd *abfd, asymbol *asym) 2993 1.1 christos { 2994 1.1 christos elf_symbol_type * elfsym = (elf_symbol_type *) asym; 2995 1.1 christos unsigned int indx; 2996 1.1 christos 2997 1.1 christos indx = elfsym->internal_elf_sym.st_shndx; 2998 1.1 christos 2999 1.1 christos /* If the section index is an "ordinary" index, then it may 3000 1.1 christos refer to a v850 specific section created by the assembler. 3001 1.1 christos Check the section's type and change the index it matches. 3002 1.1 christos 3003 1.1 christos FIXME: Should we alter the st_shndx field as well ? */ 3004 1.1 christos 3005 1.1 christos if (indx < elf_numsections (abfd)) 3006 1.1 christos switch (elf_elfsections (abfd)[indx]->sh_type) 3007 1.1 christos { 3008 1.1 christos case SHT_V850_SCOMMON: 3009 1.1 christos indx = SHN_V850_SCOMMON; 3010 1.1 christos break; 3011 1.1 christos 3012 1.1 christos case SHT_V850_TCOMMON: 3013 1.1 christos indx = SHN_V850_TCOMMON; 3014 1.1 christos break; 3015 1.1 christos 3016 1.1 christos case SHT_V850_ZCOMMON: 3017 1.1 christos indx = SHN_V850_ZCOMMON; 3018 1.1 christos break; 3019 1.1 christos 3020 1.1 christos default: 3021 1.1 christos break; 3022 1.1 christos } 3023 1.1 christos 3024 1.1 christos switch (indx) 3025 1.1 christos { 3026 1.1 christos case SHN_V850_SCOMMON: 3027 1.1 christos asym->section = & v850_elf_scom_section; 3028 1.1 christos asym->value = elfsym->internal_elf_sym.st_size; 3029 1.1 christos break; 3030 1.1 christos 3031 1.1 christos case SHN_V850_TCOMMON: 3032 1.1 christos asym->section = & v850_elf_tcom_section; 3033 1.1 christos asym->value = elfsym->internal_elf_sym.st_size; 3034 1.1 christos break; 3035 1.1 christos 3036 1.1 christos case SHN_V850_ZCOMMON: 3037 1.1 christos asym->section = & v850_elf_zcom_section; 3038 1.1 christos asym->value = elfsym->internal_elf_sym.st_size; 3039 1.1 christos break; 3040 1.1.1.10 christos } 3041 1.1 christos } 3042 1.1 christos 3043 1.1 christos /* Hook called by the linker routine which adds symbols from an object 3044 1.1 christos file. We must handle the special v850 section numbers here. */ 3045 1.1 christos 3046 1.1 christos static bool 3047 1.1 christos v850_elf_add_symbol_hook (bfd *abfd, 3048 1.1 christos struct bfd_link_info *info ATTRIBUTE_UNUSED, 3049 1.1 christos Elf_Internal_Sym *sym, 3050 1.1 christos const char **namep ATTRIBUTE_UNUSED, 3051 1.1 christos flagword *flagsp ATTRIBUTE_UNUSED, 3052 1.1 christos asection **secp, 3053 1.1 christos bfd_vma *valp) 3054 1.1 christos { 3055 1.1 christos unsigned int indx = sym->st_shndx; 3056 1.1 christos 3057 1.1 christos /* If the section index is an "ordinary" index, then it may 3058 1.1 christos refer to a v850 specific section created by the assembler. 3059 1.1 christos Check the section's type and change the index it matches. 3060 1.1 christos 3061 1.1 christos FIXME: Should we alter the st_shndx field as well ? */ 3062 1.1 christos 3063 1.1 christos if (indx < elf_numsections (abfd)) 3064 1.1 christos switch (elf_elfsections (abfd)[indx]->sh_type) 3065 1.1 christos { 3066 1.1 christos case SHT_V850_SCOMMON: 3067 1.1 christos indx = SHN_V850_SCOMMON; 3068 1.1 christos break; 3069 1.1 christos 3070 1.1 christos case SHT_V850_TCOMMON: 3071 1.1 christos indx = SHN_V850_TCOMMON; 3072 1.1 christos break; 3073 1.1 christos 3074 1.1 christos case SHT_V850_ZCOMMON: 3075 1.1 christos indx = SHN_V850_ZCOMMON; 3076 1.1 christos break; 3077 1.1 christos 3078 1.1 christos default: 3079 1.1 christos break; 3080 1.1.1.9 christos } 3081 1.1 christos 3082 1.1 christos switch (indx) 3083 1.1 christos { 3084 1.1 christos case SHN_V850_SCOMMON: 3085 1.1 christos *secp = bfd_make_section_old_way (abfd, ".scommon"); 3086 1.1.1.9 christos (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA; 3087 1.1 christos *valp = sym->st_size; 3088 1.1 christos break; 3089 1.1 christos 3090 1.1 christos case SHN_V850_TCOMMON: 3091 1.1 christos *secp = bfd_make_section_old_way (abfd, ".tcommon"); 3092 1.1.1.9 christos (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA; 3093 1.1 christos *valp = sym->st_size; 3094 1.1 christos break; 3095 1.1 christos 3096 1.1 christos case SHN_V850_ZCOMMON: 3097 1.1.1.10 christos *secp = bfd_make_section_old_way (abfd, ".zcommon"); 3098 1.1 christos (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA; 3099 1.1 christos *valp = sym->st_size; 3100 1.1 christos break; 3101 1.1 christos } 3102 1.1 christos 3103 1.1 christos return true; 3104 1.1 christos } 3105 1.1 christos 3106 1.1 christos static int 3107 1.1 christos v850_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED, 3108 1.1 christos const char *name ATTRIBUTE_UNUSED, 3109 1.1 christos Elf_Internal_Sym *sym, 3110 1.1 christos asection *input_sec, 3111 1.1 christos struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) 3112 1.1 christos { 3113 1.1 christos /* If we see a common symbol, which implies a relocatable link, then 3114 1.1 christos if a symbol was in a special common section in an input file, mark 3115 1.1 christos it as a special common in the output file. */ 3116 1.1 christos 3117 1.1 christos if (sym->st_shndx == SHN_COMMON) 3118 1.1 christos { 3119 1.1 christos if (strcmp (input_sec->name, ".scommon") == 0) 3120 1.1 christos sym->st_shndx = SHN_V850_SCOMMON; 3121 1.1 christos else if (strcmp (input_sec->name, ".tcommon") == 0) 3122 1.1 christos sym->st_shndx = SHN_V850_TCOMMON; 3123 1.1 christos else if (strcmp (input_sec->name, ".zcommon") == 0) 3124 1.1 christos sym->st_shndx = SHN_V850_ZCOMMON; 3125 1.1 christos } 3126 1.1 christos 3127 1.1 christos /* The price we pay for using h->other unused bits as flags in the 3128 1.1 christos linker is cleaning up after ourselves. */ 3129 1.1 christos 3130 1.1.1.10 christos sym->st_other &= ~(V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA 3131 1.1 christos | V850_OTHER_ERROR); 3132 1.1 christos 3133 1.1 christos return 1; 3134 1.1 christos } 3135 1.1 christos 3136 1.1.1.9 christos static bool 3137 1.1.1.9 christos v850_elf_section_from_shdr (bfd *abfd, 3138 1.1 christos Elf_Internal_Shdr *hdr, 3139 1.1 christos const char *name, 3140 1.1 christos int shindex) 3141 1.1 christos { 3142 1.1 christos flagword flags; 3143 1.1.1.10 christos 3144 1.1 christos /* There ought to be a place to keep ELF backend specific flags, but 3145 1.1.1.9 christos at the moment there isn't one. We just keep track of the 3146 1.1 christos sections by their name, instead. */ 3147 1.1 christos 3148 1.1 christos if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) 3149 1.1 christos return false; 3150 1.1 christos 3151 1.1.1.9 christos flags = 0; 3152 1.1 christos switch (hdr->sh_type) 3153 1.1 christos { 3154 1.1.1.9 christos case SHT_V850_SCOMMON: 3155 1.1.1.9 christos case SHT_V850_TCOMMON: 3156 1.1.1.9 christos case SHT_V850_ZCOMMON: 3157 1.1.1.9 christos flags = SEC_IS_COMMON; 3158 1.1.1.9 christos } 3159 1.1.1.9 christos 3160 1.1 christos if ((hdr->sh_flags & SHF_V850_GPREL) != 0) 3161 1.1 christos flags |= SEC_SMALL_DATA; 3162 1.1 christos 3163 1.1 christos return (flags == 0 3164 1.1 christos || bfd_set_section_flags (hdr->bfd_section, 3165 1.1.1.10 christos hdr->bfd_section->flags | flags)); 3166 1.1 christos } 3167 1.1 christos 3168 1.1 christos /* Set the correct type for a V850 ELF section. We do this 3169 1.1 christos by the section name, which is a hack, but ought to work. */ 3170 1.1 christos 3171 1.1 christos static bool 3172 1.1.1.9 christos v850_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, 3173 1.1 christos Elf_Internal_Shdr *hdr, 3174 1.1 christos asection *sec) 3175 1.1 christos { 3176 1.1 christos const char * name; 3177 1.1 christos 3178 1.1 christos name = bfd_section_name (sec); 3179 1.1 christos 3180 1.1.1.5 christos if (strcmp (name, ".scommon") == 0) 3181 1.1.1.5 christos hdr->sh_type = SHT_V850_SCOMMON; 3182 1.1.1.5 christos else if (strcmp (name, ".tcommon") == 0) 3183 1.1.1.5 christos hdr->sh_type = SHT_V850_TCOMMON; 3184 1.1.1.5 christos else if (strcmp (name, ".zcommon") == 0) 3185 1.1.1.5 christos hdr->sh_type = SHT_V850_ZCOMMON; 3186 1.1 christos /* Tweak the section type of .note.renesas. */ 3187 1.1.1.10 christos else if (strcmp (name, V850_NOTE_SECNAME) == 0) 3188 1.1 christos { 3189 1.1 christos hdr->sh_type = SHT_RENESAS_INFO; 3190 1.1 christos hdr->sh_entsize = SIZEOF_V850_NOTE; 3191 1.1 christos } 3192 1.1.1.10 christos 3193 1.1 christos return true; 3194 1.1 christos } 3195 1.1 christos 3196 1.1 christos /* Delete some bytes from a section while relaxing. */ 3197 1.1 christos 3198 1.1 christos static bool 3199 1.1 christos v850_elf_relax_delete_bytes (bfd *abfd, 3200 1.1 christos asection *sec, 3201 1.1 christos bfd_vma addr, 3202 1.1 christos bfd_vma toaddr, 3203 1.1 christos int count) 3204 1.1 christos { 3205 1.1 christos Elf_Internal_Shdr *symtab_hdr; 3206 1.1 christos Elf32_External_Sym *extsyms; 3207 1.1 christos Elf32_External_Sym *esym; 3208 1.1 christos Elf32_External_Sym *esymend; 3209 1.1 christos int sym_index; 3210 1.1 christos unsigned int sec_shndx; 3211 1.1 christos bfd_byte *contents; 3212 1.1 christos Elf_Internal_Rela *irel; 3213 1.1 christos Elf_Internal_Rela *irelend; 3214 1.1 christos struct elf_link_hash_entry *sym_hash; 3215 1.1 christos Elf_External_Sym_Shndx *shndx; 3216 1.1 christos 3217 1.1 christos symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 3218 1.1 christos extsyms = (Elf32_External_Sym *) symtab_hdr->contents; 3219 1.1 christos 3220 1.1 christos sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); 3221 1.1 christos 3222 1.1 christos contents = elf_section_data (sec)->this_hdr.contents; 3223 1.1 christos 3224 1.1 christos /* The deletion must stop at the next ALIGN reloc for an alignment 3225 1.1 christos power larger than the number of bytes we are deleting. */ 3226 1.1 christos 3227 1.1 christos /* Actually delete the bytes. */ 3228 1.1 christos #if (DEBUG_RELAX & 2) 3229 1.1 christos fprintf (stderr, "relax_delete: contents: sec: %s %p .. %p %x\n", 3230 1.1 christos sec->name, addr, toaddr, count ); 3231 1.1 christos #endif 3232 1.1 christos memmove (contents + addr, contents + addr + count, 3233 1.1.1.6 christos toaddr - addr - count); 3234 1.1.1.6 christos memset (contents + toaddr-count, 0, count); 3235 1.1.1.6 christos 3236 1.1.1.6 christos /* Adjust all the relocs. */ 3237 1.1.1.6 christos irel = elf_section_data (sec)->relocs; 3238 1.1.1.6 christos irelend = irel + sec->reloc_count; 3239 1.1.1.6 christos if (elf_symtab_shndx_list (abfd)) 3240 1.1.1.6 christos { 3241 1.1.1.6 christos Elf_Internal_Shdr *shndx_hdr; 3242 1.1.1.6 christos 3243 1.1.1.6 christos shndx_hdr = & elf_symtab_shndx_list (abfd)->hdr; 3244 1.1 christos shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents; 3245 1.1 christos } 3246 1.1 christos else 3247 1.1 christos { 3248 1.1 christos shndx = NULL; 3249 1.1 christos } 3250 1.1 christos 3251 1.1 christos for (; irel < irelend; irel++) 3252 1.1 christos { 3253 1.1 christos bfd_vma raddr, paddr, symval; 3254 1.1 christos Elf_Internal_Sym isym; 3255 1.1 christos 3256 1.1 christos /* Get the new reloc address. */ 3257 1.1 christos raddr = irel->r_offset; 3258 1.1 christos if ((raddr >= (addr + count) && raddr < toaddr)) 3259 1.1 christos irel->r_offset -= count; 3260 1.1 christos 3261 1.1 christos if (raddr >= addr && raddr < addr + count) 3262 1.1 christos { 3263 1.1 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), 3264 1.1 christos (int) R_V850_NONE); 3265 1.1 christos continue; 3266 1.1 christos } 3267 1.1 christos 3268 1.1 christos if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN) 3269 1.1 christos continue; 3270 1.1 christos 3271 1.1 christos bfd_elf32_swap_symbol_in (abfd, 3272 1.1 christos extsyms + ELF32_R_SYM (irel->r_info), 3273 1.1 christos shndx ? shndx + ELF32_R_SYM (irel->r_info) : NULL, 3274 1.1 christos & isym); 3275 1.1 christos 3276 1.1 christos if (isym.st_shndx != sec_shndx) 3277 1.1 christos continue; 3278 1.1 christos 3279 1.1 christos /* Get the value of the symbol referred to by the reloc. */ 3280 1.1.1.8 christos if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) 3281 1.1 christos { 3282 1.1 christos symval = isym.st_value; 3283 1.1 christos #if (DEBUG_RELAX & 2) 3284 1.1 christos { 3285 1.1 christos char * name = bfd_elf_string_from_elf_section 3286 1.1 christos (abfd, symtab_hdr->sh_link, isym.st_name); 3287 1.1 christos fprintf (stderr, 3288 1.1 christos "relax_delete: local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n", 3289 1.1 christos sec->name, name, isym.st_name, 3290 1.1 christos sec->output_section->vma, sec->output_offset, 3291 1.1 christos isym.st_value, irel->r_addend); 3292 1.1 christos } 3293 1.1 christos #endif 3294 1.1 christos } 3295 1.1 christos else 3296 1.1 christos { 3297 1.1 christos unsigned long indx; 3298 1.1 christos struct elf_link_hash_entry * h; 3299 1.1 christos 3300 1.1 christos /* An external symbol. */ 3301 1.1 christos indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; 3302 1.1 christos 3303 1.1 christos h = elf_sym_hashes (abfd) [indx]; 3304 1.1 christos BFD_ASSERT (h != NULL); 3305 1.1 christos 3306 1.1 christos symval = h->root.u.def.value; 3307 1.1 christos #if (DEBUG_RELAX & 2) 3308 1.1 christos fprintf (stderr, 3309 1.1 christos "relax_delete: defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n", 3310 1.1 christos sec->name, h->root.root.string, h->root.u.def.value, 3311 1.1 christos sec->output_section->vma, sec->output_offset, irel->r_addend); 3312 1.1 christos #endif 3313 1.1 christos } 3314 1.1 christos 3315 1.1.1.8 christos paddr = symval + irel->r_addend; 3316 1.1 christos 3317 1.1 christos if ( (symval >= addr + count && symval < toaddr) 3318 1.1 christos && (paddr < addr + count || paddr >= toaddr)) 3319 1.1 christos irel->r_addend += count; 3320 1.1 christos else if ( (symval < addr + count || symval >= toaddr) 3321 1.1 christos && (paddr >= addr + count && paddr < toaddr)) 3322 1.1 christos irel->r_addend -= count; 3323 1.1 christos } 3324 1.1 christos 3325 1.1 christos /* Adjust the local symbols defined in this section. */ 3326 1.1 christos esym = extsyms; 3327 1.1 christos esymend = esym + symtab_hdr->sh_info; 3328 1.1 christos 3329 1.1 christos for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL)) 3330 1.1 christos { 3331 1.1 christos Elf_Internal_Sym isym; 3332 1.1 christos 3333 1.1 christos bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym); 3334 1.1 christos 3335 1.1 christos if (isym.st_shndx == sec_shndx 3336 1.1 christos && isym.st_value >= addr + count 3337 1.1 christos && isym.st_value < toaddr) 3338 1.1 christos { 3339 1.1 christos isym.st_value -= count; 3340 1.1 christos 3341 1.1 christos if (isym.st_value + isym.st_size >= toaddr) 3342 1.1 christos isym.st_size += count; 3343 1.1 christos 3344 1.1 christos bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx); 3345 1.1 christos } 3346 1.1 christos else if (isym.st_shndx == sec_shndx 3347 1.1 christos && isym.st_value < addr + count) 3348 1.1 christos { 3349 1.1 christos if (isym.st_value+isym.st_size >= addr + count 3350 1.1 christos && isym.st_value+isym.st_size < toaddr) 3351 1.1 christos isym.st_size -= count; 3352 1.1 christos 3353 1.1 christos if (isym.st_value >= addr 3354 1.1 christos && isym.st_value < addr + count) 3355 1.1 christos isym.st_value = addr; 3356 1.1 christos 3357 1.1 christos bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx); 3358 1.1 christos } 3359 1.1 christos } 3360 1.1 christos 3361 1.1 christos /* Now adjust the global symbols defined in this section. */ 3362 1.1 christos esym = extsyms + symtab_hdr->sh_info; 3363 1.1 christos esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)); 3364 1.1 christos 3365 1.1 christos for (sym_index = 0; esym < esymend; esym ++, sym_index ++) 3366 1.1 christos { 3367 1.1 christos Elf_Internal_Sym isym; 3368 1.1 christos 3369 1.1 christos bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym); 3370 1.1 christos sym_hash = elf_sym_hashes (abfd) [sym_index]; 3371 1.1 christos 3372 1.1 christos if (isym.st_shndx == sec_shndx 3373 1.1 christos && ((sym_hash)->root.type == bfd_link_hash_defined 3374 1.1 christos || (sym_hash)->root.type == bfd_link_hash_defweak) 3375 1.1 christos && (sym_hash)->root.u.def.section == sec 3376 1.1 christos && (sym_hash)->root.u.def.value >= addr + count 3377 1.1 christos && (sym_hash)->root.u.def.value < toaddr) 3378 1.1 christos { 3379 1.1 christos if ((sym_hash)->root.u.def.value + isym.st_size >= toaddr) 3380 1.1 christos { 3381 1.1 christos isym.st_size += count; 3382 1.1 christos bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx); 3383 1.1 christos } 3384 1.1 christos 3385 1.1 christos (sym_hash)->root.u.def.value -= count; 3386 1.1 christos } 3387 1.1 christos else if (isym.st_shndx == sec_shndx 3388 1.1 christos && ((sym_hash)->root.type == bfd_link_hash_defined 3389 1.1 christos || (sym_hash)->root.type == bfd_link_hash_defweak) 3390 1.1 christos && (sym_hash)->root.u.def.section == sec 3391 1.1 christos && (sym_hash)->root.u.def.value < addr + count) 3392 1.1 christos { 3393 1.1 christos if ((sym_hash)->root.u.def.value+isym.st_size >= addr + count 3394 1.1 christos && (sym_hash)->root.u.def.value+isym.st_size < toaddr) 3395 1.1 christos isym.st_size -= count; 3396 1.1 christos 3397 1.1 christos if ((sym_hash)->root.u.def.value >= addr 3398 1.1 christos && (sym_hash)->root.u.def.value < addr + count) 3399 1.1 christos (sym_hash)->root.u.def.value = addr; 3400 1.1 christos 3401 1.1 christos bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx); 3402 1.1.1.10 christos } 3403 1.1 christos 3404 1.1 christos if (shndx) 3405 1.1.1.8 christos ++ shndx; 3406 1.1.1.8 christos } 3407 1.1.1.8 christos 3408 1.1 christos return true; 3409 1.1 christos } 3410 1.1.1.8 christos 3411 1.1.1.8 christos #define NOP_OPCODE (0x0000) 3412 1.1 christos #define MOVHI 0x0640 /* 4byte. */ 3413 1.1 christos #define MOVHI_MASK 0x07e0 3414 1.1.1.8 christos #define MOVHI_R1(insn) ((insn) & 0x1f) /* 4byte. */ 3415 1.1.1.8 christos #define MOVHI_R2(insn) ((insn) >> 11) 3416 1.1 christos #define MOVEA 0x0620 /* 2byte. */ 3417 1.1.1.8 christos #define MOVEA_MASK 0x07e0 3418 1.1.1.8 christos #define MOVEA_R1(insn) ((insn) & 0x1f) 3419 1.1 christos #define MOVEA_R2(insn) ((insn) >> 11) 3420 1.1 christos #define JARL_4 0x00040780 /* 4byte. */ 3421 1.1.1.8 christos #define JARL_4_MASK 0xFFFF07FF 3422 1.1.1.8 christos #define JARL_R2(insn) (int)(((insn) & (~JARL_4_MASK)) >> 11) 3423 1.1 christos #define ADD_I 0x0240 /* 2byte. */ 3424 1.1 christos #define ADD_I_MASK 0x07e0 3425 1.1.1.10 christos #define ADD_I5(insn) ((((insn) & 0x001f) << 11) >> 11) /* 2byte. */ 3426 1.1 christos #define ADD_R2(insn) ((insn) >> 11) 3427 1.1 christos #define JMP_R 0x0060 /* 2byte. */ 3428 1.1 christos #define JMP_R_MASK 0xFFE0 3429 1.1.1.10 christos #define JMP_R1(insn) ((insn) & 0x1f) 3430 1.1 christos 3431 1.1 christos static bool 3432 1.1 christos v850_elf_relax_section (bfd *abfd, 3433 1.1 christos asection *sec, 3434 1.1 christos struct bfd_link_info *link_info, 3435 1.1 christos bool *again) 3436 1.1 christos { 3437 1.1 christos Elf_Internal_Shdr *symtab_hdr; 3438 1.1 christos Elf_Internal_Rela *internal_relocs; 3439 1.1 christos Elf_Internal_Rela *irel; 3440 1.1 christos Elf_Internal_Rela *irelend; 3441 1.1.1.10 christos Elf_Internal_Rela *irelalign = NULL; 3442 1.1 christos Elf_Internal_Sym *isymbuf = NULL; 3443 1.1.1.10 christos bfd_byte *contents = NULL; 3444 1.1 christos bfd_vma addr = 0; 3445 1.1.1.6 christos bfd_vma toaddr; 3446 1.1.1.11 christos int align_pad_size = 0; 3447 1.1 christos bool result = true; 3448 1.1 christos 3449 1.1.1.10 christos *again = false; 3450 1.1 christos 3451 1.1 christos if (bfd_link_relocatable (link_info) 3452 1.1 christos || (sec->flags & SEC_HAS_CONTENTS) == 0 3453 1.1 christos || (sec->flags & SEC_RELOC) == 0 3454 1.1 christos || sec->reloc_count == 0) 3455 1.1 christos return true; 3456 1.1 christos 3457 1.1 christos symtab_hdr = & elf_tdata (abfd)->symtab_hdr; 3458 1.1 christos 3459 1.1 christos internal_relocs = (_bfd_elf_link_read_relocs 3460 1.1 christos (abfd, sec, NULL, NULL, link_info->keep_memory)); 3461 1.1 christos if (internal_relocs == NULL) 3462 1.1 christos goto error_return; 3463 1.1 christos 3464 1.1 christos irelend = internal_relocs + sec->reloc_count; 3465 1.1 christos 3466 1.1 christos while (addr < sec->size) 3467 1.1 christos { 3468 1.1 christos toaddr = sec->size; 3469 1.1 christos 3470 1.1 christos for (irel = internal_relocs; irel < irelend; irel ++) 3471 1.1 christos if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN 3472 1.1 christos && irel->r_offset > addr 3473 1.1 christos && irel->r_offset < toaddr) 3474 1.1 christos toaddr = irel->r_offset; 3475 1.1 christos 3476 1.1 christos #ifdef DEBUG_RELAX 3477 1.1 christos fprintf (stderr, "relax region 0x%x to 0x%x align pad %d\n", 3478 1.1 christos addr, toaddr, align_pad_size); 3479 1.1 christos #endif 3480 1.1 christos if (irelalign) 3481 1.1 christos { 3482 1.1 christos bfd_vma alignto; 3483 1.1 christos bfd_vma alignmoveto; 3484 1.1.1.3 christos 3485 1.1 christos alignmoveto = BFD_ALIGN (addr - align_pad_size, 1 << irelalign->r_addend); 3486 1.1 christos alignto = BFD_ALIGN (addr, 1 << irelalign->r_addend); 3487 1.1 christos 3488 1.1 christos if (alignmoveto < alignto) 3489 1.1 christos { 3490 1.1 christos bfd_vma i; 3491 1.1 christos 3492 1.1 christos align_pad_size = alignto - alignmoveto; 3493 1.1 christos #ifdef DEBUG_RELAX 3494 1.1 christos fprintf (stderr, "relax move region 0x%x to 0x%x delete size 0x%x\n", 3495 1.1 christos alignmoveto, toaddr, align_pad_size); 3496 1.1 christos #endif 3497 1.1 christos if (!v850_elf_relax_delete_bytes (abfd, sec, alignmoveto, 3498 1.1 christos toaddr, align_pad_size)) 3499 1.1 christos goto error_return; 3500 1.1 christos 3501 1.1 christos for (i = BFD_ALIGN (toaddr - align_pad_size, 1); 3502 1.1 christos (i + 1) < toaddr; i += 2) 3503 1.1 christos bfd_put_16 (abfd, NOP_OPCODE, contents + i); 3504 1.1 christos 3505 1.1 christos addr = alignmoveto; 3506 1.1 christos } 3507 1.1 christos else 3508 1.1 christos align_pad_size = 0; 3509 1.1 christos } 3510 1.1 christos 3511 1.1 christos for (irel = internal_relocs; irel < irelend; irel++) 3512 1.1 christos { 3513 1.1 christos bfd_vma laddr; 3514 1.1 christos bfd_vma addend; 3515 1.1 christos bfd_vma symval; 3516 1.1.1.2 christos int insn[5]; 3517 1.1 christos int no_match = -1; 3518 1.1 christos Elf_Internal_Rela *hi_irelfn; 3519 1.1 christos Elf_Internal_Rela *lo_irelfn; 3520 1.1 christos Elf_Internal_Rela *irelcall; 3521 1.1 christos bfd_signed_vma foff; 3522 1.1 christos unsigned int r_type; 3523 1.1 christos 3524 1.1 christos if (! (irel->r_offset >= addr && irel->r_offset < toaddr 3525 1.1 christos && (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL 3526 1.1 christos || ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP))) 3527 1.1 christos continue; 3528 1.1 christos 3529 1.1 christos #ifdef DEBUG_RELAX 3530 1.1 christos fprintf (stderr, "relax check r_info 0x%x r_offset 0x%x r_addend 0x%x\n", 3531 1.1 christos irel->r_info, 3532 1.1 christos irel->r_offset, 3533 1.1 christos irel->r_addend ); 3534 1.1 christos #endif 3535 1.1 christos 3536 1.1 christos /* Get the section contents. */ 3537 1.1 christos if (contents == NULL) 3538 1.1 christos { 3539 1.1 christos if (elf_section_data (sec)->this_hdr.contents != NULL) 3540 1.1 christos contents = elf_section_data (sec)->this_hdr.contents; 3541 1.1 christos else 3542 1.1 christos { 3543 1.1 christos if (! bfd_malloc_and_get_section (abfd, sec, &contents)) 3544 1.1 christos goto error_return; 3545 1.1 christos } 3546 1.1 christos } 3547 1.1 christos 3548 1.1 christos /* Read this BFD's local symbols if we haven't done so already. */ 3549 1.1 christos if (isymbuf == NULL && symtab_hdr->sh_info != 0) 3550 1.1 christos { 3551 1.1 christos isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 3552 1.1 christos if (isymbuf == NULL) 3553 1.1 christos isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 3554 1.1 christos symtab_hdr->sh_info, 0, 3555 1.1 christos NULL, NULL, NULL); 3556 1.1 christos if (isymbuf == NULL) 3557 1.1 christos goto error_return; 3558 1.1 christos } 3559 1.1 christos 3560 1.1 christos laddr = irel->r_offset; 3561 1.1 christos 3562 1.1 christos if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL) 3563 1.1 christos { 3564 1.1 christos /* Check code for -mlong-calls output. */ 3565 1.1 christos if (laddr + 16 <= (bfd_vma) sec->size) 3566 1.1 christos { 3567 1.1 christos insn[0] = bfd_get_16 (abfd, contents + laddr); 3568 1.1 christos insn[1] = bfd_get_16 (abfd, contents + laddr + 4); 3569 1.1 christos insn[2] = bfd_get_32 (abfd, contents + laddr + 8); 3570 1.1 christos insn[3] = bfd_get_16 (abfd, contents + laddr + 12); 3571 1.1 christos insn[4] = bfd_get_16 (abfd, contents + laddr + 14); 3572 1.1 christos 3573 1.1 christos if ((insn[0] & MOVHI_MASK) != MOVHI 3574 1.1 christos || MOVHI_R1 (insn[0]) != 0) 3575 1.1 christos no_match = 0; 3576 1.1 christos 3577 1.1 christos if (no_match < 0 3578 1.1 christos && ((insn[1] & MOVEA_MASK) != MOVEA 3579 1.1 christos || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1]))) 3580 1.1 christos no_match = 1; 3581 1.1 christos 3582 1.1 christos if (no_match < 0 3583 1.1 christos && (insn[2] & JARL_4_MASK) != JARL_4) 3584 1.1 christos no_match = 2; 3585 1.1 christos 3586 1.1 christos if (no_match < 0 3587 1.1 christos && ((insn[3] & ADD_I_MASK) != ADD_I 3588 1.1 christos || ADD_I5 (insn[3]) != 4 3589 1.1 christos || JARL_R2 (insn[2]) != ADD_R2 (insn[3]))) 3590 1.1 christos no_match = 3; 3591 1.1 christos 3592 1.1 christos if (no_match < 0 3593 1.1.1.7 christos && ((insn[4] & JMP_R_MASK) != JMP_R 3594 1.1.1.7 christos || MOVEA_R2 (insn[1]) != JMP_R1 (insn[4]))) 3595 1.1.1.8 christos no_match = 4; 3596 1.1.1.7 christos } 3597 1.1.1.8 christos else 3598 1.1 christos { 3599 1.1 christos _bfd_error_handler 3600 1.1 christos /* xgettext:c-format */ 3601 1.1 christos (_("%pB: %#" PRIx64 ": warning: %s points to " 3602 1.1 christos "unrecognized insns"), 3603 1.1.1.7 christos abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL"); 3604 1.1.1.7 christos continue; 3605 1.1.1.8 christos } 3606 1.1.1.8 christos 3607 1.1.1.7 christos if (no_match >= 0) 3608 1.1.1.8 christos { 3609 1.1.1.8 christos _bfd_error_handler 3610 1.1.1.7 christos /* xgettext:c-format */ 3611 1.1 christos (_("%pB: %#" PRIx64 ": warning: %s points to " 3612 1.1 christos "unrecognized insn %#x"), 3613 1.1 christos abfd, 3614 1.1 christos (uint64_t) (irel->r_offset + no_match), 3615 1.1.1.8 christos "R_V850_LONGCALL", 3616 1.1.1.8 christos insn[no_match]); 3617 1.1.1.2 christos continue; 3618 1.1 christos } 3619 1.1.1.2 christos 3620 1.1.1.2 christos /* Get the reloc for the address from which the register is 3621 1.1.1.2 christos being loaded. This reloc will tell us which function is 3622 1.1.1.2 christos actually being called. */ 3623 1.1.1.2 christos 3624 1.1.1.2 christos for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++) 3625 1.1.1.2 christos { 3626 1.1 christos r_type = ELF32_R_TYPE (hi_irelfn->r_info); 3627 1.1 christos 3628 1.1.1.2 christos if (hi_irelfn->r_offset == laddr + 2 3629 1.1.1.2 christos && (r_type == (int) R_V850_HI16_S || r_type == (int) R_V810_WHI1)) 3630 1.1.1.2 christos break; 3631 1.1.1.2 christos } 3632 1.1.1.2 christos 3633 1.1.1.2 christos for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++) 3634 1.1.1.2 christos { 3635 1.1 christos r_type = ELF32_R_TYPE (lo_irelfn->r_info); 3636 1.1 christos 3637 1.1.1.2 christos if (lo_irelfn->r_offset == laddr + 6 3638 1.1.1.2 christos && (r_type == (int) R_V850_LO16 || r_type == (int) R_V810_WLO)) 3639 1.1.1.2 christos break; 3640 1.1.1.2 christos } 3641 1.1.1.2 christos 3642 1.1.1.2 christos for (irelcall = internal_relocs; irelcall < irelend; irelcall ++) 3643 1.1.1.2 christos { 3644 1.1 christos r_type = ELF32_R_TYPE (irelcall->r_info); 3645 1.1 christos 3646 1.1 christos if (irelcall->r_offset == laddr + 8 3647 1.1 christos && (r_type == (int) R_V850_22_PCREL || r_type == (int) R_V850_PCR22)) 3648 1.1 christos break; 3649 1.1.1.7 christos } 3650 1.1.1.7 christos 3651 1.1.1.8 christos if ( hi_irelfn == irelend 3652 1.1.1.7 christos || lo_irelfn == irelend 3653 1.1.1.8 christos || irelcall == irelend) 3654 1.1 christos { 3655 1.1 christos _bfd_error_handler 3656 1.1 christos /* xgettext:c-format */ 3657 1.1 christos (_("%pB: %#" PRIx64 ": warning: %s points to " 3658 1.1 christos "unrecognized reloc"), 3659 1.1 christos abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL"); 3660 1.1 christos 3661 1.1 christos continue; 3662 1.1 christos } 3663 1.1 christos 3664 1.1 christos if (ELF32_R_SYM (irelcall->r_info) < symtab_hdr->sh_info) 3665 1.1 christos { 3666 1.1 christos Elf_Internal_Sym * isym; 3667 1.1 christos 3668 1.1 christos /* A local symbol. */ 3669 1.1 christos isym = isymbuf + ELF32_R_SYM (irelcall->r_info); 3670 1.1 christos 3671 1.1 christos symval = isym->st_value; 3672 1.1 christos } 3673 1.1 christos else 3674 1.1 christos { 3675 1.1 christos unsigned long indx; 3676 1.1 christos struct elf_link_hash_entry * h; 3677 1.1 christos 3678 1.1 christos /* An external symbol. */ 3679 1.1 christos indx = ELF32_R_SYM (irelcall->r_info) - symtab_hdr->sh_info; 3680 1.1 christos h = elf_sym_hashes (abfd)[indx]; 3681 1.1 christos BFD_ASSERT (h != NULL); 3682 1.1 christos 3683 1.1 christos if ( h->root.type != bfd_link_hash_defined 3684 1.1 christos && h->root.type != bfd_link_hash_defweak) 3685 1.1 christos /* This appears to be a reference to an undefined 3686 1.1 christos symbol. Just ignore it--it will be caught by the 3687 1.1 christos regular reloc processing. */ 3688 1.1 christos continue; 3689 1.1.1.7 christos 3690 1.1.1.7 christos symval = h->root.u.def.value; 3691 1.1.1.8 christos } 3692 1.1.1.8 christos 3693 1.1.1.8 christos if (symval + irelcall->r_addend != irelcall->r_offset + 4) 3694 1.1.1.8 christos { 3695 1.1 christos _bfd_error_handler 3696 1.1 christos /* xgettext:c-format */ 3697 1.1 christos (_("%pB: %#" PRIx64 ": warning: %s points to " 3698 1.1 christos "unrecognized reloc %#" PRIx64), 3699 1.1 christos abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL", 3700 1.1 christos (uint64_t) irelcall->r_offset); 3701 1.1 christos continue; 3702 1.1 christos } 3703 1.1 christos 3704 1.1 christos /* Get the value of the symbol referred to by the reloc. */ 3705 1.1 christos if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info) 3706 1.1 christos { 3707 1.1 christos Elf_Internal_Sym *isym; 3708 1.1 christos asection *sym_sec; 3709 1.1 christos 3710 1.1 christos /* A local symbol. */ 3711 1.1 christos isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info); 3712 1.1 christos 3713 1.1 christos if (isym->st_shndx == SHN_UNDEF) 3714 1.1 christos sym_sec = bfd_und_section_ptr; 3715 1.1 christos else if (isym->st_shndx == SHN_ABS) 3716 1.1 christos sym_sec = bfd_abs_section_ptr; 3717 1.1 christos else if (isym->st_shndx == SHN_COMMON) 3718 1.1 christos sym_sec = bfd_com_section_ptr; 3719 1.1 christos else 3720 1.1 christos sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); 3721 1.1 christos symval = (isym->st_value 3722 1.1 christos + sym_sec->output_section->vma 3723 1.1 christos + sym_sec->output_offset); 3724 1.1 christos } 3725 1.1 christos else 3726 1.1 christos { 3727 1.1 christos unsigned long indx; 3728 1.1 christos struct elf_link_hash_entry *h; 3729 1.1 christos 3730 1.1 christos /* An external symbol. */ 3731 1.1 christos indx = ELF32_R_SYM (hi_irelfn->r_info) - symtab_hdr->sh_info; 3732 1.1 christos h = elf_sym_hashes (abfd)[indx]; 3733 1.1 christos BFD_ASSERT (h != NULL); 3734 1.1 christos 3735 1.1 christos if ( h->root.type != bfd_link_hash_defined 3736 1.1 christos && h->root.type != bfd_link_hash_defweak) 3737 1.1 christos /* This appears to be a reference to an undefined 3738 1.1 christos symbol. Just ignore it--it will be caught by the 3739 1.1 christos regular reloc processing. */ 3740 1.1 christos continue; 3741 1.1 christos 3742 1.1 christos symval = (h->root.u.def.value 3743 1.1 christos + h->root.u.def.section->output_section->vma 3744 1.1 christos + h->root.u.def.section->output_offset); 3745 1.1 christos } 3746 1.1 christos 3747 1.1 christos addend = irel->r_addend; 3748 1.1 christos 3749 1.1 christos foff = (symval + addend 3750 1.1 christos - (irel->r_offset 3751 1.1 christos + sec->output_section->vma 3752 1.1 christos + sec->output_offset 3753 1.1 christos + 4)); 3754 1.1 christos #ifdef DEBUG_RELAX 3755 1.1 christos fprintf (stderr, "relax longcall r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n", 3756 1.1 christos irel->r_offset, 3757 1.1 christos (irel->r_offset 3758 1.1 christos + sec->output_section->vma 3759 1.1 christos + sec->output_offset), 3760 1.1 christos symval, addend, foff); 3761 1.1 christos #endif 3762 1.1.1.8 christos 3763 1.1.1.8 christos if (foff < -0x100000 || foff >= 0x100000) 3764 1.1.1.8 christos /* After all that work, we can't shorten this function call. */ 3765 1.1.1.8 christos continue; 3766 1.1.1.8 christos 3767 1.1.1.8 christos /* For simplicity of coding, we are going to modify the section 3768 1.1 christos contents, the section relocs, and the BFD symbol table. We 3769 1.1 christos must tell the rest of the code not to free up this 3770 1.1 christos information. It would be possible to instead create a table 3771 1.1 christos of changes which have to be made, as is done in coff-mips.c; 3772 1.1 christos that would be more work, but would require less memory when 3773 1.1.1.2 christos the linker is run. */ 3774 1.1.1.2 christos elf_section_data (sec)->relocs = internal_relocs; 3775 1.1.1.2 christos elf_section_data (sec)->this_hdr.contents = contents; 3776 1.1.1.2 christos symtab_hdr->contents = (bfd_byte *) isymbuf; 3777 1.1 christos 3778 1.1 christos /* Replace the long call with a jarl. */ 3779 1.1 christos if (bfd_get_arch (abfd) == bfd_arch_v850_rh850) 3780 1.1 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_PCR22); 3781 1.1 christos else 3782 1.1 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_22_PCREL); 3783 1.1 christos 3784 1.1 christos addend = 0; 3785 1.1 christos 3786 1.1 christos if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info) 3787 1.1 christos /* If this needs to be changed because of future relaxing, 3788 1.1 christos it will be handled here like other internal IND12W 3789 1.1 christos relocs. */ 3790 1.1 christos bfd_put_32 (abfd, 3791 1.1 christos 0x00000780 | (JARL_R2 (insn[2])<<11) | ((addend << 16) & 0xffff) | ((addend >> 16) & 0xf), 3792 1.1 christos contents + irel->r_offset); 3793 1.1 christos else 3794 1.1 christos /* We can't fully resolve this yet, because the external 3795 1.1 christos symbol value may be changed by future relaxing. 3796 1.1 christos We let the final link phase handle it. */ 3797 1.1 christos bfd_put_32 (abfd, 0x00000780 | (JARL_R2 (insn[2])<<11), 3798 1.1 christos contents + irel->r_offset); 3799 1.1 christos 3800 1.1 christos hi_irelfn->r_info = 3801 1.1 christos ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE); 3802 1.1 christos lo_irelfn->r_info = 3803 1.1 christos ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE); 3804 1.1 christos irelcall->r_info = 3805 1.1 christos ELF32_R_INFO (ELF32_R_SYM (irelcall->r_info), R_V850_NONE); 3806 1.1 christos 3807 1.1 christos if (! v850_elf_relax_delete_bytes (abfd, sec, 3808 1.1 christos irel->r_offset + 4, toaddr, 12)) 3809 1.1 christos goto error_return; 3810 1.1 christos 3811 1.1 christos align_pad_size += 12; 3812 1.1 christos } 3813 1.1 christos else if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP) 3814 1.1 christos { 3815 1.1 christos /* Check code for -mlong-jumps output. */ 3816 1.1 christos if (laddr + 10 <= (bfd_vma) sec->size) 3817 1.1 christos { 3818 1.1 christos insn[0] = bfd_get_16 (abfd, contents + laddr); 3819 1.1 christos insn[1] = bfd_get_16 (abfd, contents + laddr + 4); 3820 1.1 christos insn[2] = bfd_get_16 (abfd, contents + laddr + 8); 3821 1.1 christos 3822 1.1 christos if ((insn[0] & MOVHI_MASK) != MOVHI 3823 1.1 christos || MOVHI_R1 (insn[0]) != 0) 3824 1.1 christos no_match = 0; 3825 1.1 christos 3826 1.1 christos if (no_match < 0 3827 1.1 christos && ((insn[1] & MOVEA_MASK) != MOVEA 3828 1.1.1.9 christos || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1]))) 3829 1.1 christos no_match = 1; 3830 1.1 christos 3831 1.1 christos if (no_match < 0 3832 1.1.1.7 christos && ((insn[2] & JMP_R_MASK) != JMP_R 3833 1.1.1.7 christos || MOVEA_R2 (insn[1]) != JMP_R1 (insn[2]))) 3834 1.1.1.8 christos no_match = 2; 3835 1.1.1.7 christos } 3836 1.1.1.8 christos else 3837 1.1 christos { 3838 1.1 christos _bfd_error_handler 3839 1.1 christos /* xgettext:c-format */ 3840 1.1 christos (_("%pB: %#" PRIx64 ": warning: %s points to " 3841 1.1 christos "unrecognized insns"), 3842 1.1.1.7 christos abfd, (uint64_t) irel->r_offset, "R_V850_LONGJUMP"); 3843 1.1.1.7 christos continue; 3844 1.1.1.8 christos } 3845 1.1.1.8 christos 3846 1.1.1.7 christos if (no_match >= 0) 3847 1.1.1.8 christos { 3848 1.1.1.8 christos _bfd_error_handler 3849 1.1.1.7 christos /* xgettext:c-format */ 3850 1.1 christos (_("%pB: %#" PRIx64 ": warning: %s points to " 3851 1.1 christos "unrecognized insn %#x"), 3852 1.1 christos abfd, 3853 1.1 christos (uint64_t) (irel->r_offset + no_match), 3854 1.1.1.8 christos "R_V850_LONGJUMP", 3855 1.1.1.8 christos insn[no_match]); 3856 1.1 christos continue; 3857 1.1.1.2 christos } 3858 1.1.1.2 christos 3859 1.1.1.2 christos /* Get the reloc for the address from which the register is 3860 1.1.1.2 christos being loaded. This reloc will tell us which function is 3861 1.1.1.2 christos actually being called. */ 3862 1.1.1.2 christos for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++) 3863 1.1.1.2 christos { 3864 1.1 christos r_type = ELF32_R_TYPE (hi_irelfn->r_info); 3865 1.1 christos 3866 1.1.1.2 christos if (hi_irelfn->r_offset == laddr + 2 3867 1.1.1.2 christos && ((r_type == (int) R_V850_HI16_S) || r_type == (int) R_V810_WHI1)) 3868 1.1.1.2 christos break; 3869 1.1.1.2 christos } 3870 1.1.1.2 christos 3871 1.1.1.2 christos for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++) 3872 1.1.1.2 christos { 3873 1.1 christos r_type = ELF32_R_TYPE (lo_irelfn->r_info); 3874 1.1 christos 3875 1.1 christos if (lo_irelfn->r_offset == laddr + 6 3876 1.1 christos && (r_type == (int) R_V850_LO16 || r_type == (int) R_V810_WLO)) 3877 1.1.1.7 christos break; 3878 1.1.1.7 christos } 3879 1.1.1.8 christos 3880 1.1.1.7 christos if ( hi_irelfn == irelend 3881 1.1.1.8 christos || lo_irelfn == irelend) 3882 1.1 christos { 3883 1.1 christos _bfd_error_handler 3884 1.1 christos /* xgettext:c-format */ 3885 1.1 christos (_("%pB: %#" PRIx64 ": warning: %s points to " 3886 1.1 christos "unrecognized reloc"), 3887 1.1 christos abfd, (uint64_t) irel->r_offset, "R_V850_LONGJUMP"); 3888 1.1 christos continue; 3889 1.1.1.8 christos } 3890 1.1 christos 3891 1.1 christos /* Get the value of the symbol referred to by the reloc. */ 3892 1.1 christos if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info) 3893 1.1 christos { 3894 1.1 christos Elf_Internal_Sym * isym; 3895 1.1 christos asection * sym_sec; 3896 1.1 christos 3897 1.1 christos /* A local symbol. */ 3898 1.1 christos isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info); 3899 1.1 christos 3900 1.1 christos if (isym->st_shndx == SHN_UNDEF) 3901 1.1 christos sym_sec = bfd_und_section_ptr; 3902 1.1 christos else if (isym->st_shndx == SHN_ABS) 3903 1.1 christos sym_sec = bfd_abs_section_ptr; 3904 1.1 christos else if (isym->st_shndx == SHN_COMMON) 3905 1.1 christos sym_sec = bfd_com_section_ptr; 3906 1.1 christos else 3907 1.1 christos sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); 3908 1.1 christos symval = (isym->st_value 3909 1.1 christos + sym_sec->output_section->vma 3910 1.1 christos + sym_sec->output_offset); 3911 1.1 christos #ifdef DEBUG_RELAX 3912 1.1 christos { 3913 1.1 christos char * name = bfd_elf_string_from_elf_section 3914 1.1 christos (abfd, symtab_hdr->sh_link, isym->st_name); 3915 1.1 christos 3916 1.1 christos fprintf (stderr, "relax long jump local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n", 3917 1.1 christos sym_sec->name, name, isym->st_name, 3918 1.1 christos sym_sec->output_section->vma, 3919 1.1 christos sym_sec->output_offset, 3920 1.1 christos isym->st_value, irel->r_addend); 3921 1.1 christos } 3922 1.1 christos #endif 3923 1.1 christos } 3924 1.1 christos else 3925 1.1 christos { 3926 1.1 christos unsigned long indx; 3927 1.1 christos struct elf_link_hash_entry * h; 3928 1.1 christos 3929 1.1 christos /* An external symbol. */ 3930 1.1 christos indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; 3931 1.1 christos h = elf_sym_hashes (abfd)[indx]; 3932 1.1 christos BFD_ASSERT (h != NULL); 3933 1.1 christos 3934 1.1 christos if ( h->root.type != bfd_link_hash_defined 3935 1.1 christos && h->root.type != bfd_link_hash_defweak) 3936 1.1 christos /* This appears to be a reference to an undefined 3937 1.1 christos symbol. Just ignore it--it will be caught by the 3938 1.1 christos regular reloc processing. */ 3939 1.1 christos continue; 3940 1.1 christos 3941 1.1 christos symval = (h->root.u.def.value 3942 1.1 christos + h->root.u.def.section->output_section->vma 3943 1.1 christos + h->root.u.def.section->output_offset); 3944 1.1 christos #ifdef DEBUG_RELAX 3945 1.1 christos fprintf (stderr, 3946 1.1 christos "relax longjump defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n", 3947 1.1 christos sec->name, h->root.root.string, h->root.u.def.value, 3948 1.1 christos sec->output_section->vma, sec->output_offset, irel->r_addend); 3949 1.1 christos #endif 3950 1.1 christos } 3951 1.1 christos 3952 1.1 christos addend = irel->r_addend; 3953 1.1 christos 3954 1.1 christos foff = (symval + addend 3955 1.1 christos - (irel->r_offset 3956 1.1 christos + sec->output_section->vma 3957 1.1 christos + sec->output_offset 3958 1.1 christos + 4)); 3959 1.1 christos #ifdef DEBUG_RELAX 3960 1.1 christos fprintf (stderr, "relax longjump r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n", 3961 1.1 christos irel->r_offset, 3962 1.1 christos (irel->r_offset 3963 1.1 christos + sec->output_section->vma 3964 1.1 christos + sec->output_offset), 3965 1.1 christos symval, addend, foff); 3966 1.1.1.8 christos #endif 3967 1.1.1.8 christos if (foff < -0x100000 || foff >= 0x100000) 3968 1.1.1.8 christos /* After all that work, we can't shorten this function call. */ 3969 1.1.1.8 christos continue; 3970 1.1.1.8 christos 3971 1.1.1.8 christos /* For simplicity of coding, we are going to modify the section 3972 1.1 christos contents, the section relocs, and the BFD symbol table. We 3973 1.1 christos must tell the rest of the code not to free up this 3974 1.1 christos information. It would be possible to instead create a table 3975 1.1 christos of changes which have to be made, as is done in coff-mips.c; 3976 1.1 christos that would be more work, but would require less memory when 3977 1.1 christos the linker is run. */ 3978 1.1 christos elf_section_data (sec)->relocs = internal_relocs; 3979 1.1 christos elf_section_data (sec)->this_hdr.contents = contents; 3980 1.1.1.2 christos symtab_hdr->contents = (bfd_byte *) isymbuf; 3981 1.1.1.2 christos 3982 1.1.1.2 christos if (foff < -0x100 || foff >= 0x100) 3983 1.1.1.2 christos { 3984 1.1.1.2 christos /* Replace the long jump with a jr. */ 3985 1.1 christos 3986 1.1 christos if (bfd_get_arch (abfd) == bfd_arch_v850_rh850) 3987 1.1 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_PCR22); 3988 1.1 christos else 3989 1.1 christos irel->r_info = 3990 1.1 christos ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_22_PCREL); 3991 1.1 christos 3992 1.1 christos irel->r_addend = addend; 3993 1.1 christos addend = 0; 3994 1.1 christos 3995 1.1 christos if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info) 3996 1.1 christos /* If this needs to be changed because of future relaxing, 3997 1.1 christos it will be handled here like other internal IND12W 3998 1.1 christos relocs. */ 3999 1.1 christos bfd_put_32 (abfd, 4000 1.1 christos 0x00000780 | ((addend << 15) & 0xffff0000) | ((addend >> 17) & 0xf), 4001 1.1 christos contents + irel->r_offset); 4002 1.1 christos else 4003 1.1 christos /* We can't fully resolve this yet, because the external 4004 1.1 christos symbol value may be changed by future relaxing. 4005 1.1 christos We let the final link phase handle it. */ 4006 1.1 christos bfd_put_32 (abfd, 0x00000780, contents + irel->r_offset); 4007 1.1 christos 4008 1.1 christos hi_irelfn->r_info = 4009 1.1 christos ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE); 4010 1.1 christos lo_irelfn->r_info = 4011 1.1 christos ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE); 4012 1.1 christos if (!v850_elf_relax_delete_bytes (abfd, sec, 4013 1.1 christos irel->r_offset + 4, toaddr, 6)) 4014 1.1 christos goto error_return; 4015 1.1 christos 4016 1.1.1.2 christos align_pad_size += 6; 4017 1.1.1.2 christos } 4018 1.1.1.2 christos else 4019 1.1.1.2 christos { 4020 1.1.1.2 christos /* Replace the long jump with a br. */ 4021 1.1 christos 4022 1.1 christos if (bfd_get_arch (abfd) == bfd_arch_v850_rh850) 4023 1.1 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_PC9); 4024 1.1 christos else 4025 1.1 christos irel->r_info = 4026 1.1 christos ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_9_PCREL); 4027 1.1 christos 4028 1.1 christos irel->r_addend = addend; 4029 1.1 christos addend = 0; 4030 1.1 christos 4031 1.1 christos if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info) 4032 1.1 christos /* If this needs to be changed because of future relaxing, 4033 1.1 christos it will be handled here like other internal IND12W 4034 1.1 christos relocs. */ 4035 1.1 christos bfd_put_16 (abfd, 4036 1.1 christos 0x0585 | ((addend << 10) & 0xf800) | ((addend << 3) & 0x0070), 4037 1.1 christos contents + irel->r_offset); 4038 1.1 christos else 4039 1.1 christos /* We can't fully resolve this yet, because the external 4040 1.1 christos symbol value may be changed by future relaxing. 4041 1.1 christos We let the final link phase handle it. */ 4042 1.1 christos bfd_put_16 (abfd, 0x0585, contents + irel->r_offset); 4043 1.1 christos 4044 1.1 christos hi_irelfn->r_info = 4045 1.1 christos ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE); 4046 1.1 christos lo_irelfn->r_info = 4047 1.1 christos ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE); 4048 1.1 christos if (!v850_elf_relax_delete_bytes (abfd, sec, 4049 1.1 christos irel->r_offset + 2, toaddr, 8)) 4050 1.1 christos goto error_return; 4051 1.1 christos 4052 1.1 christos align_pad_size += 8; 4053 1.1 christos } 4054 1.1 christos } 4055 1.1 christos } 4056 1.1 christos 4057 1.1 christos irelalign = NULL; 4058 1.1 christos for (irel = internal_relocs; irel < irelend; irel++) 4059 1.1 christos { 4060 1.1 christos if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN 4061 1.1 christos && irel->r_offset == toaddr) 4062 1.1 christos { 4063 1.1 christos irel->r_offset -= align_pad_size; 4064 1.1 christos 4065 1.1 christos if (irelalign == NULL || irelalign->r_addend > irel->r_addend) 4066 1.1 christos irelalign = irel; 4067 1.1 christos } 4068 1.1 christos } 4069 1.1 christos 4070 1.1 christos addr = toaddr; 4071 1.1 christos } 4072 1.1 christos 4073 1.1 christos if (!irelalign) 4074 1.1 christos { 4075 1.1 christos #ifdef DEBUG_RELAX 4076 1.1 christos fprintf (stderr, "relax pad %d shorten %d -> %d\n", 4077 1.1 christos align_pad_size, 4078 1.1 christos sec->size, 4079 1.1.1.9 christos sec->size - align_pad_size); 4080 1.1 christos #endif 4081 1.1 christos sec->size -= align_pad_size; 4082 1.1.1.9 christos } 4083 1.1 christos 4084 1.1 christos finish: 4085 1.1.1.9 christos if (elf_section_data (sec)->relocs != internal_relocs) 4086 1.1 christos free (internal_relocs); 4087 1.1 christos 4088 1.1 christos if (elf_section_data (sec)->this_hdr.contents != (unsigned char *) contents) 4089 1.1 christos free (contents); 4090 1.1 christos 4091 1.1.1.10 christos if (symtab_hdr->contents != (bfd_byte *) isymbuf) 4092 1.1 christos free (isymbuf); 4093 1.1 christos 4094 1.1 christos return result; 4095 1.1 christos 4096 1.1 christos error_return: 4097 1.1 christos result = false; 4098 1.1 christos goto finish; 4099 1.1 christos } 4100 1.1.1.8 christos 4101 1.1 christos static const struct bfd_elf_special_section v850_elf_special_sections[] = 4102 1.1.1.8 christos { 4103 1.1 christos { STRING_COMMA_LEN (".call_table_data"), 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE) }, 4104 1.1.1.8 christos { STRING_COMMA_LEN (".call_table_text"), 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE 4105 1.1 christos + SHF_EXECINSTR) }, 4106 1.1.1.8 christos { STRING_COMMA_LEN (".rosdata"), -2, SHT_PROGBITS, (SHF_ALLOC 4107 1.1 christos + SHF_V850_GPREL) }, 4108 1.1.1.8 christos { STRING_COMMA_LEN (".rozdata"), -2, SHT_PROGBITS, (SHF_ALLOC 4109 1.1 christos + SHF_V850_R0REL) }, 4110 1.1.1.8 christos { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE 4111 1.1 christos + SHF_V850_GPREL) }, 4112 1.1.1.8 christos { STRING_COMMA_LEN (".scommon"), -2, SHT_V850_SCOMMON, (SHF_ALLOC + SHF_WRITE 4113 1.1 christos + SHF_V850_GPREL) }, 4114 1.1.1.8 christos { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE 4115 1.1 christos + SHF_V850_GPREL) }, 4116 1.1.1.8 christos { STRING_COMMA_LEN (".tbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE 4117 1.1 christos + SHF_V850_EPREL) }, 4118 1.1.1.8 christos { STRING_COMMA_LEN (".tcommon"), -2, SHT_V850_TCOMMON, (SHF_ALLOC + SHF_WRITE 4119 1.1 christos + SHF_V850_R0REL) }, 4120 1.1.1.8 christos { STRING_COMMA_LEN (".tdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE 4121 1.1 christos + SHF_V850_EPREL) }, 4122 1.1.1.8 christos { STRING_COMMA_LEN (".zbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE 4123 1.1 christos + SHF_V850_R0REL) }, 4124 1.1 christos { STRING_COMMA_LEN (".zcommon"), -2, SHT_V850_ZCOMMON, (SHF_ALLOC + SHF_WRITE 4125 1.1.1.4 christos + SHF_V850_R0REL) }, 4126 1.1 christos { STRING_COMMA_LEN (".zdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE 4127 1.1 christos + SHF_V850_R0REL) }, 4128 1.1 christos { NULL, 0, 0, 0, 0 } 4129 1.1 christos }; 4130 1.1 christos 4131 1.1 christos #define TARGET_LITTLE_SYM v850_elf32_vec 4133 1.1 christos #define TARGET_LITTLE_NAME "elf32-v850" 4134 1.1 christos #define ELF_ARCH bfd_arch_v850 4135 1.1 christos #define ELF_MACHINE_CODE EM_V850 4136 1.1.1.8 christos #define ELF_MACHINE_ALT1 EM_CYGNUS_V850 4137 1.1 christos #define ELF_MAXPAGESIZE 0x1000 4138 1.1.1.8 christos 4139 1.1.1.8 christos #define elf_info_to_howto v850_elf_info_to_howto_rela 4140 1.1 christos #define elf_info_to_howto_rel v850_elf_info_to_howto_rel 4141 1.1 christos 4142 1.1.1.8 christos #define elf_backend_check_relocs v850_elf_check_relocs 4143 1.1 christos #define elf_backend_relocate_section v850_elf_relocate_section 4144 1.1 christos #define elf_backend_object_p v850_elf_object_p 4145 1.1.1.8 christos #define elf_backend_final_write_processing v850_elf_final_write_processing 4146 1.1 christos #define elf_backend_section_from_bfd_section v850_elf_section_from_bfd_section 4147 1.1 christos #define elf_backend_symbol_processing v850_elf_symbol_processing 4148 1.1.1.8 christos #define elf_backend_add_symbol_hook v850_elf_add_symbol_hook 4149 1.1.1.5 christos #define elf_backend_link_output_symbol_hook v850_elf_link_output_symbol_hook 4150 1.1 christos #define elf_backend_section_from_shdr v850_elf_section_from_shdr 4151 1.1 christos #define elf_backend_fake_sections v850_elf_fake_sections 4152 1.1.1.3 christos #define elf_backend_gc_mark_hook v850_elf_gc_mark_hook 4153 1.1.1.3 christos #define elf_backend_special_sections v850_elf_special_sections 4154 1.1 christos 4155 1.1.1.8 christos #define elf_backend_can_gc_sections 1 4156 1.1.1.8 christos #define elf_backend_rela_normal 1 4157 1.1 christos 4158 1.1 christos #define bfd_elf32_bfd_is_local_label_name v850_elf_is_local_label_name 4159 1.1 christos #define bfd_elf32_bfd_is_target_special_symbol v850_elf_is_target_special_symbol 4160 1.1 christos 4161 1.1 christos #define bfd_elf32_bfd_reloc_type_lookup v850_elf_reloc_type_lookup 4162 1.1 christos #define bfd_elf32_bfd_reloc_name_lookup v850_elf_reloc_name_lookup 4163 1.1.1.2 christos #define bfd_elf32_bfd_merge_private_bfd_data v850_elf_merge_private_bfd_data 4164 1.1.1.2 christos #define bfd_elf32_bfd_set_private_flags v850_elf_set_private_flags 4165 1.1.1.2 christos #define bfd_elf32_bfd_print_private_bfd_data v850_elf_print_private_bfd_data 4166 1.1.1.2 christos #define bfd_elf32_bfd_relax_section v850_elf_relax_section 4167 1.1.1.2 christos 4168 1.1.1.2 christos #define elf_symbol_leading_char '_' 4169 1.1.1.2 christos 4170 1.1.1.2 christos #undef elf32_bed 4171 1.1.1.2 christos #define elf32_bed elf32_v850_bed 4172 1.1.1.8 christos 4173 1.1.1.8 christos #include "elf32-target.h" 4174 1.1.1.8 christos 4175 1.1.1.8 christos /* Map BFD reloc types to V800 ELF reloc types. */ 4176 1.1.1.8 christos 4177 1.1.1.8 christos static const struct v850_elf_reloc_map v800_elf_reloc_map[] = 4178 1.1.1.8 christos { 4179 1.1.1.8 christos { BFD_RELOC_NONE, R_V810_NONE }, 4180 1.1.1.8 christos { BFD_RELOC_8, R_V810_BYTE }, 4181 1.1.1.8 christos { BFD_RELOC_16, R_V810_HWORD }, 4182 1.1.1.8 christos { BFD_RELOC_32, R_V810_WORD }, 4183 1.1.1.2 christos { BFD_RELOC_LO16, R_V810_WLO }, 4184 1.1.1.8 christos { BFD_RELOC_HI16, R_V810_WHI }, 4185 1.1.1.8 christos { BFD_RELOC_HI16_S, R_V810_WHI1 }, 4186 1.1.1.2 christos { BFD_RELOC_V850_32_PCREL, R_V850_PC32 }, 4187 1.1.1.2 christos { BFD_RELOC_V850_22_PCREL, R_V850_PCR22 }, 4188 1.1.1.2 christos { BFD_RELOC_V850_17_PCREL, R_V850_PC17 }, 4189 1.1.1.2 christos { BFD_RELOC_V850_16_PCREL, R_V850_PC16U }, 4190 1.1.1.2 christos { BFD_RELOC_V850_9_PCREL, R_V850_PC9 }, 4191 1.1.1.2 christos { BFD_RELOC_V850_LO16_S1, R_V810_WLO_1 }, /* Or R_V850_HWLO or R_V850_HWLO_1. */ 4192 1.1.1.2 christos { BFD_RELOC_V850_23, R_V850_WLO23 }, 4193 1.1.1.2 christos { BFD_RELOC_V850_LO16_SPLIT_OFFSET, R_V850_BLO }, 4194 1.1.1.2 christos { BFD_RELOC_V850_ZDA_16_16_OFFSET, R_V810_HWORD }, 4195 1.1.1.2 christos { BFD_RELOC_V850_TDA_16_16_OFFSET, R_V810_HWORD }, 4196 1.1.1.2 christos { BFD_RELOC_V850_SDA_16_16_OFFSET, R_V810_HWORD }, 4197 1.1.1.2 christos { BFD_RELOC_V850_SDA_15_16_OFFSET, R_V810_GPWLO_1 } 4198 1.1.1.2 christos }; 4199 1.1.1.2 christos 4200 1.1.1.2 christos /* Map a bfd relocation into the appropriate howto structure. */ 4201 1.1.1.2 christos 4202 1.1.1.2 christos static reloc_howto_type * 4203 1.1.1.2 christos v800_elf_reloc_type_lookup (bfd * abfd, bfd_reloc_code_real_type code) 4204 1.1.1.2 christos { 4205 1.1.1.2 christos unsigned int i; 4206 1.1.1.2 christos 4207 1.1.1.2 christos BFD_ASSERT (bfd_get_arch (abfd) == bfd_arch_v850_rh850); 4208 1.1.1.2 christos 4209 1.1.1.2 christos for (i = ARRAY_SIZE (v800_elf_reloc_map); i --;) 4210 1.1.1.2 christos if (v800_elf_reloc_map[i].bfd_reloc_val == code) 4211 1.1.1.2 christos { 4212 1.1.1.2 christos unsigned int elf_reloc_val = v800_elf_reloc_map[i].elf_reloc_val; 4213 1.1.1.2 christos unsigned int idx = elf_reloc_val - R_V810_NONE; 4214 1.1.1.2 christos 4215 1.1.1.2 christos BFD_ASSERT (v800_elf_howto_table[idx].type == elf_reloc_val); 4216 1.1.1.2 christos 4217 1.1.1.2 christos return v800_elf_howto_table + idx; 4218 1.1.1.2 christos } 4219 1.1.1.2 christos 4220 1.1.1.2 christos #ifdef DEBUG 4221 1.1.1.2 christos fprintf (stderr, "failed to find v800 equiv of bfd reloc code %d\n", code); 4222 1.1.1.2 christos #endif 4223 1.1.1.2 christos return NULL; 4224 1.1.1.2 christos } 4225 1.1.1.2 christos 4226 1.1.1.2 christos static reloc_howto_type * 4227 1.1.1.2 christos v800_elf_reloc_name_lookup (bfd * abfd, const char * r_name) 4228 1.1.1.2 christos { 4229 1.1.1.2 christos unsigned int i; 4230 1.1.1.2 christos 4231 1.1.1.2 christos BFD_ASSERT (bfd_get_arch (abfd) == bfd_arch_v850_rh850); 4232 1.1.1.2 christos 4233 1.1.1.2 christos for (i = ARRAY_SIZE (v800_elf_howto_table); i--;) 4234 1.1.1.2 christos if (v800_elf_howto_table[i].name != NULL 4235 1.1.1.2 christos && strcasecmp (v800_elf_howto_table[i].name, r_name) == 0) 4236 1.1.1.2 christos return v800_elf_howto_table + i; 4237 1.1.1.10 christos 4238 1.1.1.8 christos return NULL; 4239 1.1.1.8 christos } 4240 1.1.1.2 christos 4241 1.1.1.2 christos 4242 1.1.1.2 christos /* Set the howto pointer in CACHE_PTR for a V800 ELF reloc. */ 4243 1.1.1.2 christos 4244 1.1.1.2 christos static bool 4245 1.1.1.2 christos v800_elf_info_to_howto (bfd * abfd, 4246 1.1.1.2 christos arelent * cache_ptr, 4247 1.1.1.8 christos Elf_Internal_Rela * dst) 4248 1.1.1.8 christos { 4249 1.1.1.8 christos unsigned int r_type = ELF32_R_TYPE (dst->r_info); 4250 1.1.1.8 christos 4251 1.1.1.8 christos if (r_type == R_V800_NONE) 4252 1.1.1.8 christos r_type = R_V810_NONE; 4253 1.1.1.8 christos 4254 1.1.1.8 christos if (bfd_get_arch (abfd) != bfd_arch_v850_rh850 4255 1.1.1.8 christos || r_type >= (unsigned int) R_V800_max 4256 1.1.1.10 christos || r_type < (unsigned int) R_V810_NONE 4257 1.1.1.8 christos || (r_type - R_V810_NONE) >= ARRAY_SIZE (v800_elf_howto_table)) 4258 1.1.1.2 christos { 4259 1.1.1.8 christos /* xgettext:c-format */ 4260 1.1.1.10 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), 4261 1.1.1.2 christos abfd, r_type); 4262 1.1.1.2 christos bfd_set_error (bfd_error_bad_value); 4263 1.1.1.2 christos return false; 4264 1.1.1.4 christos } 4265 1.1.1.2 christos 4266 1.1.1.2 christos cache_ptr->howto = v800_elf_howto_table + (r_type - R_V810_NONE); 4267 1.1.1.2 christos return true; 4268 1.1.1.2 christos } 4269 1.1.1.2 christos 4270 1.1.1.2 christos #undef TARGET_LITTLE_SYM 4272 1.1.1.2 christos #define TARGET_LITTLE_SYM v800_elf32_vec 4273 1.1.1.2 christos #undef TARGET_LITTLE_NAME 4274 1.1.1.2 christos #define TARGET_LITTLE_NAME "elf32-v850-rh850" 4275 1.1.1.2 christos #undef ELF_ARCH 4276 1.1.1.2 christos #define ELF_ARCH bfd_arch_v850_rh850 4277 1.1.1.2 christos #undef ELF_MACHINE_CODE 4278 1.1.1.2 christos #define ELF_MACHINE_CODE EM_V800 4279 1.1.1.2 christos #undef ELF_MACHINE_ALT1 4280 1.1.1.2 christos 4281 1.1.1.2 christos #undef elf32_bed 4282 1.1.1.2 christos #define elf32_bed elf32_v850_rh850_bed 4283 1.1.1.2 christos 4284 1.1.1.2 christos #undef elf_info_to_howto 4285 1.1 christos #define elf_info_to_howto v800_elf_info_to_howto 4286 #undef elf_info_to_howto_rel 4287 #define elf_info_to_howto_rel NULL 4288 #undef bfd_elf32_bfd_reloc_type_lookup 4289 #define bfd_elf32_bfd_reloc_type_lookup v800_elf_reloc_type_lookup 4290 #undef bfd_elf32_bfd_reloc_name_lookup 4291 #define bfd_elf32_bfd_reloc_name_lookup v800_elf_reloc_name_lookup 4292 4293 #include "elf32-target.h" 4294