brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · c89ac1f Raw
103 lines · plain
1# REQUIRES: riscv2# RUN: llvm-mc -filetype=obj -triple=riscv64 /dev/null -o %t2.o3# RUN: ld.lld -shared -soname=t2 %t2.o -o %t2.so4# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.o5# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=RELOC %s6 7# RUN: ld.lld -e absolute %t.o -o %t8# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefixes=CHECK,PC %s9# RUN: llvm-readelf -x .data %t | FileCheck --check-prefixes=HEX,HEX-WITHOUT-PLT %s10 11# RUN: ld.lld -e absolute %t.o -o %t %t2.so12# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefixes=CHECK,PLT %s13# RUN: llvm-readelf -x .data %t | FileCheck --check-prefixes=HEX,HEX-WITH-PLT %s14 15.option exact16 17.weak target18.global absolute, relative, branch19 20## Absolute relocations are resolved to 0.21# RELOC:      0x0 R_RISCV_HI20 target 0x122# RELOC-NEXT: 0x4 R_RISCV_LO12_I target 0x123 24# CHECK-LABEL: <absolute>:25# CHECK-NEXT:  lui t0, 0x026# CHECK-NEXT:  addi t0, t0, 0x127absolute:28  lui t0, %hi(target+1)29  addi t0, t0, %lo(target+1)30 31## Currently, PC-relative relocations are resolved to 0.32# RELOC-NEXT: 0x8 R_RISCV_PCREL_HI20 target 0x033# RELOC-NEXT: 0xC R_RISCV_PCREL_LO12_I .Lpcrel_hi0 0x034# RELOC-NEXT: 0x10 R_RISCV_PCREL_HI20 target 0x235# RELOC-NEXT: 0x14 R_RISCV_PCREL_LO12_S .Lpcrel_hi1 0x036 37## 1048559 should be -0x11.38# CHECK-LABEL: <relative>:39# CHECK-NEXT:  11{{...}}: auipc a1, 0xfffef40# PC-NEXT:     addi a1, a1, -0x16041# PLT-NEXT:    addi a1, a1, -0x29042# CHECK-LABEL: <.Lpcrel_hi1>:43# CHECK-NEXT:  11{{...}}: auipc t1, 0xfffef44# PC-NEXT:     sd a2, -0x166(t1)45# PLT-NEXT:    sd a2, -0x296(t1)46relative:47  la a1, target48  sd a2, target+2, t149 50## Branch relocations51## If .dynsym does not exist, an undefined weak symbol is non-preemptible.52## Treat them as PC relative relocations.53# RELOC:      0x18 R_RISCV_CALL_PLT target 0x054# RELOC-NEXT: 0x20 R_RISCV_JAL target 0x055# RELOC-NEXT: 0x24 R_RISCV_BRANCH target 0x056 57# PC-LABEL:    <branch>:58# PC-NEXT:     auipc ra, 0x059# PC-NEXT:     jalr ra60# PC-NEXT:     [[#%x,ADDR:]]:61# PC-SAME:                    j 0x[[#ADDR]]62# PC-NEXT:     [[#%x,ADDR:]]:63# PC-SAME:                    beqz zero, 0x[[#ADDR]]64 65## If .dynsym exists, an undefined weak symbol is preemptible.66## We create a PLT entry and redirect the reference to it.67# PLT-LABEL:   <branch>:68# PLT-NEXT:    auipc ra, 0x069# PLT-NEXT:    jalr 0x30(ra)70# PLT-NEXT:    [[#%x,ADDR:]]:71# PLT-SAME:                   j 0x[[#ADDR]]72# PLT-NEXT:    [[#%x,ADDR:]]:73# PLT-SAME:                   beqz zero, 0x[[#ADDR]]74branch:75  call target76  jal x0, target77  beq x0, x0, target78 79## Absolute relocations are resolved to 0.80# RELOC:      0x0 R_RISCV_64 target 0x381# RELOC-NEXT: 0x8 R_RISCV_32 target 0x482# RELOC-NEXT: 0xC R_RISCV_PLT32 target 0x083 84# HEX:      section '.data':85# HEX-NEXT: 03000000 00000000 0400000086# HEX-WITHOUT-PLT-SAME: 0000000087 88## A plt entry is created for target, so this is the offset between the89## plt entry and this address.90##91##   S - A + P = -0x0x20ec = 0xffffdf1492# HEX-WITH-PLT-SAME: 14dfffff93 94.data95.p2align 396.quad target+397.long target+498 99# PC-NOT:      .plt:100# PLT:         .plt:101 102.word %pltpcrel(target)103