Skip to content

Commit

Permalink
RISC-V: Fix lui relax failure with relro.
Browse files Browse the repository at this point in the history
	bfd/ChangeLog
	Ilia Diachkov  <ilia.diachkov@optimitech.com>
	* elfnn-riscv.c (_bfd_riscv_relax_lui): Set lui relax safety area to
	two pages in relro presence.
  • Loading branch information
Jim Wilson committed Aug 1, 2019
1 parent 0eba165 commit 0f52d45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions bfd/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2019-08-01 Ilia Diachkov <ilia.diachkov@optimitech.com>

* elfnn-riscv.c (_bfd_riscv_relax_lui): Set lui relax safety area to
two pages in relro presence.

2019-08-01 Max Filippov <jcmvbkbc@gmail.com>

* elf32-xtensa.c (insn_num_slots, get_rsr_lend_opcode)
Expand Down
9 changes: 7 additions & 2 deletions bfd/elfnn-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3562,11 +3562,16 @@ _bfd_riscv_relax_lui (bfd *abfd,
}

/* Can we relax LUI to C.LUI? Alignment might move the section forward;
account for this assuming page alignment at worst. */
account for this assuming page alignment at worst. In the presence of
RELRO segment the linker aligns it by one page size, therefore sections
after the segment can be moved more than one page. */

if (use_rvc
&& ELFNN_R_TYPE (rel->r_info) == R_RISCV_HI20
&& VALID_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (symval))
&& VALID_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (symval + ELF_MAXPAGESIZE)))
&& VALID_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (symval)
+ (link_info->relro ? 2 * ELF_MAXPAGESIZE
: ELF_MAXPAGESIZE)))
{
/* Replace LUI with C.LUI if legal (i.e., rd != x0 and rd != x2/sp). */
bfd_vma lui = bfd_get_32 (abfd, contents + rel->r_offset);
Expand Down

0 comments on commit 0f52d45

Please sign in to comment.