binutils-gdb/bfd/elfxx-riscv.h
Nelson Chu ebdcad3fdd RISC-V: Improve multiple relax passes problem.
According to the commit abd20cb637, 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.
2021-03-11 17:27:13 +08:00

114 lines
2.8 KiB
C

/* RISC-V ELF specific backend routines.
Copyright (C) 2011-2021 Free Software Foundation, Inc.
Contributed by Andrew Waterman (andrew@sifive.com).
Based on MIPS target.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING3. If not,
see <http://www.gnu.org/licenses/>. */
#include "elf/common.h"
#include "elf/internal.h"
#include "opcode/riscv.h"
extern reloc_howto_type *
riscv_reloc_name_lookup (bfd *, const char *);
extern reloc_howto_type *
riscv_reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
extern reloc_howto_type *
riscv_elf_rtype_to_howto (bfd *, unsigned int r_type);
/* The information of architecture attribute. */
struct riscv_subset_t
{
const char *name;
int major_version;
int minor_version;
struct riscv_subset_t *next;
};
typedef struct riscv_subset_t riscv_subset_t;
typedef struct
{
riscv_subset_t *head;
riscv_subset_t *tail;
} riscv_subset_list_t;
extern void
riscv_release_subset_list (riscv_subset_list_t *);
extern void
riscv_add_subset (riscv_subset_list_t *,
const char *,
int, int);
extern bfd_boolean
riscv_lookup_subset (const riscv_subset_list_t *,
const char *,
riscv_subset_t **);
typedef struct
{
riscv_subset_list_t *subset_list;
void (*error_handler) (const char *,
...) ATTRIBUTE_PRINTF_1;
unsigned *xlen;
void (*get_default_version) (const char *,
int *,
int *);
} riscv_parse_subset_t;
extern bfd_boolean
riscv_parse_subset (riscv_parse_subset_t *,
const char *);
extern const char *
riscv_supported_std_ext (void);
extern void
riscv_release_subset_list (riscv_subset_list_t *);
extern char *
riscv_arch_str (unsigned, const riscv_subset_list_t *);
extern size_t
riscv_estimate_digit (unsigned);
/* ISA extension prefixed name class. */
typedef enum riscv_isa_ext_class
{
RV_ISA_CLASS_S,
RV_ISA_CLASS_H,
RV_ISA_CLASS_Z,
RV_ISA_CLASS_X,
RV_ISA_CLASS_UNKNOWN
} riscv_isa_ext_class_t;
riscv_isa_ext_class_t
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 *);