This is an archive of the discontinued LLVM Phabricator instance.

[ELF][RISCV] Relax local-exec TLS model
ClosedPublic

Authored by MaskRay on Jul 9 2022, 10:39 AM.

Details

Summary

In -mrelax mode, GCC/Clang may generate a local-exec TLS code sequence like:

# R_RISCV_TPREL_HI20, R_RISCV_RELAX
lui rd, %tprel_hi(x)
# R_RISCV_TPREL_ADD, R_RISCV_RELAX
add rd, rd, tp, %tprel_add(x)
# (R_RISCV_TPREL_LO12_I || R_RISCV_TPREL_LO12_S), R_RISCV_RELAX
addi rd, rd, %tprel_lo(x) || sw rs, %tprel(x)(rd)

Note: st_value(x) for TLS should be in the range [0,p_memsz(PT_TLS)).
When st_value(x) < 2048 (i.e. hi20(x) == 0), the linker can relax
the code sequence to:

addi rd, tp, st_value(x) || sw rs, st_value(x)(rd)

Diff Detail

Event Timeline

MaskRay created this revision.Jul 9 2022, 10:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2022, 10:39 AM
MaskRay published this revision for review.Jul 9 2022, 10:39 AM
MaskRay added inline comments.Jul 9 2022, 10:40 AM
lld/ELF/Arch/RISCV.cpp
576

I'll remove the used-once sym

jrtc27 added inline comments.Jul 9 2022, 11:12 AM
llvm/include/llvm/BinaryFormat/ELFRelocs/RISCV.def
49

These encodings are reserved for future standard use

MaskRay updated this revision to Diff 443450.Jul 9 2022, 11:23 AM

avoid R_RISCV_TPREL_{I,S}

MaskRay edited the summary of this revision. (Show Details)Jul 9 2022, 12:23 PM
pierce added a subscriber: pierce.Jul 10 2022, 9:29 PM

I'll push this on Friday.

MaskRay updated this revision to Diff 445040.Jul 15 2022, 9:59 AM

Test non-adjacent instructions

MaskRay accepted this revision.Jul 15 2022, 9:59 AM
This revision is now accepted and ready to land.Jul 15 2022, 9:59 AM
MaskRay edited the summary of this revision. (Show Details)Jul 15 2022, 10:05 AM
This revision was landed with ongoing or failed builds.Jul 15 2022, 10:08 AM
This revision was automatically updated to reflect the committed changes.