aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfxx-riscv.h
diff options
context:
space:
mode:
authorNelson Chu <nelson.chu@sifive.com>2020-12-18 10:59:41 +0800
committerNelson Chu <nelson.chu@sifive.com>2021-03-11 17:27:13 +0800
commitebdcad3fddf6ec21f6d4dcc702379a12718cf0c4 (patch)
tree82686d88a94b9113de754458ef5ecf8e9b6806d6 /bfd/elfxx-riscv.h
parent0b9f3e546384710ccb158b2a5137ee916158580d (diff)
downloadgdb-ebdcad3fddf6ec21f6d4dcc702379a12718cf0c4.zip
gdb-ebdcad3fddf6ec21f6d4dcc702379a12718cf0c4.tar.gz
gdb-ebdcad3fddf6ec21f6d4dcc702379a12718cf0c4.tar.bz2
RISC-V: Improve multiple relax passes problem.
According to the commit abd20cb637008da9d32018b4b03973e119388a0a, an intersting thing is that - the more relax passes, the more chances of relaxations are reduced [1]. Originally, we set the boolean `again` to TRUE once the code is actually deleted, and then we run the relaxations repeatedly if `again` is still TRUE. But `again` only works for the relax pass itself, and won't affect others. That is - we can not use `again` to re-run the relax pass when we already enter into the following passes (can not run the relax passes backwards). Besides, we must seperate the PCREL relaxations into two relax passes for some reasons [2], it make us lose some relax opportunities. This patch try to fix the problem, and the basic idea was come from Jim Wilson - we use a new boolean, restart_relax, to determine if we need to run the whole relax passes again from 0 to 2. Once we have deleted the code between relax pass 0 to 2, the restart_relax will be set to TRUE, we should run the whole relaxations again to give them more chances to shorten the code. We will only enter into the relax pass 3 when the restart_relax is FALSE, since we can't relax anything else once we start to handle the alignments. I have passed the gcc/binutils regressions by riscv-gnu-toolchain, and looks fine for now. [1] https://sourceware.org/pipermail/binutils/2020-November/114223.html [2] https://sourceware.org/pipermail/binutils/2020-November/114235.html bfd/ * elfnn-riscv.c (riscv_elf_link_hash_table): New boolean restart_relax, used to check if we need to run the whole relaxations from relax pass 0 to 2 again. (riscv_elf_link_hash_table_create): Init restart_relax to FALSE. (_bfd_riscv_relax_align): Remove obsolete sec_flg0 set. (_bfd_riscv_relax_delete): Set again to TRUE if we do delete the code. (bfd_elfNN_riscv_restart_relax_sections): New function. Called by after_allocation to check if we need to run the whole relaxations again. (_bfd_riscv_relax_section): We will only enter into the relax pass 3 when the restart_relax is FALSE; At last set restart_relax to TRUE if again is TRUE, too. * elfxx-riscv.h (bfd_elf32_riscv_restart_relax_sections): Declaration. (bfd_elf64_riscv_restart_relax_sections): Likewise. ld/ * emultempl/riscvelf.em (after_allocation): Run ldelf_map_segments many times if riscv_restart_relax_sections returns TRUE. * testsuite/ld-riscv-elf/restart-relax.d: New testcase. Before applying this patch, the call won't be relaxed to jal; But now we have more chances to do relaxations. * testsuite/ld-riscv-elf/restart-relax.s: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
Diffstat (limited to 'bfd/elfxx-riscv.h')
-rw-r--r--bfd/elfxx-riscv.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/bfd/elfxx-riscv.h b/bfd/elfxx-riscv.h
index a7d348c..a676d5c 100644
--- a/bfd/elfxx-riscv.h
+++ b/bfd/elfxx-riscv.h
@@ -105,3 +105,9 @@ riscv_get_prefix_class (const char *);
extern int
riscv_compare_subsets (const char *, const char *);
+
+extern bfd_boolean
+bfd_elf32_riscv_restart_relax_sections (struct bfd_link_info *);
+
+extern bfd_boolean
+bfd_elf64_riscv_restart_relax_sections (struct bfd_link_info *);