#pragma once #include "format/reloc_ir.hpp" #include #include #include namespace voidlibc::loader::macos { struct MachoExportedSymbol { std::string name; std::uint64_t code_offset = 0; std::uint64_t size = 0; bool is_function = true; bool weak = false; }; struct MachoImportedSymbol { std::uint32_t sym_id = 0; std::string name; std::string library; // dylib install name; "" → /usr/lib/libSystem.B.dylib }; struct MachoInternalSymbol { std::uint32_t sym_id = 0; std::uint64_t code_offset = 0; std::string name; }; struct MachoDataSymbol { std::uint32_t sym_id = 0; std::uint64_t data_offset = 0; std::string name; }; struct MachoSynthInput { std::vector code; std::vector exports; std::vector relocs; std::vector internal_symbols; std::vector imports; std::vector data_blob; std::vector data_symbols; std::string soname; // Explicit LC_LOAD_DYLIB entries. Empty + imports present → defaults to // /usr/lib/libSystem.B.dylib. Empty + no imports → static (no NEEDED). std::vector needed_libs; }; struct MachoSynthOutput { std::vector bytes; std::string error; bool ok = true; }; // Produce a minimal Mach-O64 dylib (MH_DYLIB, x86_64) that dlopen will accept. // Layout: __TEXT (header+LCs+code+stubs) / __DATA (data+nl_symbol_ptr) / __LINKEDIT. // Non-lazy binding via LC_DYLD_INFO_ONLY bind opcodes; no lazy stubs. MachoSynthOutput synthesize_macho(const MachoSynthInput& input); } // namespace voidlibc::loader::macos