#pragma once #include #include #include #include #include namespace voidlibc::voidlink::elf { struct ParsedSymbol { std::string name; std::uint64_t value = 0; // offset within its section std::uint64_t size = 0; std::uint16_t section_index = 0; // 0 = SHN_UNDEF std::uint8_t bind = 0; // STB_* std::uint8_t type = 0; // STT_* bool defined = false; // false iff section_index == SHN_UNDEF // Version index from .gnu.version (SHT_GNU_versym): 0=absent, 1=global, 2+=versioned. std::uint16_t version_index = 0; }; struct ParsedRelocation { std::uint64_t offset = 0; // byte offset within the target section std::uint32_t sym_index = 0; // index into ParsedObject::symbols std::uint32_t type = 0; // R_X86_64_* std::int64_t addend = 0; }; struct ParsedSection { std::string name; std::uint32_t type = 0; std::uint64_t flags = 0; std::vector bytes; std::uint64_t file_offset = 0; std::uint64_t size_in_file = 0; // 0 for NOBITS (BSS) std::uint64_t mem_size = 0; // sh_size; for BSS: memory footprint std::vector relocs; // relocs applied TO this section }; // One entry per unique version index found in SHT_GNU_verneed. struct VersionRequirement { std::uint16_t index; // vna_other (version index referenced in .gnu.version) std::uint32_t hash; // vna_hash std::uint16_t flags; // vna_flags std::string version_name; // e.g., "GLIBC_2.14" std::string library; // DT_NEEDED name from parent Verneed, e.g., "libc.so.6" }; struct ParsedObject { std::vector sections; std::vector symbols; std::vector version_reqs; // from .gnu.version_r std::size_t text_index = static_cast(-1); }; using ParseResult = std::variant; ParseResult parse_elf64_object(const std::filesystem::path& path); } // namespace voidlibc::voidlink::elf