From eb3a64a4da48ce30bd10c34cb57e7ea6a3e60289 Mon Sep 17 00:00:00 2001 From: Alex Bradbury Date: Thu, 20 Dec 2018 14:52:15 +0000 Subject: [RISCV] Properly evaluate fixup_riscv_pcrel_lo12 This is a update to D43157 to correctly handle fixup_riscv_pcrel_lo12. Notable changes: Rebased onto trunk Handle and test S-type Test case pcrel-hilo.s is merged into relocations.s D43157 description: VK_RISCV_PCREL_LO has to be handled specially. The MCExpr inside is actually the location of an auipc instruction with a VK_RISCV_PCREL_HI fixup pointing to the real target. Differential Revision: https://reviews.llvm.org/D54029 Patch by Chih-Mao Chen and Michael Spencer. llvm-svn: 349764 --- llvm/test/MC/RISCV/fixups.s | 15 +++++++++++++-- llvm/test/MC/RISCV/pcrel-lo12-invalid.s | 5 +++++ llvm/test/MC/RISCV/relocations.s | 27 +++++++++------------------ 3 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 llvm/test/MC/RISCV/pcrel-lo12-invalid.s (limited to 'llvm/test/MC/RISCV') diff --git a/llvm/test/MC/RISCV/fixups.s b/llvm/test/MC/RISCV/fixups.s index 0f5432dd117..f0377debabb 100644 --- a/llvm/test/MC/RISCV/fixups.s +++ b/llvm/test/MC/RISCV/fixups.s @@ -24,15 +24,26 @@ sw a0, %lo(val)(t1) # CHECK-FIXUP: fixup A - offset: 0, value: %lo(val), kind: fixup_riscv_lo12_s # CHECK-INSTR: sw a0, 1656(t1) +1: +auipc t1, %pcrel_hi(.LBB0) +# CHECK-FIXUP: fixup A - offset: 0, value: %pcrel_hi(.LBB0), kind: fixup_riscv_pcrel_hi20 +# CHECK-INSTR: auipc t1, 0 +addi t1, t1, %pcrel_lo(1b) +# CHECK-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_i +# CHECK-INSTR: addi t1, t1, -16 +sw t1, %pcrel_lo(1b)(t1) +# CHECK-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_s +# CHECK-INSTR: sw t1, -16(t1) + jal zero, .LBB0 # CHECK-FIXUP: fixup A - offset: 0, value: .LBB0, kind: fixup_riscv_jal -# CHECK-INSTR: jal zero, -16 +# CHECK-INSTR: jal zero, -28 jal zero, .LBB2 # CHECK-FIXUP: fixup A - offset: 0, value: .LBB2, kind: fixup_riscv_jal # CHECK-INSTR: jal zero, 330996 beq a0, a1, .LBB0 # CHECK-FIXUP: fixup A - offset: 0, value: .LBB0, kind: fixup_riscv_branch -# CHECK-INSTR: beq a0, a1, -24 +# CHECK-INSTR: beq a0, a1, -36 blt a0, a1, .LBB1 # CHECK-FIXUP: fixup A - offset: 0, value: .LBB1, kind: fixup_riscv_branch # CHECK-INSTR: blt a0, a1, 1108 diff --git a/llvm/test/MC/RISCV/pcrel-lo12-invalid.s b/llvm/test/MC/RISCV/pcrel-lo12-invalid.s new file mode 100644 index 00000000000..7cf2494ad8e --- /dev/null +++ b/llvm/test/MC/RISCV/pcrel-lo12-invalid.s @@ -0,0 +1,5 @@ +# RUN: not llvm-mc -triple riscv32 -mattr=-relax -filetype obj < %s -o /dev/null 2>&1 | FileCheck %s +# RUN: not llvm-mc -triple riscv32 -mattr=+relax -filetype obj < %s -o /dev/null 2>&1 | FileCheck %s + +1: + addi a0, a0, %pcrel_lo(1b) # CHECK: :[[@LINE]]:3: error: could not find corresponding %pcrel_hi diff --git a/llvm/test/MC/RISCV/relocations.s b/llvm/test/MC/RISCV/relocations.s index b68b11bf195..a879c9a54ad 100644 --- a/llvm/test/MC/RISCV/relocations.s +++ b/llvm/test/MC/RISCV/relocations.s @@ -44,6 +44,7 @@ sb t1, %lo(foo+4)(a2) # INSTR: sb t1, %lo(foo+4)(a2) # FIXUP: fixup A - offset: 0, value: %lo(foo+4), kind: fixup_riscv_lo12_s +.L0: auipc t1, %pcrel_hi(foo) # RELOC: R_RISCV_PCREL_HI20 foo 0x0 # INSTR: auipc t1, %pcrel_hi(foo) @@ -54,25 +55,15 @@ auipc t1, %pcrel_hi(foo+4) # INSTR: auipc t1, %pcrel_hi(foo+4) # FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo+4), kind: fixup_riscv_pcrel_hi20 -addi t1, t1, %pcrel_lo(foo) -# RELOC: R_RISCV_PCREL_LO12_I foo 0x0 -# INSTR: addi t1, t1, %pcrel_lo(foo) -# FIXUP: fixup A - offset: 0, value: %pcrel_lo(foo), kind: fixup_riscv_pcrel_lo12_i +addi t1, t1, %pcrel_lo(.L0) +# RELOC: R_RISCV_PCREL_LO12_I .L0 0x0 +# INSTR: addi t1, t1, %pcrel_lo(.L0) +# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L0), kind: fixup_riscv_pcrel_lo12_i -addi t1, t1, %pcrel_lo(foo+4) -# RELOC: R_RISCV_PCREL_LO12_I foo 0x4 -# INSTR: addi t1, t1, %pcrel_lo(foo+4) -# FIXUP: fixup A - offset: 0, value: %pcrel_lo(foo+4), kind: fixup_riscv_pcrel_lo12_i - -sb t1, %pcrel_lo(foo)(a2) -# RELOC: R_RISCV_PCREL_LO12_S foo 0x0 -# INSTR: sb t1, %pcrel_lo(foo)(a2) -# FIXUP: fixup A - offset: 0, value: %pcrel_lo(foo), kind: fixup_riscv_pcrel_lo12_s - -sb t1, %pcrel_lo(foo+4)(a2) -# RELOC: R_RISCV_PCREL_LO12_S foo 0x4 -# INSTR: sb t1, %pcrel_lo(foo+4)(a2) -# FIXUP: fixup A - offset: 0, value: %pcrel_lo(foo+4), kind: fixup_riscv_pcrel_lo12_s +sb t1, %pcrel_lo(.L0)(a2) +# RELOC: R_RISCV_PCREL_LO12_S .L0 0x0 +# INSTR: sb t1, %pcrel_lo(.L0)(a2) +# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L0), kind: fixup_riscv_pcrel_lo12_s jal zero, foo # RELOC: R_RISCV_JAL -- cgit v1.2.3