cloudius-systems / osv

OSv, a new operating system for the cloud.
osv.io
Other
4.12k stars 605 forks source link

Dynamic linker: support loading and processing statically linked executables #1253

Closed wkozaczuk closed 1 year ago

wkozaczuk commented 1 year ago

The two commits provide necessary modifications to the OSv dynamic linker to support loading and processing statically linked executables.

Please note these changes are NOT enough to make OSv run statically linked executables.

nyh commented 1 year ago

Oh, before I commit this there is something I want to ask and verify:

Does this patch change what happens if you try to execute a statically-linked executable on OSv? Did it use to fail on some clear error message in the past and now will fail on some obscure crash? Or did it always fail obscurely?

wkozaczuk commented 1 year ago

Maybe is_dynamically_linked_executable is a better name than is_interpretable? Yes is_pic simply means if given ELF is a position-independent code (by detecting if elf_type is equal to DYN).

So to sum it up:

wkozaczuk commented 1 year ago

Regarding your 2nd question, OSv would crash with this error if one tried to run statically linked non-PIE (aka position dependent):

Cmdline: /hello-static-non-pie
Statically linked executables are not supported!

[backtrace]
0x00000000402bbf7b <elf::object::process_headers()+1147>
0x00000000402c53d7 <elf::program::load_object(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::vector<std::shared_ptr<elf::object>, std::allocator<std::shared_ptr<elf::object> > >&)+2263>
...

but would stop and refuse to run a static PIE:

Cmdline: /hello-static-pie
Failed looking up main. Powering off.

After this patch, it consistently crashes with the 1st message.

Please note I am taking an incremental approach so even if one commented out this code in process_headers:

if (!is_core() && is_statically_linked()) {
        abort("Statically linked executables are not supported yet!\n");
    }

OSv would not be able to run those. I will remove these 3 lines if enough support of the statically linked ELF is in (entry_point, arch_prctl, TLS, more syscalls, etc).

However, all these somewhat minimal changes to the dynamic linker are necessary to support loading and processing statically linked executables once they are enabled all the way in.

wkozaczuk commented 1 year ago

So I will update this MR with the name change and add some more comments.

wkozaczuk commented 1 year ago

I have force pushed latest version.