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

Implement transitive eager relocation #20

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

0152la
Copy link
Contributor

@0152la 0152la commented Feb 20, 2024

We now gather all symbols to be relocated from all so libraries within a compartment, and perform eager relocation at map time. This means, primarily, that we handle each so file within a compartment the same, then perform a sweep to relocate required symbols after parsing and mapping. This closes #15.

Other small changes:

  • Improve and add more simple tests, to test more specific functionality;
  • Some overall code refactoring;
  • Add -Wextra, and fix more warnings

@0152la 0152la requested a review from ltratt February 20, 2024 15:54
@0152la
Copy link
Contributor Author

0152la commented Feb 20, 2024

Apparently saying "closes #[issue]" (or other keywords) instead of "handles #[issues]" automatically will be closing the linked issue. Horrifying, but cool.

https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests

do_pread(lib_fd, &curr_shdr, sizeof(Elf64_Shdr),
lib_ehdr.e_shoff + i * sizeof(Elf64_Shdr));

if (curr_shdr.sh_type == SHT_SYMTAB)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is unlikely, or maybe impossible, but what if there are two sections of the same type (e.g. SHT-SYMTAB)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cry For now, things will break horribly. I would need to see an actual example to try to understand what would happen practically. I'll need to read and see if it's possible to produce such a binary. I think this would be beyond the current PR, however. I will at least have a read around for now to see, and then update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the ELF specification 1, page 66 (Book III, page 1-2) suggests that there can only be one SHT_SYMTAB, SHT_DYNSYM, and SHT_DYNAMIC (at least for now). I will also assume there can only be one section named .rela.plt. Therefore it seems your original assumption is (currently) impossible. I added a comment saying as such in 344cce8.

Footnotes

  1. https://refspecs.linuxfoundation.org/elf/elf.pdf

Copy link
Contributor

Choose a reason for hiding this comment

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

Phew!

src/compartment.c Outdated Show resolved Hide resolved
src/compartment.c Outdated Show resolved Hide resolved
tests/CMakeLists.txt Outdated Show resolved Hide resolved
@ltratt
Copy link
Contributor

ltratt commented Feb 21, 2024

Please squash.

We now gather all symbols to be relocated from all `so` libraries within
a compartment, and perform eager relocation at map time. This means,
primarily, that we handle each `so` file within a compartment the same,
then perform a sweep to relocate required symbols after parsing and
mapping.

Other small changes:
* Improve and add more `simple` tests, to test more specific
  functionality;
* Some overall code refactoring;
* Add `-Wextra`, and fix more warnings
@0152la 0152la force-pushed the transitive_eager_relo branch from 344cce8 to 1c2d2c9 Compare February 21, 2024 13:33
@0152la
Copy link
Contributor Author

0152la commented Feb 21, 2024

Squashed.

@ltratt ltratt added this pull request to the merge queue Feb 21, 2024
Merged via the queue into capablevms:master with commit dd7627c Feb 21, 2024
2 checks passed
@0152la 0152la deleted the transitive_eager_relo branch February 21, 2024 16:45
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.

Handling symbol relocations for all libraries
2 participants