RISC-V: PR30449, Add lga assembler macro support.

Originally discussion, https://github.com/riscv/riscv-isa-manual/pull/539

Added new load address pseudo instruction which is always expanded to GOT
access, no matter the .option rvc is set or not.

gas/
	PR 30449
	* config/tc-riscv.c (macro): Add M_LGA support.
	* testsuite/gas/riscv/la-variants.d: New.
	* testsuite/gas/riscv/la-variants.s: New.
include/
	PR 30449
	* opcode/riscv.h (M_LGA): New.
opcodes/
	PR 30449
	* riscv-opc.c (riscv_opcodes): Add lga support.
This commit is contained in:
Jim Wilson
2023-06-01 12:10:16 +08:00
committed by Nelson Chu
parent 20ef84ed2a
commit ec2260af61
5 changed files with 61 additions and 2 deletions

View File

@@ -2010,16 +2010,20 @@ macro (struct riscv_cl_insn *ip, expressionS *imm_expr,
case M_LA:
case M_LLA:
case M_LGA:
/* Load the address of a symbol into a register. */
if (!IS_SEXT_32BIT_NUM (imm_expr->X_add_number))
as_bad (_("offset too large"));
if (imm_expr->X_op == O_constant)
load_const (rd, imm_expr);
else if (riscv_opts.pic && mask == M_LA) /* Global PIC symbol. */
/* Global PIC symbol. */
else if ((riscv_opts.pic && mask == M_LA)
|| mask == M_LGA)
pcrel_load (rd, rd, imm_expr, LOAD_ADDRESS_INSN,
BFD_RELOC_RISCV_GOT_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
else /* Local PIC symbol, or any non-PIC symbol. */
/* Local PIC symbol, or any non-PIC symbol. */
else
pcrel_load (rd, rd, imm_expr, "addi",
BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
break;