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

core: support launching statically linked executables #1254

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

wkozaczuk
Copy link
Collaborator

@wkozaczuk wkozaczuk commented Sep 5, 2023

This patch enhances the dynamic linker to support launching statically linked executables.

The dynamically linked executables or shared libraries are typically launched by calling a "main" function which is exported and can be resolved using the ELF symbol table. The statically linked executables do not export
such symbols and instead must be launched by jumping to the ELF entry point specified in the header. To that end this patch implements new functions - run_entry_point() - specific for each architecture - x86_64 and aarch64 which fundamentally do a similar thing - put argc, argv, environment variables, and auxiliary vector on the stack and jump to the elf entry point.

In addition, this patch enhances other parts of the dynamic linker logic to do things a little bit differently for statically linked executables:

  • do not relocate as the executable comes with its own code that does this
  • do not call INIT and FINI function for the same reason as above
  • do not try to load dependent libraries as they would be none

This patch also adds augment_auxv() to add the extra auxiliary vector entries needed by statically linked executables to bootstrap themselves

In addition, this 2nd version of the PR renames the method is_statically_linked() to is_statically_linked_executable() and fixes it by identifying if an ELF is not a shared library. So it should fix the "liblua.so" problem reported by Nadav.

Closes #1140

arch/aarch64/arch-elf.hh Outdated Show resolved Hide resolved
arch/x64/arch-elf.hh Outdated Show resolved Hide resolved
arch/x64/arch-elf.hh Show resolved Hide resolved
arch/x64/arch-elf.hh Outdated Show resolved Hide resolved
core/app.cc Outdated Show resolved Hide resolved
core/app.cc Outdated Show resolved Hide resolved
core/app.cc Show resolved Hide resolved
core/app.cc Show resolved Hide resolved
core/elf.cc Show resolved Hide resolved
core/elf.cc Show resolved Hide resolved
This patch enhances the dynamic linker to support launching statically
linked executables.

The dynamically linked executables or shared libraries are typically launched
by calling a "main" function which is exported and can be resolved using
the ELF symbol table. The statically linked executables do not export
such symbol and instead must be launched by jumping to the ELF entry
point specified in the header. To that end this patch implements new
functions - run_entry_point() - specific for each architecture - x86_64 and
aarch64 which fundamentally do similar thing - put argc, argv,
environment variables and auxiliary vector on stack and jump to the elf
entry point.

In addition this patch enhances other parts of the dynamic linker logic
to do things a little bit differently for statically linked executables:

- do not relocate as the executable comes with its own code that does
  this

- do not call INIT and FINI function for the same reason as above

- do not try to load dependant libraries as they would be none

This patch also adds augment_auxv() to add extra auxiliary vector
entries needed by statically linked executables to bootstrap
themselves

In addition, this 2nd version of the PR renames the method
is_statically_linked() to is_statically_linked_executable() and fixes
it by identifying if an ELF is not a shared library. So it should
fix the "liblua.so" problem reported by Nadav.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
@wkozaczuk wkozaczuk requested a review from nyh September 25, 2023 02:57
@wkozaczuk wkozaczuk merged commit e154fc5 into cloudius-systems:master Oct 3, 2023
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.

Support loading and launching statically linked executables
2 participants