[RFC,v2,1/5] RISC-V: Add Zcmt table-jump relocation definitions
Checks
Commit Message
Add internal relocation and opcode definitions and the opt-in linker
parameter. Use the upstream registered relaxation infrastructure rather
than a numeric pass enumeration.
bfd/ChangeLog:
* elfxx-riscv.c: Add TABLE_JUMP howto.
* elfxx-riscv.h (struct riscv_elf_params): Add relax_zcmt field.
include/ChangeLog:
* elf/riscv.h (R_RISCV_TABLE_JUMP): New reloc number.
(RISCV_TABLE_JUMP_BASE_SYMBOL): New symbol name.
(TABLE_JUMP_SEC_NAME): New section name.
* opcode/riscv.h (ZCMT_TOTAL_ENTRIES): New Zcmt constants.
(ZCMT_JT_BEGIN): Ditto.
(ZCMT_JT_END): Ditto.
(ZCMT_JT_NUM_ENTRIES): Ditto.
(ZCMT_JALT_BEGIN): Ditto.
(ZCMT_JALT_END): Ditto.
(ZCMT_JALT_NUM_ENTRIES): Ditto.
---
bfd/elfxx-riscv.c | 4 ++++
bfd/elfxx-riscv.h | 2 ++
include/elf/riscv.h | 5 +++++
include/opcode/riscv.h | 9 +++++++++
4 files changed, 20 insertions(+)
Comments
> diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
> index deb8f8fe32f..5d3e27406e3 100644
> --- a/bfd/elfxx-riscv.c
> +++ b/bfd/elfxx-riscv.c
> @@ -961,6 +961,10 @@ static const reloc_howto_type howto_table_internal[] =
> 0, /* src_mask */
> ENCODE_STYPE_IMM (-1U), /* dst_mask */
> false), /* pcrel_offset */
> +
> + /* R_RISCV_TABLE_JUMP is linker-internal. It is consumed before final
> + relocations are emitted and must never become psABI-visible. */
> + EMPTY_HOWTO (0),
This part can be dropped.
> };
>
> /* A mapping from BFD reloc types to RISC-V ELF reloc types. */
> diff --git a/bfd/elfxx-riscv.h b/bfd/elfxx-riscv.h
> index ea47b499805..653a6be70e3 100644
> --- a/bfd/elfxx-riscv.h
> +++ b/bfd/elfxx-riscv.h
> @@ -44,6 +44,8 @@ struct riscv_elf_params
> bool relax_gp;
> /* Whether to check if SUB_ULEB128 relocation has non-zero addend. */
> bool check_uleb128;
> + /* Whether to relax code sequences for Zcmt. */
> + bool relax_zcmt;
Move this to "ld: Add RISC-V --relax-... option"
@@ -961,6 +961,10 @@ static const reloc_howto_type howto_table_internal[] =
0, /* src_mask */
ENCODE_STYPE_IMM (-1U), /* dst_mask */
false), /* pcrel_offset */
+
+ /* R_RISCV_TABLE_JUMP is linker-internal. It is consumed before final
+ relocations are emitted and must never become psABI-visible. */
+ EMPTY_HOWTO (0),
};
/* A mapping from BFD reloc types to RISC-V ELF reloc types. */
@@ -44,6 +44,8 @@ struct riscv_elf_params
bool relax_gp;
/* Whether to check if SUB_ULEB128 relocation has non-zero addend. */
bool check_uleb128;
+ /* Whether to relax code sequences for Zcmt. */
+ bool relax_zcmt;
};
extern void riscv_elf32_set_options (struct bfd_link_info *,
@@ -105,6 +105,7 @@ END_RELOC_NUMBERS (R_RISCV_max)
#define R_RISCV_GPREL_S (R_RISCV_max + 4)
#define R_RISCV_TPREL_I (R_RISCV_max + 5)
#define R_RISCV_TPREL_S (R_RISCV_max + 6)
+#define R_RISCV_TABLE_JUMP (R_RISCV_max + 7)
/* Processor specific flags for the ELF header e_flags field. */
@@ -132,6 +133,10 @@ END_RELOC_NUMBERS (R_RISCV_max)
/* The name of the global pointer symbol. */
#define RISCV_GP_SYMBOL "__global_pointer$"
+#define RISCV_TABLE_JUMP_BASE_SYMBOL "__jvt_base$"
+
+#define TABLE_JUMP_SEC_NAME ".riscv.jvt"
+
/* Processor specific dynamic array tags. */
#define DT_RISCV_VARIANT_CC (DT_LOPROC + 1)
@@ -746,6 +746,15 @@ struct riscv_opcode
disassembler, and requires special treatment by the assembler. */
#define INSN_MACRO 0xffffffff
+/* Define Zcmt jump table constants. */
+#define ZCMT_TOTAL_ENTRIES 256
+#define ZCMT_JT_BEGIN 0
+#define ZCMT_JT_END 31
+#define ZCMT_JT_NUM_ENTRIES (ZCMT_JT_END - ZCMT_JT_BEGIN + 1)
+#define ZCMT_JALT_BEGIN (ZCMT_JT_END + 1)
+#define ZCMT_JALT_END (ZCMT_TOTAL_ENTRIES - 1)
+#define ZCMT_JALT_NUM_ENTRIES (ZCMT_JALT_END - ZCMT_JALT_BEGIN + 1)
+
/* This is a list of macro expanded instructions. */
enum
{