-
Notifications
You must be signed in to change notification settings - Fork 26
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
Is there a way of defining a label? #82
Comments
Just to make sure I understand how this is encoded: the label needs to be an additional symbol in the resulting object file so that the relocation can reference it, right? Does the There is currently no way to do this. One way we might be able to extend the API to support it is for the |
I am not educated enough in linker stuff, and the docs are still not very detailed, but I believe yes, it must be an additional symbol pointing at the first of two instructions. The docs say nothing about the addend, but I have tried to put the
So it mentions a "relocation label", which I assume must be visible to the linker as a symbol. I guess that is how the linker knows where to look for matching
when I point Probably when the linker's encounters a I hope I got it correctly. |
If that is correct, then there should be an API to add labels to declared symbols, and once I tell |
Ok I'm not sure about my addend idea, it may be bending things too much. Can you flesh out what you think the API should look like? Here's a straw man proposal: Rather than declaring labels, they are specified simply as a symbol + offset. We add @m4b Do you have any better ideas about what this API should look like? Maybe add more fields to |
Just breezing over this my first thought re APIs was what you wrote @philipc; but before we get into details maybe @sunfishcode can give some insight into labels and how they’re assembled. I have a feeling you might know this area well :) My fuzzy memory with labels in assembler is they are assembled into a final relative offset to some memory address, and aren’t a symbol at all, but that could be wrong. Easiest way to check is to write some assembly with a label and see what object file gets emitted with what relocations ? This also assumes that labels in this generic context is the same terminology / meaning as the label used in the sense for RISKV above; perhaps we’re writing a specialized api that isn’t applicable outside of riskv? Lastly if it is just a symbol, why wouldn’t we use the same api, and the second instruction would have a data reference to the symbol? But maybe this is what philipc proposed along with addends? |
But should such a feature be platform-specific and tied to |
Also I do not think that it is a good idea to use addends for that, since they have their use in other types of relocations, so it feels be a dirty hack to use them where they are not supposed to be. See all the relocations containing "+ A" in the relocation type table. Under the "Address Calculation Symbols" title below it, there is a table explaning that "A" means the addend field. |
Update: found this comment by
|
For a concrete example, gcc (8.3.0-6ubuntu1~18.04) emits the following:
Note that it reuses the same name (.L0) for many of these labels. For ELF the linker recognizes
So the label would be another type of declaration (e.g. |
Also need to consider what is required for labels in Mach-O and COFF. |
I am generating code for RISC-V and I need to store a function pointer in a register. According to the documentation, this is done with a pair of instructions:
The code would be:
So I need to refer to that label in the relocation for
addi
, but I cannot find a way to even define a label in an Artifact.The text was updated successfully, but these errors were encountered: