Add GP-relative relocations#394
Conversation
|
Did you mind post the link of the lld or ld.bfd implementation for the process in the psABI - we require PoC for either linker :) |
Here's a link to the first implementation I am aware of of these GPREL relocations, by Evandro and Nelson / SiFive, for the bfd linker: ebahapo/riscv-binutils-gdb@615efc0. |
|
cc @Nelson1225 @MaskRay linker experts |
kito-cheng
left a comment
There was a problem hiding this comment.
LGTM from my side, just wait few more response from linker experts
|
LGTM, too. It's good to see this series is still going on :) |
ping @MaskRay and other linker experts |
|
This is looking good, but we are not going to use these relocations without relaxation because the size matters for the use case, no? If so, I think we want to define the relaxation scheme at the same time. |
I have a use case where relaxation is not essential. I've decided to split relaxation into a separate PR for ease of review but if you really want I can extend this PR. |
|
I feel more comfortable with relaxation because we want to make sure that these relocations are actually relaxable. But I think that's not really a concern, as they can obviously be relaxable in the same way as |
MaskRay
left a comment
There was a problem hiding this comment.
Looks fine to me as well. These relocations can be used when the segment containing GP does not have a link-time constant distance from the program counter.
|
I am OK to add relaxation later, let moving forward :) |
|
I'd like to revert this before it gets into a tagged release. Neither ePIC nor FDPIC will use it except possibly for linker-internal purposes after relaxation, and we don't assign numbers to linker-internal relocation types. My apologies for missing this earlier. |
I think I am indeed concerned with the rest part of ePIC, so I cannot sign off on them. |
|
You can only use it for non-preemptible symbols if you know for a fact at the reference site that the referenced symbol is allocated to writable memory. I don't think it's going to get anywhere near the amount of usage required to justify 1/48 of the RV32 relocation space. |
I agree with you. I have also checked GCC arm and sh4's codegen for GOT-indirect addressing is required for accessing data symbols under two conditions:
If the referenced data symbol is non-preemptible and guaranteed to be in the text segment, we can use PC-relative addressing. const int ro_array[] = {1, 2, 3, 4}; // text segment
int get_ro_array_elem(int i) { return ro_array[i]; }GOT-indirect addressing does not necessarily require GOT. The linker can optimize it, rendering the 3 relocation code less useful. |
|
Revert PR is #427. |
Following-up on @kito-cheng's suggestion to add the ePIC proposal content to the existing psABI documents, this initial PR adds the GP-relative relocations. These GP-relocations should be useful for purposes besides ePIC (e.g. see previous proposals of the compact/large code models).
For ease of review, I will make a separate PR to add
R_RISCV_GPREL_ADD, used for relaxation purposes, unless you prefer otherwise.I'm not sure these GP relocations merit a GP-relative addressing section, such as the existing "PC-Relative Symbol Addresses", as there aren't the same kind of complications to comment on. If you feel it's needed, I will add one to this PR.