Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
Use R_RISCV_DELETE to relax AUIPC->GP
Browse files Browse the repository at this point in the history
  • Loading branch information
palmer-dabbelt committed May 18, 2017
1 parent 4c52255 commit af7bc71
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions bfd/elfnn-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2785,27 +2785,14 @@ riscv_find_pcgp_hi_reloc(riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
}

static bfd_boolean
riscv_delete_pcgp_hi_reloc(riscv_pcgp_relocs *p, bfd_vma hi_sec_off, size_t bytes)
riscv_delete_pcgp_hi_reloc(riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
{
bfd_boolean out = FALSE;

for (riscv_pcgp_hi_reloc *c = p->hi; c != NULL; c = c->next)
{
if (c->hi_sec_off == hi_sec_off)
out = TRUE;

if (c->hi_sec_off > hi_sec_off)
c->hi_sec_off -= bytes;
}

for (riscv_pcgp_lo_reloc *c = p->lo; c != NULL; c = c->next)
{
BFD_ASSERT (c->hi_sec_off != hi_sec_off);

if (c->hi_sec_off > hi_sec_off)
c->hi_sec_off -= bytes;
}

return out;
}

Expand Down Expand Up @@ -3116,6 +3103,8 @@ _bfd_riscv_relax_align (bfd *abfd, asection *sec,
rel->r_addend - nop_bytes);
}

/* Relax PC-relative references to GP-relative references. */

static bfd_boolean
_bfd_riscv_relax_pc (bfd *abfd,
asection *sec,
Expand Down Expand Up @@ -3214,11 +3203,9 @@ _bfd_riscv_relax_pc (bfd *abfd,
ELFNN_R_SYM(rel->r_info),
sym_sec);
/* We can delete the unnecessary AUIPC and reloc. */
rel->r_info = ELFNN_R_INFO (0, R_RISCV_NONE);
*again = TRUE;
if (!riscv_relax_delete_bytes (abfd, sec, rel->r_offset, 4))
return FALSE;
return riscv_delete_pcgp_hi_reloc (pcgp_relocs, rel->r_offset, 4);
rel->r_info = ELFNN_R_INFO (0, R_RISCV_DELETE);
rel->r_addend = 4;
return riscv_delete_pcgp_hi_reloc (pcgp_relocs, rel->r_offset);

default:
abort ();
Expand Down

0 comments on commit af7bc71

Please sign in to comment.