-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LLD][RISCV] Error on PCREL_LO referencing other Section (#107558)
The RISC-V psABI states that "The `R_RISCV_PCREL_LO12_I` or `R_RISCV_PCREL_LO12_S` relocations contain a label pointing to an instruction in the same section with an `R_RISCV_PCREL_HI20` relocation entry that points to the target symbol." Without this patch, GNU ld errors, but LLD does not -- I think because LLD is doing the right thing, certainly in the testcase provided. Nonetheless, I think an error is good here to bring LLD in line with what GNU ld is doing in showing that the object the user provided is not following the psABI as written. Fixes #107304
- Loading branch information
Showing
3 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# REQUIRES: riscv | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.o | ||
# RUN: not ld.lld %t.o 2>&1 | FileCheck %s | ||
|
||
# CHECK: error: {{.*}}:(.text.sec_one+0x0): R_RISCV_PCREL_LO12 relocation points to a symbol '.Lpcrel_hi0' in a different section '.text.sec_two' | ||
# CHECK: error: {{.*}}:(.text.sec_one+0x4): R_RISCV_PCREL_LO12 relocation points to a symbol '.Lpcrel_hi1' in a different section '.text.sec_two' | ||
# CHECK-NOT: R_RISCV_PCREL_LO12 relocation points to a symbol '.Lpcrel_hi2' | ||
|
||
## This test is checking that we warn the user when the relocations in their | ||
## object don't follow the RISC-V psABI. In particular, the psABI requires | ||
## that PCREL_LO12 relocations are in the same section as the pcrel_hi | ||
## instruction they point to. | ||
|
||
.section .text.sec_one,"ax" | ||
addi a0, a0, %pcrel_lo(.Lpcrel_hi0) | ||
sw a0, %pcrel_lo(.Lpcrel_hi1)(a1) | ||
|
||
.section .text.sec_two,"ax" | ||
.Lpcrel_hi0: | ||
auipc a0, %pcrel_hi(a) | ||
.Lpcrel_hi1: | ||
auipc a1, %pcrel_hi(a) | ||
|
||
.Lpcrel_hi2: | ||
auipc a2, %pcrel_hi(a) | ||
addi a2, a2, %pcrel_lo(.Lpcrel_hi2) | ||
|
||
.data | ||
.global a | ||
a: | ||
.word 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters