[llvm-bugs] [Bug 43418] New: The linker can't find matching R_RISCV_PCREF_HI20 to the R_RISCV_PCREF_LO12

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 23 13:46:09 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43418

            Bug ID: 43418
           Summary: The linker can't find matching R_RISCV_PCREF_HI20 to
                    the R_RISCV_PCREF_LO12
           Product: lld
           Version: unspecified
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: grogers at micron.com
                CC: llvm-bugs at lists.llvm.org, peter.smith at linaro.org

lld for Risc-V can't find the matching R_RISCV_PCREF_HI for a
R_RISCV_PCREF_LO12.

The problem code is the routine getRISCVPCRelHi20 in InputSection.cpp.

To duplicate type the following commands using the attached file (memset.s):

clang -c -march=rv64g memset.s 
ld memset.o -o memset.r5.exe
ld: warning: Non-zero addend in R_RISCV_PCREL_LO12 relocation to
memset.o:(memset) is ignored
ld: error: R_RISCV_PCREL_LO12 relocation points to memset.o:(memset) without an
associated R_RISCV_PCREL_HI20 relocation
ld: warning: Non-zero addend in R_RISCV_PCREL_LO12 relocation to
memset.o:(memset) is ignored
ld: error: R_RISCV_PCREL_LO12 relocation points to memset.o:(memset) without an
associated R_RISCV_PCREL_HI20 relocation

The warning messages should be delete.

The memset.s source code is:

.text
.option relax
.global _start
.type   _start, @function
.global memset
.type   memset, @function
_start:
memset:
  li t1, 15
  move a4, a0
  bleu a2, t1, .Ltiny
  and a5, a4, 15
  bnez a5, .Lmisaligned

.Laligned:
  bnez a1, .Lwordify

.Lwordified:
  andi a3, a2, %lo(-15)
  andi a2, a2, 15
  add a3, a3, a4

.Ltmp1:sd a1, 0(a4)
  sd a1, 8(a4)
  add a4, a4, 16
  bltu a4, a3, .Ltmp1

  bnez a2, .Ltiny
  ret

.Ltiny:
  sub a3, t1, a2
  sll a3, a3, 2
.Ltmp2:auipc t0, %pcrel_hi(.Ltable)
  add a3, a3, t0
.option push
.option norvc
.Ltable_misaligned:
  jalr x0, a3, %pcrel_lo(.Ltmp2)
.Ltable:
  sb a1,14(a4)
  sb a1,13(a4)
  sb a1,12(a4)
  sb a1,11(a4)
  sb a1,10(a4)
  sb a1, 9(a4)
  sb a1, 8(a4)
  sb a1, 7(a4)
  sb a1, 6(a4)
  sb a1, 5(a4)
  sb a1, 4(a4)
  sb a1, 3(a4)
  sb a1, 2(a4)
  sb a1, 1(a4)
  sb a1, 0(a4)
.option pop
  ret

.Lwordify:
  and a1, a1, 0xFF
  sll a3, a1, 8
  or  a1, a1, a3
  sll a3, a1, 16
  or  a1, a1, a3
#if __riscv_xlen == 64
  sll a3, a1, 32
  or  a1, a1, a3
#endif
  j .Lwordified

.Lmisaligned:
  sll a3, a5, 2
.Ltmp3:auipc t0, %pcrel_hi(.Ltable_misaligned)
  add a3, a3, t0
  mv t0, ra
  jalr x0, a3, %pcrel_lo(.Ltmp3)
  mv ra, t0

  add a5, a5, -16
  sub a4, a4, a5
  add a2, a2, a5
  bleu a2, t1, .Ltiny
  j .Laligned
  .size memset, .-memset

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190923/467e1f72/attachment.html>


More information about the llvm-bugs mailing list