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

[WIP] Vtable fixup and relocation #56

Closed

Conversation

torfmaster
Copy link
Collaborator

@torfmaster torfmaster commented Sep 10, 2018

Vtable fixup and relocation

Pull request Overview

This PR is for tracking work and discussion on relocation. The changes aim to enable correct relocation of vtables in order to make dynamic dispatch on Trait objects work.

Content

Calls to methods on trait objects use vtables for dynamic dispatch. As the functions which are
called are relocated in flash also the vtables must be changed.

The vtables are stored in the rodata-segment and are accessed from flash. However,
the addresses in the vtables need fixup, still. My proposed solution is to move .rodata
to RAM.

Advantages:

  • &str-s can now be shared using "allow". So we can now make calls like console.write("hello") instead of console.write(String::from("hello"))

Disadvantages:

  • we will propably have to align applications in flash and in memory proportionality (see below)

Progress:

[x] write a PoC (dynamic dispatch now works)
[ ] improve the linker script
[ ] put necessary information in the header
[ ] write a PoC to show that proportionally aligned apps do relocation right
[ ] refine the vtable fixup to keep integrity of non-vtable data
[ ] solve the problem of non-proportionality of ram and flash

Not contained in this pull request

RWPI-relocation. This is propably blocked due to missing features in lld. We might give an
ad-hoc solution to construct a global drivers object in a separate PR.

Implementation

The current implementation moves the .rodata from flash to ram. It manipulates the load address
in the linker script so that (assuming proportionality) the references to elements in .rodata are still valid.

Entries in the vtable are manipulated at loading time. The data which entries to fixup is taken from the relocation section which is put into the binary by the patched version of elf2tab (see https://github.com/torfmaster/elf2tab/tree/experimental/store-vtable-location).
It assumes that elements
which need to be fixed have 0x80_00_00_00 set. This potentially destroys non-vtable data.
Currently, the rust compiler makes it hard to identify the Vtable-Symbols during link time
as recently the name of these symbols changed from Vtable* to unknown* which makes them
harder to distinguish from string literals in .rodata
.

In order for this procedure to work we must align two applications in flash as we do
in ram, i.e. if app 1 and app 2 occupie 1kBytes in flash respectively, then the same
should be true for their ram-segments.

Discussion

What do you think about apps beeing forced to be proptionally aligned?

@torfmaster
Copy link
Collaborator Author

@alevy @bradjc: Do do vtable fixup right one way is storing the position and length of the vtables in the crt0-header. I have been successful in letting elf2tab do this job. Would you allow us to create a "--store-rust-vtable-fixup-data" option in elf2tab?

@torfmaster
Copy link
Collaborator Author

Fixing up vtables indeed fixes the format-macro.

@torfmaster
Copy link
Collaborator Author

One can now flash copies of traitobj to the chip and vtables and in particular the format macro work

@Woyten Woyten force-pushed the feature/fix-vtable-relocation branch from cf8e26f to 1dd23a6 Compare September 27, 2018 11:25
@Woyten Woyten mentioned this pull request Oct 6, 2018
2 tasks
@torfmaster
Copy link
Collaborator Author

You will need the patched version of elf2tab at https://github.com/torfmaster/elf2tab/tree/experimental/store-vtable-location to get the relocation information. I'm working on making my changes to elf2tab minimal and configurable.

@torfmaster torfmaster closed this Feb 8, 2019
@torfmaster torfmaster deleted the feature/fix-vtable-relocation branch February 9, 2019 16:07
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.

2 participants