This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support TLSDESC in the RISC-V backend
AbandonedPublic

Authored by paulkirth on May 25 2023, 8:41 AM.

Details

Summary

TLS Descriptors (TLSDESC) are an alternative implementation of the
Global Dynamic model that allows the dynamic linker to achieve
performance close to that of Initial Exec when the library was not
loaded dynamically with dlopen. For each TLSDESC relocation inside
the GOT, the dynamic linker fills in the TLS descriptor.

This patch adds basic support in the RISC-V backend by adding new
relocation types and some new pseudo instructions. Optimization for the
local dynamic case will be handled in future patches.

The implementation is currently only enabled by passing the
riscv-enable-tlsdesc flag, since support in libc is not generally
available yet. Subsequent patches can enable TLSDESC by default for
RISCV.

This work is based on the RISC-V psABI proposal:
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373

Diff Detail

Event Timeline

paulkirth created this revision.May 25 2023, 8:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2023, 8:41 AM
paulkirth requested review of this revision.May 25 2023, 8:41 AM
paulkirth updated this revision to Diff 525640.May 25 2023, 8:42 AM

Format patch

TLSDESC has a calling convention that assumes most registers are not clobbered. Does this patch implement it?

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
76

Delete cl::init(false),

TLSDESC has a calling convention that assumes most registers are not clobbered. Does this patch implement it?

yes. the pseudo we introduce and the JALR are marked to indicate that registers are not clobbered.

paulkirth planned changes to this revision.May 25 2023, 11:38 AM

hmm, looks like some part of this patch is missing. expandLoadTLSDescAddress is where a lot of work happens, and it seems like I didn't fix the rebase as well as I earlier thought, and that function has been dropped.

Restore deleted function.

paulkirth updated this revision to Diff 525905.May 25 2023, 6:45 PM

Match naming in the psABI proposal.

paulkirth updated this revision to Diff 525907.May 25 2023, 6:50 PM

Update tests.

paulkirth added inline comments.May 25 2023, 6:59 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
5326

Remove cl::init