This is an archive of the discontinued LLVM Phabricator instance.

[JITLink][RISCV] Only generate PLT entries for external symbols
ClosedPublic

Authored by jobnoorman on Apr 29 2023, 12:11 PM.

Details

Summary

R_RISCV_CALL has been deprecated. [1] Both GCC and LLVM seem to not
generate it anymore and always use R_RISCV_CALL_PLT (even for calls that
do not need a PLT entry). Generating PLT entries based on relocation
type is not recommended and a better heuristic is to only generate them
when the target symbol is preemptable [2]. This patch implements this by
only generating PLT entries for undefined symbols.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/340
[2] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/98

Diff Detail

Event Timeline

jobnoorman created this revision.Apr 29 2023, 12:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2023, 12:11 PM
Herald added subscribers: asb, luke, pmatos and 28 others. · View Herald Transcript
jobnoorman requested review of this revision.Apr 29 2023, 12:11 PM
jobnoorman edited the summary of this revision. (Show Details)

Rebase, remove dependency on abandoned revision.

MaskRay added inline comments.May 2 2023, 3:27 PM
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
74

Use R_RISCV_CALL_PLT?

80

I don't know the object file model of jitlink, but adding a condition is definitely moving toward the right direction.

isExternal looks a bit strange. If the jitlink built object files are used as executables, !isDefined() should be a good enough proxy.

StephenFan added inline comments.May 3 2023, 10:02 PM
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
80

It seems isExternal can exclude absolute symbols.

jobnoorman added inline comments.May 4 2023, 12:29 AM
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
74

That indeed feels more correct (given the deprecation of R_RISCV_CALL) but for now both of them work so I'm not sure if that change should be part of this patch.

80

Indeed, so I would suggest to keep it like this.

MaskRay added inline comments.May 4 2023, 12:44 AM
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
80

An absolute symbol is defined in ELF. isExternal seems Mach-O specific and is not meaningful for ELF.

lhames added inline comments.May 4 2023, 3:21 PM
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
80

isExternal (in this context) is a LinkGraph concept -- it's not format specific. It just means that the Symbol isn't defined by this graph, it's defined somewhere else.

In this context absolute symbols are not external -- they are defined by the graph (though they don't have any content associated with them).

Calls to absolutes should use a PLT (at least when JITing) as there's no way to know that the graph will be allocated within direct-branch range of the absolute.

jobnoorman updated this revision to Diff 519767.May 5 2023, 1:38 AM
jobnoorman edited the summary of this revision. (Show Details)

Change condition from isExternal() to !isDefined() to make sure PLT entries
are also created for absolute symbols.

jobnoorman marked 4 inline comments as done.May 5 2023, 1:39 AM
jobnoorman added inline comments.
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
80

Updated to !isDefined() to include absolute symbols.

lhames accepted this revision.May 7 2023, 7:13 PM

LGTM. Thanks @jobnoorman!

This revision is now accepted and ready to land.May 7 2023, 7:13 PM
This revision was automatically updated to reflect the committed changes.
jobnoorman marked an inline comment as done.