#pragma once #include "format/reloc_ir.hpp" #include #include #include namespace voidlibc::loader { struct ExportedSymbol { std::string name; // C-name (null-terminated when written) std::uint64_t code_offset; // offset into the code blob std::uint64_t size; // 0 if unknown bool is_function = true; bool weak = false; }; // For Slice 1B the synthesizer needs to resolve internal relocations // at synthesis time (PC-relative). Each `InternalSymbol` is a defined // symbol referenced by a relocation, identified by `sym_id` matching // the relocation's sym_id, and located at `code_offset` within the // code blob. struct InternalSymbol { std::uint32_t sym_id = 0; std::uint64_t code_offset = 0; std::string name; // for error messages }; // External (undefined) symbol resolved by the native linker via .rela.plt. struct ImportedSymbol { std::uint32_t sym_id = 0; std::string name; std::string library; // DT_NEEDED soname that provides this symbol; "" → default libc // GNU symbol version requirement forwarded from input .o (SHT_GNU_verneed). // Empty version_name → emit VER_NDX_GLOBAL (1) in .gnu.version; no .gnu.version_r entry. std::string version_name; std::uint32_t version_hash = 0; std::uint16_t version_flags = 0; }; // Writable symbol in the data blob (mapped in the RW segment). // PC32 relocs from .text to data symbols are patched using vaddr arithmetic. struct DataSymbol { std::uint32_t sym_id = 0; std::uint64_t data_offset = 0; // byte offset within data_blob std::string name; }; struct ElfSynthInput { std::vector code; std::vector exports; std::vector relocs; std::vector internal_symbols; std::vector imports; std::vector data_blob; // .data + .bss (RW) std::vector data_symbols; std::string soname; // Explicit DT_NEEDED entries for the synthesized ELF's .dynamic section. // Empty = no host dependencies (statically linked VLC, ldd shows "statically linked"). // Set via voidlink --need at pack time. std::vector needed_libs; }; struct ElfSynthOutput { std::vector bytes; // synthesized in-memory ELF64 DSO std::uint64_t code_vaddr = 0; // base vaddr where code is mapped std::string error; // empty on success bool ok = true; }; // Produce a valid in-memory ELF64 DSO (ET_DYN, EM_X86_64) that dlopen // will accept. Single contiguous .text + .dynsym/.dynstr/.hash/.dynamic. // No relocations, imports, or section headers — enough for M1 export. ElfSynthOutput synthesize_elf(const ElfSynthInput& input); } // namespace voidlibc::loader