@@ -1,3 +1,17 @@
+2026-03-24 wengliqin <liqin.weng@spacemit.com>
+
+ * reloc.c (BFD_RELOC_RISCV_REGREL12_I, BFD_RELOC_RISCV_REGREL12_S,
+ BFD_RELOC_RISCV_REGREL_LO12_I, BFD_RELOC_RISCV_REGREL_LO12_S,
+ BFD_RELOC_RISCV_REGREL_ADD, BFD_RELOC_RISCV_REGREL_SHXADD): New
+ relocation types.
+ * bfd-in2.h: Regenerate.
+ * libbfd.h: Regenerate.
+ * elfnn-riscv.c (perform_relocation): Add support for new REGREL
+ relocations.
+ (riscv_elf_relocate_section): Handle REGREL relocations for global
+ array accesses with non-constant indices.
+ * elfxx-riscv.c: Define relocation information for new REGREL types.
+
2025-09-16 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* config.bfd <powerpc-*-solaris2*>: Remove.
@@ -5373,8 +5373,8 @@ enum bfd_reloc_code_real
BFD_RELOC_RISCV_PCREL_LO12_S,
BFD_RELOC_RISCV_LO12_I,
BFD_RELOC_RISCV_LO12_S,
- BFD_RELOC_RISCV_GPREL12_I,
- BFD_RELOC_RISCV_GPREL12_S,
+ BFD_RELOC_RISCV_REGREL12_I,
+ BFD_RELOC_RISCV_REGREL12_S,
BFD_RELOC_RISCV_TPREL_HI20,
BFD_RELOC_RISCV_TPREL_LO12_I,
BFD_RELOC_RISCV_TPREL_LO12_S,
@@ -5416,6 +5416,10 @@ enum bfd_reloc_code_real
BFD_RELOC_RISCV_32_PCREL,
BFD_RELOC_RISCV_SET_ULEB128,
BFD_RELOC_RISCV_SUB_ULEB128,
+ BFD_RELOC_RISCV_REGREL_LO12_I,
+ BFD_RELOC_RISCV_REGREL_LO12_S,
+ BFD_RELOC_RISCV_REGREL_ADD,
+ BFD_RELOC_RISCV_REGREL_SHXADD,
/* Renesas RL78 Relocations. */
BFD_RELOC_RL78_NEG8,
@@ -1999,7 +1999,9 @@ perform_relocation (const reloc_howto_type *howto,
break;
case R_RISCV_LO12_I:
+ case R_RISCV_REGREL_LO12_I:
case R_RISCV_GPREL_I:
+ case INTERNAL_R_RISCV_REGREL_LO12_I:
case R_RISCV_TPREL_LO12_I:
case R_RISCV_TPREL_I:
case R_RISCV_PCREL_LO12_I:
@@ -2009,7 +2011,9 @@ perform_relocation (const reloc_howto_type *howto,
break;
case R_RISCV_LO12_S:
+ case R_RISCV_REGREL_LO12_S:
case R_RISCV_GPREL_S:
+ case INTERNAL_R_RISCV_REGREL_LO12_S:
case R_RISCV_TPREL_LO12_S:
case R_RISCV_TPREL_S:
case R_RISCV_PCREL_LO12_S:
@@ -2112,6 +2116,12 @@ perform_relocation (const reloc_howto_type *howto,
return bfd_reloc_ok;
}
+ case R_RISCV_REGREL_ADD:
+ case R_RISCV_REGREL_SHXADD:
+ case INTERNAL_R_RISCV_REGREL_ADD:
+ case INTERNAL_R_RISCV_REGREL_SHXADD:
+ break;
+
case R_RISCV_32:
case R_RISCV_64:
case R_RISCV_ADD8:
@@ -2722,6 +2732,10 @@ riscv_elf_relocate_section (bfd *output_bfd,
case R_RISCV_HI20:
case R_RISCV_LO12_I:
case R_RISCV_LO12_S:
+ case R_RISCV_REGREL_LO12_I:
+ case R_RISCV_REGREL_LO12_S:
+ case R_RISCV_REGREL_ADD:
+ case R_RISCV_REGREL_SHXADD:
goto do_relocation;
case R_RISCV_PCREL_HI20:
@@ -2788,6 +2802,10 @@ riscv_elf_relocate_section (bfd *output_bfd,
case R_RISCV_RVC_LUI:
case R_RISCV_LO12_I:
case R_RISCV_LO12_S:
+ case R_RISCV_REGREL_LO12_I:
+ case R_RISCV_REGREL_LO12_S:
+ case R_RISCV_REGREL_ADD:
+ case R_RISCV_REGREL_SHXADD:
case R_RISCV_SET6:
case R_RISCV_SET8:
case R_RISCV_SET16:
@@ -3089,6 +3107,30 @@ riscv_elf_relocate_section (bfd *output_bfd,
break;
}
+ case INTERNAL_R_RISCV_REGREL_LO12_I:
+ case INTERNAL_R_RISCV_REGREL_LO12_S:
+ {
+ bfd_vma gp = riscv_global_pointer_value (info);
+ if (VALID_ITYPE_IMM (relocation + rel->r_addend - gp))
+ {
+ bfd_vma insn = bfd_getl32 (contents + rel->r_offset);
+ rel->r_addend -= gp;
+ bfd_putl32 (insn, contents + rel->r_offset);
+ }
+ else
+ r = bfd_reloc_overflow;
+ break;
+ }
+
+ case INTERNAL_R_RISCV_REGREL_ADD:
+ case INTERNAL_R_RISCV_REGREL_SHXADD:
+ {
+ bfd_vma insn = bfd_getl32 (contents + rel->r_offset);
+ insn = (insn & ~(OP_MASK_RS2 << OP_SH_RS2)) | (X_GP << OP_SH_RS2);
+ bfd_putl32 (insn, contents + rel->r_offset);
+ break;
+ }
+
case R_RISCV_PCREL_HI20:
absolute = riscv_zero_pcrel_hi_reloc (rel, info, pc, &relocation,
contents, howto);
@@ -5148,6 +5190,22 @@ _bfd_riscv_relax_lui (bfd *abfd,
rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_S);
return true;
+ case R_RISCV_REGREL_LO12_I:
+ rel->r_info = ELFNN_R_INFO (sym, INTERNAL_R_RISCV_REGREL_LO12_I);
+ return true;
+
+ case R_RISCV_REGREL_LO12_S:
+ rel->r_info = ELFNN_R_INFO (sym, INTERNAL_R_RISCV_REGREL_LO12_S);
+ return true;
+
+ case R_RISCV_REGREL_ADD:
+ rel->r_info = ELFNN_R_INFO (sym, INTERNAL_R_RISCV_REGREL_ADD);
+ return true;
+
+ case R_RISCV_REGREL_SHXADD:
+ rel->r_info = ELFNN_R_INFO (sym, INTERNAL_R_RISCV_REGREL_SHXADD);
+ return true;
+
case R_RISCV_HI20:
/* Delete unnecessary LUI and reuse the reloc. */
*again = true;
@@ -5539,7 +5597,11 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
relax_func = _bfd_riscv_relax_call;
else if (type == R_RISCV_HI20
|| type == R_RISCV_LO12_I
- || type == R_RISCV_LO12_S)
+ || type == R_RISCV_LO12_S
+ || type == R_RISCV_REGREL_LO12_I
+ || type == R_RISCV_REGREL_LO12_S
+ || type == R_RISCV_REGREL_ADD
+ || type == R_RISCV_REGREL_SHXADD)
relax_func = _bfd_riscv_relax_lui;
else if (type == R_RISCV_TPREL_HI20
|| type == R_RISCV_TPREL_ADD
@@ -876,7 +876,70 @@ static const reloc_howto_type howto_table[] =
false, /* partial_inplace */
0, /* src_mask */
ENCODE_ITYPE_IMM (-1U), /* dst_mask */
- false) /* pcrel_offset */
+ false), /* pcrel_offset */
+
+ /* Global array non-constant subscript addressing */
+ HOWTO (R_RISCV_REGREL_LO12_I, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 32, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_RISCV_REGREL_LO12_I", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ ENCODE_ITYPE_IMM (-1U), /* dst_mask */
+ false), /* pcrel_offset */
+
+ HOWTO (R_RISCV_REGREL_LO12_S, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 32, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_RISCV_REGREL_LO12_S", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ ENCODE_STYPE_IMM (-1U), /* dst_mask */
+ false), /* pcrel_offset */
+
+ HOWTO (R_RISCV_REGREL_ADD, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 32, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_RISCV_REGREL_ADD", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ false), /* pcrel_offset */
+
+ HOWTO (R_RISCV_REGREL_SHXADD, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 32, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_RISCV_REGREL_SHXADD", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ false), /* pcrel_offset */
+
+ EMPTY_HOWTO (70),
+ EMPTY_HOWTO (71),
+ EMPTY_HOWTO (72),
+ EMPTY_HOWTO (73),
+
};
static const reloc_howto_type howto_table_internal[] =
@@ -961,6 +1024,63 @@ static const reloc_howto_type howto_table_internal[] =
0, /* src_mask */
ENCODE_STYPE_IMM (-1U), /* dst_mask */
false), /* pcrel_offset */
+
+ /* Global array non-constant subscript addressing */
+ HOWTO (INTERNAL_R_RISCV_REGREL_LO12_I, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 32, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "INTERNAL_R_RISCV_REGREL_LO12_I", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ ENCODE_ITYPE_IMM (-1U), /* dst_mask */
+ false), /* pcrel_offset */
+
+ HOWTO (INTERNAL_R_RISCV_REGREL_LO12_S, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 32, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "INTERNAL_R_RISCV_REGREL_LO12_S", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ ENCODE_STYPE_IMM (-1U), /* dst_mask */
+ false), /* pcrel_offset */
+
+ HOWTO (INTERNAL_R_RISCV_REGREL_ADD, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 32, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "INTERNAL_R_RISCV_REGREL_ADD", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ false), /* pcrel_offset */
+
+ HOWTO (INTERNAL_R_RISCV_REGREL_SHXADD, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 32, /* bitsize */
+ false, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "INTERNAL_R_RISCV_REGREL_SHXADD", /* name */
+ false, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ false) /* pcrel_offset */
};
/* A mapping from BFD reloc types to RISC-V ELF reloc types. */
@@ -1023,6 +1143,10 @@ static const struct elf_reloc_map riscv_reloc_map[] =
{ BFD_RELOC_RISCV_32_PCREL, R_RISCV_32_PCREL },
{ BFD_RELOC_RISCV_SET_ULEB128, R_RISCV_SET_ULEB128 },
{ BFD_RELOC_RISCV_SUB_ULEB128, R_RISCV_SUB_ULEB128 },
+ { BFD_RELOC_RISCV_REGREL_LO12_I, R_RISCV_REGREL_LO12_I},
+ { BFD_RELOC_RISCV_REGREL_LO12_S, R_RISCV_REGREL_LO12_S},
+ { BFD_RELOC_RISCV_REGREL_ADD, R_RISCV_REGREL_ADD},
+ { BFD_RELOC_RISCV_REGREL_SHXADD, R_RISCV_REGREL_SHXADD},
};
struct riscv_profiles
@@ -2402,6 +2402,10 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
"BFD_RELOC_RISCV_TLSDESC_LOAD_LO12",
"BFD_RELOC_RISCV_TLSDESC_ADD_LO12",
"BFD_RELOC_RISCV_TLSDESC_CALL",
+ "BFD_RELOC_RISCV_REGREL_LO12_I",
+ "BFD_RELOC_RISCV_REGREL_LO12_S",
+ "BFD_RELOC_RISCV_REGREL_ADD",
+ "BFD_RELOC_RISCV_REGREL_SHXADD",
"BFD_RELOC_RISCV_ALIGN",
"BFD_RELOC_RISCV_RVC_BRANCH",
"BFD_RELOC_RISCV_RVC_JUMP",
@@ -4861,6 +4861,14 @@ ENUMX
BFD_RELOC_RISCV_TLSDESC_ADD_LO12
ENUMX
BFD_RELOC_RISCV_TLSDESC_CALL
+ENUMX
+ BFD_RELOC_RISCV_REGREL_LO12_I
+ENUMX
+ BFD_RELOC_RISCV_REGREL_LO12_S
+ENUMX
+ BFD_RELOC_RISCV_REGREL_ADD
+ENUMX
+ BFD_RELOC_RISCV_REGREL_SHXADD
ENUMX
BFD_RELOC_RISCV_ALIGN
ENUMX
@@ -1,3 +1,13 @@
+2026-03-24 wengliqin <liqin.weng@spacemit.com>
+
+ * config/tc-riscv.c: Add support for RISC-V REGREL relocations.
+ * testsuite/gas/riscv/regrel-add.s: New test for REGREL_ADD.
+ * testsuite/gas/riscv/regrel-add.d: Corresponding test output.
+ * testsuite/gas/riscv/regrel-add.l: Corresponding test output.
+ * testsuite/gas/riscv/regrel-shxadd.s: New test for REGREL_SHXADD.
+ * testsuite/gas/riscv/regrel-shxadd.d: Corresponding test output.
+ * testsuite/gas/riscv/regrel-shxadd.l: Corresponding test output.
+
2025-09-16 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* NEWS: Mention Solaris/PowerPC removal.
@@ -1957,6 +1957,13 @@ riscv_apply_const_reloc (bfd_reloc_code_real_type reloc_type, bfd_vma value)
case BFD_RELOC_RISCV_LO12_I:
return ENCODE_ITYPE_IMM (value);
+
+ case BFD_RELOC_RISCV_REGREL_LO12_S:
+ return ENCODE_STYPE_IMM (value);
+
+ case BFD_RELOC_RISCV_REGREL_LO12_I:
+ return ENCODE_ITYPE_IMM (value);
+
default:
abort ();
}
@@ -2021,7 +2028,9 @@ append_insn (struct riscv_cl_insn *ip, expressionS *address_expr,
if (reloc_type == BFD_RELOC_RISCV_HI20
|| reloc_type == BFD_RELOC_RISCV_PCREL_HI20
|| reloc_type == BFD_RELOC_RISCV_TPREL_HI20
- || reloc_type == BFD_RELOC_RISCV_TPREL_ADD)
+ || reloc_type == BFD_RELOC_RISCV_TPREL_ADD
+ || reloc_type == BFD_RELOC_RISCV_REGREL_ADD
+ || reloc_type == BFD_RELOC_RISCV_REGREL_SHXADD)
{
frag_wane (frag_now);
frag_new (0);
@@ -2454,6 +2463,7 @@ static const struct percent_op_match percent_op_utype[] =
static const struct percent_op_match percent_op_itype[] =
{
{"lo", BFD_RELOC_RISCV_LO12_I},
+ {"regrel_lo", BFD_RELOC_RISCV_REGREL_LO12_I},
{"tprel_lo", BFD_RELOC_RISCV_TPREL_LO12_I},
{"pcrel_lo", BFD_RELOC_RISCV_PCREL_LO12_I},
{"tlsdesc_load_lo", BFD_RELOC_RISCV_TLSDESC_LOAD_LO12},
@@ -2464,6 +2474,7 @@ static const struct percent_op_match percent_op_itype[] =
static const struct percent_op_match percent_op_stype[] =
{
{"lo", BFD_RELOC_RISCV_LO12_S},
+ {"regrel_lo", BFD_RELOC_RISCV_REGREL_LO12_S},
{"tprel_lo", BFD_RELOC_RISCV_TPREL_LO12_S},
{"pcrel_lo", BFD_RELOC_RISCV_PCREL_LO12_S},
{0, 0}
@@ -2473,6 +2484,8 @@ static const struct percent_op_match percent_op_relax_only[] =
{
{"tlsdesc_call", BFD_RELOC_RISCV_TLSDESC_CALL},
{"tprel_add", BFD_RELOC_RISCV_TPREL_ADD},
+ {"regrel_add", BFD_RELOC_RISCV_REGREL_ADD},
+ {"regrel_shxadd", BFD_RELOC_RISCV_REGREL_SHXADD},
{0, 0}
};
@@ -3631,16 +3644,25 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
continue;
case 'j': /* Sign-extended immediate. */
- p = percent_op_itype;
- *imm_reloc = BFD_RELOC_RISCV_LO12_I;
+ p = percent_op_itype;
+ if (strncmp(asarg, "%regrel_lo", 9) == 0)
+ *imm_reloc = BFD_RELOC_RISCV_REGREL_LO12_I;
+ else
+ *imm_reloc = BFD_RELOC_RISCV_LO12_I;
goto alu_op;
case 'q': /* Store displacement. */
- p = percent_op_stype;
- *imm_reloc = BFD_RELOC_RISCV_LO12_S;
+ p = percent_op_stype;
+ if (strncmp(asarg, "%regrel_lo", 9) == 0)
+ *imm_reloc = BFD_RELOC_RISCV_REGREL_LO12_S;
+ else
+ *imm_reloc = BFD_RELOC_RISCV_LO12_S;
goto load_store;
case 'o': /* Load displacement. */
- p = percent_op_itype;
- *imm_reloc = BFD_RELOC_RISCV_LO12_I;
+ p = percent_op_itype;
+ if (strncmp(asarg, "%regrel_lo", 9) == 0)
+ *imm_reloc = BFD_RELOC_RISCV_REGREL_LO12_I;
+ else
+ *imm_reloc = BFD_RELOC_RISCV_LO12_I;
goto load_store;
case '1':
/* This is used for TLS relocations that acts as relaxation
@@ -4686,6 +4708,8 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg)
case BFD_RELOC_RISCV_HI20:
case BFD_RELOC_RISCV_LO12_I:
case BFD_RELOC_RISCV_LO12_S:
+ case BFD_RELOC_RISCV_REGREL_LO12_I:
+ case BFD_RELOC_RISCV_REGREL_LO12_S:
bfd_putl32 (riscv_apply_const_reloc (fixP->fx_r_type, *valP)
| bfd_getl32 (buf), buf);
if (fixP->fx_addsy == NULL)
@@ -4693,6 +4717,11 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg)
relaxable = true;
break;
+ case BFD_RELOC_RISCV_REGREL_ADD:
+ case BFD_RELOC_RISCV_REGREL_SHXADD:
+ relaxable = true;
+ break;
+
case BFD_RELOC_RISCV_GOT_HI20:
/* R_RISCV_GOT_HI20 and the following R_RISCV_LO12_I are relaxable
only if it is created as a result of la or lga assembler macros. */
new file mode 100644
@@ -0,0 +1,3 @@
+#as: -march=rv32ia
+#source regrel-add.s
+#error_output: regrel-add.l
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,3 @@
+.*: Assembler messages:
+.*: Error: illegal operands `amoadd.w x8,x9,%regrel_add\(sym\)\(x10\)'
+.*: Error: illegal operands `add a5,a5,a0,0'
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,12 @@
+ # Don't allow regrel_add in amoadd.
+.option arch, +a
+ amoadd.w x8,x9,%regrel_add(sym)(x10)
+ # Do require regrel_add in 4-operand add.
+ add a5,a5,a0,0
+ .globl sym
+ .section .tbss,"awT",@nobits
+ .align 2
+ .type sym, @object
+ .size sym, 4
+sym:
+ .zero 4
new file mode 100644
@@ -0,0 +1,3 @@
+#as: -march=rv64imafdc_zicsr_zifencei_zaamo_zalrsc_zba_zbb_zbc_zbs
+#source regrel-shxadd.s
+#error_output: regrel-shxadd.l
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,9 @@
+.*: Assembler messages:
+.*: Error: illegal operands `amoadd.w x8,x9,%regrel_add\(sym\)\(x10\)'
+.*: Error: illegal operands `sh1add a0,a0,a5,0'
+.*: Error: illegal operands `sh1add.uw a0,a0,a5,0'
+.*: Error: illegal operands `sh2add a0,a0,a5,0'
+.*: Error: illegal operands `sh2add.uw a0,a0,a5,0'
+.*: Error: illegal operands `sh3add a0,a0,a5,0'
+.*: Error: illegal operands `sh3add.uw a0,a0,a5,0'
+.*: Error: illegal operands `add.uw a0,a0,a5,0'
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,18 @@
+.option arch, +a
+ # Don't allow regrel_add in amoadd.
+ amoadd.w x8,x9,%regrel_add(sym)(x10)
+ # Do require regrel_add in 4-operand add.
+ sh1add a0,a0,a5,0
+ sh1add.uw a0,a0,a5,0
+ sh2add a0,a0,a5,0
+ sh2add.uw a0,a0,a5,0
+ sh3add a0,a0,a5,0
+ sh3add.uw a0,a0,a5,0
+ add.uw a0,a0,a5,0
+ .globl sym
+ .section .tbss,"awT",@nobits
+ .align 2
+ .type sym, @object
+ .size sym, 4
+sym:
+ .zero 4
@@ -1,3 +1,7 @@
+2026-03-24 wengliqin <liqin.weng@spacemit.com>
+
+ * elf/riscv.h: Define new RISC-V REGREL relocation macros.
+
2025-07-13 Nick Clifton <nickc@redhat.com>
* 2.45 Branch point.
@@ -95,6 +95,14 @@ START_RELOC_NUMBERS (elf_riscv_reloc_type)
RELOC_NUMBER (R_RISCV_TLSDESC_LOAD_LO12, 63)
RELOC_NUMBER (R_RISCV_TLSDESC_ADD_LO12, 64)
RELOC_NUMBER (R_RISCV_TLSDESC_CALL, 65)
+ RELOC_NUMBER (R_RISCV_REGREL_LO12_I, 77)
+ RELOC_NUMBER (R_RISCV_REGREL_LO12_S, 78)
+ RELOC_NUMBER (R_RISCV_REGREL_ADD, 79)
+ RELOC_NUMBER (R_RISCV_REGREL_SHXADD, 80)
+ RELOC_NUMBER (INTERNAL_R_RISCV_REGREL_LO12_I, 81)
+ RELOC_NUMBER (INTERNAL_R_RISCV_REGREL_LO12_S, 82)
+ RELOC_NUMBER (INTERNAL_R_RISCV_REGREL_ADD, 83)
+ RELOC_NUMBER (INTERNAL_R_RISCV_REGREL_SHXADD, 84)
END_RELOC_NUMBERS (R_RISCV_max)
/* Internal relocations used exclusively by the relaxation pass. */
@@ -105,6 +113,10 @@ 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 INTERNAL_R_RISCV_REGREL_LO12_I (R_RISCV_max + 7)
+#define INTERNAL_R_RISCV_REGREL_LO12_S (R_RISCV_max + 8)
+#define INTERNAL_R_RISCV_REGREL_ADD (R_RISCV_max + 9)
+#define INTERNAL_R_RISCV_REGREL_SHXADD (R_RISCV_max + 10)
/* Processor specific flags for the ELF header e_flags field. */
@@ -1,3 +1,7 @@
+2026-03-24 wengliqin <liqin.weng@spacemit.com>
+
+ * riscv-opc.c: Update relocation definitions for new REGREL types.
+
2025-07-13 Nick Clifton <nickc@redhat.com>
* 2.45 Branch point.
@@ -1378,16 +1378,23 @@ const struct riscv_opcode riscv_opcodes[] =
{"rorw", 64, INSN_CLASS_ZBB_OR_ZBKB, "d,s,<", MATCH_RORIW, MASK_RORIW, match_opcode, INSN_ALIAS },
/* Zba instructions. */
-{"sh1add", 0, INSN_CLASS_ZBA, "d,s,t", MATCH_SH1ADD, MASK_SH1ADD, match_opcode, 0 },
-{"sh2add", 0, INSN_CLASS_ZBA, "d,s,t", MATCH_SH2ADD, MASK_SH2ADD, match_opcode, 0 },
-{"sh3add", 0, INSN_CLASS_ZBA, "d,s,t", MATCH_SH3ADD, MASK_SH3ADD, match_opcode, 0 },
-{"sh1add.uw", 64, INSN_CLASS_ZBA, "d,s,t", MATCH_SH1ADD_UW, MASK_SH1ADD_UW, match_opcode, 0 },
-{"sh2add.uw", 64, INSN_CLASS_ZBA, "d,s,t", MATCH_SH2ADD_UW, MASK_SH2ADD_UW, match_opcode, 0 },
-{"sh3add.uw", 64, INSN_CLASS_ZBA, "d,s,t", MATCH_SH3ADD_UW, MASK_SH3ADD_UW, match_opcode, 0 },
+{"sh1add", 0, INSN_CLASS_ZBA, "d,s,t", MATCH_SH1ADD, MASK_SH1ADD, match_opcode, 0 },
+{"sh1add", 0, INSN_CLASS_ZBA, "d,s,t,1", MATCH_SH1ADD, MASK_SH1ADD, match_opcode, 0 },
+{"sh2add", 0, INSN_CLASS_ZBA, "d,s,t", MATCH_SH2ADD, MASK_SH2ADD, match_opcode, 0 },
+{"sh2add", 0, INSN_CLASS_ZBA, "d,s,t,1", MATCH_SH2ADD, MASK_SH2ADD, match_opcode, 0 },
+{"sh3add", 0, INSN_CLASS_ZBA, "d,s,t", MATCH_SH3ADD, MASK_SH3ADD, match_opcode, 0 },
+{"sh3add", 0, INSN_CLASS_ZBA, "d,s,t,1", MATCH_SH3ADD, MASK_SH3ADD, match_opcode, 0 },
+{"sh1add.uw", 64, INSN_CLASS_ZBA, "d,s,t", MATCH_SH1ADD_UW, MASK_SH1ADD_UW, match_opcode, 0 },
+{"sh1add.uw", 64, INSN_CLASS_ZBA, "d,s,t,1", MATCH_SH1ADD_UW, MASK_SH1ADD_UW, match_opcode, 0 },
+{"sh2add.uw", 64, INSN_CLASS_ZBA, "d,s,t", MATCH_SH2ADD_UW, MASK_SH2ADD_UW, match_opcode, 0 },
+{"sh2add.uw", 64, INSN_CLASS_ZBA, "d,s,t,1", MATCH_SH2ADD_UW, MASK_SH2ADD_UW, match_opcode, 0 },
+{"sh3add.uw", 64, INSN_CLASS_ZBA, "d,s,t", MATCH_SH3ADD_UW, MASK_SH3ADD_UW, match_opcode, 0 },
+{"sh3add.uw", 64, INSN_CLASS_ZBA, "d,s,t,1", MATCH_SH3ADD_UW, MASK_SH3ADD_UW, match_opcode, 0 },
{"zext.w", 64, INSN_CLASS_ZCB_AND_ZBA, "Cs,Cw", MATCH_C_ZEXT_W, MASK_C_ZEXT_W, match_opcode, INSN_ALIAS },
{"zext.w", 64, INSN_CLASS_ZBA, "d,s", MATCH_ADD_UW, MASK_ADD_UW | MASK_RS2, match_opcode, INSN_ALIAS },
{"zext.w", 64, INSN_CLASS_I, "d,s", 0, (int) M_ZEXTW, NULL, INSN_MACRO },
{"add.uw", 64, INSN_CLASS_ZBA, "d,s,t", MATCH_ADD_UW, MASK_ADD_UW, match_opcode, 0 },
+{"add.uw", 64, INSN_CLASS_ZBA, "d,s,t,1", MATCH_ADD_UW, MASK_ADD_UW, match_opcode, 0 },
{"slli.uw", 64, INSN_CLASS_ZBA, "d,s,>", MATCH_SLLI_UW, MASK_SLLI_UW, match_opcode, 0 },
/* Zbc or zbkc instructions. */