Skip to content
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 support for static symbols and GOT #60

Merged
merged 10 commits into from
Jan 31, 2025
Merged

Conversation

janvrany
Copy link
Owner

@janvrany janvrany commented Dec 3, 2024

This PR adds support for static symbols and for loading/storing into them via GOT. This is implemented by handling AcRelocationRequestGOTEntry in TRCodeCache >> #link. GOT entries are allocated from the "end" of the code cache.

This tests compilation of relocatable calls.
So far each label symbol (`TRLabelSymbol`) has been associated with
block (`TRILBlock`). This commits relaxes this association - every
label now may or may not be associated with block. This allows labels to
be also used in "local control flows" (local meaning within one
evaluator). It will also allow to unify labels with other symbol types
(such as function symbols or statics).

Technically, a `TRLabelSymbol` the association is still from symbol to
block. I have tried to make it the other way round, from block to it's
symbol, but that made code managing CFG bit ugly so I decided to keep it
like this for time being.
Static symbols represent data stored on the heap (as opposed to data
stored in frame which are represented by `TRRegisterMappedSymbol`s)
and therefore have a single unique absolute address.

The address however may not be known in advance so code individual code
generators must always generate proper relocations when accessing static
symbols.

Jump labels and functions are special kind of static symbols.
This commit adds `TRTarget >> endian` which can be used by various parts
when reading from / writing to (target) memory.

As of now, both RISC-V and POWER targets are hard-coded as little endian
even thought this is not always true. This may be fixes in the future.

The rest of Tinyrossa code should consult `TRTarget >> endian` wherever
necessary.
Commit b32bc8e added `TRDataType >> #sizeInBytes`. While it is
convenient and looks like a good OO design, it does not really work.
The size of `Address` (pointer) is architecture-dependent.

This commit deprecates `TRDataType >> #sizeInBytes` in favour of
`TRTarget >> sizeInBytesOf:` and updates users.

Note, that `TRDataType >> #sizeInBytes` has been kept there as
"should-not-implement" with comment to prevent future myself to make
this tempting mistake again.
This commit adds support for GOT-based accesses (for loading / storing
values from / to static symbols).

This is implemented by handling `AcRelocationRequestGOTEntry`.
This commit changes `TRRV64GSystemLinkage` to compile relocatable calls
using pair of `auipc` and `jalr` with `R_RISCV_CALL_PLT` relocation.
This commit implements loads and stores for static symbols using
32bit PC-relative addressing. In the future, we should use GOT access
to allow static symbols to be located anywhere in address space, but
this needs to wait for GOT (and PLT) support in code cache.
@janvrany janvrany closed this Dec 4, 2024
@janvrany janvrany reopened this Jan 31, 2025
@janvrany janvrany merged commit 03b25a9 into master Jan 31, 2025
2 of 4 checks passed
@janvrany janvrany deleted the pr/add-support-for-got branch January 31, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant