aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binutils/gas/config/tc-riscv.c10
-rw-r--r--glibc/sysdeps/riscv/start.S3
2 files changed, 10 insertions, 3 deletions
diff --git a/binutils/gas/config/tc-riscv.c b/binutils/gas/config/tc-riscv.c
index 2d77871..d7e5bb6 100644
--- a/binutils/gas/config/tc-riscv.c
+++ b/binutils/gas/config/tc-riscv.c
@@ -937,12 +937,18 @@ macro (struct riscv_cl_insn *ip, expressionS *imm_expr,
if (imm_expr->X_op == O_constant)
load_const (rd, imm_expr);
- else if (riscv_opts.pic && mask == M_LA) /* Global PIC symbol */
+ else if (riscv_opts.pic && mask == M_LA) /* Global symbol in PIC */
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 */
+ else if (riscv_opts.pic) /* Local symbol in PIC */
pcrel_load (rd, rd, imm_expr, "addi",
BFD_RELOC_RISCV_PCREL_HI20, BFD_RELOC_RISCV_PCREL_LO12_I);
+ else /* Any symbol in non-PIC */
+ {
+ macro_build (imm_expr, "lui", "d,u", rd, BFD_RELOC_RISCV_HI20);
+ macro_build (imm_expr, "addi", "d,s,j", rd, rd,
+ BFD_RELOC_RISCV_LO12_I);
+ }
break;
case M_LA_TLS_GD:
diff --git a/glibc/sysdeps/riscv/start.S b/glibc/sysdeps/riscv/start.S
index 8195002..1f64d80 100644
--- a/glibc/sysdeps/riscv/start.S
+++ b/glibc/sysdeps/riscv/start.S
@@ -45,7 +45,8 @@
__libc_start_main wants this in a5. */
ENTRY(ENTRY_POINT)
- lla gp, _gp
+1: auipc gp, %pcrel_hi(_gp)
+ addi gp, gp, %pcrel_lo(1b)
move a5, a0 /* rtld_fini */
lla a0, main
REG_L a1, 0(sp) /* argc */