[ld.so] Add dynamic library linking

ld.so will now go through all DT_NEEDED entries in the dynamic table and load and relocate
those shared libraries as well. Lazy linking of functions via the PLT is not yet supported,
all PLT entries are looked up ahead of time by ld.so.
This commit is contained in:
Justin C. Miller
2024-02-18 17:39:42 -08:00
parent c27f8baa31
commit c245949ea4
17 changed files with 607 additions and 203 deletions

View File

@@ -2,7 +2,9 @@
/// \file init.h
/// Process initialization utility functions
#include <stddef.h>
#include <stdint.h>
#include <j6/types.h>
#include <util/api.h>
@@ -38,9 +40,7 @@ struct j6_arg_loader
add_header(loader);
uintptr_t loader_base;
uintptr_t image_base;
uintptr_t phdr;
size_t phdr_size;
size_t phdr_count;
uintptr_t *got;
uintptr_t entrypoint;
};
@@ -84,4 +84,4 @@ int driver_main(unsigned, const char **, const char **, const j6_init_args *);
} // extern "C"
#endif
#undef add_header
#undef add_header

View File

@@ -18,7 +18,8 @@ public:
/// Load a file into a VMA
/// \arg path Path of the file to load
/// \arg vma [out] Handle to the loaded VMA, or invalid if not found
j6_status_t load_file(char *path, j6_handle_t &vma);
/// \arg size [out] Size of the file
j6_status_t load_file(char *path, j6_handle_t &vma, size_t &size);
private:
j6_handle_t m_service;

View File

@@ -10,7 +10,7 @@
#include <j6/types.h>
namespace {
constexpr size_t static_arr_count = 8;
constexpr size_t static_arr_count = 32;
j6_handle_descriptor handle_array[static_arr_count];
j6_init_args init_args;
} // namespace

View File

@@ -15,7 +15,7 @@ client::client(j6_handle_t vfs_mb) :
inline size_t simple_strlen(const char *s) { size_t n = 0; while (s && *s) s++, n++; return n; }
j6_status_t
client::load_file(char *path, j6_handle_t &vma)
client::load_file(char *path, j6_handle_t &vma, size_t &size)
{
if (!path)
return j6_err_invalid_arg;
@@ -43,8 +43,16 @@ client::load_file(char *path, j6_handle_t &vma)
if (s != j6_status_ok)
return s;
if (tag == j6_proto_vfs_file)
if (tag == j6_proto_vfs_file) {
size = 0;
// Get the size into `size`
s = j6_vma_resize(vma, &size);
if (s != j6_status_ok)
return s;
return j6_status_ok; // handle is already in `vma`
}
else if (tag == j6_proto_base_status)
return *reinterpret_cast<j6_status_t*>(data); // contains a status