Skip to content
WALDEMAR KOZACZUK edited this page Dec 17, 2019 · 31 revisions

Introduction

OSv is made of many components but the dynamic linker is probably the most essential one as it interacts with and ties all other components together and is responsible for bootstrapping an application. In essence, it involves locating ELF file on the filesystem, loading it into memory using mmap(), processing its headers and segments to relocate symbols, configuring TLS, executing its init functions, loading any dependant ELF objects and finally starting the app. Please note that unlike Linux, the dynamic linker is an integral part of the OSv kernel. Most of the dynamic linker code is located in core/elf.cc, arch/<arch>/arch-elf.cc and core/app.cc.

Concepts

  • app_registry
  • application - represents running program (there is _program pointer it points to)
  • elf::program - typically there is only one instance of it so effectively it is a singleton, but it is possible to create new programs for new ELF namespaces
  • elf::object
    • symbol_module object::symbol(unsigned idx, bool ignore_missing) - entry point to symbol lookup; accepts symbol index, finds its name in the object symbols table (dynamic_ptr<Elf64_Sym>(DT_SYMTAB)) and searches for a symbol by name in all objects programs knows about by calling program::lookup(name); if symbol not found it aborts if ignore_missing is false otherwise just warns; returns symbol_module that is a tuple of the object the symbol resides and the symbol definition (Elf64_Sym *)
  • elf::file
  • elf::memory_image
  • elf::symbol_module

Flow

The program::get_library() is the critical point where dynamic linker gets involved in instantiating new application.

The main program (kernel?) gets instantiated by elf::create_main_program() called from loader.cc

application::new_program() instantiates new program for new ELF namespace with new base address.

Clone this wiki locally