+2020-11-21 Nelson Chu <nelson.chu@sifive.com>
+
+ * elfnn-riscv.c (_bfd_riscv_relax_section): Add a new relax pass
+ to do the pcgp relaxation later, after the lui and call relaxations,
+ but before the delete and alignment relaxations.
+
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* elflink.c (elf_finalize_dynstr): Call examine_strtab after
|| (sec->flags & SEC_RELOC) == 0
|| sec->reloc_count == 0
|| (info->disable_target_specific_optimizations
- && info->relax_pass == 0))
+ && info->relax_pass < 2))
return TRUE;
riscv_init_pcgp_relocs (&pcgp_relocs);
relax_func = NULL;
if (info->relax_pass == 0)
{
- if (type == R_RISCV_CALL || type == R_RISCV_CALL_PLT)
+ if (type == R_RISCV_CALL
+ || type == R_RISCV_CALL_PLT)
relax_func = _bfd_riscv_relax_call;
else if (type == R_RISCV_HI20
|| type == R_RISCV_LO12_I
|| type == R_RISCV_LO12_S)
relax_func = _bfd_riscv_relax_lui;
- else if (!bfd_link_pic(info)
- && (type == R_RISCV_PCREL_HI20
- || type == R_RISCV_PCREL_LO12_I
- || type == R_RISCV_PCREL_LO12_S))
- relax_func = _bfd_riscv_relax_pc;
else if (type == R_RISCV_TPREL_HI20
|| type == R_RISCV_TPREL_ADD
|| type == R_RISCV_TPREL_LO12_I
relax_func = _bfd_riscv_relax_tls_le;
else
continue;
+ }
+ else if (info->relax_pass == 1
+ && !bfd_link_pic(info)
+ && (type == R_RISCV_PCREL_HI20
+ || type == R_RISCV_PCREL_LO12_I
+ || type == R_RISCV_PCREL_LO12_S))
+ relax_func = _bfd_riscv_relax_pc;
+ else if (info->relax_pass == 2 && type == R_RISCV_DELETE)
+ relax_func = _bfd_riscv_relax_delete;
+ else if (info->relax_pass == 3 && type == R_RISCV_ALIGN)
+ relax_func = _bfd_riscv_relax_align;
+ else
+ continue;
+ if (info->relax_pass < 2)
+ {
/* Only relax this reloc if it is paired with R_RISCV_RELAX. */
if (i == sec->reloc_count - 1
|| ELFNN_R_TYPE ((rel + 1)->r_info) != R_RISCV_RELAX
/* Skip over the R_RISCV_RELAX. */
i++;
}
- else if (info->relax_pass == 1 && type == R_RISCV_DELETE)
- relax_func = _bfd_riscv_relax_delete;
- else if (info->relax_pass == 2 && type == R_RISCV_ALIGN)
- relax_func = _bfd_riscv_relax_align;
- else
- continue;
data->relocs = relocs;
+2020-11-21 Nelson Chu <nelson.chu@sifive.com>
+
+ * emultempl/riscvelf.em (riscv_elf_before_allocation): Change
+ link_info.relax_pass from 3 to 4.
+ * testsuite/ld-riscv-elf/pcgp-relax.d: New testcase.
+ * testsuite/ld-riscv-elf/pcgp-relax.s: Likewise.
+ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
+
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* testsuite/ld-ctf/data-func-conflicted.d: Shrink the expected
ENABLE_RELAXATION;
}
- link_info.relax_pass = 3;
+ link_info.relax_pass = 4;
}
static void
if [istarget "riscv*-*-*"] {
run_dump_test "call-relax"
+ run_dump_test "pcgp-relax"
run_dump_test "c-lui"
run_dump_test "c-lui-2"
run_dump_test "disas-jalr"
--- /dev/null
+#source: pcgp-relax.s
+#ld: --relax
+#objdump: -d -Mno-aliases
+
+.*:[ ]+file format .*
+
+
+Disassembly of section \.text:
+
+0+[0-9a-f]+ <_start>:
+.*:[ ]+[0-9a-f]+[ ]+addi[ ]+a0,a0,[0-9]+
+.*:[ ]+[0-9a-f]+[ ]+jal[ ]+ra,[0-9a-f]+ <_start>
+.*:[ ]+[0-9a-f]+[ ]+addi[ ]+a1,gp,\-[0-9]+ # [0-9a-f]+ <data_g>
+.*:[ ]+[0-9a-f]+[ ]+addi[ ]+a2,gp,\-[0-9]+ # [0-9a-f]+ <data_g>
+.*:[ ]+[0-9a-f]+[ ]+addi[ ]+a3,tp,0 # 0 <data_t>
+.*:[ ]+[0-9a-f]+[ ]+auipc[ ]+a0,0x[0-9a-f]+
--- /dev/null
+ .text
+ .globl _start
+_start:
+ addi a0, a0, %pcrel_lo(.L2)
+
+ call _start
+.L1:
+ auipc a1, %pcrel_hi(data_g)
+ addi a1, a1, %pcrel_lo(.L1)
+
+ lui a2, %hi(data_g)
+ addi a2, a2, %lo(data_g)
+
+ lui a3, %tprel_hi(data_t)
+ add a3, a3, tp, %tprel_add(data_t)
+ addi a3, a3, %tprel_lo(data_t)
+
+.L2:
+ auipc a0, %pcrel_hi(data_g)
+
+ .data
+ .word 0x0
+ .globl data_g
+data_g:
+ .word 0x1
+
+ .section .tbss
+data_t:
+ .word 0x0