-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RELOCID for vendor-specific relocations #423
Conversation
Thanks for raising this! I think this solution is kinda discussed for a while, and also agreed from many different parties, I guess the only only remaining controversy is the vendor ID: build our own list or use JEDEC manufacturer ID like Added this into today's psABI meeting agenda, thanks again :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the addend precludes the use of Elf_Rel, which some platforms (Fuschia) use for dynamic relocations. It needs to be encoded in the symbol instead.
<| | ||
.2+| 192-255 .2+| *Reserved* .2+| - | .2+| Reserved for nonstandard ABI extensions | ||
<| | ||
|=== | ||
|
||
Nonstandard extensions are free to use relocation numbers 192-255 for any | ||
purpose. These relocations may conflict with other nonstandard extensions. | ||
purpose. These vendor-specific relocations must be preceded by a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You say must yet the next paragraph says where possible? It can’t be must, that’s not compatible with the historic definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed re compatibility with existing objects, this is an optional addition, we will fix that in the text.
The intent for the following paragraph was to talk about presentation in objdump, etc. where if it is possible to show for the custom reloc a name that takes into account the full pair of relocations it should (e.g. R_RISCV_MYVENDOR_MEANINGFUL_NAME, rather than say R_RISCV_CUSTOM192), rather than emphasising/making optional the existence of a differentiator reloc.
Is this suggesting encoding in the symbol in all cases, or being generic enough that Sym (if Elf_Rel) or Sym+Addend (if Elf_Rela; probably the absolute section symbol) results in the "vendor identifier"? I understand the need to cover the Elf_Rel case if we have users that need that (and forbidding such functionality because you don't have addends in your ELF file makes no sense), but I'm not sure of an immediate strong argument of always adding symbols to hold this information if addends are available |
One idea for resolve both issue: 1) Organization don't have JEDEC manufacturer ID, 2) REL type relocation. RELA: Encoding JEDEC manufacturer ID in addend, and 0 for those organization don't have JEDEC manufacturer ID, relocation symbol will point to a special symbol REL: Relocation symbol will point to a special symbol: |
I think it would be more straightforward to only use symbols with the vendor name: this way we have a single way to use this relocation for both REL and RELA without needing to differentiate for vendors with or without a JEDEC ID. Also, if a vendor really wants to use their JEDEC ID, they are free to use it in the symbol name. |
I am happy with special/dummy symbol only scheme. @jrtc27 does it address your concern? |
Just cc more linker experts to make sure it's not insane to linker implementation. Some background: We have only limited relocation can be used within the RISC-V psABI due to RV32, we already divide few portion of relocation to vendor extension, however we didn't have a mechanism to well maintain the vendor relocation, that cause those relocation never go back to upstream, therefore, some vendor extension start upstream, like Core-V, they have few vendor relocation, and I believe they are not along...SiFive has also defined some vendor relocation within downstream, also IIRC CHERRI also defined few relocation...so having a mechanism defined in psABI would be great. |
CHERI is less relevant here; as a custom research extension we have no need to coexist with other vendor extensions, and the standard extension we're working towards now in the CHERI SIG+TG won't be a vendor extension so will coexist just fine. |
It seems the fundamental issue here is that the (This idea was inspired by the concept of UTF-16 surrogates.) |
We cannot change the meaning of any of the existing relocations reserved for custom use. The whole point of reserving them for custom use like that is so that others can rely on being able to use them in perpetuity. |
Then how about defining [176, 191] as "vendor-specific relocation prefixes"? That allows 16*256=4096 new vendor-specific relocations. |
How are you encoding all vendor relocations in 12 bits? |
Actually we can just reserve a single relocation number, say, 191, as a vendor-specific prefix and use UTF-8-like encoding scheme by using following relocations to represent any number of relocation types, eliminating the need to use different relocation numbers for RV32 and RV64 for those who need more than 64 relocation types. |
Alternative approach would be to define 191 as the first relocation of a vendor-specific relocation pair, whose actual |
So, my proposal is to resolve the issue that RV32's "A relocation whose And then we can reserve a plenty space (say, 0x8000'0000 to 0xffff'ffff) for vendor specific relocations, allowing vendors to use non-overlapping regions. How does this sound to you guys? |
You need r_offset to point at the right location otherwise every single tool will need to have special casing in what is normally highly generic code. |
We can use |
|
I think REL disallowing r_addend as an identifier is less relevant since there is no requirement to make REL work. How urgent do people need reserved relocation types in the specification? |
@jrtc27 I agree with MaskRay on Fuchsia. Fuchsia (or anyone) reserves the right to deviate from this psABI, and that's what they are doing for dynamic relocations, but the consequence would also be on them if they choose to do so. We are not obligated to make nonstandard deviations work smoothly with new psABI features. If I were a Fuchsia developer, I'd use |
@MaskRay : Sorry for late reply, I was stuck at releasing stuffs. Thanks you bring RELR and RELLEB(CREL), it's my first time know that, I think both are useful for code size reduction around the relocation info, I got few code size request around the kernel module (relocatable files), so I was considering to introducing mixing
[1] https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#addends-and-pc-bias Back to the the vendor relocation, I am inclined to using dummy symbol scheme at this moment, since I think new relocation format may still require more than one release cycle to implement that into all tools, however vendor instruction has merged into upstream recently, I don't want to block this behind that. At the end, let me emphasize again, I am really looking forward to RELR and RELLEB(CREL) can improve the code size issue, I saw RELR already merged into glibc since 2.36, so I gonna to prepare some PR to mention that in the RISC-V psABI :) |
9d80257
to
bc8b2e8
Compare
Updated to use symbols instead of the addend as vendor ID. |
bc8b2e8
to
064cd8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
This PR already provide toolchain PoC, so the only missing part is we need few blessing from linker experts per the rule we set before, @rui314 @MaskRay @Nelson1225 do you mind give one?
No objection to vendor relocations taking one type code. However, the inclusion of a relocation symbol for vendor identification raises some questions. Why does a vendor relocation need to identify the vendor name? We reserve one code so that vendor relocations will not conflict with standard relocations. That said, vendor identification might be useful for other purposes and we probably need a per-file mechanism. |
Unfortunately that has been expressed very explicitly as a goal, hence how we've ended up here. |
We may have multi-version function for different vendor, so that may contain relocation from more than one vendor in theory. |
Can you share an example of how vendor relocations from various vendors are combined? What actions should upstream linkers take? I think it's crucial that they avoid recognizing vendor-specific semantics. (A dummy symbol, if ever adopted, can be implemented with STB_WEAK STV_HIDDEN so that after linking there is only one copy.) |
064cd8e
to
7aaba4e
Compare
RISC-V community agree taking vendor-specific extensions, so that may introduce new relocation you could imagine :P, but require vendor to maintain that, one agreement here is that require an open spec on toolchian-convention, give some piratical example is we have vendor extension from T-head, Core-V (OpenHW), Ventana and SiFive on upstream now.
So back to this question, because we allow vendor upstream their extension, so yes they may contain within single file. |
7aaba4e
to
e6332b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This proposal has discussed for long time, and address most concern so far, give an explicit LGTM to notify everyone this is ready to land.
@MaskRay any further concern? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This expands the current support for custom relocations to have a vendor identifier which would allow to avoid conflicts between vendor relocations in tools. This would also allow a greater number of relocations, such that these could eventually be supported in upstream tools.
A proof of concept implementation can be found in https://github.com/embecosm/corev-binutils-gdb-vendor-relocs.