-/* FIXME: This should not be a static variable. */
-
-static struct m32r_hi16 *m32r_hi16_list;
-
-static bfd_reloc_status_type
-m32r_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
- input_section, output_bfd, error_message)
- bfd *abfd ATTRIBUTE_UNUSED;
- arelent *reloc_entry;
- asymbol *symbol;
- PTR data;
- asection *input_section;
- bfd *output_bfd;
- char **error_message ATTRIBUTE_UNUSED;
-{
- bfd_reloc_status_type ret;
- bfd_vma relocation;
- struct m32r_hi16 *n;
-
- /* This part is from bfd_elf_generic_reloc.
- If we're relocating, and this an external symbol, we don't want
- to change anything. */
- if (output_bfd != (bfd *) NULL
- && (symbol->flags & BSF_SECTION_SYM) == 0
- && reloc_entry->addend == 0)
- {
- reloc_entry->address += input_section->output_offset;
- return bfd_reloc_ok;
- }
-
- /* Sanity check the address (offset in section). */
- if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
- return bfd_reloc_outofrange;
-
- ret = bfd_reloc_ok;
- if (bfd_is_und_section (symbol->section)
- && output_bfd == (bfd *) NULL)
- ret = bfd_reloc_undefined;
-
- if (bfd_is_com_section (symbol->section))
- relocation = 0;
- else
- relocation = symbol->value;
-
- relocation += symbol->section->output_section->vma;
- relocation += symbol->section->output_offset;
- relocation += reloc_entry->addend;
-
- /* Save the information, and let LO16 do the actual relocation. */
- n = (struct m32r_hi16 *) bfd_malloc ((bfd_size_type) sizeof *n);
- if (n == NULL)
- return bfd_reloc_outofrange;
- n->addr = (bfd_byte *) data + reloc_entry->address;
- n->addend = relocation;
- n->next = m32r_hi16_list;
- m32r_hi16_list = n;
-
- if (output_bfd != (bfd *) NULL)
- reloc_entry->address += input_section->output_offset;
-
- return ret;
-}
-
-/* Handle an M32R ELF HI16 reloc. */
-
-static void
-m32r_elf_relocate_hi16 (input_bfd, type, relhi, rello, contents, addend)
- bfd *input_bfd;
- int type;
- Elf_Internal_Rela *relhi;
- Elf_Internal_Rela *rello;
- bfd_byte *contents;
- bfd_vma addend;
-{
- unsigned long insn;
- bfd_vma addlo;
-
- insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
-
- addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
- if (type == R_M32R_HI16_SLO)
- addlo = ((addlo & 0xffff) ^ 0x8000) - 0x8000;
- else
- addlo &= 0xffff;
-
- addend += ((insn & 0xffff) << 16) + addlo;
-
- /* Reaccount for sign extension of low part. */
- if (type == R_M32R_HI16_SLO
- && (addend & 0x8000) != 0)
- addend += 0x10000;
-
- bfd_put_32 (input_bfd,
- (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
- contents + relhi->r_offset);
-}
-
-/* Do an R_M32R_LO16 relocation. This is a straightforward 16 bit
- inplace relocation; this function exists in order to do the
- R_M32R_HI16_[SU]LO relocation described above. */
-
-bfd_reloc_status_type
-m32r_elf_lo16_reloc (input_bfd, reloc_entry, symbol, data,
- input_section, output_bfd, error_message)
- bfd *input_bfd;
- arelent *reloc_entry;
- asymbol *symbol;
- PTR data;
- asection *input_section;
- bfd *output_bfd;
- char **error_message;
-{
- /* This part is from bfd_elf_generic_reloc.
- If we're relocating, and this an external symbol, we don't want
- to change anything. */
- if (output_bfd != (bfd *) NULL
- && (symbol->flags & BSF_SECTION_SYM) == 0
- && reloc_entry->addend == 0)
- {
- reloc_entry->address += input_section->output_offset;
- return bfd_reloc_ok;
- }
-
- if (m32r_hi16_list != NULL)
- {
- struct m32r_hi16 *l;
-
- l = m32r_hi16_list;
- while (l != NULL)
- {
- unsigned long insn;
- unsigned long val;
- unsigned long vallo;
- struct m32r_hi16 *next;
-
- /* Do the HI16 relocation. Note that we actually don't need
- to know anything about the LO16 itself, except where to
- find the low 16 bits of the addend needed by the LO16. */
- insn = bfd_get_32 (input_bfd, l->addr);
- vallo = ((bfd_get_32 (input_bfd, (bfd_byte *) data + reloc_entry->address)
- & 0xffff) ^ 0x8000) - 0x8000;
- val = ((insn & 0xffff) << 16) + vallo;
- val += l->addend;
-
- /* Reaccount for sign extension of low part. */
- if ((val & 0x8000) != 0)
- val += 0x10000;
-
- insn = (insn &~ (bfd_vma) 0xffff) | ((val >> 16) & 0xffff);
- bfd_put_32 (input_bfd, (bfd_vma) insn, l->addr);
-
- next = l->next;
- free (l);
- l = next;
- }
-
- m32r_hi16_list = NULL;
- }
-
- /* Now do the LO16 reloc in the usual way.
- ??? It would be nice to call bfd_elf_generic_reloc here,
- but we have partial_inplace set. bfd_elf_generic_reloc will
- pass the handling back to bfd_install_relocation which will install
- a section relative addend which is wrong. */
- return m32r_elf_generic_reloc (input_bfd, reloc_entry, symbol, data,
- input_section, output_bfd, error_message);
-}
-
-/* Do generic partial_inplace relocation.
- This is a local replacement for bfd_elf_generic_reloc. */
-
-bfd_reloc_status_type
-m32r_elf_generic_reloc (input_bfd, reloc_entry, symbol, data,
- input_section, output_bfd, error_message)
- bfd *input_bfd;
- arelent *reloc_entry;
- asymbol *symbol;
- PTR data;
- asection *input_section;
- bfd *output_bfd;
- char **error_message ATTRIBUTE_UNUSED;
-{
- bfd_reloc_status_type ret;
- bfd_vma relocation;
- bfd_byte *inplace_address;
-
- /* This part is from bfd_elf_generic_reloc.
- If we're relocating, and this an external symbol, we don't want
- to change anything. */
- if (output_bfd != (bfd *) NULL
- && (symbol->flags & BSF_SECTION_SYM) == 0
- && reloc_entry->addend == 0)
- {
- reloc_entry->address += input_section->output_offset;
- return bfd_reloc_ok;
- }
-
- /* Now do the reloc in the usual way.
- ??? It would be nice to call bfd_elf_generic_reloc here,
- but we have partial_inplace set. bfd_elf_generic_reloc will
- pass the handling back to bfd_install_relocation which will install
- a section relative addend which is wrong. */
-
- /* Sanity check the address (offset in section). */
- if (reloc_entry->address > bfd_get_section_limit (input_bfd, input_section))
- return bfd_reloc_outofrange;