summaryrefslogtreecommitdiff
path: root/gas/config/tc-mips.c
diff options
context:
space:
mode:
authorRichard Sandiford <rsandifo@nildram.co.uk>2003-12-18 10:23:10 +0000
committerRichard Sandiford <rsandifo@nildram.co.uk>2003-12-18 10:23:10 +0000
commitfd10a6073147b017460ec70d83e7f05baceab8c5 (patch)
tree9c0b710972bc7418a9612826481132becd0b9435 /gas/config/tc-mips.c
parent7b5390363ebf0b04607df1f0abcc3ec68ca50459 (diff)
downloadbinutils-redhat-fd10a6073147b017460ec70d83e7f05baceab8c5.tar.gz
bfd/
* elf32-mips.c (elf_mips_howto_table_rel): Replace all uses of mips_elf_generic_reloc with _bfd_mips_elf_generic_reloc. Use _bfd_mips_elf_hi16_reloc for R_MIPS_HI16 and R_MIPS_GNU_REL_HI16, _bfd_mips_elf_lo16_reloc for R_MIPS_LO16 and R_MIPS_GNU_REL_LO16, and _bfd_mips_elf_got16_reloc for R_MIPS_GOT16. Change rightshift to 16 for R_MIPS_HI16 and R_MIPS_GNU_REL_HI16. (mips_elf_generic_reloc, struct mips_hi16, mips_elf_hi16_reloc) (mips_elf_lo16_reloc, mips_elf_got16_reloc): Delete. (_bfd_mips_elf32_gprel16_reloc): Remove special case. (mips_elf_gprel32_reloc, mips32_64bit_reloc): Likewise. * elf64-mips.c (mips_elf64_howto_table_rel): Replace all uses of mips_elf_generic_reloc with _bfd_mips_elf_generic_reloc. Use _bfd_mips_elf_hi16_reloc for R_MIPS_HI16, _bfd_mips_elf_lo16_reloc for R_MIPS_LO16 and _bfd_mips_elf_got16_reloc for R_MIPS_GOT16. Change R_MIPS_HI16's rightshift to 16. (mips_elf64_howto_table_rela): Replace all uses of mips_elf_generic_reloc with _bfd_mips_elf_generic_reloc. Use _bfd_mips_elf_generic_reloc for R_MIPS_GOT16 as well. (mips_elf64_hi16_reloc, mips_elf64_got16_reloc): Delete. (mips_elf64_shift6_reloc): Remove special case. Use _bfd_mips_elf_generic_reloc instead of returning bfd_reloc_continue. * elfn32-mips.c (prev_reloc_section): Delete. (prev_reloc_address, prev_reloc_addend): Delete. (elf_mips_howto_table_rel, elf_mips_howto_table_rela): As for elf64-mips.c (GET_RELOC_ADDEND, SET_RELOC_ADDEND): Delete. (mips_elf_generic_reloc, struct mips_hi16, mips_elf_hi16_reloc) (mips_elf_lo16_reloc, mips_elf_got16_reloc): Delete. (mips_elf_gprel16_reloc): Delete use of GET_RELOC_ADDEND. (mips_elf_literal_reloc, mips_elf_gprel32_reloc): Likewise. (mips16_jump_reloc, mips16_gprel_reloc): Likewise. (mips_elf_shift6_reloc): Likewise. Delete use of SET_RELOC_ADDEND. * elfxx-mips.c (_bfd_mips_elf_gprel16_with_gp): Use _bfd_relocate_contents to install an in-place addend. (mips_hi16): New structure. (mips_hi16_list): Moved from elf32-mips.c. (_bfd_mips_elf_hi16_reloc, _bfd_mips_elf_got16_reloc): New functions. (_bfd_mips_elf_lo16_reloc, _bfd_mips_elf_generic_reloc): New functions. (mips_elf_calculate_relocation): Assume addend is unshifted. (_bfd_mips_elf_relocate_section): Don't apply the howto rightshift on top of the usual high-part shift. Don't shift the addend right before calling mips_elf_calculate_relocation. * elfxx-mips.h (_bfd_mips_elf_hi16_reloc): Declare. (_bfd_mips_elf_got16_reloc, _bfd_mips_elf_lo16_reloc): Declare. (_bfd_mips_elf_generic_reloc): Declare. gas/ * config/tc-mips.c (mips_need_elf_addend_fixup): Delete. (md_apply_fix3): Remove bfd_install_relocation workarounds. (tc_gen_reloc): Likewise. Factor handling of pc-relative relocations and treat fx_addnumber as relative to the relocation address. gas/testsuite/ * gas/mips/mips16-jalx.d: Use -mabi=o64. * gas/mips/mips16.d: Likewise. * gas/mips/elf-rel17.[sd]: New test. * gas/mips/mips.exp: Run it.
Diffstat (limited to 'gas/config/tc-mips.c')
-rw-r--r--gas/config/tc-mips.c148
1 files changed, 32 insertions, 116 deletions
diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
index e6997ca78f..eb5be496f2 100644
--- a/gas/config/tc-mips.c
+++ b/gas/config/tc-mips.c
@@ -11339,31 +11339,6 @@ mips_validate_fix (struct fix *fixP, asection *seg)
return 1;
}
-#ifdef OBJ_ELF
-static int
-mips_need_elf_addend_fixup (fixS *fixP)
-{
- if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16)
- return 1;
- if (mips_pic == EMBEDDED_PIC
- && S_IS_WEAK (fixP->fx_addsy))
- return 1;
- if (mips_pic != EMBEDDED_PIC
- && (S_IS_WEAK (fixP->fx_addsy)
- || S_IS_EXTERNAL (fixP->fx_addsy))
- && !S_IS_COMMON (fixP->fx_addsy))
- return 1;
- if (((bfd_get_section_flags (stdoutput,
- S_GET_SEGMENT (fixP->fx_addsy))
- & (SEC_LINK_ONCE | SEC_MERGE)) != 0)
- || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
- ".gnu.linkonce",
- sizeof (".gnu.linkonce") - 1))
- return 1;
- return 0;
-}
-#endif
-
/* Apply a fixup to the object file. */
void
@@ -11389,61 +11364,6 @@ md_apply_fix3 (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
- /* If we aren't adjusting this fixup to be against the section
- symbol, we need to adjust the value. */
-#ifdef OBJ_ELF
- if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
- {
- if (mips_need_elf_addend_fixup (fixP)
- && howto->partial_inplace
- && fixP->fx_r_type != BFD_RELOC_GPREL16
- && fixP->fx_r_type != BFD_RELOC_GPREL32
- && fixP->fx_r_type != BFD_RELOC_MIPS16_GPREL)
- {
- /* In this case, the bfd_install_relocation routine will
- incorrectly add the symbol value back in. We just want
- the addend to appear in the object file.
-
- The condition above used to include
- "&& (! fixP->fx_pcrel || howto->pcrel_offset)".
-
- However, howto can't be trusted here, because we
- might change the reloc type in tc_gen_reloc. We can
- check howto->partial_inplace because that conversion
- happens to preserve howto->partial_inplace; but it
- does not preserve howto->pcrel_offset. I've just
- eliminated the check, because all MIPS PC-relative
- relocations are marked howto->pcrel_offset.
-
- howto->pcrel_offset was originally added for
- R_MIPS_PC16, which is generated for code like
-
- globl g1 .text
- .text
- .space 20
- g1:
- x:
- bal g1
- */
- *valP -= S_GET_VALUE (fixP->fx_addsy);
- }
-
- /* This code was generated using trial and error and so is
- fragile and not trustworthy. If you change it, you should
- rerun the elf-rel, elf-rel2, and empic testcases and ensure
- they still pass. */
- if (fixP->fx_pcrel)
- {
- *valP += fixP->fx_frag->fr_address + fixP->fx_where;
-
- /* BFD's REL handling, for MIPS, is _very_ weird.
- This gives the right results, but it can't possibly
- be the way things are supposed to work. */
- *valP += fixP->fx_frag->fr_address + fixP->fx_where;
- }
- }
-#endif
-
/* We are not done if this is a composite relocation to set up gp. */
if (fixP->fx_addsy == NULL && ! fixP->fx_pcrel
&& !(fixP->fx_r_type == BFD_RELOC_MIPS_SUB
@@ -13406,52 +13326,49 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
fixp->fx_r_type = BFD_RELOC_GPREL32;
}
- else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
+ else if (fixp->fx_pcrel)
{
- if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
- reloc->addend = fixp->fx_addnumber;
+ bfd_vma pcrel_address;
+
+ /* Set PCREL_ADDRESS to this relocation's "PC". The PC for high
+ high-part relocs is the address of the low-part reloc. */
+ if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
+ {
+ assert (fixp->fx_next != NULL
+ && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
+ pcrel_address = (fixp->fx_next->fx_where
+ + fixp->fx_next->fx_frag->fr_address);
+ }
else
+ pcrel_address = reloc->address;
+
+ if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
+ {
+ /* At this point, fx_addnumber is "symbol offset - pcrel_address".
+ Relocations want only the symbol offset. */
+ reloc->addend = fixp->fx_addnumber + pcrel_address;
+ }
+ else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16
+ || fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
{
- /* We use a special addend for an internal RELLO reloc. */
+ /* We use a special addend for an internal RELLO or RELHI reloc. */
if (symbol_section_p (fixp->fx_addsy))
- reloc->addend = reloc->address - S_GET_VALUE (fixp->fx_subsy);
+ reloc->addend = pcrel_address - S_GET_VALUE (fixp->fx_subsy);
else
- reloc->addend = fixp->fx_addnumber + reloc->address;
+ reloc->addend = fixp->fx_addnumber + pcrel_address;
}
- }
- else if (fixp->fx_r_type == BFD_RELOC_PCREL_HI16_S)
- {
- assert (fixp->fx_next != NULL
- && fixp->fx_next->fx_r_type == BFD_RELOC_PCREL_LO16);
-
- /* The reloc is relative to the RELLO; adjust the addend
- accordingly. */
- if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
- reloc->addend = fixp->fx_next->fx_addnumber;
else
{
- /* We use a special addend for an internal RELHI reloc. */
- if (symbol_section_p (fixp->fx_addsy))
- reloc->addend = (fixp->fx_next->fx_frag->fr_address
- + fixp->fx_next->fx_where
- - S_GET_VALUE (fixp->fx_subsy));
+ if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
+ /* A gruesome hack which is a result of the gruesome gas reloc
+ handling. */
+ reloc->addend = pcrel_address;
else
- reloc->addend = (fixp->fx_addnumber
- + fixp->fx_next->fx_frag->fr_address
- + fixp->fx_next->fx_where);
+ reloc->addend = -pcrel_address;
}
}
- else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
- reloc->addend = fixp->fx_addnumber;
else
- {
- if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
- /* A gruesome hack which is a result of the gruesome gas reloc
- handling. */
- reloc->addend = reloc->address;
- else
- reloc->addend = -reloc->address;
- }
+ reloc->addend = fixp->fx_addnumber;
/* If this is a variant frag, we may need to adjust the existing
reloc and generate a new one. */
@@ -13500,8 +13417,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
reloc2->address = (reloc->address
+ (RELAX_RELOC2 (fixp->fx_frag->fr_subtype)
- RELAX_RELOC1 (fixp->fx_frag->fr_subtype)));
- reloc2->addend = fixp->fx_addnumber - S_GET_VALUE (fixp->fx_addsy)
- + fixp->fx_frag->tc_frag_data.tc_fr_offset;
+ reloc2->addend = reloc->addend;
reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16);
assert (reloc2->howto != NULL);