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

Improve how elf2tab parses ELF files #23

Merged
merged 3 commits into from
Jun 26, 2020
Merged

Improve how elf2tab parses ELF files #23

merged 3 commits into from
Jun 26, 2020

Conversation

bradjc
Copy link
Contributor

@bradjc bradjc commented Jun 24, 2020

This fixes two things:

  1. Calculating how much RAM the app needs based on the ELF sections. Before we stopped after finding any segment that is destined for RAM. This doesn't work for libtock-c now that .stack is its own section. So not only do we consider multiple segments if necessary, but the checking for if it should count towards the amount of RAM required is more robust.
  2. Finding fixed addresses. The fixed address in flash is mostly the same, made a little more robust for libtock-rs. RAM however won't work the same way since libtock-rs doesn't generate any segments at the correct address in RAM. Therefore, we use a special symbol the linker file has to specify.

Use safer ELF parsing methods to find the fields we need.
@alistair23
Copy link
Contributor

Why are the RAM segments different for libtock-rs?

@bradjc
Copy link
Contributor Author

bradjc commented Jun 24, 2020 via email

README.md Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic looks good; the README could use a bit more of an explainer on what's expected to happen when things aren't present.

README.md Outdated
instead of being position independent. To detect a fixed flash address, elf2tab
looks to see if the flash segment is at the dummy flash address for PIC apps or
not. To detect a fixed RAM address, elf2tab looks for a `_sram_origin` symbol,
and checks if the address matches the dummy RAM address for PIC apps or not.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does elf2tab do if there is neither a _sram_origin symbol nor does the PIC address match? (I'll read the code in a second, but I think the intent should probably be specified here (i.e. will/should it error?))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that would break backwards compatibility. elf2tab just does what it does now: nothing.

Comment on lines +188 to +190
// by the app when it first starts. If for some reason an app is PIC and
// wants to use different dummy PIC addresses, then this logic will have to
// be updated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but I think this logic shouldn't change; rather these constant should just be exposed as flags.

README.md Outdated Show resolved Hide resolved
Copy link
Member

@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors d+

@bradjc bradjc merged commit 267e499 into master Jun 26, 2020
@ppannuto
Copy link
Member

Haha, there's no bors ... or even tests (😢) ... in this repo is there

@bradjc
Copy link
Contributor Author

bradjc commented Jun 26, 2020

There are tests! But bors doesn't do anything if there is only one PR/week or month or year.

bors bot added a commit to tock/libtock-rs that referenced this pull request Jul 7, 2020
208: linker: add sram origin symbol r=bradjc a=bradjc

This allows elf2tab to determine what the start of RAM address is when generating a fixed address header in the TBF.

See tock/elf2tab#23 and tock/tock#1845.

Co-authored-by: Brad Campbell <bradjc5@gmail.com>
@bradjc bradjc deleted the better-elf-parsing branch September 5, 2022 16: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.

None yet

3 participants