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

Code cache and code cache manager #59

Merged
merged 7 commits into from
Nov 29, 2024

Conversation

janvrany
Copy link
Owner

This PR adds TRCodeCache and TRCodeCacheManager classes.

These serve as an example of how results of compilation (AcDLSCodeObject) interacts with rest of execution environment (VM) and also as an implementation used by test shell.

The shell itself has been extended to contain two code zones and two heaps, far apart of each other in address space to allow testing of relocations, GOT-based accesses, PLT calls and so on.

This is a preparation for introducing `TRRuntime` and related classes
that will also make use of target. So it is no longer just target for
compilation.
This commit introduces a `TRRuntime`, a class that provides an entry
point for runtime services.

Downstream projects (if any) may (should) provide customized subclass.
Note that "runtime" is only useful / used in JIT scenarios.
This commit adds new class - `TRCodeCache` - that implements simple
runtime code cache to put compiled code (result of compilation) for
later execution.

Downstream project may need to provide customized implementations
of code cache fitting the needs of particular runtime. `TRCodeCache`
should serves (i) as  example implementation, (ii) possibly as a base
class for downstream projects and finally (iii) as code cache
implementation to be used in tests.

As of now, the implementation is fairly simple. Its functionality
will be expanded in further commits.
This commit makes use of `TRCodeCache` introduced in previous commit.
This is a necessary step for writing tests that compile multiple functions
and/or refer to external (relocatable) symbols.
This commit extends test shell in two ways:

 * add another code section (`nzone2`) and two data sections (`heap1`
   and `heap2`). They're laid out in memory such that `nzone2` is
   further then 4GB from `nzone2`, similarly for data sections. This
   will allow testing of GOT / PLT based relocations on most platforms.
   Memory placement is done by linker script.

 * Add new variable `entry` whose value specifies the entrypoint of
   (injected) function (in either `nzone1` or `nzone2`. This is usefull
   when one wants to test complete program. Address of `entry` variable
   is fixed and again, specified by a linker script.
`TRCodeCacheManager` ties multiple code caches (here referred as
'segments') together. An (exported) symbol added to any of the segments
is automatically made visible (and linked to) by all other segments
managed by this manager.

As with `TRCodeCache`, downstream project may need to provide customized
implementations of code cache manager fitting the needs of particular
runtime.  This class serves example implementation and it is used in
tests (see class `TRCompilationTestShell`)

Downstream projects may also add new functionality such as automatically
choosing the best segment to put new code object and/or invalidating/
flushing of code objects.

As of now, the implementation is fairly simple. Its functionality may
be expanded in further commits.
This commit makes use of `TRCodeCacheManager` in test shell, tying both
nzones and heaps (introduced in commit "Extend test shell") together.

This allows to test PIC code and relocation processing in various
scenarios such as when relaxation is or is not possible and/or use of
GOT/PLT entries.
@janvrany janvrany force-pushed the pr/add-code-cache-and-code-cache-manager branch from 022e4ec to 441dc6d Compare November 29, 2024 14:03
@janvrany janvrany merged commit 9a4b755 into master Nov 29, 2024
2 checks passed
@janvrany janvrany deleted the pr/add-code-cache-and-code-cache-manager branch November 29, 2024 14:13
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