+2019-11-12 Jim Wilson <jimw@sifive.com>
+
+ PR 25181
+ * elfnn-riscv.c (_bfd_riscv_relax_call): Always add max_alignment to
+ foff. If sym_sec->output_section and sec->output_section are the same
+ and not *ABS* then set max_alignment to that section's alignment.
+
2019-11-07 Alan Modra <amodra@gmail.com>
* cpu-cr16c.c: Delete.
int rd, r_type, len = 4, rvc = elf_elfheader (abfd)->e_flags & EF_RISCV_RVC;
/* If the call crosses section boundaries, an alignment directive could
- cause the PC-relative offset to later increase. */
- if (VALID_UJTYPE_IMM (foff) && sym_sec->output_section != sec->output_section)
- foff += (foff < 0 ? -max_alignment : max_alignment);
+ cause the PC-relative offset to later increase, so we need to add in the
+ max alignment of any section inclusive from the call to the target.
+ Otherwise, we only need to use the alignment of the current section. */
+ if (VALID_UJTYPE_IMM (foff))
+ {
+ if (sym_sec->output_section == sec->output_section
+ && sym_sec->output_section != bfd_abs_section_ptr)
+ max_alignment = (bfd_vma) 1 << sym_sec->output_section->alignment_power;
+ foff += (foff < 0 ? -max_alignment : max_alignment);
+ }
/* See if this function call can be shortened. */
if (!VALID_UJTYPE_IMM (foff) && !(!bfd_link_pic (link_info) && near_zero))
+2019-11-12 Jim Wilson <jimw@sifive.com>
+
+ PR 25181
+ * testsuite/ld-riscv-elf/call-relax-0.s: New file.
+ * testsuite/ld-riscv-elf/call-relax-1.s: New file.
+ * testsuite/ld-riscv-elf/call-relax-2.s: New file.
+ * testsuite/ld-riscv-elf/call-relax-3.s: New file.
+ * testsuite/ld-riscv-elf/call-relax.d: New test.
+ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run call-relax test.
+
2019-11-08 Alan Modra <amodra@gmail.com>
* emulparams/aarch64elf.sh: Revert 2019-11-05 change.