[RFC PATCH 1/5] RISC-V: Add Zcmt table-jump relocation definitions

Jiawei <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
Add a ZCMT table jump relaxation pass in the linker, the ELF relocation
number, opcode constants, and RISC-V BFD parameter
state needed by linker table-jump relaxation.

bfd/ChangeLog:

	* elfxx-riscv.c: Add TABLE_JUMP howto.
	* elfxx-riscv.h (struct riscv_elf_params): Add relax_zcmt field.
	(enum riscv_relax_pass): New enum.
	(enum jvt_profiling_trip): Ditto.

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      | 21 +++++++++++++++++++++
 include/elf/riscv.h    |  5 +++++
 include/opcode/riscv.h |  9 +++++++++
 4 files changed, 39 insertions(+)

diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index 961c44a9206..615f644d336 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),
 };
 
 /* 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 e57e90462f8..6adf1d6d0ca 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;
 };
 
 extern void riscv_elf32_set_options (struct bfd_link_info *,
@@ -101,6 +103,25 @@ typedef struct
   bool check_unknown_prefixed_ext;
 } riscv_parse_subset_t;
 
+/* List the relaxation passes.  */
+enum riscv_relax_pass
+{
+  RELAX_PASS_SHORTEN_LUI_CALL_TRREL_PCREL,
+  RELAX_PASS_CAN_BE_DISABLED = RELAX_PASS_SHORTEN_LUI_CALL_TRREL_PCREL,
+  RELAX_PASS_TABLE_JUMP_PROFILING,
+  RELAX_PASS_ALIGNMENT,
+  RELAX_PASS_END,
+};
+
+/* Trips for jvt profiling relaxation pass.  */
+enum jvt_profiling_trip
+{
+  JVT_PROFILING_RECORD_SYM,
+  JVT_PROFILING_RANK,
+  JVT_PROFILING_DETERMINE,
+  JVT_PROFILING_TRIM,
+};
+
 extern bool
 riscv_parse_subset (riscv_parse_subset_t *,
 		    const char *);
diff --git a/include/elf/riscv.h b/include/elf/riscv.h
index f6ca3d4acd8..02a0184b7ee 100644
--- a/include/elf/riscv.h
+++ b/include/elf/riscv.h
@@ -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)
 
diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h
index b4587976ea2..5e1157e3e50 100644
--- a/include/opcode/riscv.h
+++ b/include/opcode/riscv.h
@@ -698,6 +698,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
 {
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.