-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lld][RISCV] Implement GP relaxation for R_RISCV_HI20/R_RISCV_LO12_I/…
…R_RISCV_LO12_S. This implements support for relaxing these relocations to use the GP register to compute addresses of globals in the .sdata and .sbss sections. This feature is off by default and must be enabled by passing --relax-gp to the linker. The GP register might not always be the "global pointer". It can be used for other purposes. See discussion here riscv-non-isa/riscv-elf-psabi-doc#371 Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D143673
- Loading branch information
Showing
10 changed files
with
177 additions
and
4 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
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
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
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
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,33 @@ | ||
# REQUIRES: riscv | ||
# RUN: rm -rf %t && split-file %s %t && cd %t | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=riscv32-unknown-elf -mattr=+relax a.s -o rv32.o | ||
# RUN: llvm-mc -filetype=obj -triple=riscv64-unknown-elf -mattr=+relax a.s -o rv64.o | ||
# RUN: llvm-mc -filetype=obj -triple=riscv64-unknown-elf -mattr=+relax a.s -o rv64-pie.o | ||
|
||
# RUN: ld.lld --relax-gp --undefined=__global_pointer$ rv32.o lds -pie -o rv32 | ||
# RUN: ld.lld --relax-gp --undefined=__global_pointer$ rv64.o lds -shared -o rv64 | ||
# RUN: llvm-objdump -td -M no-aliases --no-show-raw-insn rv32 | FileCheck %s | ||
# RUN: llvm-objdump -td -M no-aliases --no-show-raw-insn rv64 | FileCheck %s | ||
|
||
# CHECK: lui a0, 512 | ||
# CHECK-NEXT: addi a0, a0, 1 | ||
# CHECK-NEXT: lw a0, 1(a0) | ||
# CHECK-NEXT: sw a0, 1(a0) | ||
|
||
#--- a.s | ||
.globl abs | ||
abs = 0x200001 | ||
|
||
.global _start | ||
_start: | ||
lui a0, %hi(abs) | ||
addi a0, a0, %lo(abs) | ||
lw a0, %lo(abs)(a0) | ||
sw a0, %lo(abs)(a0) | ||
|
||
#--- lds | ||
SECTIONS { | ||
.text : {*(.text) } | ||
.sdata 0x200000 : {} | ||
} |
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,61 @@ | ||
# REQUIRES: riscv | ||
# RUN: rm -rf %t && split-file %s %t && cd %t | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=riscv32-unknown-elf -mattr=+relax a.s -o rv32.o | ||
# RUN: llvm-mc -filetype=obj -triple=riscv64-unknown-elf -mattr=+relax a.s -o rv64.o | ||
|
||
# RUN: ld.lld --relax-gp --undefined=__global_pointer$ rv32.o lds -o rv32 | ||
# RUN: ld.lld --relax-gp --undefined=__global_pointer$ rv64.o lds -o rv64 | ||
# RUN: llvm-objdump -td -M no-aliases --no-show-raw-insn rv32 | FileCheck %s | ||
# RUN: llvm-objdump -td -M no-aliases --no-show-raw-insn rv64 | FileCheck %s | ||
|
||
# CHECK: 00000028 l .text {{0*}}0 a | ||
|
||
# CHECK-NOT: lui | ||
# CHECK: addi a0, gp, -2048 | ||
# CHECK-NEXT: lw a0, -2048(gp) | ||
# CHECK-NEXT: sw a0, -2048(gp) | ||
# CHECK-NOT: lui | ||
# CHECK-NEXT: addi a0, gp, 2047 | ||
# CHECK-NEXT: lb a0, 2047(gp) | ||
# CHECK-NEXT: sb a0, 2047(gp) | ||
# CHECK-NEXT: lui a0, 513 | ||
# CHECK-NEXT: addi a0, a0, 0 | ||
# CHECK-NEXT: lw a0, 0(a0) | ||
# CHECK-NEXT: sw a0, 0(a0) | ||
# CHECK-EMPTY: | ||
# CHECK-NEXT: <a>: | ||
# CHECK-NEXT: addi a0, a0, 1 | ||
|
||
#--- a.s | ||
.global _start | ||
_start: | ||
lui a0, %hi(foo) | ||
addi a0, a0, %lo(foo) | ||
lw a0, %lo(foo)(a0) | ||
sw a0, %lo(foo)(a0) | ||
lui a0, %hi(bar) | ||
addi a0, a0, %lo(bar) | ||
lb a0, %lo(bar)(a0) | ||
sb a0, %lo(bar)(a0) | ||
lui a0, %hi(norelax) | ||
addi a0, a0, %lo(norelax) | ||
lw a0, %lo(norelax)(a0) | ||
sw a0, %lo(norelax)(a0) | ||
a: | ||
addi a0, a0, 1 | ||
|
||
.section .sdata,"aw" | ||
foo: | ||
.word 0 | ||
.space 4091 | ||
bar: | ||
.byte 0 | ||
norelax: | ||
.word 0 | ||
|
||
#--- lds | ||
SECTIONS { | ||
.text : {*(.text) } | ||
.sdata 0x200000 : { } | ||
} |